下面列出了org.eclipse.ui.IWorkbenchPage#findEditor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@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;
}
@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);
}
}
/**
* 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;
}
@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);
}
}
}
/**
* @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;
}
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;
}
@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;
}
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;
}
}
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);
}
}
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);
}
}
/**
* @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);
}
}
}
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;
}
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;
}
@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
}
}
}
}
}
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);
}
}
}
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();
}
}