下面列出了org.eclipse.ui.IWorkbenchPage#bringToTop ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void openAsView(IWorkbenchPage page) throws PartInitException {
WebBrowserView view = null;
IViewReference findViewReference = page.findViewReference(WebBrowserView.WEB_BROWSER_VIEW_ID,
WebBrowserUtil.encodeStyle(id, IWorkbenchBrowserSupport.AS_VIEW));
if (findViewReference == null) {
view = (WebBrowserView) page.showView(WebBrowserView.WEB_BROWSER_VIEW_ID,
WebBrowserUtil.encodeStyle(id, IWorkbenchBrowserSupport.AS_VIEW),
IWorkbenchPage.VIEW_CREATE);
} else {
view = (WebBrowserView) findViewReference.getView(true);
}
if (name != null && name.length() > 0) {
view.setBrowserViewName(name);
}
if (view != null) {
view.setURL(url.toExternalForm());
if (bringPartToTop) {
page.bringToTop(view);
}
}
}
@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);
}
}
}
@Override
public void run(IAction action) {
IResource resource = (IResource)select.getFirstElement();
String url = resource.getLocation().toOSString();
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if(window == null) return;
IWorkbenchPage page = window.getActivePage();
if(page == null) return;
WebBrowserView part = (WebBrowserView)page.findView("com.aptana.browser.views.webbrowser");
if(part != null) {
page.bringToTop(part);
part.setURL(url);
return;
}
try {
WebBrowserView view = (WebBrowserView)page.showView("com.aptana.browser.views.webbrowser");
view.setURL(url);
} catch (PartInitException e) {
e.printStackTrace();
}
}
@Override
public void run(IAction action) {
IFile file = null;
IEditorInput input = targetEditor.getEditorInput();
if(input instanceof IFileEditorInput) {
file = ((IFileEditorInput) input).getFile();
}
String url = file.getLocation().toOSString();
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if(window == null) return;
IWorkbenchPage page = window.getActivePage();
if(page == null) return;
WebBrowserView part = (WebBrowserView)page.findView("com.aptana.browser.views.webbrowser");
if(part != null) {
page.bringToTop(part);
part.setURL(url);
return;
}
try {
WebBrowserView view = (WebBrowserView)page.showView("com.aptana.browser.views.webbrowser");
view.setURL(url);
} catch (PartInitException e) {
e.printStackTrace();
}
}
public void openURL(URL url) throws PartInitException {
WebBrowserView view = (WebBrowserView) part;
IWorkbenchWindow workbenchWindow = WebBrowserUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage workbenchPage = null;
if (workbenchWindow != null) {
workbenchPage = workbenchWindow.getActivePage();
}
if (workbenchPage == null) {
throw new PartInitException("Cannot get Workbench page"); //$NON-NLS-1$
}
if (view == null) {
view = (WebBrowserView) workbenchPage.showView(WebBrowserView.VIEW_ID, getId(), IWorkbenchPage.VIEW_CREATE);
hookPart(workbenchPage, view);
}
if (view != null) {
workbenchPage.bringToTop(view);
view.setURL((url != null) ? url.toExternalForm() : null);
}
}
@Override
public void activateEditor(IWorkbenchPage page,
IStructuredSelection selection) {
Object element= selection.getFirstElement();
IEditorPart part= CoreEditorUtils.isOpenInEditor(element);
if (part != null) {
page.bringToTop(part);
}
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IViewPart webAppView = page.findView(WebAppLaunchView.ID);
if (webAppView == null) {
try {
webAppView = page.showView(WebAppLaunchView.ID);
} catch (PartInitException e) {
return StatusUtilities.newErrorStatus(e, Activator.PLUGIN_ID);
}
}
if (webAppView != null) {
synchronized(boldingLock) {
if (bolding) {
if (webAppView.getSite() != null) {
IWorkbenchSiteProgressService service =
(IWorkbenchSiteProgressService) webAppView.getSite().getAdapter(
IWorkbenchSiteProgressService.class);
if (service != null) {
service.warnOfContentChange();
}
}
} else {
page.bringToTop(webAppView);
}
}
}
}
}
return Status.OK_STATUS;
}
/**
* Links to editor (if option enabled)
* @param selection the selection
*/
private void linkToEditor(ISelection selection) {
Object obj= SelectionUtil.getSingleElement(selection);
if (obj != null) {
IEditorPart part= EditorUtility.isOpenInEditor(obj);
if (part != null) {
IWorkbenchPage page= getSite().getPage();
page.bringToTop(part);
if (obj instanceof IJavaElement)
EditorUtility.revealInEditor(part, (IJavaElement)obj);
}
}
}
public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) {
if (selection == null || selection.isEmpty())
return;
Object element= selection.getFirstElement();
IEditorPart part= EditorUtility.isOpenInEditor(element);
if (part != null) {
page.bringToTop(part);
if (element instanceof IJavaElement)
EditorUtility.revealInEditor(part, (IJavaElement) element);
}
}
/**
* Links to editor (if option enabled)
* @param selection the selection
*/
private void linkToEditor(ISelection selection) {
Object obj= SelectionUtil.getSingleElement(selection);
if (obj != null) {
IEditorPart part= EditorUtility.isOpenInEditor(obj);
if (part != null) {
IWorkbenchPage page= getSite().getPage();
page.bringToTop(part);
if (obj instanceof IJavaElement)
EditorUtility.revealInEditor(part, (IJavaElement) obj);
}
}
}
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);
}
}
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);
}
}
}
/**
* @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);
}
}
}
/**
* Get the next position off the global mark ring and move to that file and location
*
* @param editor
* @param document
* @param currentSelection
* @param norotate - if true, pop else rotate and pop
* @return NO_OFFSET
* @throws BadLocationException
*/
protected int doTransform(ITextEditor editor, IDocument document, ITextSelection currentSelection, boolean norotate, boolean isTags)
throws BadLocationException {
// get editor and offset
IBufferLocation location = (isTags ? MarkUtils.popTagMark() : MarkUtils.popGlobalMark(norotate));
if (location != null) {
if (currentSelection != null &&
location.getEditor() == editor && location.getOffset() == currentSelection.getOffset()) {
// if we're already at the global mark location, move to next location
// recurse with no selection to avoid infinite loop if only one global location
return doTransform(editor,document,null,norotate, isTags);
}
ITextEditor jumpTo = location.getEditor();
int offset = location.getOffset();
IWorkbenchPage page = getWorkbenchPage();
IEditorPart part = jumpTo;
if (part != null) {
// move to the correct page
IEditorPart apart = part;
IEditorSite esite = part.getEditorSite();
if (esite instanceof MultiPageEditorSite) {
apart = ((MultiPageEditorSite)esite).getMultiPageEditor();
// handle multi page by activating the correct part within the parent
if (apart instanceof MultiPageEditorPart) {
((MultiPageEditorPart)apart).setActiveEditor(part);
}
}
// check to make sure the editor is still valid
if (page.findEditor(apart.getEditorInput()) != null) {
// then activate
page.activate(apart);
page.bringToTop(apart);
if (part instanceof ITextEditor) {
selectAndReveal((ITextEditor) part,offset,offset);
EmacsPlusUtils.clearMessage(part);
}
} else {
EmacsPlusUtils.showMessage(editor, String.format(BAD_MARK, apart.getTitle()), true);
}
}
} else {
beep();
}
return NO_OFFSET;
}
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;
}
/**
* @see com.mulgasoft.emacsplus.minibuffer.IMinibufferExecutable#executeResult(org.eclipse.ui.texteditor.ITextEditor, java.lang.Object)
*/
public boolean doExecuteResult(ITextEditor editor, Object minibufferResult) {
if (minibufferResult != null) {
String key = (String)minibufferResult;
IRegisterLocation location = TecoRegister.getInstance().getLocation(key);
if (location != null) {
IWorkbenchPage page = getWorkbenchPage();
IEditorPart part = location.getEditor();
int offset = location.getOffset();
if (part != null) {
// move to the correct page
IEditorPart apart = part;
IEditorSite esite = part.getEditorSite();
if (esite instanceof MultiPageEditorSite) {
apart = ((MultiPageEditorSite)esite).getMultiPageEditor();
// handle multi page by activating the correct part within the parent
if (apart instanceof MultiPageEditorPart) {
((MultiPageEditorPart)apart).setActiveEditor(part);
}
}
// now activate
page.activate(apart);
page.bringToTop(apart);
} else {
// restore the resource from the file system
if (location.getPath() != null) {
try {
// loads and activates
part = IDE.openEditor(page, location.getPath(), true);
if (part instanceof IEditorPart) {
if (part instanceof MultiPageEditorPart) {
IEditorPart[] parts = ((MultiPageEditorPart)part).findEditors(part.getEditorInput());
// TODO this will only work on the first load of a multi page
// There is no supported way to determine the correct sub part in this case
// Investigate org.eclipse.ui.PageSwitcher (used in org.eclipse.ui.part.MultiPageEditorPart)
// as a means for locating the correct sub page at this level
for (int i = 0; i < parts.length; i++) {
if (parts[i] instanceof ITextEditor) {
((MultiPageEditorPart)part).setActiveEditor(parts[i]);
part = parts[i];
break;
}
}
}
location.setEditor((ITextEditor)part);
}
} catch (PartInitException e) {
showResultMessage(editor, String.format(BAD_LOCATION,key + ' ' + e.getLocalizedMessage()), true);
}
} else {
showResultMessage(editor, String.format(NO_LOCATION,key), true);
}
}
if (part instanceof ITextEditor) {
((ITextEditor) part).selectAndReveal(offset, 0);
showResultMessage(editor, String.format(LOCATED, key), false);
} else {
}
} else {
showResultMessage(editor, NO_REGISTER, true);
}
}
return true;
}
public IEditorPart openBeanEditor(BeanItem beanItem, boolean readOnly) throws SystemException, PartInitException {
if (beanItem == null) {
return null;
}
ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault()
.getService(ICodeGeneratorService.class);
ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY))
.getProject().getLanguage();
ITalendSynchronizer routineSynchronizer = service.createRoutineSynchronizer();
// check if the related editor is open.
IWorkbenchPage page = getActivePage();
IEditorReference[] editorParts = page.getEditorReferences();
String talendEditorID = "org.talend.designer.core.ui.editor.StandAloneTalend" + lang.getCaseName() + "Editor"; //$NON-NLS-1$ //$NON-NLS-2$
boolean found = false;
IEditorPart talendEditor = null;
for (IEditorReference reference : editorParts) {
IEditorPart editor = reference.getEditor(false);
if (talendEditorID.equals(editor.getSite().getId())) {
// TextEditor talendEditor = (TextEditor) editor;
RepositoryEditorInput editorInput = (RepositoryEditorInput) editor.getEditorInput();
if (editorInput.getItem().equals(beanItem)) {
page.bringToTop(editor);
found = true;
talendEditor = editor;
break;
}
}
}
if (!found) {
routineSynchronizer.syncRoutine(beanItem, true);
IFile file = routineSynchronizer.getFile(beanItem);
if (file == null) {
return null;
}
RepositoryEditorInput input = new BeanEditorInput(file, beanItem);
input.setReadOnly(readOnly);
talendEditor = page.openEditor(input, talendEditorID); // $NON-NLS-1$
}
return talendEditor;
}