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

The following examples show how to use org.eclipse.ui.IWorkbenchPage#findViewReference() . 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: CallHierarchyUI.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static CallHierarchyViewPart openView(IMember[] input, IWorkbenchWindow window) {
  	if (input.length == 0) {
	MessageDialog.openInformation(window.getShell(), CallHierarchyMessages.CallHierarchyUI_selectionDialog_title,
			CallHierarchyMessages.CallHierarchyUI_open_operation_unavialable);
	return null;
}
      IWorkbenchPage page= window.getActivePage();
try {
	CallHierarchyViewPart viewPart= getDefault().findLRUCallHierarchyViewPart(page); //find the first view which is not pinned
	String secondaryId= null;
	if (viewPart == null) {
		if (page.findViewReference(CallHierarchyViewPart.ID_CALL_HIERARCHY) != null) //all the current views are pinned, open a new instance
			secondaryId= String.valueOf(++getDefault().fViewCount);
	} else
		secondaryId= viewPart.getViewSite().getSecondaryId();
	viewPart= (CallHierarchyViewPart)page.showView(CallHierarchyViewPart.ID_CALL_HIERARCHY, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
	viewPart.setInputElements(input);
	return viewPart;
      } catch (CoreException e) {
          ExceptionHandler.handle(e, window.getShell(),
              CallHierarchyMessages.CallHierarchyUI_error_open_view, e.getMessage());
      }
      return null;
  }
 
Example 2
Source File: UIUtils.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static ViewPart getView(String viewId, boolean forceVisible) {
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    try {
        if (workbenchWindow == null) {
            return null;
        }
        IWorkbenchPage page = workbenchWindow.getActivePage();
        if (forceVisible) {
            return (ViewPart) page.showView(viewId, null, IWorkbenchPage.VIEW_VISIBLE);

        } else {
            IViewReference viewReference = page.findViewReference(viewId);
            if (viewReference != null) {
                //if it's there, return it (but don't restore it if it's still not there).
                //when made visible, it'll handle things properly later on.
                return (ViewPart) viewReference.getView(false);
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return null;

}
 
Example 3
Source File: PyCodeCoverageView.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets the py code coverage view. May only be called in the UI thread. If the view is not visible, if createIfNotThere
 * is true, it's made visible.
 *
 * Note that it may return null if createIfNotThere == false and the view is not currently shown or if not in the
 * UI thread.
 */
public static PyCodeCoverageView getView(boolean createIfNotThere) {
    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    try {
        if (workbenchWindow == null) {
            return null;
        }
        IWorkbenchPage page = workbenchWindow.getActivePage();
        if (createIfNotThere) {
            return (PyCodeCoverageView) page.showView(PY_COVERAGE_VIEW_ID, null, IWorkbenchPage.VIEW_ACTIVATE);
        } else {
            IViewReference viewReference = page.findViewReference(PY_COVERAGE_VIEW_ID);
            if (viewReference != null) {
                //if it's there, return it (but don't restore it if it's still not there).
                //when made visible, it'll handle things properly later on.
                return (PyCodeCoverageView) viewReference.getView(false);
            }
        }
    } catch (Exception e) {
        Log.log(e);
    }
    return null;
}
 
Example 4
Source File: OpenBrowserOperation.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
private void openAsView(IWorkbenchPage page) throws PartInitException {
    WebBrowserView view = null;
    IViewReference findViewReference = page.findViewReference(WebBrowserView.WEB_BROWSER_VIEW_ID,
            WebBrowserUtil.encodeStyle(id, IWorkbenchBrowserSupport.AS_VIEW));
    if (findViewReference == null) {
        view = (WebBrowserView) page.showView(WebBrowserView.WEB_BROWSER_VIEW_ID,
                WebBrowserUtil.encodeStyle(id, IWorkbenchBrowserSupport.AS_VIEW),
                IWorkbenchPage.VIEW_CREATE);
    } else {
        view = (WebBrowserView) findViewReference.getView(true);
    }
    if (name != null && name.length() > 0) {
        view.setBrowserViewName(name);
    }
    if (view != null) {
        view.setURL(url.toExternalForm());
        if (bringPartToTop) {
            page.bringToTop(view);
        }
    }
}
 
Example 5
Source File: WorkbenchHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static IGamaView.Display findDisplay(final String id) {
	final IWorkbenchPage page = WorkbenchHelper.getPage();
	if (page == null) { return null; } // Closing the workbench
	final IViewReference ref = page.findViewReference(id);
	if (ref == null) { return null; }
	final IViewPart view = ref.getView(false);
	if (view instanceof IGamaView.Display) { return (IGamaView.Display) view; }
	return null;
}
 
Example 6
Source File: WorkbenchHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isDisplay(final String id) {
	if (!id.startsWith(SwtGui.GL_LAYER_VIEW_ID) && !id.startsWith(SwtGui.LAYER_VIEW_ID)) { return false; }
	final IWorkbenchPage page = WorkbenchHelper.getPage();
	if (page == null) { return false; } // Closing the workbench
	final IViewReference ref = page.findViewReference(id);
	return ref != null;
	// final IViewPart view = ref.getView(false);
	// if (view instanceof IGamaView.Display) { return (IGamaView.Display) view; }
	// return <
}
 
Example 7
Source File: WorkbenchHelper.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static IViewPart findView(final String id, final String second, final boolean restore) {
	final IWorkbenchPage page = WorkbenchHelper.getPage();
	if (page == null) { return null; } // Closing the workbench
	final IViewReference ref = page.findViewReference(id, second);
	if (ref == null) { return null; }
	final IViewPart part = ref.getView(restore);
	return part;
}
 
Example 8
Source File: OpenDashboardHandler.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
/**
 * hide eclipse welcome page
 */
private void hideIntroView() {
	try {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		IWorkbenchPage page = window.getActivePage();
		IViewReference ref = page.findViewReference(INTRO_VIEW_ID);
		page.hideView(ref);
	} catch (Exception e) {
		log.error("Error occured while hiding the eclipse welcome page", e);
	}
}
 
Example 9
Source File: LoadersManager.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Returns the loader in use in this Sequence Diagram View
 *
 * @param viewId The Sequence Diagram viewId
 * @param view The Sequence Diagram view (if known). Use null to reference the primary SD View.
 * @return the current loader if any - null otherwise
 */
public IUml2SDLoader getCurrentLoader(String viewId, SDView view) {
    if (viewId == null) {
        return null;
    }

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    // During Eclipse shutdown the active workbench window is null
    if (window == null) {
        return null;
    }

    IWorkbenchPage persp = window.getActivePage();

    SDView sdView = view;

    try {
        // Search the view corresponding to the viewId
        if (sdView == null) {
            IViewReference viewref = persp.findViewReference(viewId);
            if (viewref != null) {
                sdView = (SDView) viewref.getView(false);
            }

            if (sdView == null) {
                // no corresponding view exists -> return null for the loader
                return null;
            }
        }

        // Return the loader corresponding to that view (if any)
        IUml2SDLoader loader = fViewLoaderMap.get(viewId);
        if (loader == null) {
            createLastLoaderIfAny(viewId);
            loader = fViewLoaderMap.get(viewId);
        }

        return loader;
    } catch (Exception e) {
        Activator.getDefault().logError("Error getting loader class", e); //$NON-NLS-1$
    }
    return null;
}
 
Example 10
Source File: LoadersManager.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Changes the current unique loader to the given secondary viewId.
 *
 * @param loader The current loader
 * @param id the view secondary id or null
 */
private void setCurrentLoader(IUml2SDLoader loader, String id) {
    if (id == null) {
        return;
    }

    // Get the loader in use
    IUml2SDLoader currentLoader = fViewLoaderMap.get(id);

    if ((currentLoader != null) && (currentLoader != loader)) {
        if (loader != null) {
            IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
            // During Eclipse shutdown the active workbench window is null
            if (window == null) {
                return;
            }
            IWorkbenchPage persp = window.getActivePage();
            try {
                // Search view corresponding to the viewId
                SDView sdview = null;
                IViewReference viewref = persp.findViewReference(id);
                if (viewref != null) {
                    sdview = (SDView) viewref.getView(false);
                }

                // Make everything clean for the new loader
                if (sdview != null) {
                    sdview.resetProviders();
                }

            } catch (Exception e) {
                Activator.getDefault().logError("Error setting current loader class", e); //$NON-NLS-1$
            }
        }
        // The old loader is going to be kicked
        currentLoader.dispose();
    }

    // Replace the current loader by the new one in the map
    fViewLoaderMap.put(id, loader);

    // Store this loader in the preferences to be able to restore it when the workbench will be re-launched
    if (loader != null) {
        saveLastLoader(loader.getClass().getName(), id);
    }
}