org.eclipse.ui.IEditorPart#getSite ( )源码实例Demo

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

源代码1 项目: tm4e   文件: TMinGenericEditorTest.java
@After
public void tearDown() {
	final IEditorPart currentEditor = editor;
	if (currentEditor != null) {
		final IWorkbenchPartSite currentSite = currentEditor.getSite();
		if (currentSite != null) {
			final IWorkbenchPage currentPage = currentSite.getPage();
			if (currentPage != null) {
				currentPage.closeEditor(currentEditor, false);
			}
		}
	}
	editor = null;
	f.delete();
	f = null;
}
 
源代码2 项目: google-cloud-eclipse   文件: ServiceUtils.java
/**
 * Returns an OSGi service from {@link ExecutionEvent}. It looks up a service in the following
 * locations (if exist) in the given order:
 *
 * {@code HandlerUtil.getActiveSite(event)}
 * {@code HandlerUtil.getActiveEditor(event).getEditorSite()}
 * {@code HandlerUtil.getActiveEditor(event).getSite()}
 * {@code HandlerUtil.getActiveWorkbenchWindow(event)}
 * {@code PlatformUI.getWorkbench()}
 */
public static <T> T getService(ExecutionEvent event, Class<T> api) {
  IWorkbenchSite activeSite = HandlerUtil.getActiveSite(event);
  if (activeSite != null) {
    return activeSite.getService(api);
  }

  IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
  if (activeEditor != null) {
    IEditorSite editorSite = activeEditor.getEditorSite();
    if (editorSite != null) {
      return editorSite.getService(api);
    }
    IWorkbenchPartSite site = activeEditor.getSite();
    if (site != null) {
      return site.getService(api);
    }
  }

  IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
  if (workbenchWindow != null) {
    return workbenchWindow.getService(api);
  }

  return PlatformUI.getWorkbench().getService(api);
}
 
源代码3 项目: gama   文件: GamlSearchField.java
public void search() {
	final IWorkbenchPart part = WorkbenchHelper.getActivePart();
	if (part instanceof IEditorPart) {
		final IEditorPart editor = (IEditorPart) part;
		final IWorkbenchPartSite site = editor.getSite();
		if (site != null) {
			final ISelectionProvider provider = site.getSelectionProvider();
			if (provider != null) {
				final ISelection viewSiteSelection = provider.getSelection();
				if (viewSiteSelection instanceof TextSelection) {
					final TextSelection textSelection = (TextSelection) viewSiteSelection;
					text.setText(textSelection.getText());
				}
			}
		}

	}
	activate(null);
	text.setFocus();

}
 
源代码4 项目: Pydev   文件: EditorUtils.java
public static IWorkbenchPartSite getSite() {
    final IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
    if (activeWorkbenchWindow == null) {
        return null;
    }
    IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
    if (activePage == null) {
        return null;
    }
    IEditorPart activeEditor = activePage.getActiveEditor();
    if (activeEditor == null) {
        return null;
    }
    return activeEditor.getSite();
}
 
源代码5 项目: CogniCrypt   文件: CodeGenerator.java
/**
 * This method organizes imports for all generated files and the file, in which the call code for the generated classes is inserted.
 *
 * @param editor
 *        Editor with the currently open file
 * @throws CoreException
 *         {@link DeveloperProject#refresh() refresh()} and {@link DeveloperProject#getPackagesOfProject(String) getPackagesOfProject()}
 */
protected void cleanUpProject(IEditorPart editor) throws CoreException {
	this.project.refresh();
	final ICompilationUnit[] generatedCUnits = this.project.getPackagesOfProject(Constants.PackageNameAsName).getCompilationUnits();
	boolean anyFileOpen = false;

	if (editor == null && generatedCUnits[0].getResource().getType() == IResource.FILE) {
		IFile genClass = (IFile) generatedCUnits[0].getResource();
		IDE.openEditor(UIUtils.getCurrentlyOpenPage(), genClass);
		editor = UIUtils.getCurrentlyOpenPage().getActiveEditor();
		anyFileOpen = true;
	}

	final OrganizeImportsAction organizeImportsActionForAllFilesTouchedDuringGeneration = new OrganizeImportsAction(editor.getSite());
	final FormatAllAction faa = new FormatAllAction(editor.getSite());
	faa.runOnMultiple(generatedCUnits);
	organizeImportsActionForAllFilesTouchedDuringGeneration.runOnMultiple(generatedCUnits);

	if (anyFileOpen) {
		UIUtils.closeEditor(editor);
	}

	final ICompilationUnit openClass = JavaCore.createCompilationUnitFrom(UIUtils.getCurrentlyOpenFile(editor));
	organizeImportsActionForAllFilesTouchedDuringGeneration.run(openClass);
	faa.runOnMultiple(new ICompilationUnit[] { openClass });
	editor.doSave(null);
}
 
private IProgressService getProgressService() {
	IEditorPart editor= getTextEditor();
	if (editor != null) {
		IWorkbenchPartSite site= editor.getSite();
		if (site != null)
			return (IWorkbenchSiteProgressService) editor.getSite().getAdapter(IWorkbenchSiteProgressService.class);
	}
	return PlatformUI.getWorkbench().getProgressService();
}
 
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;
}
 
源代码8 项目: bonita-studio   文件: FullscreenHandler.java
public Object execute(ExecutionEvent event) throws ExecutionException {
		IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() ;

		if(part != null && part.getEditorSite().getPage().isPageZoomed()){
			PlatformUtil.restoreWindow(part.getEditorSite().getPage()) ;
			if(coolbarSize > 0 && coolbarSize < 60){
				new SmallCoolBarHandler().execute(null) ;
			}else if(coolbarSize >= 60){
				new NormalCoolBarHandler().execute(null) ;
			}
		}else{
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow() ;
			for(Control c : window.getShell().getChildren()){
				if(((Composite)c).getChildren().length > 0){
					if( (((Composite)c).getChildren())[0] instanceof BonitaSashForm){
						BonitaSashForm sash = (BonitaSashForm) (((Composite)c).getChildren())[0] ;
						coolbarSize = sash.getWeights()[0] ;
					}
				}
			}
			new SmallCoolBarHandler().execute(null) ;
//			if(part instanceof DiagramEditor){
////				FlyoutPaletteComposite paletteComposite = (FlyoutPaletteComposite) ((FigureCanvas) ((DiagramEditor)part).getDiagramGraphicalViewer().getControl()).getParent().getParent() ;
////
////				for(Method m : FlyoutPaletteComposite.class.getDeclaredMethods()){
////					if(m.getName().equals("setState")){
////						m.setAccessible(true) ;
////						try {
////							m.invoke(paletteComposite, new Integer(PaletteViewerPreferences.COLLAPSE_ALWAYS)) ;
////						} catch (Exception e) {
////							BonitaStudioLog.error(e) ;
////						}
////					}
////				}
//			}
			if(part != null && part.getSite() != null){
				PlatformUtil.maximizeWindow(part.getEditorSite().getPage(),part.getEditorSite().getPage().getReference(part)) ;
			}
		}
		return null;
	}