Java Code Examples for org.eclipse.ui.IWorkbenchWindow#getPages()

The following examples show how to use org.eclipse.ui.IWorkbenchWindow#getPages() . 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: 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 2
Source File: RustManager.java    From corrosion with Eclipse Public License 2.0 6 votes vote down vote up
private static LSPDocumentInfo infoFromOpenEditors() {
	for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
		for (IWorkbenchPage page : window.getPages()) {
			for (IEditorReference editor : page.getEditorReferences()) {
				IEditorInput input;
				try {
					input = editor.getEditorInput();
				} catch (PartInitException e) {
					continue;
				}
				if (input.getName().endsWith(".rs") && editor.getEditor(false) instanceof ITextEditor) { //$NON-NLS-1$
					IDocument document = (((ITextEditor) editor.getEditor(false)).getDocumentProvider())
							.getDocument(input);
					Collection<LSPDocumentInfo> infos = LanguageServiceAccessor.getLSPDocumentInfosFor(document,
							capabilities -> Boolean.TRUE.equals(capabilities.getReferencesProvider()));
					if (!infos.isEmpty()) {
						return infos.iterator().next();
					}
				}
			}
		}
	}
	return null;
}
 
Example 3
Source File: OpenDocumentTracker.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Inject(optional=true)
protected void initialize(final IWorkbench workbench) {
	Assert.isNotNull(Display.getCurrent());
	partListener = new PartListener();
	pageListener = new PageListener();
	for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
		window.addPageListener(pageListener);
		for (IWorkbenchPage page : window.getPages()) {
			page.addPartListener(partListener);
			for (IEditorReference editorRef : page.getEditorReferences()) {
				Pair<URI, IXtextDocument> entry = getEntry(editorRef);
				if (entry != null) {
					resourceUri2document.put(entry.getFirst(), entry.getSecond());
				}
			}
		}
	}
}
 
Example 4
Source File: AnnotationEditor.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a list of all {@link AnnotationEditor} which are currently opened.
 *
 * @return the annotation editors
 */
public static AnnotationEditor[] getAnnotationEditors() {

  List<AnnotationEditor> dirtyParts = new ArrayList<>();
  IWorkbenchWindow windows[] = PlatformUI.getWorkbench().getWorkbenchWindows();
  for (IWorkbenchWindow element : windows) {
    IWorkbenchPage pages[] = element.getPages();
    for (IWorkbenchPage page : pages) {
      IEditorReference[] references = page.getEditorReferences();

      for (IEditorReference reference : references) {

        IEditorPart part = reference.getEditor(false);

        if (part instanceof AnnotationEditor) {
          AnnotationEditor editor = (AnnotationEditor) part;
          dirtyParts.add(editor);
        }
      }
    }
  }

  return dirtyParts.toArray(new AnnotationEditor[dirtyParts.size()]);
}
 
Example 5
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 6
Source File: EditorUtilities.java    From ContentAssist with MIT License 5 votes vote down vote up
/**
 * Obtains an editor that may edits the contents of a file.
 * @param file the file
 * @return the editor of the file, or <code>null</code> if none
 */
public static IEditorPart getEditor(IFile file) {
    IEditorInput input = new FileEditorInput(file);
    IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
    
    for (IWorkbenchWindow window : windows) {
        IWorkbenchPage[] pages = window.getPages();
        
        for (IWorkbenchPage page : pages) {
            IEditorPart part = page.findEditor(input);
            return part;
        }
    }
    return null;
}
 
Example 7
Source File: ExampleModelOpener.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected IWorkbenchPage getPage() {
	IWorkbenchWindow[] workbenchWindows = PlatformUI.getWorkbench().getWorkbenchWindows();
	if (workbenchWindows.length > 0) {
		IWorkbenchWindow workbenchWindow = workbenchWindows[0];
		IWorkbenchPage[] pages = workbenchWindow.getPages();
		if (pages.length > 0) {
			return pages[0];
		}
	}
	return null;
}
 
Example 8
Source File: TmfAlignmentSynchronizer.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Realign all views
 */
private void realignViews() {
    for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        for (IWorkbenchPage page : window.getPages()) {
            realignViews(page);
        }
    }
}
 
Example 9
Source File: XMLAnalysesManagerPreferencePage.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Get editor references.
 *
 * @return the set of editor references
 */
private static Set<IEditorReference> getEditorReferences() {
    Set<IEditorReference> editorReferences = new HashSet<>();
    IWorkbench wb = PlatformUI.getWorkbench();
    for (IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) {
        for (IWorkbenchPage wbPage : wbWindow.getPages()) {
            editorReferences.addAll(Arrays.asList(wbPage.getEditorReferences()));
        }
    }
    return editorReferences;
}
 
Example 10
Source File: JSDTEditorTracker.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public void windowOpened(IWorkbenchWindow window) {
	if (window.getShell() != null) {
		IWorkbenchPage[] pages = window.getPages();
		for (IWorkbenchPage page : pages) {
			pageOpened(page);
		}
		window.addPageListener(this);
	}
}
 
Example 11
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 12
Source File: AllInOneWorkbenchListener.java    From typescript.java with MIT License 5 votes vote down vote up
private void unhookListeners(IWorkbenchWindow window) {
	if (window == null)
		return;
	window.removePageListener(this);
	window.removePerspectiveListener(this);
	for (IWorkbenchPage page : window.getPages()) {
		unhookListeners(page);
	}
}
 
Example 13
Source File: AllInOneWorkbenchListener.java    From typescript.java with MIT License 5 votes vote down vote up
private void hookListeners(IWorkbenchWindow window) {
	if (window == null)
		return;
	window.addPageListener(this);
	window.addPerspectiveListener(this);
	for (IWorkbenchPage page : window.getPages()) {
		hookListeners(page);
	}
}
 
Example 14
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 15
Source File: CodeCheckerContext.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Refresh change project.
 *
 * @param project the project, the user change his/her view to
 */
public void refreshChangeProject(IProject project) {
    IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

    if(activeWindow == null) {
        Logger.log(IStatus.ERROR, NULL_WINDOW);
        return;
    }

    IWorkbenchPage[] pages = activeWindow.getPages();

    this.refreshProject(pages, project, true);
    this.refreshCustom(pages, project, "", true);
    this.activeProject = project;
}
 
Example 16
Source File: CodeCheckerContext.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Refresh change editor part.
 *
 * @param partRef the IEditorPart which the user has switched.
 */
public void refreshChangeEditorPart(IEditorPart partRef) {        
    if (partRef.getEditorInput() instanceof IFileEditorInput){
        //could be FileStoreEditorInput
        //for files which are not part of the
        //current workspace
        activeEditorPart = partRef;
        IFile file = ((IFileEditorInput) partRef.getEditorInput()).getFile();
        IProject project = file.getProject();

        CodeCheckerProject ccProj = projects.get(project);
        String filename = "";
        if (ccProj != null)
            filename = ((FileEditorInput) partRef.getEditorInput()).getFile().getLocation().toFile().toPath()
                    .toString();

        IWorkbenchWindow activeWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (activeWindow == null) {
            Logger.log(IStatus.ERROR, NULL_WINDOW);
            return;
        }
        IWorkbenchPage[] pages = activeWindow.getPages();

        this.refreshProject(pages, project, true);
        this.refreshCurrent(pages, project, filename, true);
        this.refreshCustom(pages, project, "", true);
        this.activeProject = project;
    }
}
 
Example 17
Source File: SyncUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void reconcileAllEditors(IWorkbench workbench, final boolean saveAll, final IProgressMonitor monitor) {
	for (IWorkbenchWindow window : workbench.getWorkbenchWindows()) {
		for (IWorkbenchPage page : window.getPages()) {
			for (IEditorReference editorReference : page.getEditorReferences()) {
				if (monitor.isCanceled())
					return;
				final IEditorPart editor = editorReference.getEditor(false);
				if (editor != null) {
					if (editor instanceof XtextEditor) {
						waitForReconciler((XtextEditor) editor);
					}
					if (saveAll) {
						Display display = workbench.getDisplay();
						display.syncExec(new Runnable() {
							@Override
							public void run() {
								if (editor.isDirty()) {
									editor.doSave(monitor);
								}
							}
						});
					}
				}
			}
		}
	}
}
 
Example 18
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;
}
 
Example 19
Source File: StartLaunchHandler.java    From tlaplus with MIT License 4 votes vote down vote up
private ModelEditor getModelEditor(final IEvaluationContext context) {
	// is current editor a model editor?
	Object variable = context.getVariable(ISources.ACTIVE_EDITOR_ID_NAME);
	final String id = (variable != IEvaluationContext.UNDEFINED_VARIABLE) ? (String)variable : null;
	
	if ((id != null) && (id.startsWith(ModelEditor.ID))) {
		variable = context.getVariable(ISources.ACTIVE_EDITOR_NAME);
		
		if (variable instanceof IEditorPart) {
			lastModelEditor = (ModelEditor)variable;
		}
	}
	// If lastModelEditor is still null, it means we haven't run the model
	// checker yet AND the model editor view is *not* active. Lets search
	// through all editors to find a model checker assuming only a single one
	// is open right now. If more than one model editor is open, randomly
	// select one. In case it's not the one intended to be run by the user,
	// she has to activate the correct model editor manually.
	//
	// It is tempting to store the name of the lastModelEditor
	// in e.g. an IDialogSetting to persistently store even across Toolbox
	// restarts. However, the only way to identify a model editor here is by
	// its name and almost all model editors carry the name "Model_1" (the
	// default name). So we might end up using Model_1 which was the last
	// model that ran for spec A, but right now spec B and two of its model
	// editors are open ("Model_1" and "Model_2"). It would launch Model_1,
	// even though Model_2 might be what the user wants.
	if (lastModelEditor == null) {
		final IWorkbenchWindow workbenchWindow = (IWorkbenchWindow) context
				.getVariable(ISources.ACTIVE_WORKBENCH_WINDOW_NAME);

		for (final IWorkbenchPage page : workbenchWindow.getPages()) {
			for (final IEditorReference editorRefs : page.getEditorReferences()) {
				if (editorRefs.getId().equals(ModelEditor.ID)) {
					lastModelEditor = (ModelEditor) editorRefs.getEditor(true);
					break;
				}
			}
		}
	}
	// Validate that the lastModelEditor still belongs to the current
	// open spec. E.g. lastModelEditor might still be around from when
	// the user ran a it on spec X, but has switched to spec Y in the
	// meantime. Closing the spec nulls the ModelEditor
	if ((lastModelEditor != null) && lastModelEditor.isDisposed()) {
		lastModelEditor = null;
	}
	
	// If the previous two attempts to find a model editor have failed, lets
	// return whatever we have... which might be null.
	return lastModelEditor;
}
 
Example 20
Source File: StackWindowAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private void changeEnabled( IAction action )
{
	IWorkbenchWindow window = PlatformUI.getWorkbench( )
			.getActiveWorkbenchWindow( );
	IWorkbenchPage[] pages = window.getPages( );

	boolean isEnabled = false;
	for ( int i = 0; i < pages.length; i++ )
	{
		IEditorReference[] refs = pages[i].getEditorReferences( );

		for ( int j = 0; j < refs.length; j++ )
		{
			IEditorPart editor = refs[j].getEditor( false );

			// if ( editor != null
			// && editor.getEditorInput( ) instanceof IReportEditorInput )
			// {
			// if ( editor instanceof AbstractMultiPageEditor )
			// {
			// isEnabled = canDo( );
			// break;
			// }
			// }

			if ( editor instanceof AbstractMultiPageEditor )
			{
				isEnabled = canDo( );
				break;
			}
			else if ( editor instanceof IReportEditor )
			{
				IEditorPart activeEditor = ( (IReportEditor) editor ).getEditorPart( );
				if ( activeEditor instanceof AbstractMultiPageEditor )
				{
					isEnabled = canDo( );
					break;
				}
			}
		}
	}
	setAction( action, isEnabled );
}