/* * (non-Javadoc) * * @see org.eclipse.jface.action.Action#run() */ protected void doRun() { ISelection selection = getSelection(); Object obj = ((IStructuredSelection) selection).getFirstElement(); RepositoryNode node = (RepositoryNode) obj; CamelProcessItem processItem = (CamelProcessItem) node.getObject().getProperty().getItem(); IWorkbenchPage page = getActivePage(); try { CamelProcessEditorInput fileEditorInput = new CamelProcessEditorInput(processItem, true, null, true); checkUnLoadedNodeForProcess(fileEditorInput); IEditorPart editorPart = page.findEditor(fileEditorInput); if (editorPart == null) { fileEditorInput.setRepositoryNode(node); page.openEditor(fileEditorInput, CamelMultiPageTalendEditor.ID, true); } else { page.activate(editorPart); } } catch (PartInitException e) { MessageBoxExceptionHandler.process(e); } catch (PersistenceException e) { MessageBoxExceptionHandler.process(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); }
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); } }
private boolean openFileImpl(IProject project, IPath sourceLoc, int lineNumber) { if (sourceLoc == null || "??".equals(sourceLoc.toString())) return false; try { IEditorInput editorInput = getEditorInput(sourceLoc, project); IWorkbenchPage p= CUIPlugin.getActivePage(); if (p != null) { if (editorInput == null) { p.openEditor( new STCSourceNotFoundEditorInput(project, sourceLoc, lineNumber), "org.eclipse.linuxtools.binutils.link2source.STCSourceNotFoundEditor", true); } else { IEditorPart editor = p.openEditor(editorInput, CUIPlugin.EDITOR_ID, true); if (lineNumber > 0 && editor instanceof ITextEditor){ IDocumentProvider provider= ((ITextEditor)editor).getDocumentProvider(); IDocument document= provider.getDocument(editor.getEditorInput()); try { int start = document.getLineOffset(lineNumber-1); ((ITextEditor)editor).selectAndReveal(start, 0); IWorkbenchPage page= editor.getSite().getPage(); page.activate(editor); return true; } catch (BadLocationException x) { // ignore } } } } } catch (Exception _) { } return false; }
/** * 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); }
private void openEditor(IFile file) throws PartInitException { IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPage page = workbenchWindow.getActivePage(); IEditorPart editor = page.openEditor(new FileEditorInput(file), ID_JSP_EDITOR, true); page.activate(editor); esc(); }
public void activate() { // just check we're alive - just in case we've been called before // the init is complete final IWorkbenchPartSite site = getSite(); final IWorkbenchWindow window = site.getWorkbenchWindow(); final IWorkbenchPage page = window.getActivePage(); if (page != null) { page.activate(site.getPart()); } }
private void openInCompare(ITypedElement ancestor, ITypedElement left, ITypedElement right) { IWorkbenchPage workBenchPage = getTargetPage(); CompareEditorInput input = new SaveablesCompareEditorInput(ancestor, left, right, workBenchPage); IEditorPart editor = Utils.findReusableCompareEditor( input, workBenchPage, new Class[] {CompareFileRevisionEditorInput.class}); if (editor != null) { IEditorInput otherInput = editor.getEditorInput(); if (otherInput.equals(input)) { // simply provide focus to editor workBenchPage.activate(editor); } else { // if editor is currently not open on that input either re-use // existing CompareUI.reuseCompareEditor(input, (IReusableEditor) editor); workBenchPage.activate(editor); } } else { CompareUI.openCompareEditor(input); } }
private IEditorPart openFileInEditorWithProblemsViewOpened(String filePath) throws Exception { InputStream inputStream = MarkersRemoverValidatorIT.class.getClassLoader().getResourceAsStream(filePath); final IFile fileWithoutContext = fuseProject .getProject() .getFile(filePath.startsWith("/") ? filePath.substring(1) : filePath); fileWithoutContext.create(inputStream, true, new NullProgressMonitor()); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); page.closeAllPerspectives(false, false); PlatformUI.getWorkbench().showPerspective(FusePerspective.ID, page.getWorkbenchWindow()); readAndDispatch(20); this.problemView = PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .showView("org.eclipse.ui.views.ProblemView"); readAndDispatch(20); IEditorPart editor = IDE.openEditor(page, fileWithoutContext, true); page.activate(editor); readAndDispatch(20); return editor; }
@Override protected void doSaveDocument( IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException { try { // Automatic validation with result IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); CustomValidateAction action = new CustomValidateAction(page, (IEditorInput) element); monitor.setTaskName("Validation"); action.run(monitor); if (!action.result) { // If validation failed, do not save ProblemsView problem = (ProblemsView) page.findView("org.eclipse.ui.views.ProblemView"); page.activate(problem); monitor.setCanceled(true); return; } } catch (Exception e) { MindDiagramEditorPlugin.getInstance().logError("Problems occured during validation", e); return; } MindProxy mindRoot = MindProxyFactory.INSTANCE.getRootProxy(); HashMap<String, Rectangle> boundsMemory = new HashMap<String, Rectangle>(); HashMap<String, Bendpoints> bendpointsMemory = new HashMap<String, Bendpoints>(); if (mindRoot != null) { SaveUtil.saveBounds(mindRoot.getEditPart(), boundsMemory, bendpointsMemory); } // Prepare the transaction that will prepare the main definition // All merged items are deleted because they must not be serialized TransactionalEditingDomain domain = getDiagramDocument(element).getEditingDomain(); TransactionImpl transaction = new TransactionImpl(domain, false); EObject root = ((DiagramImpl) document.getContent()).getElement(); ResourceSetInfo info = getResourceSetInfo(element); if (info != null) { if (!overwrite && !info.isSynchronized()) { throw new CoreException( new Status( IStatus.ERROR, MindDiagramEditorPlugin.ID, IResourceStatus.OUT_OF_SYNC_LOCAL, Messages.MindDocumentProvider_UnsynchronizedFileSaveError, null)); } info.stopResourceListening(); fireElementStateChanging(element); try { monitor.beginTask( Messages.MindDocumentProvider_SaveDiagramTask, info.getResourceSet().getResources().size() + 1); // "Saving diagram" LazyLinkingResource xtextResource = null; GMFResource gmfResource = null; for (Iterator /*<org.eclipse.emf.ecore.resource.Resource>*/<?> it = info.getLoadedResourcesIterator(); it.hasNext(); ) { Resource nextResource = (Resource) it.next(); monitor.setTaskName( NLS.bind(Messages.MindDocumentProvider_SaveNextResourceTask, nextResource.getURI())); if (nextResource.isLoaded() && !info.getEditingDomain().isReadOnly(nextResource)) { if (nextResource instanceof LazyLinkingResource) { // Serialize later xtextResource = (LazyLinkingResource) nextResource; } else { // Save GMF try { if (nextResource instanceof GMFResource) gmfResource = (GMFResource) nextResource; nextResource.save(MindDiagramEditorUtil.getSaveOptions()); } catch (IOException e) { fireElementStateChangeFailed(element); throw new CoreException( new Status( IStatus.ERROR, MindDiagramEditorPlugin.ID, EditorStatusCodes.RESOURCE_FAILURE, e.getLocalizedMessage(), null)); } } } monitor.worked(1); } // Delete merged elements from the model before saving if (root instanceof AdlDefinitionCustomImpl) { try { transaction.start(); prepareMainDefinitionBeforeSave((AdlDefinitionCustomImpl) root); transaction.commit(); } catch (InterruptedException e) { MindDiagramEditorPlugin.getInstance().logError("Clean merge failed", e); } catch (RollbackException e) { MindDiagramEditorPlugin.getInstance().logError("Clean merge failed", e); transaction.rollback(); } finally { } } // Merged items are deleted, they will not to be serialized // We can save xtext resource try { xtextResource.save(MindDiagramEditorUtil.getSaveOptions()); } catch (IOException e) { fireElementStateChangeFailed(element); throw new CoreException( new Status( IStatus.ERROR, MindDiagramEditorPlugin.ID, EditorStatusCodes.RESOURCE_FAILURE, e.getLocalizedMessage(), null)); } // Restore merged elements if (root instanceof AdlDefinitionCustomImpl) { try { transaction.start(); restoreMainDefinitionAfterSave((AdlDefinitionCustomImpl) root); transaction.commit(); } catch (InterruptedException e) { MindDiagramEditorPlugin.getInstance().logError("Restore merge failed", e); } catch (RollbackException e) { e.printStackTrace(); MindDiagramEditorPlugin.getInstance().logError("Restore merge failed", e); transaction.rollback(); } finally { } } // Update diagram try { MindDiagramUpdateCommand update = new MindDiagramUpdateAllCommand(false); update.execute(new ExecutionEvent()); } catch (ExecutionException e) { MindDiagramEditorPlugin.getInstance().logError("Update failed", e); } finally { } // Now that editParts have been recreated by the update, // we are able to restore the saved bounds if (mindRoot != null) { SaveUtil.restoreBounds(mindRoot.getEditPart(), boundsMemory, bendpointsMemory); boundsMemory.clear(); } // DocumentProvider thinks resource is modified because of restoreMainDefinition // Set value to false gmfResource.setModified(false); monitor.done(); info.setModificationStamp(computeModificationStamp(info)); } catch (RuntimeException x) { fireElementStateChangeFailed(element); throw x; } finally { info.startResourceListening(); } } else { URI newResoruceURI; List<IFile> affectedFiles = null; if (element instanceof FileEditorInput) { IFile newFile = ((FileEditorInput) element).getFile(); affectedFiles = Collections.singletonList(newFile); newResoruceURI = URI.createPlatformResourceURI(newFile.getFullPath().toString(), true); } else if (element instanceof URIEditorInput) { newResoruceURI = ((URIEditorInput) element).getURI(); } else { fireElementStateChangeFailed(element); throw new CoreException( new Status( IStatus.ERROR, MindDiagramEditorPlugin.ID, 0, NLS.bind( Messages.MindDocumentProvider_IncorrectInputError, new Object[] { element, "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ null)); } if (false == document instanceof IDiagramDocument) { fireElementStateChangeFailed(element); throw new CoreException( new Status( IStatus.ERROR, MindDiagramEditorPlugin.ID, 0, "Incorrect document used: " + document + " instead of org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument", null)); //$NON-NLS-1$ //$NON-NLS-2$ } IDiagramDocument diagramDocument = (IDiagramDocument) document; final Resource newResource = diagramDocument.getEditingDomain().getResourceSet().createResource(newResoruceURI); final Diagram diagramCopy = (Diagram) EcoreUtil.copy(diagramDocument.getDiagram()); try { new AbstractTransactionalCommand( diagramDocument.getEditingDomain(), NLS.bind(Messages.MindDocumentProvider_SaveAsOperation, diagramCopy.getName()), affectedFiles) { protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { newResource.getContents().add(diagramCopy); return CommandResult.newOKCommandResult(); } }.execute(monitor, null); newResource.save(MindDiagramEditorUtil.getSaveOptions()); } catch (ExecutionException e) { fireElementStateChangeFailed(element); throw new CoreException( new Status( IStatus.ERROR, MindDiagramEditorPlugin.ID, 0, e.getLocalizedMessage(), null)); } catch (IOException e) { fireElementStateChangeFailed(element); throw new CoreException( new Status( IStatus.ERROR, MindDiagramEditorPlugin.ID, 0, e.getLocalizedMessage(), null)); } newResource.unload(); } }