Java Code Examples for org.eclipse.ui.IWorkbenchPage

The following examples show how to use org.eclipse.ui.IWorkbenchPage. These examples are extracted from open source projects. 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 Project: ADT_Frontend   Source File: TestsPdeAbapGitStagingUtil.java    License: 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 2
Source Project: Pydev   Source File: EditorOpener.java    License: 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 3
Source Project: saros   Source File: EditorAPI.java    License: 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 4
Source Project: uima-uimaj   Source File: MultiPageEditor.java    License: 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 5
@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 6
/**
 * 创建工具菜单
 * @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 7
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 8
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 9
Source Project: ContentAssist   Source File: EditorUtilities.java    License: 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 10
Source Project: jbt   Source File: Utilities.java    License: 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 11
Source Project: erflute   Source File: NewDiagramWizard.java    License: 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 12
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 13
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 14
Source Project: neoscada   Source File: EditorHelper.java    License: 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 15
Source Project: birt   Source File: ScriptDebugUtil.java    License: 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 16
/**
 * 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 17
/**
 * 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 18
/**
 * 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 19
Source Project: Pydev   Source File: FileSearchPage.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void showMatch(Match match, int offset, int length, boolean activate) throws PartInitException {
    IFile file = (IFile) match.getElement();
    IWorkbenchPage page = getSite().getPage();
    if (offset >= 0 && length != 0) {
        fEditorOpener.openAndSelect(page, file, offset, length, activate);
    } else {
        fEditorOpener.open(page, file, activate);
    }
}
 
Example 20
@Override
public boolean isEnabled() {
    // Check if we are closing down
    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }

    // Get the selection
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final IWorkbenchPart part = page.getActivePart();
    if (part == null) {
        return false;
    }
    final ISelectionProvider selectionProvider = part.getSite().getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    final ISelection selection = selectionProvider.getSelection();

    // Make sure there is only one selection and that it is a trace
    fAnalysis = null;
    if (selection instanceof TreeSelection) {
        final TreeSelection sel = (TreeSelection) selection;
        // There should be only one item selected as per the plugin.xml
        final Object element = sel.getFirstElement();
        if (element instanceof TmfAnalysisElement) {
            fAnalysis = (TmfAnalysisElement) element;
        }
    }

    return (fAnalysis != null);
}
 
Example 21
public void install(IWorkbenchPage page) {
	page.addPartListener(this);
	fIsVisible= page.isPartVisible(getViewPart());
	if (fIsVisible) {
		installOnActiveEditor(page);
	}
}
 
Example 22
Source Project: jbt   Source File: BTEditor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Opens a BTEditor for editing the guard of a BTNode.
 */
private void openGuardEditor(final BTNode node) throws PartInitException {
	IWorkbenchPage activePage = Utilities.getMainWindowActivePage();

	BTEditorInput editorInput = new BTEditorInput(
			((BTEditorInput) getEditorInput()).getEditorID() + File.pathSeparator
					+ node.getID().toString(), false, true);

	BTEditor openEditor = (BTEditor) activePage.openEditor(editorInput, BTEditor.ID);

	if (!openGuardEditors.containsKey(node)) {
		openGuardEditors.put(node, openEditor);
	}
}
 
Example 23
@Override
public void open(IWorkbenchPage page) {
	try {
		page.openEditor(input, editorId, true, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
	} catch (PartInitException e) {
		LOG.error(e.getMessage(), e);
	}
}
 
Example 24
Source Project: wildwebdeveloper   Source File: TestJSON.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFormatEnabled() throws IOException, PartInitException, CoreException {
	File file = File.createTempFile("test", ".json");
	IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	IDE.openEditorOnFileStore(activePage, EFS.getStore(file.toURI()));
	ICommandService service = activePage.getWorkbenchWindow().getService(ICommandService.class);
	Command formatCommand = service.getCommand("org.eclipse.lsp4e.format");
	assertNotNull("Format command not found", formatCommand);
	assertTrue("Format command not defined", formatCommand.isDefined());
	assertTrue("Format command not enabled", formatCommand.isEnabled());
	assertTrue("Format command not handled", formatCommand.isHandled());
}
 
Example 25
Source Project: APICloud-Studio   Source File: UIUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Finds a view with the given ID
 * 
 * @param viewID
 *            the view ID
 * @return the view part
 * @throws PartInitException
 */
public static IViewPart findView(String viewID)
{
	IWorkbenchPage page = getActivePage();
	if (page != null)
	{
		return page.findView(viewID);
	}
	return null;
}
 
Example 26
Source Project: n4js   Source File: EclipseUIUtils.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/** Waits for a given editor to be active in a given workbench page. */
public static void waitForEditorToBeActive(final IWorkbenchPage page, IEditorPart editor) {
	if (editor == null)
		throw new IllegalArgumentException("Provided editor was null.");

	final boolean runsInUI = UIUtils.runsInUIThread();
	if (runsInUI)
		LOGGER.warn("Waiting for editor runs in the UI thread which can lead to UI thread starvation.");

	final long maxWait = 5000;
	boolean editorIsActive = false;
	boolean wasInterrupted = false;

	Stopwatch sw = Stopwatch.createStarted();
	do {

		editorIsActive = page.getActiveEditor() == editor;
		if (!editorIsActive) {
			try {
				if (runsInUI)
					UIUtils.waitForUiThread();
				else
					Thread.sleep(100);
			} catch (InterruptedException e) {
				wasInterrupted = true;
				LOGGER.error("Waiting for editor was interrupted after " + sw + ".", e);
			}
		}
	} while (sw.elapsed(TimeUnit.MILLISECONDS) < maxWait && editorIsActive == false && wasInterrupted == false);
	sw.stop();
	if (editorIsActive == false && wasInterrupted == false) {
		throw new TimeoutRuntimeException("Provided editor " + editor + " was not active after " + sw + ".");
	}
}
 
Example 27
/**
 * Constructs and updates the action.
 *
 * @param page the workbench page
 * @param inContextMenu <code>true</code> iff this action is shown in the context menu of a breadcrumb
 * 
 * @since 3.7
 */
public ToggleBreadcrumbAction(IWorkbenchPage page, boolean inContextMenu) {
	super(JavaEditorMessages.getBundleForConstructedKeys(),
			inContextMenu ? "ToggleBreadcrumbAction.Hide." : "ToggleBreadcrumbAction.", //$NON-NLS-1$ //$NON-NLS-2$
			inContextMenu ? IAction.AS_PUSH_BUTTON : IAction.AS_CHECK_BOX);
	
	PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.TOGGLE_BREADCRUMB_ACTION);
	fPage= page;
	if (!inContextMenu) {
		JavaPluginImages.setToolImageDescriptors(this, "toggle_breadcrumb.gif"); //$NON-NLS-1$
		fPage.getWorkbenchWindow().addPerspectiveListener(this);
	}
	update();
}
 
Example 28
public void partVisible(IWorkbenchPartReference ref) {
	if (ref != null && ref.getId() == getSite().getId()){
		fProcessSelectionEvents= true;
		IWorkbenchPage page= getSite().getWorkbenchWindow().getActivePage();
		if (page != null) {
			ISelection selection= page.getSelection();
			if (selection != null)
				selectionChanged(page.getActivePart(), selection);
		}
	}
}
 
Example 29
@Override
public Boolean execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    final File logFile = BOSWebServerManager.getInstance().getBonitaLogFile();
    if (logFile != null && logFile.exists()) {
        IFileStore fileStore;
        try {
            fileStore = EFS.getLocalFileSystem().getStore(logFile.toURI());
            final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR);
            final long fileSize = localFile.length();
            if (fileSize < MAX_FILE_SIZE) {
                IDE.openEditorOnFileStore(page, fileStore);
            } else {
                Program textEditor = Program.findProgram("log");
                if (textEditor == null) {
                    textEditor = Program.findProgram("txt");
                }
                if (textEditor != null) {
                    final boolean success = textEditor.execute(localFile.getAbsolutePath());
                    if (!success) {
                        showWarningMessage(localFile);
                    }
                } else {
                    showWarningMessage(localFile);
                }
            }

            return Boolean.TRUE;
        } catch (final Exception e) {
            BonitaStudioLog.error(e);
            return Boolean.FALSE;
        }
    } else {
        MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                Messages.unableTofindLogTitle, Messages.unableTofindLogMessage);
        return Boolean.FALSE;
    }
}
 
Example 30
Source Project: txtUML   Source File: EditorOpener.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Opens an editor for the file
 * @param diFile A file in the project
 * @return The EditorPart of the editor
 * @throws PartInitException
 */
public static final IMultiDiagramEditor openPapyrusEditor(final IFile diFile){
		IMultiDiagramEditor ed = null;
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		if(page != null) {
			try {
				IEditorInput editorInput = new FileEditorInput(diFile);
				ed = (IMultiDiagramEditor) IDE.openEditor(page, editorInput, PapyrusEditorId, true);
			} catch (PartInitException e) {
				Dialogs.errorMsgb(null, null, e);
			}
		}
		return ed;
}