org.eclipse.ui.IWorkbenchPage#findEditor ( )源码实例Demo

下面列出了org.eclipse.ui.IWorkbenchPage#findEditor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: n4js   文件: N4JSResourceLinkHelper.java
@Override
public void activateEditor(final IWorkbenchPage page, final IStructuredSelection selection) {
	if (null != selection && !selection.isEmpty()) {
		final Object firstElement = selection.getFirstElement();
		if (firstElement instanceof ResourceNode) {
			SafeURI<?> nodeLocation = ((ResourceNode) firstElement).getLocation();
			if (nodeLocation.isFile()) {
				final URI uri = nodeLocation.toURI();
				final IEditorInput editorInput = EditorUtils.createEditorInput(new URIBasedStorage(uri));
				final IEditorPart editor = page.findEditor(editorInput);
				if (null != editor) {
					page.bringToTop(editor);
				} else {
					languageSpecificURIEditorOpener.open(uri, true);
				}
				return;
			}
		}
	}
	super.activateEditor(page, selection);
}
 
源代码2 项目: gama   文件: NavigatorLinkHelper.java
@Override
public void activateEditor(final IWorkbenchPage aPage, final IStructuredSelection aSelection) {
	if (aSelection == null || aSelection.isEmpty()) { return; }
	final Object o = aSelection.getFirstElement();
	// if (o instanceof WrappedLink) {
	// if (!NavigatorRoot.INSTANCE.mapper.validateLocation(((WrappedLink) o).getResource())) {
	// MessageDialog.openError(WorkbenchHelper.getShell(), "Unknown file",
	// "The file at location '" + ((WrappedLink) o).getResource().getLocation() + " does not exist");
	// return;
	// }
	//
	// }
	if (o instanceof WrappedFile) {
		final IEditorInput fileInput = new FileEditorInput(((WrappedFile) o).getResource());
		final IEditorPart editor = aPage.findEditor(fileInput);
		if (editor != null) {
			aPage.bringToTop(editor);
		}
	}

}
 
/**
 * Tests if a CU is currently shown in an editor
 *
 * @param inputElement the input element
 * @return the IEditorPart if shown, null if element is not open in an editor
 */
public static IEditorPart isOpenInEditor(Object inputElement) {
	IEditorPart editor= findEditor(inputElement, false);
	if (editor != null)
		return editor;

	IEditorInput input= getEditorInput(inputElement);

	if (input != null) {
		IWorkbenchPage p= JavaPlugin.getActivePage();
		if (p != null) {
			return p.findEditor(input);
		}
	}

	return null;
}
 
源代码4 项目: tesb-studio-se   文件: ReadCamelProcess.java
@Override
protected void doRun() {
    final IRepositoryNode node = (IRepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    CamelProcessItem processItem = (CamelProcessItem) node.getObject().getProperty().getItem();

    IWorkbenchPage page = getActivePage();

    try {
        CamelProcessEditorInput fileEditorInput = new CamelProcessEditorInput(processItem, true, null, true);
        checkUnLoadedNodeForProcess(fileEditorInput);
        IEditorPart editorPart = page.findEditor(fileEditorInput);

        if (editorPart == null) {
            fileEditorInput.setRepositoryNode(node);
            page.openEditor(fileEditorInput, CamelMultiPageTalendEditor.ID, true);
        } else {
            page.activate(editorPart);
        }
    } catch (PartInitException | PersistenceException e) {
        MessageBoxExceptionHandler.process(e);
    }
}
 
源代码5 项目: ContentAssist   文件: EditorUtilities.java
/**
 * 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;
}
 
源代码6 项目: Pydev   文件: PythonLinkHelper.java
@Override
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    if (aSelection == null || aSelection.isEmpty()) {
        return;
    }

    Object firstElement = aSelection.getFirstElement();

    //if it is a python element, let's first get the actual object for finding the editor
    if (firstElement instanceof IWrappedResource) {
        IWrappedResource resource = (IWrappedResource) firstElement;
        firstElement = resource.getActualObject();
    }

    //and now, if it is really a file...
    if (firstElement instanceof IFile) {

        //ok, let's check if the active editor is already the selection, because although the findEditor(editorInput) method
        //may return an editor for the correct file, we may have multiple editors for the same file, and if the current
        //editor is already correct, we don't want to change it
        //@see bug: https://sourceforge.net/tracker/?func=detail&atid=577329&aid=2037682&group_id=85796
        IEditorPart activeEditor = aPage.getActiveEditor();
        if (activeEditor != null) {
            IEditorInput editorInput = activeEditor.getEditorInput();
            IFile currFile = (IFile) editorInput.getAdapter(IFile.class);
            if (currFile != null && currFile.equals(firstElement)) {
                return; //the current editor is already the active editor.
            }
        }

        //if we got here, the active editor is not a match, so, let's find one and show it.
        IEditorPart editor = null;
        IEditorInput fileInput = new FileEditorInput((IFile) firstElement);
        if ((editor = aPage.findEditor(fileInput)) != null) {
            aPage.bringToTop(editor);
        }
    }

}
 
源代码7 项目: xtext-eclipse   文件: XtextDocumentUtil.java
/**
 * @since 2.19
 */
public IXtextDocument getXtextDocument(IResource resource) {
	if (resource instanceof IFile) {
		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IEditorPart editor = activePage.findEditor(new FileEditorInput((IFile) resource));
		if (editor != null) {
			return getXtextDocument(editor);
		}
		return getXtextDocument(new FileEditorInput((IFile) resource));
	}
	return null;
}
 
源代码8 项目: xtext-eclipse   文件: MarkerResolutionGenerator.java
public XtextEditor findEditor(IResource resource) {
	if(resource instanceof IFile) {
		IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
		IEditorPart editor = activePage.findEditor(new FileEditorInput((IFile) resource));
		if(editor instanceof XtextEditor) {
			return (XtextEditor)editor;
		} else if (editor != null) {
			return Adapters.adapt(editor, XtextEditor.class);
		}
	}
	return null;

}
 
源代码9 项目: tlaplus   文件: ModelEditorAdapterFactory.java
@SuppressWarnings("unchecked")
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
	if (!ModelEditor.class.equals(adapterType)) {
		return null;
	}
	if (adaptableObject instanceof Model) {
		final IWorkbenchPage activePage = UIHelper.getActivePage();
		if (activePage != null) {
			final Model model = (Model) adaptableObject;
			return (T) activePage.findEditor(new FileEditorInput(model.getFile()));
		}
	}
	return null;
}
 
源代码10 项目: gama   文件: PerspectiveHelper.java
private static void applyActiveEditor(final IWorkbenchPage page) {
	if ( activeEditor == null ) { return; }
	final IEditorPart part = page.findEditor(activeEditor);
	if ( part != null ) {
		page.activate(part);
		// DEBUG.OUT("Applying memorized editor to " + page.getPerspective().getId() + " = " + activeEditor.getName());
		// page.bringToTop(part);
	}

}
 
@Override
public void run(IAction action) {
	IWorkbenchPage page = window.getActivePage();
	getInput();
	IEditorPart part = page.findEditor(input);
	if(part != null ) {
		page.bringToTop(part);
		return;
	}
	open(page);
	
}
 
private IEditorPart showInEditor(IWorkbenchPage page, IEditorInput input, String editorId) {
	IEditorPart editor= page.findEditor(input);
	if (editor != null) {
		page.bringToTop(editor);
		return editor;
	}
	IEditorReference reusedEditorRef= fReusedEditor;
	if (reusedEditorRef !=  null) {
		boolean isOpen= reusedEditorRef.getEditor(false) != null;
		boolean canBeReused= isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned();
		if (canBeReused) {
			boolean showsSameInputType= reusedEditorRef.getId().equals(editorId);
			if (!showsSameInputType) {
				page.closeEditors(new IEditorReference[] { reusedEditorRef }, false);
				fReusedEditor= null;
			} else {
				editor= reusedEditorRef.getEditor(true);
				if (editor instanceof IReusableEditor) {
					((IReusableEditor) editor).setInput(input);
					page.bringToTop(editor);
					return editor;
				}
			}
		}
	}
	// could not reuse
	try {
		editor= page.openEditor(input, editorId, false);
		if (editor instanceof IReusableEditor) {
			IEditorReference reference= (IEditorReference) page.getReference(editor);
			fReusedEditor= reference;
		} else {
			fReusedEditor= null;
		}
		return editor;
	} catch (PartInitException ex) {
		MessageDialog.openError(JavaPlugin.getActiveWorkbenchShell(), SearchMessages.Search_Error_openEditor_title, SearchMessages.Search_Error_openEditor_message);
		return null;
	}
}
 
源代码13 项目: translationstudio8   文件: ResourceLinkHelper.java
public void activateEditor(IWorkbenchPage aPage,
		IStructuredSelection aSelection) {
	if (aSelection == null || aSelection.isEmpty())
		return;
	if (aSelection.getFirstElement() instanceof IFile) {
		IEditorInput fileInput = new FileEditorInput((IFile) aSelection.getFirstElement());
		IEditorPart editor = null;
		if ((editor = aPage.findEditor(fileInput)) != null)
			aPage.bringToTop(editor);
	}

}
 
源代码14 项目: tmxeditor8   文件: ResourceLinkHelper.java
public void activateEditor(IWorkbenchPage aPage,
		IStructuredSelection aSelection) {
	if (aSelection == null || aSelection.isEmpty())
		return;
	if (aSelection.getFirstElement() instanceof IFile) {
		IEditorInput fileInput = new FileEditorInput((IFile) aSelection.getFirstElement());
		IEditorPart editor = null;
		if ((editor = aPage.findEditor(fileInput)) != null)
			aPage.bringToTop(editor);
	}

}
 
源代码15 项目: bonita-studio   文件: ProcessNavigatorLinkHelper.java
/**
* @generated
*/
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
	if (aSelection == null || aSelection.isEmpty()) {
		return;
	}
	if (false == aSelection.getFirstElement() instanceof ProcessAbstractNavigatorItem) {
		return;
	}

	ProcessAbstractNavigatorItem abstractNavigatorItem = (ProcessAbstractNavigatorItem) aSelection
			.getFirstElement();
	View navigatorView = null;
	if (abstractNavigatorItem instanceof ProcessNavigatorItem) {
		navigatorView = ((ProcessNavigatorItem) abstractNavigatorItem).getView();
	} else if (abstractNavigatorItem instanceof ProcessNavigatorGroup) {
		ProcessNavigatorGroup navigatorGroup = (ProcessNavigatorGroup) abstractNavigatorItem;
		if (navigatorGroup.getParent() instanceof ProcessNavigatorItem) {
			navigatorView = ((ProcessNavigatorItem) navigatorGroup.getParent()).getView();
		}
	}
	if (navigatorView == null) {
		return;
	}
	IEditorInput editorInput = getEditorInput(navigatorView.getDiagram());
	IEditorPart editor = aPage.findEditor(editorInput);
	if (editor == null) {
		return;
	}
	aPage.bringToTop(editor);
	if (editor instanceof DiagramEditor) {
		DiagramEditor diagramEditor = (DiagramEditor) editor;
		ResourceSet diagramEditorResourceSet = diagramEditor.getEditingDomain().getResourceSet();
		EObject selectedView = diagramEditorResourceSet.getEObject(EcoreUtil.getURI(navigatorView), true);
		if (selectedView == null) {
			return;
		}
		GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor.getAdapter(GraphicalViewer.class);
		EditPart selectedEditPart = (EditPart) graphicalViewer.getEditPartRegistry().get(selectedView);
		if (selectedEditPart != null) {
			graphicalViewer.select(selectedEditPart);
		}
	}
}
 
源代码16 项目: Pydev   文件: EditorOpener.java
private IEditorPart showWithReuse(IFile file, IWorkbenchPage page, String editorId, boolean activate)
        throws PartInitException {
    IEditorInput input = new FileEditorInput(file);
    IEditorPart editor = page.findEditor(input);
    if (editor != null) {
        page.bringToTop(editor);
        if (activate) {
            page.activate(editor);
        }
        return editor;
    }
    IEditorReference reusedEditorRef = fReusedEditor;
    if (reusedEditorRef != null) {
        boolean isOpen = reusedEditorRef.getEditor(false) != null;
        boolean canBeReused = isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned();
        if (canBeReused) {
            boolean showsSameInputType = reusedEditorRef.getId().equals(editorId);
            if (!showsSameInputType) {
                page.closeEditors(new IEditorReference[] { reusedEditorRef }, false);
                fReusedEditor = null;
            } else {
                editor = reusedEditorRef.getEditor(true);
                if (editor instanceof IReusableEditor) {
                    ((IReusableEditor) editor).setInput(input);
                    page.bringToTop(editor);
                    if (activate) {
                        page.activate(editor);
                    }
                    return editor;
                }
            }
        }
    }
    editor = page.openEditor(input, editorId, activate);
    if (editor instanceof IReusableEditor) {
        IEditorReference reference = (IEditorReference) page.getReference(editor);
        fReusedEditor = reference;
    } else {
        fReusedEditor = null;
    }
    return editor;
}
 
源代码17 项目: typescript.java   文件: EditorOpener.java
private IEditorPart showWithReuse(IFile file, IWorkbenchPage page, String editorId, boolean activate) throws PartInitException {
	IEditorInput input= new FileEditorInput(file);
	IEditorPart editor= page.findEditor(input);
	if (editor != null) {
		page.bringToTop(editor);
		if (activate) {
			page.activate(editor);
		}
		return editor;
	}
	IEditorReference reusedEditorRef= fReusedEditor;
	if (reusedEditorRef !=  null) {
		boolean isOpen= reusedEditorRef.getEditor(false) != null;
		boolean canBeReused= isOpen && !reusedEditorRef.isDirty() && !reusedEditorRef.isPinned();
		if (canBeReused) {
			boolean showsSameInputType= reusedEditorRef.getId().equals(editorId);
			if (!showsSameInputType) {
				page.closeEditors(new IEditorReference[] { reusedEditorRef }, false);
				fReusedEditor= null;
			} else {
				editor= reusedEditorRef.getEditor(true);
				if (editor instanceof IReusableEditor) {
					((IReusableEditor) editor).setInput(input);
					page.bringToTop(editor);
					if (activate) {
						page.activate(editor);
					}
					return editor;
				}
			}
		}
	}
	editor= page.openEditor(input, editorId, activate);
	if (editor instanceof IReusableEditor) {
		IEditorReference reference= (IEditorReference) page.getReference(editor);
		fReusedEditor= reference;
	} else {
		fReusedEditor= null;
	}
	return editor;
}
 
源代码18 项目: tracecompass   文件: TmfEditorLinkHelper.java
@Override
public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
    if (aSelection == null || aSelection.isEmpty()) {
        return;
    }

    IFile file = null;

    if ((aSelection.getFirstElement() instanceof TmfTraceElement)) {
        TmfTraceElement traceElement = ((TmfTraceElement)aSelection.getFirstElement());

        // If trace is under an experiment, use the original trace from the traces folder
        traceElement = traceElement.getElementUnderTraceFolder();
        file = traceElement.getBookmarksFile();
    } else if ((aSelection.getFirstElement() instanceof TmfExperimentElement)) {
        TmfExperimentElement experimentElement = (TmfExperimentElement) aSelection.getFirstElement();
        file = experimentElement.getBookmarksFile();
    }

    if (file != null) {
        IEditorInput tmpInput = new FileEditorInput(file);
        IEditorPart localEditor = aPage.findEditor(tmpInput);
        if (localEditor != null) {
            // Editor found.
            aPage.bringToTop(localEditor);
        } else {
            // Search in references for corresponding editor
            IEditorReference[] refs = aPage.getEditorReferences();
            for (IEditorReference editorReference : refs) {
                try {
                    if (editorReference.getEditorInput().equals(tmpInput)) {
                        localEditor = editorReference.getEditor(true);
                        if (localEditor != null) {
                            aPage.bringToTop(localEditor);
                        }
                    }
                } catch (PartInitException e) {
                    // Ignore
                }
            }
        }
    }
}
 
源代码19 项目: statecharts   文件: NavigatorLinkHelper.java
public void activateEditor(IWorkbenchPage aPage,
		IStructuredSelection aSelection) {

	if (aSelection == null || aSelection.isEmpty()) {
		return;
	}
	if (false == aSelection.getFirstElement() instanceof DomainNavigatorItem) {
		return;
	}

	DomainNavigatorItem abstractNavigatorItem = (DomainNavigatorItem) aSelection
			.getFirstElement();

	View navigatorView = abstractNavigatorItem.getView();
	if (navigatorView == null) {
		return;
	}
	IEditorInput editorInput = getEditorInput(navigatorView.getDiagram());
	IEditorPart editor = aPage.findEditor(editorInput);
	if (editor == null) {
		return;
	}
	aPage.bringToTop(editor);
	if (editor instanceof DiagramEditor) {
		DiagramEditor diagramEditor = (DiagramEditor) editor;
		ResourceSet diagramEditorResourceSet = diagramEditor
				.getEditingDomain().getResourceSet();
		EObject selectedView = diagramEditorResourceSet.getEObject(
				EcoreUtil.getURI(navigatorView), true);
		if (selectedView == null) {
			return;
		}
		GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor
				.getAdapter(GraphicalViewer.class);
		EditPart selectedEditPart = (EditPart) graphicalViewer
				.getEditPartRegistry().get(selectedView);
		if (selectedEditPart != null) {
			graphicalViewer.select(selectedEditPart);
			graphicalViewer.reveal(selectedEditPart);
		}
	}
}
 
源代码20 项目: APICloud-Studio   文件: ThemeUIComposite.java
private void showUZWizard() {
	IWorkbenchPage page = PlatformUI.getWorkbench()
			.getActiveWorkbenchWindow().getActivePage();
	if (OpenAPICloudWizardActionDelegate.input == null) {
		OpenAPICloudWizardActionDelegate.input = new IEditorInput() {
			@SuppressWarnings("rawtypes")
			public Object getAdapter(Class adapter) {
				return null;
			}

			public String getToolTipText() {
				return "test";
			}

			public IPersistableElement getPersistable() {
				return null;
			}

			public String getName() {
				return "uz";
			}

			public ImageDescriptor getImageDescriptor() {
				return null;
			}

			public boolean exists() {
				return true;
			}
		};
	}
	IEditorPart part = page.findEditor(OpenAPICloudWizardActionDelegate.input);
	if (part != null) {
		page.bringToTop(part);
		return;
	}
	try {
		IDE.openEditor(page, OpenAPICloudWizardActionDelegate.input,
				"com.apicloud.navigator.APICloudWizard");
	} catch (PartInitException e) {
		e.printStackTrace();
	}

}