@SuppressWarnings("deprecation") public void stop_Event() { System.out.println("Stop"); stop = true; pause = true; if (playThreadAnimation != null && (playThreadAnimation.isAlive() || playThreadAnimation.isDaemon())) playThreadAnimation.stop(); ISourceProviderService service = (ISourceProviderService) getSite().getService(ISourceProviderService.class); DebugToolsCommandSourceProvider sourceProvider = (DebugToolsCommandSourceProvider) service.getSourceProvider(DebugToolsCommandSourceProvider.PLAY_COMMAND_STATE); sourceProvider.setPlayState(true); sourceProvider.setStopState(false); sourceProvider.setPauseState(false); sourceProvider.setStepState(false); IWorkbenchPage page = getSite().getPage(); System.out.println("page:" + page); if (page != null) { IPerspectiveDescriptor perspective = page.getPerspective(); if (perspective != null) { page.closePerspective(perspective, false, true); } } }
@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())); } } } }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); View view = (View) page.findView(View.ID); view.getViewer().refresh(); // open dialog to get path FileDialog filedlg = new FileDialog(window.getShell(), SWT.SAVE); filedlg.setText("Create Sequence Diagram File"); filedlg.setFilterPath("SystemRoot"); filedlg.setFilterExtensions(new String[] {"di"}); String selected = filedlg.open(); // create & initial the sequence diagram MyCreater myCreater = new MyCreater(); myCreater.init(window.getWorkbench(), new StructuredSelection()); // fixed bug IFile iFile = myCreater.create(selected); // create the model SequenceDiagram sdDiagram = new SequenceDiagram(); sdDiagram.setiFile(iFile); sdDiagram.setFilePath( new Path(selected).removeFileExtension().addFileExtension("uml").toOSString()); ModelManager.getInstance().AddModel(sdDiagram); // open the editor myCreater.open(iFile); // refresh the model viewer view.getViewer().refresh(); return null; }
public void partVisible(IWorkbenchPartReference ref) { if (ref != null && ref.getId() == getSite().getId()) { fProcessSelectionEvents = true; IWorkbenchPage page = getSite().getWorkbenchWindow().getActivePage(); if (page != null) selectionChanged(page.getActivePart(), page.getSelection()); } }
@Override public boolean isEnabled() { // Check if we are closing down IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (window == null) { return false; } // Get the selection IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IWorkbenchPart part = page.getActivePart(); if (part == null) { return false; } ISelectionProvider selectionProvider = part.getSite().getSelectionProvider(); if (selectionProvider == null) { return false; } ISelection selection = selectionProvider.getSelection(); // Make sure there is only one selection and that it is an experiment fExperiment = null; if (selection instanceof TreeSelection) { TreeSelection sel = (TreeSelection) selection; // There should be only one item selected as per the plugin.xml Object element = sel.getFirstElement(); if (element instanceof TmfExperimentElement) { fExperiment = (TmfExperimentElement) element; } } return (fExperiment != 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); }
private void hideMenuCheck() { try { URL pluginUrl = Platform.getBundle(GrassUiPlugin.PLUGIN_ID).getResource("/"); String pluginPath = FileLocator.toFileURL(pluginUrl).getPath(); File pluginFile = new File(pluginPath); File installFolder = pluginFile.getParentFile().getParentFile().getParentFile(); File grassFolderFile = new File(installFolder, "grass"); if (Platform.getOS().equals(Platform.OS_WIN32)) { if (!grassFolderFile.exists() || !grassFolderFile.isDirectory()) { IWorkbenchWindow[] wwindows = PlatformUI.getWorkbench().getWorkbenchWindows(); String actionSetID = "eu.hydrologis.jgrass.ui.grassactionset"; for (IWorkbenchWindow iWorkbenchWindow : wwindows) { IWorkbenchPage activePage = iWorkbenchWindow.getActivePage(); if (activePage != null) { activePage.hideActionSet(actionSetID); MenuManager mbManager = ((ApplicationWindow) iWorkbenchWindow).getMenuBarManager(); for (int i = 0; i < mbManager.getItems().length; i++) { IContributionItem item = mbManager.getItems()[i]; if (item.getId().equals(actionSetID)) { item.setVisible(false); } } } } } } } catch (IOException e) { e.printStackTrace(); } }
public static IEditorPart[] getDirtyEditors() { IWorkbenchPage page = UIUtils.getActivePage(); if (page == null) { return null; } return page.getDirtyEditors(); }
/** * Finds a view with the given ID * * @param viewID the view ID * @return the view part * @throws PartInitException */ public static IViewPart findView(String viewID) { IWorkbenchPage page = getActivePage(); if (page != null) { return page.findView(viewID); } return null; }
/** * Returns the active part in the current workbench window. * * @return the active part */ public static IWorkbenchPart getActivePart() { IWorkbenchPage workbenchPage = getActivePage(); if (workbenchPage == null) { return null; } return workbenchPage.getActivePart(); }
/** * Returns the active perspective descriptor if there is one. * * @return the active perspective descriptor; <code>null</code> in case it could not be resolved. */ public static IPerspectiveDescriptor getActivePerspectiveDescriptor() { IWorkbenchPage activePage = getActivePage(); if (activePage != null) { return activePage.getPerspective(); } return null; }
@Override protected String perform(IAction action, IProgressMonitor monitor) throws Exception { try { final PyHierarchyView view; IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); view = (PyHierarchyView) page.showView( "com.python.pydev.ui.hierarchy.PyHierarchyView", null, IWorkbenchPage.VIEW_VISIBLE); ProgressMonitorDialog monitorDialog = new AsynchronousProgressMonitorDialog(EditorUtils.getShell()); try { IRunnableWithProgress operation = new IRunnableWithProgress() { public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { try { final HierarchyNodeModel model; // set whatever is needed for the hierarchy IPyRefactoring pyRefactoring = AbstractPyRefactoring.getPyRefactoring(); if (pyRefactoring instanceof IPyRefactoring2) { RefactoringRequest refactoringRequest = getRefactoringRequest(monitor); IPyRefactoring2 r2 = (IPyRefactoring2) pyRefactoring; model = r2.findClassHierarchy(refactoringRequest, false); if (monitor.isCanceled()) { return; } Runnable r = new Runnable() { public void run() { if (!monitor.isCanceled()) { view.setHierarchy(model); } } }; Display.getDefault().asyncExec(r); } } catch (Exception e) { Log.log(e); } } }; boolean fork = true; monitorDialog.run(fork, true, operation); } catch (Throwable e) { Log.log(e); } } catch (Exception e) { Log.log(e); } return ""; }
@Override public void switchToSolution(String id) { IWorkbenchPage activePage = getWorkbench().getActiveWorkbenchWindow().getActivePage(); // store the state of the current solution closeSolution(session.getCurrentSolution()); IWorkingSetManager wsManager = getWorkbench().getWorkingSetManager(); Map<String, IWorkingSet> workingSetMap = getWorkingSetMap(); IAggregateWorkingSet solutionSet = (IAggregateWorkingSet) workingSetMap.get(id); Assert.isNotNull(solutionSet, "Solution set is null: " + id); // IWorkingSet[] windowSet = new IWorkingSet[]{solutionSet}; IWorkingSet[] windowSet = solutionSet.getComponents(); // HACK: currently the ProcjectExplorer>WorkingSetDialog does // strange things with working sets, i.e., caches aggregate sets that can // get invalid as these are not updated, properly // workaround: delete these aggregate sets when you can :) String eclispeAggId = getAggregateIdForSets(windowSet); if (workingSetMap.containsKey(eclispeAggId)) { wsManager.removeWorkingSet(workingSetMap.get(eclispeAggId)); } activePage.setWorkingSets(windowSet); openSolution(id); session.setCurrentSolution(id); }
private void openUnclosedMapLastSession(File statusFile, final IWorkbenchPage page) throws FileNotFoundException, UnsupportedEncodingException, WorkbenchException, CoreException, PartInitException { FileInputStream input = new FileInputStream(statusFile); BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8")); // $NON-NLS-1$ IMemento memento = XMLMemento.createReadRoot(reader); IMemento childMem = memento.getChild(IWorkbenchConstants.TAG_EDITORS); // ((WorkbenchPage) page).getEditorManager().restoreState(childMem); IMemento[] childrenEditor = childMem.getChildren("editor"); // $NON-NLS-1$ IEditorPart activeEditorPart = null; for (IMemento childEditor : childrenEditor) { IMemento childInput = childEditor.getChild("input"); // $NON-NLS-1$ String path = childInput.getString("path"); // $NON-NLS-1$ if (path != null) { IEditorInput editorInput = MME.createFileEditorInput(path); IEditorPart editorPart = page.openEditor(editorInput, MindMapUI.MINDMAP_EDITOR_ID); if ("true".equals(childEditor.getString("activePart"))) { // $NON-NLS-1$ //$NON-NLS-2$ activeEditorPart = editorPart; } } } if (activeEditorPart != null) { page.activate(activeEditorPart); } }
/** * Find Open Editor for the currently selected ModelExtensionDefinition * * @param selectedMedFile the mxd file to check * @return the currently open editor or <code>null</code> if none open */ private static IEditorPart getOpenEditor(IFile selectedMedFile) { final IWorkbenchWindow window = Activator.getDefault().getCurrentWorkbenchWindow(); if (window != null) { final IWorkbenchPage page = window.getActivePage(); if (page != null) { // look through the open editors and see if there is one available for this model file. IEditorReference[] editors = page.getEditorReferences(); for (int i = 0; i < editors.length; ++i) { IEditorPart editor = editors[i].getEditor(false); if (editor != null) { IEditorInput input = editor.getEditorInput(); if (input instanceof IFileEditorInput) { if ((selectedMedFile != null) && selectedMedFile.equals(((IFileEditorInput) input).getFile())) { return editor; } } } } } } return null; }
@Override public void apply(IDocument document) { try { ITranslationUnit unit = getTranslationUnit(); IEditorPart part = null; if (unit.getResource().exists()) { boolean canEdit = performValidateEdit(unit); if (!canEdit) { return; } part = EditorUtility.isOpenInEditor(unit); if (part == null) { part = EditorUtility.openInEditor(unit); if (part != null) { document = CUIPlugin.getDefault().getDocumentProvider().getDocument(part.getEditorInput()); } } IWorkbenchPage page = CUIPlugin.getActivePage(); if (page != null && part != null) { page.bringToTop(part); } if (part != null) { part.setFocus(); } } performChange(part, document); } catch (CoreException e) { ExceptionHandler.handle( e, CorrectionMessages.TUCorrectionProposal_error_title, CorrectionMessages.TUCorrectionProposal_error_message); } }
/** * Returns a VDB editor given a vdb resource if editor is open * * @param vdb the vdb * @return the vdb editor */ public static VdbEditor getVdbEditorForFile(IResource vdb) { if (vdb != null && vdb.exists()) { IWorkbenchWindow window = UiPlugin.getDefault().getCurrentWorkbenchWindow(); if (window != null) { final IWorkbenchPage page = window.getActivePage(); if (page != null) { // look through the open editors and see if there is one available for this model file. IEditorReference[] editors = page.getEditorReferences(); for (int i = 0; i < editors.length; ++i) { IEditorPart editor = editors[i].getEditor(false); if (editor != null) { IEditorInput input = editor.getEditorInput(); if (input instanceof IFileEditorInput) { if (vdb.equals(((IFileEditorInput) input).getFile()) || vdb.getFullPath() .equals(((IFileEditorInput) input).getFile().getFullPath())) { // found it; if (ModelUtil.isVdbArchiveFile(vdb)) { return (VdbEditor) editor; } break; } } } } } } } return null; }
private void open(IFile file) { IWorkbenchWindow dw = FMUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = dw.getActivePage(); if (page != null) { IContentType contentType = null; try { IContentDescription description = file.getContentDescription(); if (description != null) { contentType = description.getContentType(); } IEditorDescriptor desc = null; if (contentType != null) { desc = PlatformUI.getWorkbench() .getEditorRegistry() .getDefaultEditor(file.getName(), contentType); } else { desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName()); } if (desc != null) { page.openEditor(new FileEditorInput(file), desc.getId()); } } catch (CoreException e) { FMUIPlugin.getDefault().logError(e); } } }
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; }
/* (non-Javadoc) * @see PerspectiveMenu#run(IPerspectiveDescriptor) */ protected void run(IPerspectiveDescriptor desc) { // IPreferenceStore store = PrefUtil.getInternalPreferenceStore(); // int mode = store.getInt(IPreferenceConstants.OPEN_PERSP_MODE); int mode = IPreferenceConstants.OPM_ACTIVE_PAGE; IWorkbenchPage page = getWindow().getActivePage(); IPerspectiveDescriptor persp = null; if (page != null) { persp = page.getPerspective(); } // Only open a new window if user preference is set and the window // has an active perspective. if (IPreferenceConstants.OPM_NEW_WINDOW == mode && persp != null) { try { IWorkbench workbench = getWindow().getWorkbench(); IAdaptable input = ((Workbench) workbench).getDefaultPageInput(); workbench.openWorkbenchWindow(desc.getId(), input); } catch (WorkbenchException e) { handleWorkbenchException(e); } } else { if (page != null) { page.setPerspective(desc); } else { try { IWorkbench workbench = getWindow().getWorkbench(); IAdaptable input = ((Workbench) workbench).getDefaultPageInput(); getWindow().openPage(desc.getId(), input); } catch (WorkbenchException e) { handleWorkbenchException(e); } } } }
/** Open a new Window with the visualization of the selected information. */ @Override public void run() { if (window == null) { return; } // get the activate page IWorkbenchPage page = window.getActivePage(); if (page == null) { return; } IViewPart view = page.findView(ConstraintView.ID); if (view == null) { return; } if (!page.isPartVisible(view)) { // use the Resource Manager View id to open up view try { view = page.showView(ConstraintView.ID); } catch (PartInitException e) { System.err.println("Failed to open the Constrains View " + e); } } // Refresh the View if (view instanceof ConstraintView) ((ConstraintView) view).refresh(); // Set Focus page.activate(view); }
/** * Returns the source part, or <code>null</code> if there is no applicable source part * * <p>This implementation returns the current part in the window. Subclasses may extend or * reimplement. * * @return the source part or <code>null</code> */ private IWorkbenchPart getSourcePart() { IWorkbenchPage page = getWindow().getActivePage(); if (page != null) { return page.getActivePart(); } return null; }
protected void setInitialSelection() { // Use the selection, if any Object input; IWorkbenchPage page = getSite().getPage(); ISelection selection = null; if (page != null) selection = page.getSelection(); if (selection instanceof ITextSelection) { IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); if (activePage != null) { Object part = activePage.getActivePart(); if (part instanceof IEditorPart) { setSelectionFromEditor((IEditorPart) part); if (fViewer.getSelection() != null) return; } } } // Use saved selection from memento if (selection == null || selection.isEmpty()) selection = restoreSelectionState(fMemento); if (selection == null || selection.isEmpty()) { // Use the input of the page input = getSite().getPage().getInput(); if (!(input instanceof IModelElement)) { if (input instanceof IAdaptable) input = ((IAdaptable) input).getAdapter(IModelElement.class); else return; } selection = new StructuredSelection(input); } selectionChanged(null, selection); }
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; }
/** * 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); }
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; } }
protected void attemptToSetActiveEditor() { IWorkbenchPage activePage = this.getSite().getWorkbenchWindow().getActivePage(); if (activePage != null) { IEditorPart activeEditor = activePage.getActiveEditor(); if (activeEditor != null) this.handleEditorActivation(activeEditor); } }
/** * Display gmon results in the GProf View. NOTE: this method has to be called from within the UI * thread. * * @param decoder * @param id Secondary id, usually path to gmon file. */ public static GmonView displayGprofView(GmonDecoder decoder, String id) { GmonView gmonview = null; try { IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = window.getActivePage(); if (id != null) { id = id.replace('.', '_'); id = id.replace(':', '_'); } gmonview = (GmonView) page.showView(ID, id, IWorkbenchPage.VIEW_ACTIVATE); if (decoder.getHistogramDecoder().getProfRate() == 0) { gmonview.switchSampleTime.setToolTipText( "Unable to display time, because profiling rate is null"); //$NON-NLS-1$ gmonview.switchSampleTime.setEnabled(false); } gmonview.setInput(decoder); GmonView.setHistTitle(decoder, gmonview.label); if (!decoder.getHistogramDecoder().hasValues()) { gmonview.action1.setChecked(true); gmonview.action2.setChecked(false); gmonview.action1.run(); } } catch (CoreException e) { Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e); Activator.getDefault().getLog().log(status); } return gmonview; }
@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; }
private IEditorPart getActiveEditor() { final IWorkbenchPage activePage = ErlideUIPlugin.getActivePage(); if (activePage != null) { return activePage.getActiveEditor(); } return null; }