org.eclipse.ui.IWorkbenchPage Java Examples

The following examples show how to use org.eclipse.ui.IWorkbenchPage. 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: EditorOpener.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public IEditorPart openAndSelect(IWorkbenchPage wbPage, IFile file, int offset, int length, boolean activate)
        throws PartInitException {
    String editorId = null;
    IEditorDescriptor desc = IDE.getEditorDescriptor(file);
    if (desc == null || !desc.isInternal()) {
        editorId = "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
    } else {
        editorId = desc.getId();
    }

    IEditorPart editor;
    if (NewSearchUI.reuseEditor()) {
        editor = showWithReuse(file, wbPage, editorId, activate);
    } else {
        editor = showWithoutReuse(file, wbPage, editorId, activate);
    }

    if (editor instanceof ITextEditor) {
        ITextEditor textEditor = (ITextEditor) editor;
        textEditor.selectAndReveal(offset, length);
    } else if (editor != null) {
        showWithMarker(editor, file, offset, length);
    }
    return editor;
}
 
Example #2
Source File: NewDiagramWizard.java    From erflute with Apache License 2.0 6 votes vote down vote up
@Override
public boolean performFinish() {
    try {
        final String database = page2.getDatabase();
        page1.createERDiagram(database);
        final IFile file = page1.createNewFile();
        if (file == null) {
            return false;
        }
        final IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
        IDE.openEditor(page, file, true);
    } catch (final Exception e) {
        Activator.showExceptionDialog(e);
    }
    return true;
}
 
Example #3
Source File: ShowHidenNonPrintingCharacterHandler.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	isSelected = !isSelected;				
	try {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (window != null) {
			IWorkbenchPage page = window.getActivePage();
			if (page != null) {
				IEditorPart editor = page.getActiveEditor();
				if (editor != null && editor instanceof IXliffEditor) {
					((IXliffEditor) editor).refreshWithNonprinttingCharacter(isSelected);
				}
			}
		}
	} catch (NullPointerException e) {
		e.printStackTrace();
	}
	
	return null;
}
 
Example #4
Source File: PerspectiveChangeResetListener.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void resetPerspective(final IWorkbenchPage page)
{
	UIJob job = new UIJob("Resetting Studio perspective...") //$NON-NLS-1$
	{

		@Override
		public IStatus runInUIThread(IProgressMonitor monitor)
		{
			if (MessageDialog.openQuestion(UIUtils.getActiveShell(),
					com.aptana.ui.Messages.UIPlugin_ResetPerspective_Title,
					com.aptana.ui.Messages.UIPlugin_ResetPerspective_Description))
			{
				page.resetPerspective();
			}
			return Status.OK_STATUS;
		}
	};
	EclipseUtil.setSystemForJob(job);
	job.setPriority(Job.INTERACTIVE);
	job.schedule();
}
 
Example #5
Source File: EditorUtilities.java    From ContentAssist with MIT License 6 votes vote down vote up
/**
 * Obtains all editors that are currently opened.
 * @return the collection of the opened editors
 */
public static List<IEditorPart> getEditors() {
    List<IEditorPart> editors = new ArrayList<IEditorPart>();
    IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
    
    for (IWorkbenchWindow window : windows) {
        IWorkbenchPage[] pages = window.getPages();
        
        for (IWorkbenchPage page : pages) {
            IEditorReference[] refs = page.getEditorReferences();
            
            for (IEditorReference ref : refs) {
                IEditorPart part = ref.getEditor(false);
                if (part != null) {
                    editors.add(part);
                }
            }
        }
    }
    return editors;
}
 
Example #6
Source File: MultiPageEditor.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Open text editor.
 *
 * @param fileToOpen the file to open
 */
public void openTextEditor(IFile fileToOpen) {
  final IFile ffile = fileToOpen;
  Shell shell = new Shell();
  shell.getDisplay().asyncExec(new Runnable() {
    @Override
    public void run() {
      IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
      try {
        page.openEditor(new FileEditorInput(ffile), "org.eclipse.ui.DefaultTextEditor"); //$NON-NLS-1$
      } catch (PartInitException e) {
        throw new InternalErrorCDE("unexpected exception");
      }
    }
  });
}
 
Example #7
Source File: EditorHelper.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
public static void handleOpen ( final IWorkbenchPage page, final ISelection selection )
{
    final MultiStatus status = new MultiStatus ( Activator.PLUGIN_ID, 0, "Open editor", null );

    final IEditorInput[] inputs = EditorHelper.createInput ( selection );

    for ( final IEditorInput input : inputs )
    {
        try
        {
            if ( input instanceof ConfigurationEditorInput )
            {
                page.openEditor ( input, MultiConfigurationEditor.EDITOR_ID, true );
            }
            else if ( input instanceof FactoryEditorInput )
            {
                page.openEditor ( input, FactoryEditor.EDITOR_ID, true );
            }
        }
        catch ( final PartInitException e )
        {
            status.add ( e.getStatus () );
        }
    }
}
 
Example #8
Source File: EditorAPI.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This method will return all editors open in all IWorkbenchWindows.
 *
 * <p>This method will ask Eclipse to restore editors which have not been loaded yet (if Eclipse
 * is started editors are loaded lazily), which is why it must run in the SWT thread. So calling
 * this method might cause partOpen events to be sent.
 *
 * @return all editors that are currently opened
 * @swt
 */
public static Set<IEditorPart> getOpenEditors() {
  Set<IEditorPart> editorParts = new HashSet<IEditorPart>();

  for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
    for (IWorkbenchPage page : window.getPages()) {
      for (IEditorReference reference : page.getEditorReferences()) {
        IEditorPart editorPart = reference.getEditor(false);

        if (editorPart == null) {
          log.debug("editor part needs to be restored: " + reference.getTitle());
          // Making this call might cause partOpen events
          editorPart = reference.getEditor(true);
        }

        if (editorPart != null) {
          editorParts.add(editorPart);
        } else {
          log.warn("editor part could not be restored: " + reference);
        }
      }
    }
  }

  return editorParts;
}
 
Example #9
Source File: ApplicationActionBarAdvisor.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 创建工具菜单
 * @return 返回工具菜单的 menu manager;
 */
private MenuManager createToolMenu() {
	MenuManager menu = new MenuManager(Messages.getString("ts.ApplicationActionBarAdvisor.menu.tool"),
			"net.heartsome.cat.ts.ui.menu.tool") {
		@Override
		public boolean isVisible() {
			IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
			if (workbenchWindow == null)
				return false;
			IWorkbenchPage activePage = workbenchWindow.getActivePage();
			if (activePage == null)
				return false;
			if (activePage.getPerspective().getId().contains("net.heartsome.cat.ts.perspective"))
				return true;
			return false;
		}
	}; // &Tool
	menu.add(new GroupMarker("pluginConfigure"));
	menu.add(new GroupMarker("preference.groupMarker"));
	// menu.add(preferenceAction);
	return menu;
}
 
Example #10
Source File: ScriptDebugUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return
 */
public static DebugJsEditor getActiveJsEditor( )
{
	IWorkbenchWindow window = PlatformUI.getWorkbench( )
			.getActiveWorkbenchWindow( );

	if ( window != null )
	{

		IWorkbenchPage pg = window.getActivePage( );

		if ( pg != null )
		{
			IEditorPart editor = pg.getActiveEditor( );

			if ( editor != null )
			{
				if ( editor instanceof DebugJsEditor )
				{
					return (DebugJsEditor) editor;
				}
			}
		}
	}
	return null;
}
 
Example #11
Source File: Utilities.java    From jbt with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a List containing all the BTEditor that are currently open.
 */
public static List<BTEditor> getBTEditors() {
	IWorkbenchPage activePage = getMainWindowActivePage();

	if (activePage != null) {
		IEditorReference[] editors = activePage.getEditorReferences();
		if (editors.length == 0)
			return new Vector<BTEditor>();
		List<BTEditor> returnedEditors = new Vector<BTEditor>();
		for (int i = 0; i < editors.length; i++) {
			if (editors[i].getEditor(false) instanceof BTEditor) {
				returnedEditors.add((BTEditor) editors[i].getEditor(false));
			}
		}
		return returnedEditors;
	}

	return new LinkedList<BTEditor>();
}
 
Example #12
Source File: TestsPdeAbapGitStagingUtil.java    From ADT_Frontend with MIT License 6 votes vote down vote up
public AbapGitStagingView initializeView() throws PartInitException{
	AbapGitStagingView view;
	IWorkbenchPage activePage = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getActivePage();
	IPerspectiveDescriptor abapPerspective = PlatformUI.getWorkbench()
			.getPerspectiveRegistry()
			.findPerspectiveWithId("com.sap.adt.ui.AbapPerspective"); //$NON-NLS-1$
	activePage.setPerspective(abapPerspective);
	view = ((AbapGitStagingView) PlatformUI.getWorkbench().getActiveWorkbenchWindow()
			.getActivePage().showView(AbapGitStagingView.VIEW_ID));
	view.init(view.getViewSite());
	Shell shell = new Shell(Display.getDefault().getActiveShell());
	Composite parent = new Composite(shell, SWT.NONE);
	view.createPartControl(parent);				
	return view;
}
 
Example #13
Source File: OpenOppositeFileHandler.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	IEditorPart editor = HandlerUtil.getActiveEditor(event);
	IWorkbenchPage page = editor.getSite().getPage();
	Collection<FileOpener> destinations = Lists.newArrayList();
	collectOpeners(editor, CollectionBasedAcceptor.of(destinations));
	switch (destinations.size()) {
		case 0:
			return null;
		case 1:
			destinations.iterator().next().open(page);
			return null;
		default:
			List<FileOpener> selected = selectOpeners(page, destinations);
			for (FileOpener sel : selected)
				sel.open(page);
			return null;
	}
}
 
Example #14
Source File: DeveloperStudioPerspective.java    From devstudio-tooling-ei with Apache License 2.0 6 votes vote down vote up
/**
 * hide open dashboards
 */
private void hideDashboards() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    try {
        IWorkbenchPage page = window.getActivePage();
        List<IEditorReference> openEditors = new ArrayList<IEditorReference>();
        IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .getEditorReferences();
        for (IEditorReference iEditorReference : editorReferences) {
            if (DASHBOARD_VIEW_ID.equals(iEditorReference.getId())) {
                openEditors.add(iEditorReference);
            }
        }
        if (openEditors.size() > 0) {
            page.closeEditors(openEditors.toArray(new IEditorReference[] {}), false);
        }
    } catch (Exception e) {
        MessageDialog.openError(window.getShell(), "Could not hide dashboards for perspective", e.getMessage());
    }
}
 
Example #15
Source File: TmfCommonProjectElement.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Close open editors associated with this experiment.
 */
public void closeEditors() {
    IFile file = getBookmarksFile();
    FileEditorInput input = new FileEditorInput(file);
    IWorkbench wb = PlatformUI.getWorkbench();
    for (IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) {
        for (IWorkbenchPage wbPage : wbWindow.getPages()) {
            for (IEditorReference editorReference : wbPage.getEditorReferences()) {
                try {
                    if (editorReference.getEditorInput().equals(input)) {
                        wbPage.closeEditor(editorReference.getEditor(false), false);
                    }
                } catch (PartInitException e) {
                    Activator.getDefault().logError(NLS.bind(Messages.TmfCommonProjectElement_ErrorClosingEditor, getName()), e);
                }
            }
        }
    }
}
 
Example #16
Source File: LamiReportViewFactory.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Create all the views from a given report
 *
 * @param report
 *            The report to open
 * @throws PartInitException
 *             If there was a problem initializing a view
 */
public static synchronized void createNewView(LamiAnalysisReport report)
        throws PartInitException {
    currentReport = report;

    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

    /*
     * Doing this in two operations here, instead of using
     * IWorkbenchPage.VIEW_ACTIVATE, works around a bug where the contextual
     * menu would get "stuck" until the Project view is defocused and
     * refocused.
     */
    page.showView(LamiReportView.VIEW_ID, String.valueOf(secondaryViewId), IWorkbenchPage.VIEW_VISIBLE);
    page.activate(page.findView(LamiReportView.VIEW_ID));

    secondaryViewId++;

    currentReport = null;
}
 
Example #17
Source File: JavaHistoryActionImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
final JavaEditor getEditor(IFile file) {
	FileEditorInput fei= new FileEditorInput(file);
	IWorkbench workbench= JavaPlugin.getDefault().getWorkbench();
	IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
	for (int i= 0; i < windows.length; i++) {
		IWorkbenchPage[] pages= windows[i].getPages();
		for (int x= 0; x < pages.length; x++) {
			IEditorPart[] editors= pages[x].getDirtyEditors();
			for (int z= 0; z < editors.length; z++) {
				IEditorPart ep= editors[z];
				if (ep instanceof JavaEditor) {
					JavaEditor je= (JavaEditor) ep;
					if (fei.equals(je.getEditorInput()))
						return (JavaEditor) ep;
				}
			}
		}
	}
	return null;
}
 
Example #18
Source File: PackageExplorerPart.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void setLinkingEnabled(boolean enabled) {
	fLinkingEnabled= enabled;
	saveDialogSettings();

	IWorkbenchPage page= getSite().getPage();
	if (enabled) {
		page.addPartListener(fLinkWithEditorListener);

		IEditorPart editor = page.getActiveEditor();
		if (editor != null)
			editorActivated(editor);
	} else {
		page.removePartListener(fLinkWithEditorListener);
	}
	fOpenAndLinkWithEditorHelper.setLinkWithEditor(enabled);
}
 
Example #19
Source File: MainController.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
private PageController getOrCreatePageController(IWorkbenchPage page) {
	PageController controller = pageControllers.get(page);

	if (controller == null || controller.isDisposed()) {
		PageModel model = new PageModel(page);
		controller = new PageController(this, model);

		pageControllers.put(page, controller);

		controller.init();
	}

	return controller;
}
 
Example #20
Source File: PlatformUtil.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public static Optional<IEditorPart> findActiveEditor() {
    if (PlatformUI.isWorkbenchRunning()) {
        return Optional.ofNullable(PlatformUI.getWorkbench())
                .map(IWorkbench::getActiveWorkbenchWindow)
                .map(IWorkbenchWindow::getActivePage)
                .map(IWorkbenchPage::getActiveEditor);
    }
    return Optional.empty();
}
 
Example #21
Source File: JSDTEditorTracker.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public void windowClosed(IWorkbenchWindow window) {
	IWorkbenchPage[] pages = window.getPages();
	for (IWorkbenchPage page : pages) {
		pageClosed(page);
	}
	window.removePageListener(this);
}
 
Example #22
Source File: HistoryMinibuffer.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.minibuffer.WithMinibuffer#removeOtherListeners(IWorkbenchPage, ISourceViewer, StyledText)
 */
@Override
protected void removeOtherListeners(IWorkbenchPage page, ISourceViewer viewer, StyledText widget) {
	if (handlesAlt()) {
		widget.removeTraverseListener(this);
	}
}
 
Example #23
Source File: OpenAPICloudWizardActionDelegate.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static void open(IWorkbenchPage page) {
	try {
		IDE.openEditor(page , input, "com.apicloud.navigator.APICloudWizard");
	} catch (PartInitException e) {
		e.printStackTrace();
	}
}
 
Example #24
Source File: OpenFileWithValidAction.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new action that will open instances of the specified editor on the then-selected file resources.
 * @param page
 *            the workbench page in which to open the editor
 * @param descriptor
 *            the editor descriptor, or <code>null</code> if unspecified
 */
public OpenFileWithValidAction(IWorkbenchPage page, IEditorDescriptor descriptor) {
	super(page);
	setText(descriptor == null ? IDEWorkbenchMessages.OpenFileAction_text : descriptor.getLabel());
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IIDEHelpContextIds.OPEN_FILE_ACTION);
	setToolTipText(IDEWorkbenchMessages.OpenFileAction_toolTip);
	setId(ID);
	this.editorDescriptor = descriptor;
}
 
Example #25
Source File: NewTemplateFileWizard.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean performFinish()
{
	IFile file = mainPage.createNewFile();
	if (file == null)
	{
		return false;
	}

	selectAndReveal(file);

	// opens editor on the new file
	IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
	try
	{
		if (window != null)
		{
			IWorkbenchPage page = window.getActivePage();
			if (page != null)
			{
				IDE.openEditor(page, file, true);
			}
		}
	}
	catch (PartInitException e)
	{
		DialogUtil.openError(window.getShell(), ResourceMessages.FileResource_errorMessage, e.getMessage(), e);
	}

	return true;
}
 
Example #26
Source File: StartBillingProposalHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private BillingProposalView getOpenView(ExecutionEvent event){
	try {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
		IWorkbenchPage page = window.getActivePage();
		return (BillingProposalView) page.showView(BillingProposalView.ID);
	} catch (PartInitException e) {
		MessageDialog.openError(HandlerUtil.getActiveShell(event), "Fehler",
			"Konnte Rechnungs-Vorschlag View nicht öffnen");
	}
	return null;
}
 
Example #27
Source File: XdsLinkHelper.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activateEditor(IWorkbenchPage page,
		IStructuredSelection selection) {
	Object element= selection.getFirstElement();
	IEditorPart part= CoreEditorUtils.isOpenInEditor(element);
	if (part != null) {
		page.bringToTop(part);
	}
}
 
Example #28
Source File: SelectAllProjectExplorerHandler.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (null == activeWorkbenchWindow) {
		return null;
	}
	IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
	if (null == activePage) {
		return null;
	}
	IWorkbenchPart activePart = activePage.getActivePart();
	if (!(activePart instanceof CommonNavigator)) {
		return null;
	}

	CommonNavigator navigator = (CommonNavigator) activePart;
	CommonViewer commonViewer = navigator.getCommonViewer();

	Tree navigatorTree = commonViewer.getTree();
	List<TreeItem> visibleItems = new ArrayList<>();
	collectChildren(navigatorTree.getItems(), visibleItems);

	List<Object> visibleData = visibleItems.stream().map(i -> i.getData()).collect(Collectors.toList());

	commonViewer.setSelection(new StructuredSelection(visibleData), false);

	return null;
}
 
Example #29
Source File: CloseAllEditors.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {
    for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        for (IWorkbenchPage page : window.getPages()) {
            page.saveAllEditors(false);

        }
    }
}
 
Example #30
Source File: CodeCheckerContext.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The refresher for Project ReportList View.
 * 
 * @param pages the page list for the currently active workbench windows.
 * @param project the project, project the buglist to be refreshed
 * @param noFetch if true, the server will not be asked for new list 
 */
private void refreshProject(IWorkbenchPage[] pages, IProject project, boolean noFetch) {
    Logger.log(IStatus.INFO, "Refreshing bug list for project:"+project.getName());
    for(IWorkbenchPage page : pages) {
        for (IViewReference vp : page.getViewReferences()) {
            if (vp.getId().equals(ReportListViewProject.ID)) {
                ReportListViewProject rlvp = (ReportListViewProject) vp.getView(true);
                if (!noFetch || this.activeProject != project) {
                    rlvp.onEditorChanged(project);
                }
            }
        }
    }
}