org.eclipse.ui.IViewPart Java Examples

The following examples show how to use org.eclipse.ui.IViewPart. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FlameGraphTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Open a flamegraph
 */
@Before
public void before() {
    fBot = new SWTWorkbenchBot();
    SWTBotUtils.openView(FLAMEGRAPH_ID);
    SWTBotView view = fBot.viewById(FLAMEGRAPH_ID);
    assertNotNull(view);
    fView = view;
    FlameGraphView flamegraph = UIThreadRunnable.syncExec((Result<FlameGraphView>) () -> {
        IViewPart viewRef = fView.getViewReference().getView(true);
        return (viewRef instanceof FlameGraphView) ? (FlameGraphView) viewRef : null;
    });
    assertNotNull(flamegraph);
    fTimeGraphViewer = flamegraph.getTimeGraphViewer();
    assertNotNull(fTimeGraphViewer);
    SWTBotUtils.maximize(flamegraph);
    fFg = flamegraph;
}
 
Example #2
Source File: UIUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Opens the internal HelpView and address it to the given doc url.
 * 
 * @param url
 */
public static void openHelp(String url)
{
	IWorkbenchPage page = getActivePage();
	if (page != null)
	{
		try
		{
			IViewPart part = page.showView(HELP_VIEW_ID);
			if (part != null)
			{
				HelpView view = (HelpView) part;
				view.showHelp(url);
			}
		}
		catch (PartInitException e)
		{
			IdeLog.logError(UIPlugin.getDefault(), e);
		}
	}
	else
	{
		IdeLog.logWarning(UIPlugin.getDefault(), "Could not open the help view. Active page was null."); //$NON-NLS-1$
	}
}
 
Example #3
Source File: InvasiveThemeHijacker.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void partActivated(IWorkbenchPartReference partRef)
{
	if (partRef instanceof IViewReference)
	{
		IViewReference viewRef = (IViewReference) partRef;
		String id = viewRef.getId();
		if ("org.eclipse.ui.console.ConsoleView".equals(id) || "org.eclipse.jdt.ui.TypeHierarchy".equals(id) //$NON-NLS-1$ //$NON-NLS-2$
				|| "org.eclipse.jdt.callhierarchy.view".equals(id)) //$NON-NLS-1$
		{
			final IViewPart part = viewRef.getView(false);
			Display.getCurrent().asyncExec(new Runnable()
			{
				public void run()
				{
					hijackView(part, false);
				}
			});
			return;
		}
	}
	if (partRef instanceof IEditorReference)
	{
		hijackOutline();
	}
}
 
Example #4
Source File: ViewHelper.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static void toggleExpansion(Object element) {
	final Object obj = element == null ? CodewindManager.getManager() : element;
	Display.getDefault().asyncExec(new Runnable() {
           @Override
           public void run() {
			IViewPart view = getViewPart(CodewindExplorerView.VIEW_ID);
			if (view instanceof CommonNavigator) {
				CommonViewer viewer = ((CommonNavigator)view).getCommonViewer();
		
				if (!viewer.getExpandedState(obj)) {
					viewer.expandToLevel(obj, AbstractTreeViewer.ALL_LEVELS);
				} else {
					viewer.collapseToLevel(obj, AbstractTreeViewer.ALL_LEVELS);
				}
            }
			}
	});
}
 
Example #5
Source File: OpenExplorerHandler.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute ( final ExecutionEvent event ) throws ExecutionException
{
    try
    {
        // the following cast might look a bit weird. But first an adapter is requested and it only adapts to "core" connection services.
        final ConnectionService connectionService = (ConnectionService)SelectionHelper.first ( getSelection (), org.eclipse.scada.core.connection.provider.ConnectionService.class );
        final IViewPart view = getActivePage ().showView ( SummaryExplorerViewPart.VIEW_ID, "" + this.counter++, IWorkbenchPage.VIEW_ACTIVATE );

        ( (SummaryExplorerViewPart)view ).setConnectionService ( connectionService );
    }
    catch ( final PartInitException e )
    {
        throw new ExecutionException ( "Failed to open view", e );
    }
    return null;
}
 
Example #6
Source File: SaveAsPDFHandler.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	IViewPart part = null;
	part = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().findView(chartViewId);
	FileDialog dialog = new FileDialog(HandlerUtil.getActiveShell(event), SWT.SAVE);
	dialog.setFilterExtensions(new String[] { "*.pdf" });
	try {
		String result = dialog.open();
		if (result != null) {
			ICommunicationView view = (ICommunicationView) part;
			view.generatePDFForCurrentChart(result);
			view.redraw();
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example #7
Source File: SystemCallLatencyStatisticsTableAnalysisTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static void testToTsv(SWTBotView view) throws NoSuchMethodException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    assertNotNull(os);
    IViewPart viewPart = view.getReference().getView(true);
    assertTrue(viewPart instanceof AbstractSegmentsStatisticsView);
    Class<@NonNull AbstractSegmentsStatisticsView> clazz = AbstractSegmentsStatisticsView.class;
    Method method = clazz.getDeclaredMethod("exportToTsv", java.io.OutputStream.class);
    method.setAccessible(true);
    final Exception[] except = new Exception[1];
    UIThreadRunnable.syncExec(() -> {
        try {
            method.invoke((AbstractSegmentsStatisticsView) viewPart, os);
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
            except[0] = e;
        }
    });
    assertNull(except[0]);
    @SuppressWarnings("null")
    String[] lines = String.valueOf(os).split(System.getProperty("line.separator"));
    assertNotNull(lines);
    assertEquals("header", "Level\tMinimum\tMaximum\tAverage\tStandard Deviation\tCount\tTotal", lines[0]);
    assertEquals("line 1", "bug446190\t\t\t\t\t\t", lines[1]);
    assertEquals("line 2", "Total\t1 µs\t5.904 s\t15.628 ms\t175.875 ms\t1801\t28.146 s", lines[2]);
}
 
Example #8
Source File: UIHelper.java    From tlaplus with MIT License 6 votes vote down vote up
public static void showDynamicHelp() {
	// This may take a while, so use the busy indicator
	BusyIndicator.showWhile(null, new Runnable() {
		public void run() {
			getActiveWindow().getWorkbench().getHelpSystem().displayDynamicHelp();
			// the following ensure that the help view receives focus
			// prior to adding this, it would not receive focus if
			// it was opened into a folder or was already
			// open in a folder in which another part had focus
			IViewPart helpView = findView("org.eclipse.help.ui.HelpView");
			if (helpView != null && getActiveWindow() != null && getActiveWindow().getActivePage() != null) {
				getActiveWindow().getActivePage().activate(helpView);
			}
		}
	});
}
 
Example #9
Source File: DeleteItemViewActionDelegate.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void init(IViewPart view) {

	// Set the reference
	viewPart = view;

	// Setup the action
	deleteItemAction = new DeleteItemAction(viewPart.getSite()
			.getWorkbenchWindow());

	// Register the action as a listener
	viewPart.getSite()
			.getPage()
			.addPostSelectionListener((ISelectionListener) deleteItemAction);

}
 
Example #10
Source File: ApplicationWorkbenchWindowAdvisor.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public void addWorkplaceListener(){
	   IWorkspace workspace = ResourcesPlugin.getWorkspace(); 
	   workspace.addResourceChangeListener(new IResourceChangeListener() {
		
		public void resourceChanged(IResourceChangeEvent event) {
			//刷新项目导航视图
			Display.getDefault().syncExec(new Runnable() {		
				public void run() {
					IViewPart findView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
							.findView("net.heartsome.cat.common.ui.navigator.view");
					if(null == findView){
						return ;
					}
					IAction refreshActionHandler = findView.getViewSite().getActionBars()
							.getGlobalActionHandler(ActionFactory.REFRESH.getId());
					if(null == refreshActionHandler){
						return;
					}
					refreshActionHandler.run();
				}
			});
		}
	});
}
 
Example #11
Source File: ImportAndReadPcapTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static IViewPart getViewPart(final String viewTile) {
    final IViewPart[] vps = new IViewPart[1];
    UIThreadRunnable.syncExec(new VoidResult() {
        @Override
        public void run() {
            IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
            for (IViewReference viewRef : viewRefs) {
                IViewPart vp = viewRef.getView(true);
                if (vp.getTitle().equals(viewTile)) {
                    vps[0] = vp;
                    return;
                }
            }
        }
    });

    return vps[0];
}
 
Example #12
Source File: MemoryUsageViewTest.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Test Memory Usage data model
 */
@Test
public void testMemoryUsage() {
    IViewPart viewPart = getSWTBotView().getViewReference().getView(true);
    assertTrue(viewPart instanceof UstMemoryUsageView);
    final TmfCommonXAxisChartViewer chartViewer = (TmfCommonXAxisChartViewer) getChartViewer(viewPart);
    assertNotNull(chartViewer);
    fBot.waitUntil(ConditionHelpers.xyViewerIsReadyCondition(chartViewer));

    final Chart chart = getChart();
    assertNotNull(chart);

    checkAllEntries();

    SWTBotUtils.waitUntil(c -> c.getSeriesSet().getSeries().length > 3, chart, "No data available");
    chartViewer.setNbPoints(50);

    /* Test data model*/
    SWTBotUtils.waitUntil(json -> isChartDataValid(chart, json, FIRST_SERIES_NAME, SECOND_SERIES_NAME, THIRD_SERIES_NAME, FOURTH_SERIES_NAME), "resources/memory-res50.json", "Chart data is not valid");

    /* Test type, style and color of series */
    verifyChartStyle();
}
 
Example #13
Source File: Utilities.java    From jbt with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a IViewPart by its class. If cannot be found, returns null.
 */
public static IViewPart getView(Class c) {
	IWorkbenchPage page = getMainWindowActivePage();

	if (page != null) {
		IViewReference[] views = page.getViewReferences();
		for (int i = 0; i < views.length; i++) {
			if (views[i].getView(true) != null) {
				if (c.isInstance(views[i].getView(false))) {
					return views[i].getView(false);
				}
			}
		}
	}
	return null;
}
 
Example #14
Source File: SwtGui.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void closeSimulationViews(final IScope scope, final boolean openModelingPerspective,
		final boolean immediately) {
	WorkbenchHelper.run(() -> {
		final IWorkbenchPage page = WorkbenchHelper.getPage();
		final IViewReference[] views = page.getViewReferences();

		for (final IViewReference view : views) {
			final IViewPart part = view.getView(false);
			if (part instanceof IGamaView) {
				DEBUG.OUT("Closing " + view.getId());
				((IGamaView) part).close(scope);
			}
		}
		if (openModelingPerspective) {
			DEBUG.OUT("Deleting simulation perspective and opening immediately the modeling perspective = "
					+ immediately);
			PerspectiveHelper.deleteCurrentSimulationPerspective();
			PerspectiveHelper.openModelingPerspective(immediately, false);
		}

		getStatus(scope).neutralStatus("No simulation running");
	});

}
 
Example #15
Source File: TmfAlignmentSynchronizer.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Get a view that corresponds to the alignment information. The view is
 * meant to be used as a "reference" for other views to align on. Heuristics
 * are applied to choose the best view. For example, the view has to be
 * visible. It also will prioritize the view with lowest time axis offset
 * because most of the interesting data should be in the time widget.
 *
 * @param alignmentInfo
 *            alignment information
 * @param blackListedView
 *            an optional black listed view that will not be used as
 *            reference (useful for a view that just got created)
 * @return the reference view
 */
private static ITmfTimeAligned getReferenceView(TmfTimeViewAlignmentInfo alignmentInfo, TmfView blackListedView) {
    IWorkbenchWindow workbenchWindow = getWorkbenchWindow(alignmentInfo.getShell());
    if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
        // Only time aligned views that are part of a workbench window are supported
        return null;
    }
    IWorkbenchPage page = workbenchWindow.getActivePage();

    int lowestTimeAxisOffset = Integer.MAX_VALUE;
    ITmfTimeAligned referenceView = null;
    for (IViewReference ref : page.getViewReferences()) {
        IViewPart view = ref.getView(false);
        if (view != blackListedView && isTimeAlignedView(view)) {
            if (isCandidateForReferenceView((TmfView) view, alignmentInfo, lowestTimeAxisOffset)) {
                referenceView = (ITmfTimeAligned) view;
                lowestTimeAxisOffset = getClampedTimeAxisOffset(referenceView.getTimeViewAlignmentInfo());
            }
        }
    }
    return referenceView;
}
 
Example #16
Source File: ItemSelectedPropertyTester.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets the <code>IViewPart</code> associated with the specified ID.
 * 
 * @param ID
 *            The string ID of the desired <code>IViewPart</code>.
 * @return The <code>IViewPart</code> corresponding to the specified ID, or
 *         null if it could not be found.
 */
protected static IViewPart getViewPart(String ID) {

	IViewPart viewPart = null;

	// We need to check all intermediate workbench components for null lest
	// we get exceptions, particularly when the workbench is starting.
	IWorkbench workbench = PlatformUI.getWorkbench();
	if (workbench != null && !workbench.isStarting()) {
		IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
		if (window != null) {
			IWorkbenchPage page = window.getActivePage();
			if (page != null) {
				// Try to get the IViewPart with the specified ID.
				viewPart = page.findView(ID);
			}
		}
	}

	return viewPart;
}
 
Example #17
Source File: SettingsHandler.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	SettingsDialog settingsDialog = new SettingsDialog(HandlerUtil.getActiveShell(event), SWT.DIALOG_TRIM);
	try {
		IViewPart part = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().showView("chart.view.chartview");
		settingsDialog.setViewPart(part);
	} catch (PartInitException e) {
		e.printStackTrace();
	}		
	settingsDialog.open();
	return null;
}
 
Example #18
Source File: ContextSensitiveHelpPolicy.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isDynamicHelpViewShowing() {
	boolean open = false;
	IWorkbenchWindow activeWindow = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow();
	if (activeWindow != null) {
		IWorkbenchPage activePage = activeWindow.getActivePage();
		if (activePage != null) {
			IViewPart view = activePage.findView(HELP_VIEW_ID);
			if (view != null) {
				open = true;
			}
		}
	}
	return open;
}
 
Example #19
Source File: TmxEditorViewer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 获取当前编辑器所在 Viewer
 * @return ;
 */
public static TmxEditorViewer getInstance() {
	IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(ID);
	if (viewPart != null && viewPart instanceof TmxEditorViewer) {
		return (TmxEditorViewer) viewPart;
	}
	return null;
}
 
Example #20
Source File: RedirectRulesPanel.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
    IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
    IActionBars bars = null;
    if(part instanceof IViewPart){
        bars = ((IViewPart)part).getViewSite().getActionBars();
        if(bars != null){
            bars.setGlobalActionHandler(ActionFactory.UNDO.getId(), null);
            bars.setGlobalActionHandler(ActionFactory.REDO.getId(), null);
        }
    }
    if(!isDisposed()){
        super.dispose();
    }
}
 
Example #21
Source File: AcceptTerm1.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/** (non-Javadoc)
 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
	IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(
			"net.heartsome.cat.ts.ui.term.view.termView");		
	if (viewPart != null && viewPart instanceof ITermViewPart) {				
		ITermViewPart matchView = (ITermViewPart) viewPart;
		matchView.acceptTermByIndex(0);
	}
	return null;
}
 
Example #22
Source File: OpenViewHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public void updateElement(final UIElement element, Map parameters) {
	if (parameters.get("ViewId") == null) {
		return;
	}
	
	final String viewId = (String) parameters.get("ViewId");
	Display.getDefault().asyncExec(new Runnable() {
		public void run() {
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
			if (window == null) {
				return;
			}
			IWorkbenchPage workbenchPage = window.getActivePage();
			
			if (workbenchPage == null) {
				return;
			}
			IViewPart view = workbenchPage.findView(viewId);
			
			if (view == null) {
				element.setIcon(Activator.getImageDescriptor("icons/disabled_co.png"));
			} else {
				element.setIcon(Activator.getImageDescriptor("icons/enabled_co.png"));
			}
		}
	});
}
 
Example #23
Source File: UIHelper.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Opens a view but does *not* give it focus (useful for informational views
 * that should not distract the user's workflow (e.g. typing in the editor).
 * 
 * @param viewId
 * @param secondId Secondary view id
 * @return the reference to the view
 */
public static IViewPart openViewNoFocus(final String viewId, final String secondaryId) {
	IViewPart view = null;
	try {
		IWorkbenchPage activePage = getActivePage();
		if (activePage != null) {
			view = activePage.showView(viewId, secondaryId, IWorkbenchPage.VIEW_VISIBLE);
		}
	} catch (PartInitException e) {
		Activator.getDefault().logError("Error opening a view " + viewId, e);
	}
	return view;
}
 
Example #24
Source File: ToggleOutlineHandler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException
{
	boolean toShow = !HandlerUtil.toggleCommandState(event.getCommand());
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	if (page != null)
	{
		if (toShow)
		{
			try
			{
				page.showView(OUTLINE_VIEW_ID);
			}
			catch (PartInitException e)
			{
				IdeLog.logError(CommonEditorPlugin.getDefault(), Messages.ToggleOutlineHandler_ERR_OpeningOutline,
						e);
			}
		}
		else
		{
			IViewPart viewPart = page.findView(OUTLINE_VIEW_ID);
			if (viewPart != null)
			{
				page.hideView(viewPart);
			}
		}
	}
	return null;
}
 
Example #25
Source File: SWTUtils.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/** @swt Needs to be called from the SWT-UI thread, otherwise <code>null</code> is returned. */
public static IViewPart findView(String id) {
  IWorkbench workbench = PlatformUI.getWorkbench();
  if (workbench == null) return null;

  IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
  if (window == null) return null;

  IWorkbenchPage page = window.getActivePage();
  if (page == null) return null;

  return page.findView(id);
}
 
Example #26
Source File: AcceptMatch1.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/** (non-Javadoc)
 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
	IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(
			"net.heartsome.cat.ts.ui.translation.view.matchview");		
	if (viewPart != null && viewPart instanceof IMatchViewPart) {				
		IMatchViewPart matchView = (IMatchViewPart) viewPart;
		matchView.acceptMatchByIndex(0);
	}
	return null;
}
 
Example #27
Source File: AcceptTerm7.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/** (non-Javadoc)
 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
	IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(
			"net.heartsome.cat.ts.ui.term.view.termView");		
	if (viewPart != null && viewPart instanceof ITermViewPart) {				
		ITermViewPart matchView = (ITermViewPart) viewPart;
		matchView.acceptTermByIndex(6);
	}
	return null;
}
 
Example #28
Source File: WebSearchHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/** (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
		String selectPureText ="";
		if (editor instanceof IXliffEditor) {		
			IXliffEditor xliffEditor = (IXliffEditor) editor;
			selectPureText= xliffEditor.getSelectPureText();
		}
		
		try {
			IViewPart showView = getActivePage().showView(BrowserViewPart.ID);
			if(showView instanceof BrowserViewPart){
				BrowserViewPart browserViewPart = (BrowserViewPart) showView;
				browserViewPart.setKeyWord(selectPureText,true);				
			}
		} catch (PartInitException e) {
			e.printStackTrace();
			logger.error("", e);
		}
// 暂时去掉VIEW弹出显示		
//		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
//		if (activePage instanceof WorkbenchPage) {
//			WorkbenchPage workbenchPage = (WorkbenchPage) activePage;
//			IViewReference findViewReference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
//					.findViewReference(BrowserViewPart.ID);			
//			workbenchPage.detachView(findViewReference);
//		}
	
		return null;

}
 
Example #29
Source File: TmfViewFactory.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Create a new view. <br>
 * If a view with the corresponding id already exists and no suffix were
 * added the existing view will be given focus.
 *
 * @param viewId
 *            The id of the view to be created. <br>
 *            Format: primary_id[:secondary_id[&uuid]|:uuid]
 * @param generateSuffix
 *            Add or replace a generated suffix id (UUID). This allows
 *            multiple views with the same id to be displayed.
 * @return The view instance, or null if an error occurred.
 */
@NonNullByDefault
public static @Nullable IViewPart newView(String viewId, boolean generateSuffix) {
    IViewPart viewPart = null;
    String primaryId = null;
    String secondaryId = null;

    /* Parse the view id */
    int index = viewId.indexOf(TmfView.VIEW_ID_SEPARATOR);
    if (index != -1) {
        primaryId = viewId.substring(0, index);
        secondaryId = getBaseSecId(viewId.substring(index + 1));
    } else {
        primaryId = viewId;
    }

    if (generateSuffix) {
        if (secondaryId == null) {
            secondaryId = UUID.randomUUID().toString();
        } else {
            secondaryId += INTERNAL_SECONDARY_ID_SEPARATOR + UUID.randomUUID().toString();
        }
    }

    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
    IWorkbenchPage page = workbenchWindow.getActivePage();
    try {
        viewPart = page.showView(primaryId, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
        page.activate(viewPart);
    } catch (PartInitException e) {
        /* Simply return null on error */
    }

    return viewPart;
}
 
Example #30
Source File: NewSearchViewActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public NewSearchViewActionGroup(IViewPart part) {
	Assert.isNotNull(part);
	OpenViewActionGroup openViewActionGroup;
	setGroups(new ActionGroup[]{
		new OpenEditorActionGroup(part),
		openViewActionGroup= new OpenViewActionGroup(part),
		new GenerateActionGroup(part),
		new RefactorActionGroup(part),
		new JavaSearchActionGroup(part)
	});
	openViewActionGroup.containsShowInMenu(false);
}