Java Code Examples for org.eclipse.ui.IWorkbenchPage#getViewReferences()

The following examples show how to use org.eclipse.ui.IWorkbenchPage#getViewReferences() . 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: TestTypeScript.java    From wildwebdeveloper with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setUpProject() throws Exception {
	ScopedPreferenceStore prefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.lsp4e");
	prefs.putValue("org.eclipse.wildwebdeveloper.angular.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.jsts.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.css.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.html.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.json.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.xml.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.yaml.file.logging.enabled", Boolean.toString(true));
	this.project = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.nanoTime());
	project.create(null);
	project.open(null);
	IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	for (IViewReference ref : activePage.getViewReferences()) {
		activePage.hideView(ref);
	}
}
 
Example 2
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets the ViewPart with the specified id
 * 
 * @param id
 *            the id of view part
 * 
 * @return Returns the view part, or null if not found
 */

public static IViewPart getView( String id )
{
	IWorkbenchPage tPage = PlatformUI.getWorkbench( )
			.getActiveWorkbenchWindow( )
			.getActivePage( );
	IViewReference[] v = tPage.getViewReferences( );
	int i;
	for ( i = 0; i < v.length; i++ )
	{
		if ( v[i].getId( ).equals( id ) )
			return (IViewPart) v[i].getPart( true );
	}
	return null;
}
 
Example 3
Source File: RenameSelectionState.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public RenameSelectionState(Object element) {
	fElement= element;
	fParts= new ArrayList<IWorkbenchPart>();
	fSelections= new ArrayList<IStructuredSelection>();

	IWorkbenchWindow dw = JavaPlugin.getActiveWorkbenchWindow();
	if (dw ==  null) {
		fDisplay= null;
		return;
	}
	fDisplay= dw.getShell().getDisplay();
	IWorkbenchPage page = dw.getActivePage();
	if (page == null)
		return;
	IViewReference vrefs[]= page.getViewReferences();
	for(int i= 0; i < vrefs.length; i++) {
		consider(vrefs[i].getPart(false));
	}
	IEditorReference refs[]= page.getEditorReferences();
	for(int i= 0; i < refs.length; i++) {
		consider(refs[i].getPart(false));
	}
}
 
Example 4
Source File: InvasiveThemeHijacker.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
protected void hijackOutline()
{
	IWorkbenchPage page = UIUtils.getActivePage();
	if (page != null)
	{
		IViewReference[] refs = page.getViewReferences();
		for (IViewReference ref : refs)
		{
			if (ref.getId().equals(IPageLayout.ID_OUTLINE))
			{
				hijackView(ref.getView(false), false);
				return;
			}
		}
	}
}
 
Example 5
Source File: TmfAlignmentSynchronizer.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Get the narrowest view that corresponds to the given alignment information.
 */
private static TmfView getNarrowestView(TmfTimeViewAlignmentInfo alignmentInfo) {
    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 narrowestWidth = Integer.MAX_VALUE;
    TmfView narrowestView = null;
    for (IViewReference ref : page.getViewReferences()) {
        IViewPart view = ref.getView(false);
        if (isTimeAlignedView(view)) {
            TmfView tmfView = (TmfView) view;
            if (isCandidateForNarrowestView(tmfView, alignmentInfo, narrowestWidth)) {
                narrowestWidth = ((ITmfTimeAligned) tmfView).getAvailableWidth(getClampedTimeAxisOffset(alignmentInfo));
                narrowestWidth = getClampedTimeAxisWidth(alignmentInfo, narrowestWidth);
                narrowestView = tmfView;
            }
        }
    }

    return narrowestView;
}
 
Example 6
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 7
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 8
Source File: CodeCheckerContext.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * The refresher for Custom ReportList View. If secondary id is empty, 
 * it checks if a refresh really needs to happen and if so updates every 
 * custom view for the current project. If secondary-id is not empty, 
 * it will search for the secondary-id custom view and 
 * updates that particular one.
 *
 * @param pages the page list for the currently active workbench windows.
 * @param project the project, the user change his/her view to
 * @param secondaryId id of the {@link ReportListViewCustom} the refresh
 * @param considerProjectChange false if the refresh should always happen despite of no real need to force refresh
 */
private void refreshCustom(IWorkbenchPage[] pages, IProject project, String secondaryId,
        boolean considerProjectChange) {
    for(IWorkbenchPage page : pages) {
        for (IViewReference vp : page.getViewReferences()) {
            if (vp.getId().equals(ReportListViewCustom.ID)) {
                ReportListViewCustom rlvc = (ReportListViewCustom) vp.getView(true);
                if(secondaryId.isEmpty() && rlvc.getViewSite().getSecondaryId() != null) {
                    if (!considerProjectChange || this.activeProject != project) {
                        rlvc.onEditorChanged(project);
                    }
                } else if(rlvc.getViewSite().getSecondaryId() != null && 
                        rlvc.getViewSite().getSecondaryId().equals(secondaryId)){
                    rlvc.onEditorChanged(project);
                    return;
                }
            }
        }
    }
}
 
Example 9
Source File: CodeCheckerContext.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * The refresher for Current ReportList View. 
 *
 * @param pages the page list for the currently active workbench windows
 * @param project the project, the user change his/her view to
 * @param filename the filename
 * @param considerViewerRefresh false if the refresh should always happen despite of no real need to force refresh
 */
private void refreshCurrent(IWorkbenchPage[] pages, IProject project, String filename,
        boolean considerViewerRefresh) {
    for(IWorkbenchPage page : pages) {
        for (IViewReference vp : page.getViewReferences()) {
            if (vp.getId().equals(ReportListView.ID)) {
                ReportListView rlv = (ReportListView) vp.getView(true);
                if (!considerViewerRefresh || rlv.getViewerRefresh()) {
                    rlv.onEditorChanged(project, filename);
                } else {
                    rlv.setViewerRefresh(true);
                }
            }
        }
    }
}
 
Example 10
Source File: ScriptConsole.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @param page the page where the console view is
 * @param restore whether we should try to restore it
 * @return a list with the parts containing the console
 */
private static List<IViewPart> getConsoleParts(IWorkbenchPage page, boolean restore) {
    List<IViewPart> consoleParts = new ArrayList<IViewPart>();

    IViewReference[] viewReferences = page.getViewReferences();
    for (IViewReference ref : viewReferences) {
        if (ref.getId().equals(IConsoleConstants.ID_CONSOLE_VIEW)) {
            IViewPart part = ref.getView(restore);
            if (part != null) {
                consoleParts.add(part);
                if (restore) {
                    return consoleParts;
                }
            }
        }
    }
    return consoleParts;
}
 
Example 11
Source File: AllCleanRule.java    From wildwebdeveloper with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void starting(Description description) {
	super.starting(description);
	IIntroPart intro = PlatformUI.getWorkbench().getIntroManager().getIntro();
	if (intro != null) {
		PlatformUI.getWorkbench().getIntroManager().closeIntro(intro);
	}
	IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	for (IViewReference ref : activePage.getViewReferences()) {
		activePage.hideView(ref);
	}
	ScopedPreferenceStore prefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.lsp4e");
	prefs.putValue("org.eclipse.wildwebdeveloper.angular.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.jsts.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.css.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.html.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.json.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.xml.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.yaml.file.logging.enabled", Boolean.toString(true));
	clearProjects();
}
 
Example 12
Source File: TestLanguageServers.java    From wildwebdeveloper with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setUpProject() throws Exception {
	ScopedPreferenceStore prefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.lsp4e");
	prefs.putValue("org.eclipse.wildwebdeveloper.angular.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.jsts.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.css.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.html.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.json.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.xml.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.yaml.file.logging.enabled", Boolean.toString(true));
	this.project = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.nanoTime());
	project.create(null);
	project.open(null);
	IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	for (IViewReference ref : activePage.getViewReferences()) {
		activePage.hideView(ref);
	}
}
 
Example 13
Source File: PlatformUtil.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isIntroOpen() {
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        final IWorkbenchPage activePage = window.getActivePage();
        if (activePage != null) {
            for (final IViewReference vr : activePage.getViewReferences()) {
                if (vr.getId().equals(INTROVIEW_ID)) {
                    return true;
                }
            }
            final IWorkbenchPart part = activePage.getActivePart();
            if (part != null) {
                final IIntroManager introManager = PlatformUI.getWorkbench().getIntroManager();
                if (introManager != null) {
                    if (introManager.getIntro() != null) {
                        return true;
                    } else {
                        final IViewPart view = activePage.findView(INTROVIEW_ID);
                        return view != null;
                    }
                }
            }
        }

    }
    return false;
}
 
Example 14
Source File: TmfViewFactoryTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Test method for
 * {@link org.eclipse.tracecompass.tmf.ui.views.TmfViewFactory#newView(java.lang.String, boolean)}.
 */
@Test
public void testNewView() {
    IViewPart firstView = TmfViewFactory.newView(checkNotNull(TmfViewStub.TMF_VIEW_STUB_ID), false);
    IViewPart sameAsFirstView = TmfViewFactory.newView(checkNotNull(TmfViewStub.TMF_VIEW_STUB_ID), false);
    IViewPart secondView = TmfViewFactory.newView(checkNotNull(TmfViewStub.TMF_VIEW_STUB_ID), true);
    IViewPart failView1 = TmfViewFactory.newView("this.is.a.failing.view.id", false);
    IViewPart failView2 = TmfViewFactory.newView("this.is.a.failing.view.id", true);

    assertNotNull("Failed to spawn first view", firstView);
    assertEquals("Same id returned different instance", sameAsFirstView, firstView);
    assertNotNull("Failed to open second view with suffix", secondView);
    assertNull("Expected to fail on dummy view id", failView1);
    assertNull("Expected to fail on dummy view id with suffix", failView2);

    /** Test for new view from a duplicate view */
    /* Fetch duplicate view complete id */
    IWorkbench wb = PlatformUI.getWorkbench();
    IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
    IWorkbenchPage page = win.getActivePage();
    IViewReference[] viewRefs = page.getViewReferences();

    String fullId = null;
    for (IViewReference view : viewRefs) {
        if (view.getSecondaryId() != null && view.getId().equals(TmfViewStub.TMF_VIEW_STUB_ID)) {
            assertTrue("Instanceof a TmfViewStub", view.getView(false) instanceof TmfViewStub);
            fullId = ((TmfViewStub) view.getView(false)).getViewId();
            break;
        }
    }
    assertNotNull(fullId);
    IViewPart thirdView = TmfViewFactory.newView(fullId, true);
    assertNotNull("Creation from a view id with suffix failed", fullId);
    assertFalse("New view from view id with suffix was not created", Arrays.asList(viewRefs).contains(thirdView));
}
 
Example 15
Source File: SDView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Checks if current view is ready to be used.
 *
 * @return boolean <code>true</code> if view is ready else <code>false</code>.
 */
protected boolean isViewReady() {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    if (page == null) {
        return false;
    }

    IViewReference[] ref = page.getViewReferences();
    for (int i = 0; i < ref.length; i++) {
        if (ref[i].getView(false) == this) {
            return true;
        }
    }
    return false;
}
 
Example 16
Source File: TmfAlignmentSynchronizer.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Restore the views to their respective maximum widths
 */
private static void restoreViews() {
    // We set the width to Integer.MAX_VALUE so that the
    // views remove any "filler" space they might have.
    for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        for (IWorkbenchPage page : window.getPages()) {
            for (IViewReference ref : page.getViewReferences()) {
                restoreView(ref);
            }
        }
    }
}
 
Example 17
Source File: TestDebugConfiguration.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
@After
@Before
public void stopLaunchesAndCloseConsoles() throws DebugException {
	for (ILaunch launch : DebugPlugin.getDefault().getLaunchManager().getLaunches()) {
		launch.terminate();
	}
	IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
	consoleManager.removeConsoles(consoleManager.getConsoles());
	IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	for (IViewReference view : activePage.getViewReferences()) {
		if (IConsoleConstants.ID_CONSOLE_VIEW.equals(view.getId())) {
			activePage.hideView(view);
		}
	}
}
 
Example 18
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected IViewReference findView(IWorkbenchPage page, String viewId)
{
	for (IViewReference ref : page.getViewReferences())
	{
		if (viewId.equals(ref.getId()))
		{
			return ref;
		}
	}
	return null;
}
 
Example 19
Source File: TestESLint.java    From wildwebdeveloper with Eclipse Public License 2.0 5 votes vote down vote up
@Before
public void setUpProject() throws Exception {
	ScopedPreferenceStore prefs = new ScopedPreferenceStore(InstanceScope.INSTANCE, "org.eclipse.lsp4e");
	prefs.putValue("org.eclipse.wildwebdeveloper.angular.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.jsts.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.css.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.html.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.json.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.xml.file.logging.enabled", Boolean.toString(true));
	prefs.putValue("org.eclipse.wildwebdeveloper.yaml.file.logging.enabled", Boolean.toString(true));
	this.project = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.nanoTime());
	project.create(null);
	project.open(null);

	// Setup ESLint configuration and dependencies
	IFile eslintConfig = project.getFile(".eslintrc");
	eslintConfig.create(getClass().getResourceAsStream("/testProjects/eslint/.eslintrc"), true, null);
	IFile tsConfig = project.getFile("tsconfig.json");
	tsConfig.create(getClass().getResourceAsStream("/testProjects/eslint/tsconfig.json"), true, null);
	IFile packageJson = project.getFile("package.json");
	packageJson.create(getClass().getResourceAsStream("/testProjects/eslint/package.json"), true, null);
	Process dependencyInstaller = new ProcessBuilder(TestAngular.getNpmLocation(), "install")
			.directory(project.getLocation().toFile()).start();
	assertEquals("npm install didn't complete properly", 0, dependencyInstaller.waitFor());

	IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	for (IViewReference ref : activePage.getViewReferences()) {
		activePage.hideView(ref);
	}
}
 
Example 20
Source File: ViewHelper.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static IViewPart getViewPart(String viewId) {
   	for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
   		for (IWorkbenchPage page : window.getPages()) {
   			for (IViewReference reference : page.getViewReferences()) {
   				if (viewId.equals(reference.getId())) {
   					return reference.getView(false);
   				}
   			}
   		}
   	}
   	return null;
}