public static @Nullable ISelection getActiveSelection(@Nullable IWorkbenchSite site) { try { if (site == null) { return null; } IWorkbenchWindow workbenchWindow = site.getWorkbenchWindow(); if (workbenchWindow == null) { return null; } IWorkbenchPage activePage = workbenchWindow.getActivePage(); if (activePage == null) { return null; } IEditorPart activeEditor = activePage.getActiveEditor(); if (activeEditor == null) { return null; } IEditorSite editorSite = activeEditor.getEditorSite(); if (editorSite == null) { return null; } ISelectionProvider selectionProvider = editorSite.getSelectionProvider(); if (selectionProvider == null) { return null; } return selectionProvider.getSelection(); } catch (Exception e) { return null; } }
/** * We just store the input and site to catch events * * @param input : the input to set * @param site : the site to set */ @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { IContextService contextService = (IContextService) site.getService(IContextService.class); contextService.activateContext(GRAPH_CONTEXT_ID); handlerService = (IHandlerService) site.getService(IHandlerService.class); setSite(site); setInput(input); }
/** * This is called during startup. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ public void init(IEditorSite site, IEditorInput editorInput) { setSite(site); setInputWithNotify(editorInput); setPartName(editorInput.getName()); site.setSelectionProvider(this); site.getPage().addPartListener(partListener); ResourcesPlugin.getWorkspace() .addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE); }
/** {@inheritDoc} */ @Override public void init(final IEditorSite site, final IEditorInput input) throws PartInitException { setSite(site); internalInit(site.getWorkbenchWindow(), site, input); }
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { super.init(site, input); // Show the 'presentation' action set with the 'Toggle Block SelectionMode' and // 'Show Whitespace Characters' actions. IWorkbenchPage page = site.getPage(); page.showActionSet("org.eclipse.ui.edit.text.actionSet.presentation"); }
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { setSite(site); setInput(input); this.display = site.getShell().getDisplay(); IPath path = ((IPathEditorInput) input).getPath(); selectedFile = path.toFile(); fileName = selectedFile.getAbsolutePath(); }
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { if (!(input instanceof TaskEditorInput)) { throw new PartInitException( "Invalid editor input \"" + input.getClass() + "\""); // $NON-NLS-1$ //$NON-NLS-2$ } super.init(site, input); this.taskEditorInput = (TaskEditorInput) input; this.task = taskEditorInput.getTask(); // initialize selection site.getSelectionProvider().setSelection(new StructuredSelection(task)); setPartName(input.getName()); // activate context IContextService contextSupport = (IContextService) site.getService(IContextService.class); if (contextSupport != null) { contextSupport.activateContext(ID_EDITOR); } }