protected void updatePictogramElement(PictogramElement pe) { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); DiagramEditor ds; if (page.getActiveEditor() instanceof DiagramEditor) { ds = (DiagramEditor) page.getActiveEditor(); } else { ds = ((MultiPageEditor) page.getActiveEditor()).getDiagramEditor(); } UpdateContext context = new UpdateContext(pe); ds.getDiagramTypeProvider().getFeatureProvider().updateIfPossible(context); }
@Override public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { // If the selection event source is different from the active part, // that means the selection change has not been triggered by a user // action. In that case we do nothing to avoid loops. if (event.getSource() != getActivePartSource()) { return; } // If the selection come from the navigator, we select the // corresponding representations elements. if (event.getSource().equals(navigator.getCommonViewer())) { IWorkbenchPage page = EclipseUIUtil.getActivePage(); IEditorPart activeEditor = page.getActiveEditor(); if (activeEditor instanceof DialectEditor) { DialectEditor dialectEditor = (DialectEditor) activeEditor; page.bringToTop(dialectEditor); selectRepresentationElements(selection, dialectEditor); } } else { Set<EObject> targets = getTargetsFromSelection((IStructuredSelection) selection); if (!targets.isEmpty()) { navigator.selectReveal(new StructuredSelection(targets.toArray())); } } } }
/** @see ContentOutlinePage#createControl */ public void createControl(Composite parent) { super.createControl(parent); ColumnViewerToolTipSupport.enableFor(getTreeViewer()); IWorkbenchPage page = getSite().getWorkbenchWindow().getActivePage(); if (page != null) { fEditor = page.getActiveEditor(); } fDragAdapter = new DelegatingDragAdapter(); fDragSource = new DragSource(getControl(), DND.DROP_COPY | DND.DROP_MOVE); fDropAdapter = new DelegatingDropAdapter(); fDropTarget = new DropTarget(getControl(), DND.DROP_COPY | DND.DROP_MOVE); setConfiguration(getConfiguration()); /* * ContentOutlinePage only implements ISelectionProvider while the * tree viewer implements both ISelectionProvider and * IPostSelectionProvider. Use an ISelectionProvider that listens to * post selection from the tree viewer and forward only post selection * to the selection service. */ getTreeViewer() .addPostSelectionChangedListener(fSelectionProvider.getPostSelectionChangedListener()); getTreeViewer().addSelectionChangedListener(fSelectionProvider.getSelectionChangedListener()); if (fDoubleClickProvider == null) { fDoubleClickProvider = new DoubleClickProvider(); } getTreeViewer().addDoubleClickListener(fDoubleClickProvider); getSite().setSelectionProvider(fSelectionProvider); }
protected void attemptToSetActiveEditor() { IWorkbenchPage activePage = this.getSite().getWorkbenchWindow().getActivePage(); if (activePage != null) { IEditorPart activeEditor = activePage.getActiveEditor(); if (activeEditor != null) this.handleEditorActivation(activeEditor); } }
@Override public Object getNewObject() { Circle circle = null; try { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); circle = new Circle(); InputDialog id = new InputDialog( new Shell(), "Circle Name", "Please give a name for the circle!", "", null); int open = id.open(); if (open == 0) { if (!id.getValue().equals("")) { circle.setName(id.getValue()); } } ModelProvider.INSTANCE.getModel().addChild(circle); UMLGraphicalEditor editor = (UMLGraphicalEditor) page.getActiveEditor(); editor.refresh(); } catch (Exception e) { e.printStackTrace(); } return circle; }
/** * Opens the editor currently associated with the given element (DartElement, IFile, IStorage...) * * @return an open editor or <code>null</code> if an external editor was opened * @throws PartInitException if the editor could not be opened or the input element is not valid */ public static IEditorPart openInEditor(Object inputElement, boolean activate) throws DartModelException, PartInitException { if (inputElement instanceof IFile) { return openInEditor((IFile) inputElement, activate); } DartX.todo(); if (inputElement instanceof ImportElement) { inputElement = ((ImportElement) inputElement).getImportedLibrary(); } if (inputElement instanceof Element) { CompilationUnitElement cu = getCompilationUnit((Element) inputElement); IWorkbenchPage page = DartToolsPlugin.getActivePage(); if (cu != null && page != null) { IEditorPart editor = page.getActiveEditor(); if (editor != null) { Element editorCU = EditorUtility.getEditorInputDartElement2(editor, false); if (cu.equals(editorCU)) { if (activate && page.getActivePart() != editor) { page.activate(editor); } return editor; } } } } IEditorInput input = getEditorInput(inputElement); if (input == null) { return null; } return openInEditor(input, getEditorID(input), activate); }
/** * Since these actions are re-created each time the run/debug as menu is filled, the enablement of * this action is static. */ private void updateEnablement() { IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow(); boolean enabled = false; if (wb != null) { IWorkbenchPage page = wb.getActivePage(); if (page != null) { ISelection selection = page.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; try { // check enablement logic, if any Expression expression = fShortcut.getShortcutEnablementExpression(); if (expression == null) { enabled = !structuredSelection.isEmpty(); } else { List list = structuredSelection.toList(); IEvaluationContext context = new EvaluationContext(null, list); context.addVariable("selection", list); // $NON-NLS-1$ enabled = fShortcut.evalEnablementExpression(context, expression); } } catch (CoreException e) { } } else { IEditorPart editor = page.getActiveEditor(); if (editor != null) { enabled = true; } } } } setEnabled(enabled); }
private IEditorPart getActiveEditor() { final IWorkbenchPage activePage = ErlideUIPlugin.getActivePage(); if (activePage != null) { return activePage.getActiveEditor(); } return null; }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart activeEditor = page.getActiveEditor(); if (activeEditor instanceof OPIEditor) { ISelection currentSelection = ((GraphicalViewer) ((OPIEditor) activeEditor).getAdapter(GraphicalViewer.class)) .getSelection(); if (currentSelection instanceof IStructuredSelection) { Object element = ((IStructuredSelection) currentSelection).getFirstElement(); if (element instanceof AbstractLayoutEditpart) { CommandStack commandStack = (CommandStack) ((OPIEditor) activeEditor).getAdapter(CommandStack.class); if (commandStack != null) LayoutWidgetsImp.run((AbstractLayoutEditpart) element, commandStack); } } } else { return null; } return null; }
public static IWorkbench getMockWorkbench(String file) { IWorkbench workbench = mock(IWorkbench.class); IWorkbenchWindow window = mock(IWorkbenchWindow.class); IWorkbenchPage page = mock(IWorkbenchPage.class); ITextEditor editor = mock(ITextEditor.class); IDocumentProvider docProvider = mock(IDocumentProvider.class); IDocument doc = mock(IDocument.class); IPath ipath = mock(IPath.class); File afile = mock(File.class); IFile inputFile = mock(IFile.class); IFileEditorInput editorInput = mock(IFileEditorInput.class); when(workbench.getWorkbenchWindows()).thenReturn(new IWorkbenchWindow[] {window}); when(window.getActivePage()).thenReturn(page); when(page.getActiveEditor()).thenReturn(editor); when(editor.getEditorInput()).thenReturn(editorInput); when(editor.getDocumentProvider()).thenReturn(docProvider); when(editorInput.getFile()).thenReturn(inputFile); when(docProvider.getDocument(any())).thenReturn(doc); when(inputFile.getLocation()).thenReturn(ipath); when(inputFile.getName()).thenReturn(file); when(ipath.toFile()).thenReturn(afile); when(afile.length()).thenReturn(33l); return workbench; }
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; } }
@Override public void doRun(ISelection selection, Event event, UIInstrumentationBuilder instrumentation) { instrumentation.metric("command", command); if (!(selection instanceof ITextSelection)) { instrumentation.metric("Problem", "Selection was not a TextSelection"); } IWorkbenchPage page = DartToolsPlugin.getActivePage(); if (page == null) { instrumentation.metric("Problem", "Page was null"); return; } IEditorPart part = page.getActiveEditor(); if (part == null) { instrumentation.metric("Problem", "Part was null"); return; } IEditorInput editorInput = part.getEditorInput(); IProject project = EditorUtility.getProject(editorInput); instrumentation.data("Project", project.getName()); savePubspecFile(project); runPubJob(project); }
/** * Returns the editor part representing the current active editor. * * @return the active editor */ public static IEditorPart getActiveEditor() { IWorkbenchPage workbenchPage = getActivePage(); if (workbenchPage == null) { return null; } return workbenchPage.getActiveEditor(); }
private GradleProject getContext() { IWorkbench wb = PlatformUI.getWorkbench(); IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); IWorkbenchPage page = win == null ? null : win.getActivePage(); if (page != null) { ISelection selection = page.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (!ss.isEmpty()) { Object obj = ss.getFirstElement(); if (obj instanceof IResource) { IResource rsrc = (IResource) obj; IProject prj = rsrc.getProject(); if (prj != null) { return GradleCore.create(prj); } } } } IEditorPart part = page.getActiveEditor(); if (part != null) { IEditorInput input = part.getEditorInput(); IResource rsrc = (IResource) input.getAdapter(IResource.class); if (rsrc != null) { IProject prj = rsrc.getProject(); if (prj != null) { return GradleCore.create(prj); } } } } return null; }
public boolean isReadOnly() { XSDSchema xsdSchema = null; try { IEditorPart editorPart = null; IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { editorPart = page.getActiveEditor(); } } if (target instanceof XSDConcreteComponent) { xsdSchema = ((XSDConcreteComponent) target).getSchema(); } if (editorPart == null) { return fallBackCheckIsReadOnly(); } XSDSchema editorSchema = (XSDSchema) editorPart.getAdapter(XSDSchema.class); if (xsdSchema != null && xsdSchema == editorSchema) { return false; } else { return fallBackCheckIsReadOnly(); } } catch (Exception e) { } return true; }
private IProject guessProject(IStructuredSelection selection) { if (selection == null) { return null; } for (Object element : selection.toList()) { if (element instanceof IAdaptable) { IResource res = (IResource) ((IAdaptable) element).getAdapter(IResource.class); IProject project = res != null ? res.getProject() : null; // Is this an Android project? try { if (project == null || !project.hasNature(AdtConstants.NATURE_DEFAULT)) { continue; } } catch (CoreException e) { // checking the nature failed, ignore this resource continue; } return project; } else if (element instanceof Pair<?, ?>) { // Pair of Project/String @SuppressWarnings("unchecked") Pair<IProject, String> pair = (Pair<IProject, String>) element; return pair.getFirst(); } } // Try to figure out the project from the active editor IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window != null) { IWorkbenchPage page = window.getActivePage(); if (page != null) { IEditorPart activeEditor = page.getActiveEditor(); if (activeEditor instanceof AndroidXmlEditor) { Object input = ((AndroidXmlEditor) activeEditor).getEditorInput(); if (input instanceof FileEditorInput) { FileEditorInput fileInput = (FileEditorInput) input; return fileInput.getFile().getProject(); } } } } IJavaProject[] projects = BaseProjectHelper.getAndroidProjects( new IProjectFilter() { public boolean accept(IProject project) { return project.isAccessible(); } }); if (projects != null && projects.length == 1) { return projects[0].getProject(); } return null; }
/** * Provide the initialization of the listeners additions. The Window, Part, and Document Listener * are added. Note that sensor shell should be instantiated before this method is called because * <code>processActivity()</code> method uses sensor shell instance. */ private void registerListeners() { IWorkbench workbench = EclipseSensorPlugin.getInstance().getWorkbench(); // :RESOLVED: JULY 1, 2003 // Supports the multiple window for sensor collection. IWorkbenchWindow[] activeWindows = workbench.getWorkbenchWindows(); // Check if window listener is not added yet. Otherwise multi instances are notified. if (this.windowListener == null) { this.windowListener = new WindowListenerAdapter(); workbench.addWindowListener(new WindowListenerAdapter()); } for (int i = 0; i < activeWindows.length; i++) { IWorkbenchPage activePage = activeWindows[i].getActivePage(); activePage.addPartListener(new PartListenerAdapter()); IEditorPart activeEditorPart = activePage.getActiveEditor(); // Adds this EclipseSensorPlugin instance to IDocumentListener // only when activeEditorPart is the instance of ITextEditor // so that null case is also ignored. if (activeEditorPart instanceof ITextEditor) { // Sets activeTextEditor. Otherwise a first activated file would not be recorded. this.activeTextEditor = (ITextEditor) activeEditorPart; // Gets opened file since the initial opened file is not notified from IPartListener. URI fileResource = EclipseSensor.this.getFileResource(this.activeTextEditor); Map<String, String> keyValueMap = new HashMap<String, String>(); keyValueMap.put(EclipseSensorConstants.SUBTYPE, "Open"); keyValueMap.put(EclipseSensorConstants.UNIT_TYPE, EclipseSensorConstants.FILE); keyValueMap.put( EclipseSensorConstants.UNIT_NAME, EclipseSensor.this.extractFileName(fileResource)); this.addDevEvent( EclipseSensorConstants.DEVEVENT_EDIT, fileResource, keyValueMap, "Opened " + fileResource.toString()); IDocumentProvider provider = this.activeTextEditor.getDocumentProvider(); IDocument document = provider.getDocument(activeEditorPart.getEditorInput()); // Initially sets active buffer and threshold buffer. // Otherwise a first activated buffer would not be recorded. this.activeBufferSize = document.getLength(); this.thresholdBufferSize = document.getLength(); document.addDocumentListener(new DocumentListenerAdapter()); } } // Handles breakpoint set/unset event. IBreakpointManager bpManager = DebugPlugin.getDefault().getBreakpointManager(); bpManager.addBreakpointListener(new BreakPointerSensor(this)); // Listens to debug event. DebugPlugin.getDefault().addDebugEventListener(new DebugSensor(this)); // Creates instance to handle build error. this.buildErrorSensor = new BuildErrorSensor(this); }
@Override protected IWorkbenchPart getBootstrapPart() { final IWorkbenchPage page = getSite().getPage(); if (page != null) { return page.getActiveEditor(); } return null; }
public void setTabEnable(boolean enable) { boolean flag = false; IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if (page != null) { if (page.getActiveEditor() instanceof MultiPageEditorPart) { MultiPageEditorPart editor = (MultiPageEditorPart) page.getActiveEditor(); if (editor != null) { if (editor.getActivePage() == PAGE) { flag = true; } } } } if (enable) { tableNebulas.setEnabled(true); } }
private IProgressMonitor getProgressMonitor() { IWorkbenchPage wbPage = JavaPlugin.getActivePage(); if (wbPage == null) return null; IEditorPart editor = wbPage.getActiveEditor(); if (editor == null) return null; return editor.getEditorSite().getActionBars().getStatusLineManager().getProgressMonitor(); }
@Override public void run() { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); IEditorPart editorPart = page.getActiveEditor(); if (editorPart instanceof MultiPageTalendEditor) { ((MultiPageTalendEditor) editorPart).showCodePage(); } }
/** If the current active editor is {@link DartEditor}, return it, else return null. */ public static DartEditor getActiveEditor() { IWorkbenchPage page = DartToolsPlugin.getActivePage(); if (page != null) { IEditorPart part = page.getActiveEditor(); if (part instanceof DartEditor) { return (DartEditor) part; } } return null; }
public void createPartControl(Composite parent) { viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); viewer.setContentProvider(contentProvider); viewer.setLabelProvider(new ViewLabelProvider()); viewer.setInput(getViewSite()); getSite().getPage().addPartListener(editorListener); IWorkbenchPage page = getSite().getPage(); setGrammarEditor(page.getActiveEditor()); }
protected IEditorPart getEditor() { IEditorPart editor = null; IWorkbenchWindow activeWorkbenchWindow = getActiveWorkbenchWindow(); if (activeWorkbenchWindow != null) { IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); if (activePage != null) { editor = activePage.getActiveEditor(); } } return editor; }
private boolean isSmartMode() { IWorkbenchPage page = AtlUIPlugin.getActivePage(); if (page != null) { IEditorPart part = page.getActiveEditor(); if (part instanceof ITextEditorExtension3) { ITextEditorExtension3 extension = (ITextEditorExtension3) part; return extension.getInsertMode() == ITextEditorExtension3.SMART_INSERT; } } return false; }
/* (non-Javadoc) * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() */ @Override protected IContributionItem[] getContributionItems() { // Get the view IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = window.getActivePage(); ILogViewEditor editor = (ILogViewEditor) page.getActiveEditor().getAdapter(ILogViewEditor.class); if (editor != null) { return doGetContributionItems(editor); } return new IContributionItem[0]; }
public IEditorPart getActiveEditor() { IWorkbenchPage activePage = fWorkbenchWindow.getActivePage(); if (activePage == null) return null; IWorkbenchPart activePart = activePage.getActivePart(); if (activePart == null) return null; IEditorPart activeEditor = activePage.getActiveEditor(); if (activeEditor == activePart || isOldSearchView(activePart)) return activeEditor; return null; }
public ISpace getCurrentSpace() { IWorkbenchPage page = getWindow().getActivePage(); if (page == null) { return null; } IEditorPart editor = page.getActiveEditor(); if (editor == null || !(editor.getEditorInput() instanceof SpaceEditorInput)) { return null; } return ((SpaceEditorInput) editor.getEditorInput()).getSpace(); }
private boolean isWorkbenchReady() { IWorkbenchPage activePage = window.getActivePage(); if (activePage == null) return false; IEditorPart editor = activePage.getActiveEditor(); if (editor == null || editor.getEditorInput() == null) return false; IWorkingCopy wc = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()); if (wc == null) return false; project = wc.getCProject(); file = (IFile) wc.getResource(); return project != null && file != null; }
/** * Runs with either the active editor or workbench selection. * * @see IAction#run() */ public void run() { IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow(); if (wb != null) { IWorkbenchPage page = wb.getActivePage(); if (page != null) { if (page.getActivePart() == page.getActiveEditor()) { IEditorPart editor = page.getActiveEditor(); if (editor != null) { fShortcut.launch(editor, fMode); } } else if (page.getActivePart() instanceof IJobSettingsView) { ISelection selection = ((IJobSettingsView) page.getActivePart()).getSelection(); fShortcut.launch(selection, fMode); } else { ISelection selection = page.getSelection(); if (selection instanceof IStructuredSelection) { fShortcut.launch(selection, fMode); } } } } }