Java Code Examples for org.eclipse.ui.IEditorPart#getSite()

The following examples show how to use org.eclipse.ui.IEditorPart#getSite() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TMinGenericEditorTest.java    From tm4e with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: ServiceUtils.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 3
Source File: GamlSearchField.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
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();

}
 
Example 4
Source File: EditorUtils.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
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();
}
 
Example 5
Source File: CodeGenerator.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: ClipboardOperationAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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();
}
 
Example 7
Source File: JavadocHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: FullscreenHandler.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
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;
	}