org.eclipse.ui.IEditorReference Java Examples

The following examples show how to use org.eclipse.ui.IEditorReference. 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: CloseResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
static List<IEditorReference> getMatchingEditors(final List<? extends IResource> resourceRoots,
		final IWorkbenchWindow w, final boolean deletedOnly) {
	final List<IEditorReference> toClose = new ArrayList<>();
	final IEditorReference[] editors = getEditors(w);
	for (final IEditorReference ref : editors) {
		final IResource resource = getAdapter(ref);
		// only collect editors for non existing resources
		if (resource != null && belongsTo(resourceRoots, resource)) {
			if (deletedOnly && resource.exists()) {
				continue;
			}
			toClose.add(ref);
		}
	}
	return toClose;
}
 
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: BufferDialog.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
private Control createBufferTip(Composite parent, IEditorReference ref) {

		Composite result = new Composite(parent, SWT.NO_FOCUS);
		Color bg = parent.getBackground();
		result.setBackground(bg);
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 1;
		result.setLayout(gridLayout);

		StyledText name = new StyledText(result, SWT.READ_ONLY | SWT.HIDE_SELECTION);
		// italics results in slightly clipped text unless extended
		String text = ref.getTitleToolTip() + ' ';
		name.setText(text);
		name.setBackground(bg);
		name.setCaret(null);
		StyleRange styleIt = new StyleRange(0, text.length(), null, bg);
		styleIt.fontStyle = SWT.ITALIC;
		name.setStyleRange(styleIt);
		
		return result;
	}
 
Example #4
Source File: ExportRepositoryWizardPage.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected ExportBosArchiveOperation createExportBOSOperation() {
    final ExportBosArchiveOperation operation = new ExportBosArchiveOperation();
    operation.setDestinationPath(getDetinationPath());
    operation.setFileStores(getSelectedFileStores());
    operation.addResources(getSelectedResoureContainer());
    try {
        final Set<IResource> toOpen = new HashSet<>();
        for (final IEditorReference ref : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                .getEditorReferences()) {
            final IFile file = (IFile) EditorUtil.retrieveResourceFromEditorInput(ref.getEditorInput());
            if (operation.getResources().contains(file)) {
                toOpen.add(file);
            }
        }
        operation.setResourcesToOpen(toOpen);
    } catch (final Exception e) {
        BonitaStudioLog.error(e);
    }

    return operation;
}
 
Example #5
Source File: PlantUmlExporter.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
protected void cleanupWorkbench(IFile targetFile, IWorkbenchPage page) throws CoreException {
	if (targetFile.exists()) {
		IEditorReference[] refs = page.getEditorReferences();
		for (IEditorReference ref : refs) {
			IEditorPart part = ref.getEditor(false);
			if (part != null) {
				IEditorInput inp = part.getEditorInput();
				if (inp instanceof FileEditorInput) {
					if (((FileEditorInput) inp).getFile().equals(targetFile)) {
						page.closeEditor(ref.getEditor(false), true);
					}
				}
			}
		}
	}
}
 
Example #6
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 #7
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 #8
Source File: NavigationLinkHelper.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) {
	if (!(selection.getFirstElement() instanceof ModelElement))
		return;
	ModelElement element = (ModelElement) selection.getFirstElement();
	for (IEditorReference ref : Editors.getReferences()) {
		try {
			if (!(ref.getEditorInput() instanceof ModelEditorInput))
				continue;
			ModelEditorInput input = (ModelEditorInput) ref.getEditorInput();
			if (element.getContent().equals(input.getDescriptor())) {
				App.openEditor(element.getContent());
			}
		} catch (PartInitException e) {
			var log = LoggerFactory.getLogger(getClass());
			log.error("Error activating editor", e);
		}
	}
}
 
Example #9
Source File: WorkspaceAction.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Most SVN workspace actions modify the workspace and thus should
 * save dirty editors.
 * @see org.tigris.subversion.subclipse.ui.actions.SVNAction#needsToSaveDirtyEditors()
 */
protected boolean needsToSaveDirtyEditors() {

	IResource[] selectedResources = getSelectedResources();
	if (selectedResources != null && selectedResources.length > 0) {
		IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
		for (IEditorReference editorReference : editorReferences) {
			if (editorReference.isDirty()) {
				try {
					IEditorInput editorInput = editorReference.getEditorInput();
					if (editorInput instanceof IFileEditorInput) {
						IFile file = ((IFileEditorInput)editorInput).getFile();
						if (needsToSave(file, selectedResources)) {
							return true;
						}
					}
				} catch (PartInitException e) {}
			}
		}
	}
	
	return false;
}
 
Example #10
Source File: InvasiveThemeHijacker.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void partActivated(IWorkbenchPartReference partRef)
{
	if (partRef instanceof IViewReference)
	{
		IViewReference viewRef = (IViewReference) partRef;
		String id = viewRef.getId();
		if ("org.eclipse.ui.console.ConsoleView".equals(id) || "org.eclipse.jdt.ui.TypeHierarchy".equals(id) //$NON-NLS-1$ //$NON-NLS-2$
				|| "org.eclipse.jdt.callhierarchy.view".equals(id)) //$NON-NLS-1$
		{
			final IViewPart part = viewRef.getView(false);
			Display.getCurrent().asyncExec(new Runnable()
			{
				public void run()
				{
					hijackView(part, false);
				}
			});
			return;
		}
	}
	if (partRef instanceof IEditorReference)
	{
		hijackOutline();
	}
}
 
Example #11
Source File: ESBService.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
/**
 * When services connection is renamed, refresh the connection label in the component view of job.
 *
 * @param item
 */
@Override
public void refreshComponentView(Item item) {
    try {
        IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
        IEditorReference[] editors = activePage.getEditorReferences();
        for (IEditorReference er : editors) {
            IEditorPart part = er.getEditor(false);
            if (part instanceof AbstractMultiPageTalendEditor) {
                AbstractMultiPageTalendEditor editor = (AbstractMultiPageTalendEditor) part;
                CommandStack stack = (CommandStack) editor.getTalendEditor().getAdapter(CommandStack.class);
                if (stack != null) {
                    IProcess process = editor.getProcess();
                    for (final INode processNode : process.getGraphicalNodes()) {
                        if (processNode instanceof Node) {
                            checkRepository((Node) processNode, item, stack);
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
 
Example #12
Source File: CloseResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tries to find opened editors matching given resource roots. The editors will be closed without confirmation and
 * only if the editor resource does not exists anymore.
 *
 * @param resourceRoots
 *            non null array with deleted resource tree roots
 * @param deletedOnly
 *            true to close only editors on resources which do not exist
 */
static void closeMatchingEditors(final List<? extends IResource> resourceRoots, final boolean deletedOnly) {
	if (resourceRoots.isEmpty()) { return; }
	final Runnable runnable = () -> SafeRunner.run(new SafeRunnable(IDEWorkbenchMessages.ErrorOnCloseEditors) {
		@Override
		public void run() {
			final IWorkbenchWindow w = getActiveWindow();
			if (w != null) {
				final List<IEditorReference> toClose = getMatchingEditors(resourceRoots, w, deletedOnly);
				if (toClose.isEmpty()) { return; }
				closeEditors(toClose, w);
			}
		}
	});
	BusyIndicator.showWhile(PlatformUI.getWorkbench().getDisplay(), runnable);
}
 
Example #13
Source File: BluemixUtil.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
public static ManifestMultiPageEditor getManifestEditor(IDominoDesignerProject project) {
    for (IEditorReference ref : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences()) {
        try {
            if (ref.getEditorInput() instanceof BluemixManifestEditorInput) {
                if (((BluemixManifestEditorInput)ref.getEditorInput()).getDesignerProject() == project) {
                    return (ManifestMultiPageEditor) ref.getEditor(false);
                }
            }
        } catch (PartInitException e) {
            if (BluemixLogger.BLUEMIX_LOGGER.isErrorEnabled()) {
                BluemixLogger.BLUEMIX_LOGGER.errorp(BluemixUtil.class, "getManifestEditor", e, "Failed to get manifest editor"); // $NON-NLS-1$ $NLE-BluemixUtil.Failedtogetmanifesteditor-2$
            }
        }
    }
    return null;  
}
 
Example #14
Source File: TestFullScenario.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @return
 */
private ProcessDiagramEditor getTheOnlyOneEditor() {
    IEditorPart editor;
    ProcessDiagramEditor processEditor;

    final IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .getEditorReferences();
    final StringBuilder sb = new StringBuilder();
    for (final IEditorReference iEditorReference : editorReferences) {
        sb.append(iEditorReference);
    }
    assertEquals("There should be only be 1 editor after save. But there are:\n" + sb.toString(),
            1,
            editorReferences.length);
    editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    assertTrue(editor instanceof ProcessDiagramEditor);
    processEditor = (ProcessDiagramEditor) editor;
    return processEditor;
}
 
Example #15
Source File: ResourceCloseManagement.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static void checkAndAddToEditorLists(
		List<IEditorPart> openedEditorRefs,
		List<IEditorPart> openedDirtyEditorRefs, IEditorReference fileRef )
{
	if ( fileRef != null )
	{
		IEditorPart part = (IEditorPart) fileRef.getPart( false );
		if ( part != null )
		{
			if ( part.isDirty( ) )
			{
				openedDirtyEditorRefs.add( part );
			}
			openedEditorRefs.add( part );
		}
	}
}
 
Example #16
Source File: SWTBotUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Finds an editor and sets focus to the editor
 *
 * @param bot
 *            the workbench bot
 * @param editorName
 *            the editor name
 * @return the corresponding SWTBotEditor
 */
public static SWTBotEditor activateEditor(SWTWorkbenchBot bot, String editorName) {
    Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(editorName);
    final SWTBotEditor editorBot = bot.editor(matcher);
    IEditorPart iep = editorBot.getReference().getEditor(true);
    final TmfEventsEditor tmfEd = (TmfEventsEditor) iep;
    editorBot.show();
    UIThreadRunnable.syncExec(new VoidResult() {
        @Override
        public void run() {
            tmfEd.setFocus();
        }
    });

    WaitUtils.waitForJobs();
    activeEventsEditor(bot);
    assertNotNull(tmfEd);
    return editorBot;
}
 
Example #17
Source File: GWTProjectPropertyPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
public static void reopenWithGWTJavaEditor(IEditorReference[] openEditors) {
  IWorkbenchPage page = JavaPlugin.getActivePage();

  for (IEditorReference editorRef : openEditors) {
    try {
      IEditorPart editor = editorRef.getEditor(false);
      IEditorInput input = editorRef.getEditorInput();

      // Close the editor, prompting the user to save if document is dirty
      if (page.closeEditor(editor, true)) {
        // Re-open the .java file in the GWT Java Editor
        IEditorPart gwtEditor = page.openEditor(input, GWTJavaEditor.EDITOR_ID);

        // Save the file from the new editor if the Java editor's
        // auto-format-on-save action screwed up the JSNI formatting
        gwtEditor.doSave(null);
      }
    } catch (PartInitException e) {
      GWTPluginLog.logError(e, "Could not open GWT Java editor on {0}", editorRef.getTitleToolTip());
    }
  }
}
 
Example #18
Source File: ResourceCloseManagement.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static IFile getEditorFile( IEditorReference fileRef )
{
	if ( fileRef != null )
	{
		IEditorPart part = (IEditorPart) fileRef.getPart( false );
		if ( part != null )
		{
			IEditorInput input = part.getEditorInput( );

			if ( input != null && input instanceof IFileEditorInput )
			{
				return ( (IFileEditorInput) input ).getFile( );
			}
		}
	}
	return null;
}
 
Example #19
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param fileName
 *            the fileName
 * @return the editor with the given fileName, or null if not found.
 */
public static IEditorPart findOpenedEditor( String fileName )
{
	IWorkbenchPage page = PlatformUI.getWorkbench( )
			.getActiveWorkbenchWindow( )
			.getActivePage( );

	IEditorReference[] editors = page.getEditorReferences( );

	for ( int i = 0; i < editors.length; i++ )
	{
		IEditorPart part = editors[i].getEditor( true );
		IPath location = ( (IPathEditorInput) part.getEditorInput( ) ).getPath( );

		if ( fileName.equalsIgnoreCase( location.toOSString( ) ) )
		{
			return part;
		}
	}

	return null;
}
 
Example #20
Source File: ResourceCloseManagement.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static void getOpenedFileInProject( IProject project,
		List<IEditorPart> openedEditorRefs,
		List<IEditorPart> openedDirtyEditorRefs )
{
	IEditorReference[] editors = getOpenedFileRefs( );
	for ( int i = 0; i < editors.length; i++ )
	{
		IFile file = getEditorFile( editors[i] );

		if ( ( file != null )
				&& ( file.getProject( ) != null )
				&& file.getProject( ).equals( project ) )
		{
			checkAndAddToEditorLists( openedEditorRefs,
					openedDirtyEditorRefs,
					editors[i] );
		}
	}
}
 
Example #21
Source File: ResourceCloseManagement.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private static void checkOpenResources( List<IResource> itemsToCheck,
		List<IEditorPart> openedEditorRefs,
		List<IEditorPart> openedDirtyEditorRefs ) throws CoreException
{
	for ( IResource resourceToCheck : itemsToCheck )
	{
		switch ( resourceToCheck.getType( ) )
		{
			case IResource.FILE :
				IEditorReference fileRef = getEditorRefInOpenFileList( (IFile) resourceToCheck );
				checkAndAddToEditorLists( openedEditorRefs,
						openedDirtyEditorRefs,
						fileRef );
				break;
			case IResource.PROJECT :
				getOpenedFileInProject( (IProject) resourceToCheck,
						openedEditorRefs,
						openedDirtyEditorRefs );
				break;
			default :
				checkOpenResources( Arrays.asList( ( (IContainer) resourceToCheck ).members( ) ),
						openedEditorRefs,
						openedDirtyEditorRefs );
		}
	}
}
 
Example #22
Source File: DeleteEditorFileHandler.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private static File getFile( IEditorReference editorReference ) {
  try {
    return getFile( editorReference.getEditorInput() );
  } catch( PartInitException e ) {
    return null;
  }
}
 
Example #23
Source File: TerminologyViewPart.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init(IViewSite site, IMemento memento) throws PartInitException {
	init(site);

	final IWorkbenchPage page = site.getPage();
	page.addPostSelectionListener(this);
	page.addPartListener(new PartAdapter2() {
		@Override
		public void partClosed(IWorkbenchPartReference partRef) {
			if (gridTable == null || gridTable.isDisposed()) {
				page.removePartListener(this); // 关闭视图后,移除此监听
			} else {
				if ("net.heartsome.cat.ts.ui.xliffeditor.nattable.editor".equals(partRef.getId())) {
					IEditorReference[] editorReferences = page.getEditorReferences();
					if (editorReferences.length == 0) { // 所有编辑器全部关闭的情况下。
						matcher.clearResources();
						firstAction.setEnabled(false);
						copyEnable.resetSelection();
						gridTable.removeAll();
					}
				}
			}
		}
	});
	site.getActionBars().getStatusLineManager()
			.setMessage(Messages.getString("view.TerminologyViewPart.statusLine"));
}
 
Example #24
Source File: CheckFileOnOpenPartListener.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the file behind the referenced workbench part.
 *
 * @param partRef
 *          the workbench part in question
 * @return the editors file or <code>null</code> if the workbench part is no file based editor
 */
private IFile getEditorFile(IWorkbenchPartReference partRef) {

  if (!(partRef instanceof IEditorReference)) {
    return null;
  }

  IFile file = null;
  IWorkbenchPart part = partRef.getPart(false); // fix for 3522695
  // do *NOT* restore the part here to prevent startup issues with large
  // number of opened files
  // instead use a different path the rip the input file reference

  IEditorInput input = null;

  if (part != null && part instanceof IEditorPart) {

    IEditorPart editor = (IEditorPart) part;
    input = editor.getEditorInput();
  } else {

    // fix for 3522695 - rip input file from editor ref without initializing
    // the actual part
    IEditorReference editRef = (IEditorReference) partRef;
    input = getRestoredInput(editRef);
  }

  if (input instanceof FileEditorInput) {
    file = ((FileEditorInput) input).getFile();
  }

  return file;
}
 
Example #25
Source File: SCTSourceDisplay.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected List<DiagramEditor> getAllOpenSubmachineEditors() {
	List<DiagramEditor> result = Lists.newArrayList();
	IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
			.getEditorReferences();
	for (IEditorReference iEditorReference : editorReferences) {
		IEditorPart editor = iEditorReference.getEditor(false);
		if (editor instanceof DiagramEditor) {
			IEditorInput editorInput = editor.getEditorInput();
			if (editorInput instanceof SubmachineEditorInput) {
				result.add((DiagramEditor) editor);
			}
		}
	}
	return result;
}
 
Example #26
Source File: DeleteEditorFileHandler.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private static void closeEditors( IWorkbenchWindow workbenchWindow, File file ) {
  IEditorReference[] editorReferences = workbenchWindow.getActivePage().getEditorReferences();
  for( IEditorReference editorReference : editorReferences ) {
    if( file.equals( getFile( editorReference ) ) ) {
      workbenchWindow.getActivePage().closeEditors( new IEditorReference[] { editorReference }, false );
    }
  }
}
 
Example #27
Source File: Editors.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public static void close(IEditorReference ref) {
	try {
		getActivePage().closeEditor(ref.getEditor(false), true);
	} catch (Exception e) {
		log.error("Failed to close an editor", e);
	}
}
 
Example #28
Source File: PreTranslationHandler.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event, List<IFile> list) {
	
	// 首先验证是否是合并打开的文件 --robert 2012-10-17
	if (isEditor) {
		try {
			IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
			IEditorReference[] editorRefe = window.getActivePage().findEditors(new FileEditorInput(list.get(0)),
					XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
			if (editorRefe.length <= 0) {
				return null;
			}

			IXliffEditor xlfEditor = (IXliffEditor) editorRefe[0].getEditor(true);
			// 针对合并打开
			if (xlfEditor.isMultiFile()) {
				list = ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList());
			}
		} catch (ExecutionException e) {
			logger.error("", e);
		}
		
	}
	
	CommonFunction.removeRepeateSelect(list);
	PreTransUitls.executeTranslation(list, shell);
	return null;
}
 
Example #29
Source File: PyAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return a set with the currently opened files in the PyEdit editors.
 */
public static Set<IFile> getOpenFiles() {
    Set<IFile> ret = new HashSet<IFile>();
    IWorkbenchWindow activeWorkbenchWindow = EditorUtils.getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        return ret;
    }

    IWorkbenchPage[] pages = activeWorkbenchWindow.getPages();
    for (int i = 0; i < pages.length; i++) {
        IEditorReference[] editorReferences = pages[i].getEditorReferences();

        for (int j = 0; j < editorReferences.length; j++) {
            IEditorReference iEditorReference = editorReferences[j];
            if (!PyEdit.EDITOR_ID.equals(iEditorReference.getId())) {
                continue; //Only PyDev editors...
            }
            try {
                IEditorInput editorInput = iEditorReference.getEditorInput();
                if (editorInput == null) {
                    continue;
                }
                IFile file = (IFile) editorInput.getAdapter(IFile.class);
                if (file != null) {
                    ret.add(file);
                }
            } catch (Exception e1) {
                Log.log(e1);
            }
        }
    }
    return ret;
}
 
Example #30
Source File: GwtFacetInstallSdkDelegate.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void reopenFilesWithGwtEditor() {
  // Get the list of Java editors opened on files in this project
  IEditorReference[] openEditors = GWTProjectPropertyPage.getOpenJavaEditors(project);
  if (openEditors.length > 0) {
    GWTProjectPropertyPage.reopenWithGWTJavaEditor(openEditors);
  }
}