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

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

源代码1 项目: bonita-studio   文件: SaveAsImageHandler.java
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    //Remove Selection
    final DiagramEditor editor = (DiagramEditor) activePage.getActiveEditor();
    editor.getDiagramGraphicalViewer().setSelection(new StructuredSelection());
    final CopyToImageAction act = new CopyToImageAction(activePage) {

        @Override
        protected List createOperationSet() {
            if (getWorkbenchPart() instanceof DiagramEditor) {
                return Collections.singletonList(((DiagramEditor) getWorkbenchPart()).getDiagramEditPart());
            }
            return Collections.emptyList();
        }

        @Override
        protected void setWorkbenchPart(final IWorkbenchPart workbenchPart) {
            super.setWorkbenchPart(getWorkbenchPage().getActiveEditor());
        }

    };
    act.init();
    act.run();
    return null;
}
 
源代码2 项目: tmxeditor8   文件: XLIFFEditorImplWithNatTable.java
/**
 * 得到当前活动的 XLIFF 编辑器实例
 * @return ;
 */
public static XLIFFEditorImplWithNatTable getCurrent() {
	try {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (window != null) {
			IWorkbenchPage page = window.getActivePage();
			if (page != null) {
				IEditorPart editor = page.getActiveEditor();
				if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
					return (XLIFFEditorImplWithNatTable) editor;
				}
			}
		}
	} catch (NullPointerException e) {
		LOGGER.error("", e);
		e.printStackTrace();
	}
	return null;
}
 
public Object execute(ExecutionEvent event) throws ExecutionException {
	isSelected = !isSelected;				
	try {
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (window != null) {
			IWorkbenchPage page = window.getActivePage();
			if (page != null) {
				IEditorPart editor = page.getActiveEditor();
				if (editor != null && editor instanceof IXliffEditor) {
					((IXliffEditor) editor).refreshWithNonprinttingCharacter(isSelected);
				}
			}
		}
	} catch (NullPointerException e) {
		e.printStackTrace();
	}
	
	return null;
}
 
源代码4 项目: texlipse   文件: TexlipsePlugin.java
/**
 * Returns the reference to the project that owns the
 * file currently open in editor.
 * @return reference to the currently active project 
 */
public static IProject getCurrentProject() {
    IWorkbenchPage page = TexlipsePlugin.getCurrentWorkbenchPage();
    IEditorPart actEditor = null;
    if (page.isEditorAreaVisible()
         && page.getActiveEditor() != null) {
        actEditor = page.getActiveEditor();
    }
    else {
        return null;
    }
    IEditorInput editorInput = actEditor.getEditorInput();
    
    IFile aFile = (IFile)editorInput.getAdapter(IFile.class);
    if (aFile != null) return aFile.getProject();
    // If the first way does not gonna work...
    // actually this returns the file of the editor that was last selected
    IResource res = SelectedResourceManager.getDefault().getSelectedResource();
    return res == null ? null : res.getProject();
}
 
源代码5 项目: typescript.java   文件: OpenSymbolAction.java
@Override
public void runWithEvent(Event event) {
	Shell parent = TypeScriptUIPlugin.getActiveWorkbenchShell();

	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window != null) {
		IWorkbenchPage page = window.getActivePage();
		if (page != null) {
			if (page.getActiveEditor() instanceof TypeScriptEditor) {
				ITypeScriptFile tsFile = ((TypeScriptEditor) page.getActiveEditor()).getTypeScriptFile();
				OpenSymbolSelectionDialog dialog = new OpenSymbolSelectionDialog(tsFile, parent, true);
				int result = dialog.open();
				if (result == 0) {
					Object[] resources = dialog.getResult();
					if (resources != null && resources.length > 0) {
						NavtoItem item = (NavtoItem) resources[0];
						EditorUtils.openInEditor(item);
					}
				}
			}
		}
	}

}
 
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
	boolean enabled = false;
	IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window != null) {
		IWorkbenchPage page = window.getActivePage();
		if (page != null) {
			IEditorPart editor = page.getActiveEditor();
			if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
				XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
				if (xliffEditor != null && xliffEditor.getTable() != null) {
					List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
					enabled = (selectedRowIds != null && selectedRowIds.size() > 0);
				}
			}
		}
	}

	return enabled;
}
 
源代码7 项目: XPagesExtensionLibrary   文件: WizardUtils.java
public static String getXPageFileName() {
    IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IWorkbenchPage page = win.getActivePage();
    if (page != null) {
        IEditorPart editor = page.getActiveEditor();
        if (editor != null) {
            IEditorInput input = editor.getEditorInput();
            if (input instanceof IFileEditorInput) {
                return ((IFileEditorInput) input).getFile().getLocation().lastSegment();
            }
        }
    }
    return null;
}
 
源代码8 项目: gama   文件: WorkbenchHelper.java
public static IGamlEditor getActiveEditor() {
	final IWorkbenchPage page = getPage();
	if (page != null) {
		final IEditorPart editor = page.getActiveEditor();
		if (editor instanceof IGamlEditor) { return (IGamlEditor) editor; }
	}
	return null;
}
 
源代码9 项目: jbt   文件: Utilities.java
/**
 * Returns the currently active BTEditor, or null if no BTEditor is active.
 */
public static BTEditor getActiveBTEditor() {
	IWorkbenchPage page = getMainWindowActivePage();

	if (page != null) {
		IEditorPart editor = page.getActiveEditor();
		if (editor instanceof BTEditor)
			return (BTEditor) editor;
		else
			return null;
	}

	return null;
}
 
源代码10 项目: xds-ide   文件: WorkbenchUtils.java
/**
 * Fetches the editor currently in use. If the active editor is a multi page
 * editor and the param getSubEditor is true, then the editor of the active
 * page is returned instead of the multi page editor.
 * 
 * @param getSubEditor
 *            indicates that a sub editor should be returned
 * @return the active editor or <code>null</code> if no editor is active
 */
public static IEditorPart getActiveEditor(boolean getSubEditor) {
    IWorkbenchPage page = getActivePage();
    if (page != null) {
        IEditorPart result = page.getActiveEditor();
        if (getSubEditor && (result instanceof FormEditor)) {
            result = ((FormEditor) result).getActiveEditor();
        }
        return result;
    }
    return null;
}
 
源代码11 项目: e4macs   文件: EmacsPlusUtils.java
public static ITextEditor getCurrentEditor() {
	ITextEditor result = null;
	IWorkbenchPage page = getWorkbenchPage();
	if (page != null) {
		IEditorPart activeEditor = page.getActiveEditor();
		result = getActiveTextEditor(activeEditor);
	}
	return result;
}
 
源代码12 项目: statecharts   文件: UIUtils.java
public static DiagramDocumentEditor getActiveEditor() {
	final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	final IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
	if (workbenchPage != null) {
		final IEditorPart editor = workbenchPage.getActiveEditor();
		if (editor instanceof DiagramDocumentEditor) {
			return (DiagramDocumentEditor)editor;
		}
	}
	return null;
}
 
源代码13 项目: xtext-xtend   文件: FieldInitializerUtil.java
public IJavaElement getSelectedResource(IStructuredSelection selection) {
	IJavaElement elem = null;
	if(selection != null && !selection.isEmpty()){
		Object o = selection.getFirstElement();
		elem = Adapters.adapt(o, IJavaElement.class);
		if(elem == null){
			elem = getPackage(o);
		}
	}
	if (elem == null) {
		IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IWorkbenchPart part = activePage.getActivePart();
		if (part instanceof ContentOutline) {
			part= activePage.getActiveEditor();
		}
		if (part instanceof XtextEditor) {
			IXtextDocument doc = ((XtextEditor)part).getDocument();
			IFile file = Adapters.adapt(doc, IFile.class);
			elem = getPackage(file);
		}
	}
	if (elem == null || elem.getElementType() == IJavaElement.JAVA_MODEL) {
		try {
			IJavaProject[] projects= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
			if (projects.length == 1) {
				elem= projects[0];
			}
		} catch (JavaModelException e) {
			throw new RuntimeException(e.getMessage());
		}
	}
	return elem;
}
 
源代码14 项目: tlaplus   文件: UIHelper.java
/**
 * @return The currently active editor
 */
public static IEditorPart getActiveEditor() {
	final IWorkbenchPage activePage = getActivePage();
	if (activePage != null) {
		// At Toolbox startup, activePage can be null.
		return activePage.getActiveEditor();
	}
	return null;
}
 
private IWorkbenchSite getSite() {
	IEditorPart editor= getEditor();
	if (editor == null) {
		IWorkbenchPage page= JavaPlugin.getActivePage();
		if (page != null)
			editor= page.getActiveEditor();
	}
	if (editor != null)
		return editor.getSite();

	return null;
}
 
源代码16 项目: gwt-eclipse-plugin   文件: SseUtilities.java
/**
 * @return the active structured text viewer, or null
 */
public static StructuredTextViewer getActiveTextViewer() {
  // Need to get the workbench window from the UI thread
  final IWorkbenchWindow[] windowHolder = new IWorkbenchWindow[1];
  Display.getDefault().syncExec(new Runnable() {
    public void run() {
      windowHolder[0] = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    }
  });
 
  IWorkbenchWindow window = windowHolder[0];
  if (window == null) {
    return null;
  }
  
  IWorkbenchPage page = window.getActivePage();
  if (page == null) {
    return null;
  }

  IEditorPart editor = page.getActiveEditor();
  if (editor == null) {
    return null;
  }

  /*
   * TODO: change the following to use AdapterUtilities.getAdapter()
   * and either a) have GWTD register an adapter factory or b) add a direct
   * IAdaptable.getAdapter() call to AdapterUtilities.getAdapter().
   */
  StructuredTextEditor structuredEditor = (StructuredTextEditor) editor.getAdapter(StructuredTextEditor.class);
  if (structuredEditor == null) {
    return null;
  }

  return structuredEditor.getTextViewer();
}
 
private ITextEditor getActiveEditor() {
	IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	if (window != null) {
		IWorkbenchPage page= window.getActivePage();
		if (page != null) {
			IEditorPart editor= page.getActiveEditor();
			if (editor instanceof ITextEditor)
				return (JavaEditor) editor;
		}
	}
	return null;
}
 
源代码18 项目: birt   文件: UIUtil.java
public static IProject getCurrentProject( )
{
    IWorkbench iworkbench = PlatformUI.getWorkbench( );
    if ( iworkbench == null )
    {
        return null;
    }

    IWorkbenchWindow iworkbenchwindow = iworkbench
            .getActiveWorkbenchWindow( );
    if ( iworkbenchwindow == null )
    {
        return null;
    }

    IWorkbenchPage iworkbenchpage = iworkbenchwindow.getActivePage( );
    if ( iworkbenchpage != null )
    {
        IEditorPart ieditorpart = iworkbenchpage.getActiveEditor( );
        if ( ieditorpart != null )
        {
            IEditorInput input = ieditorpart.getEditorInput( );
            if ( input != null )
            {
                IProject project = (IProject) ElementAdapterManager
                        .getAdapter( input, IProject.class );
                if ( project != null )
                {
                    return project;
                }
            }
        }
    }

    ISelection selection = iworkbenchwindow.getSelectionService( )
            .getSelection( );
    if ( selection instanceof IStructuredSelection )
    {
        Object element = ( (IStructuredSelection) selection )
                .getFirstElement( );
        if ( element instanceof IResource )
        {
            return ( (IResource) element ).getProject( );
        }
    }
    return null;
}
 
源代码19 项目: xtext-eclipse   文件: ImportURINavigationTest.java
protected void doTestNavigation(IUnitOfWork<URI, IFile> uriComputation, boolean expectFQN) throws Exception {
	IJavaProject project = JavaProjectSetupUtil.createJavaProject("importuriuitestlanguage.project");
	try {
		IFile first = project.getProject().getFile("src/first.importuriuitestlanguage");
		first.create(new StringInputStream("type ASimpleType"), true, null);
		
		ResourceSet resourceSet = resourceSetProvider.get(project.getProject());
		
		Resource resource = resourceFactory.createResource(URI.createURI("synthetic://second.importuriuitestlanguage"));
		resourceSet.getResources().add(resource);
		String model = "import '" + uriComputation.exec(first) + "' type MyType extends ASimpleType";
		resource.load(new StringInputStream(model), null);
		EcoreUtil.resolveAll(resource);
		Assert.assertTrue(resource.getErrors().isEmpty());
		
		IHyperlink[] hyperlinks = helper.createHyperlinksByOffset((XtextResource) resource, model.indexOf("SimpleType"), false);
		Assert.assertEquals(1, hyperlinks.length);
		IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
		Assert.assertNull(activePage.getActiveEditor());
		if (expectFQN) {
			Assert.assertEquals(URI.createURI(first.getLocationURI().toString()), ((XtextHyperlink)hyperlinks[0]).getURI().trimFragment());
		} else {
			Assert.assertEquals(URI.createPlatformResourceURI(first.getFullPath().toString(), true), ((XtextHyperlink)hyperlinks[0]).getURI().trimFragment());
		}
		hyperlinks[0].open();
		IEditorPart editor = activePage.getActiveEditor();
		Assert.assertNotNull(editor);
		IXtextDocument document = xtextDocumentUtil.getXtextDocument(editor);
		document.readOnly(new IUnitOfWork.Void<XtextResource>() {
			@Override
			public void process(XtextResource state) throws Exception {
				Assert.assertEquals("platform:/resource/importuriuitestlanguage.project/src/first.importuriuitestlanguage", state.getURI().toString());
			}
		});
		Assert.assertEquals("type ASimpleType", document.get());
		IEditorPart newPart = IDE.openEditor(activePage, first);
		Assert.assertEquals(1, activePage.getEditorReferences().length);
		Assert.assertEquals(editor, newPart);
	} finally {
		project.getProject().delete(true, null);
	}
}
 
源代码20 项目: bonita-studio   文件: ExportAsBPMNHandler.java
@CanExecute
public boolean isDiagramEditorActive(IWorkbenchPage activePage) {
    return activePage != null && activePage.getActiveEditor() instanceof ProcessDiagramEditor;
}