Java Code Examples for org.eclipse.ui.IWorkbenchPage#closeEditor()
The following examples show how to use
org.eclipse.ui.IWorkbenchPage#closeEditor() .
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 |
@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: TmfCommonProjectElement.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Close open editors associated with this experiment. */ public void closeEditors() { IFile file = getBookmarksFile(); FileEditorInput input = new FileEditorInput(file); IWorkbench wb = PlatformUI.getWorkbench(); for (IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) { for (IWorkbenchPage wbPage : wbWindow.getPages()) { for (IEditorReference editorReference : wbPage.getEditorReferences()) { try { if (editorReference.getEditorInput().equals(input)) { wbPage.closeEditor(editorReference.getEditor(false), false); } } catch (PartInitException e) { Activator.getDefault().logError(NLS.bind(Messages.TmfCommonProjectElement_ErrorClosingEditor, getName()), e); } } } } }
Example 3
Source File: GWTProjectPropertyPage.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
public static void reopenWithGWTJavaEditor(IEditorReference[] openEditors) { IWorkbenchPage page = JavaPlugin.getActivePage(); for (IEditorReference editorRef : openEditors) { try { IEditorPart editor = editorRef.getEditor(false); IEditorInput input = editorRef.getEditorInput(); // Close the editor, prompting the user to save if document is dirty if (page.closeEditor(editor, true)) { // Re-open the .java file in the GWT Java Editor IEditorPart gwtEditor = page.openEditor(input, GWTJavaEditor.EDITOR_ID); // Save the file from the new editor if the Java editor's // auto-format-on-save action screwed up the JSNI formatting gwtEditor.doSave(null); } } catch (PartInitException e) { GWTPluginLog.logError(e, "Could not open GWT Java editor on {0}", editorRef.getTitleToolTip()); } } }
Example 4
Source File: PlantUmlExporter.java From txtUML with Eclipse Public License 1.0 | 6 votes |
protected void cleanupWorkbench(IFile targetFile, IWorkbenchPage page) throws CoreException { if (targetFile.exists()) { IEditorReference[] refs = page.getEditorReferences(); for (IEditorReference ref : refs) { IEditorPart part = ref.getEditor(false); if (part != null) { IEditorInput inp = part.getEditorInput(); if (inp instanceof FileEditorInput) { if (((FileEditorInput) inp).getFile().equals(targetFile)) { page.closeEditor(ref.getEditor(false), true); } } } } } }
Example 5
Source File: UIUtils.java From CogniCrypt with Eclipse Public License 2.0 | 5 votes |
/** * This method closes the currently open editor. * * @param editor */ public static void closeEditor(final IEditorPart editor) { final IWorkbenchPage workbenchPage = UIUtils.getCurrentlyOpenPage(); if (workbenchPage != null) { workbenchPage.closeEditor(editor, true); } }
Example 6
Source File: DeleteModuleHandler.java From tlaplus with MIT License | 5 votes |
/** * {@inheritDoc} */ public Object execute(ExecutionEvent event) throws ExecutionException { final Module m = getModuleFromContext((IEvaluationContext)event.getApplicationContext()); final Job j = new ToolboxJob("Removing module...") { protected IStatus run(final IProgressMonitor monitor) { try { m.getResource().delete(IResource.NEVER_DELETE_PROJECT_CONTENT, monitor); return Status.OK_STATUS; } catch (Exception e) { return Status.CANCEL_STATUS; } } }; final IWorkbenchWindow iww = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); final IWorkbenchPage page = iww.getActivePage(); final IEditorReference[] refs = page.getEditorReferences(); final String tabName = m.getModuleName() + TLAConstants.Files.TLA_EXTENSION; boolean removeModule = true; for (final IEditorReference ier : refs) { if (tabName.equals(ier.getName())) { final IEditorPart editor = ier.getEditor(false); if (editor != null) { // If dirty and they cancel the closing, this will return false removeModule = page.closeEditor(editor, true); } } } if (removeModule) { j.schedule(); } return null; }
Example 7
Source File: DiagramPartitioningUtil.java From statecharts with Eclipse Public License 1.0 | 5 votes |
/** * Forces the user to close all opened editors for subdiagrams that are inlined. * * @return true if all editors were closed, false otherwise */ public static boolean closeSubdiagramEditors(State state) { Diagram diagram = DiagramPartitioningUtil.getSubDiagram(state); if (diagram == null) return true; IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorReference[] refs = activePage.getEditorReferences(); for (IEditorReference ref : refs) { try { if (ref.getEditorInput() instanceof IDiagramEditorInput) { IDiagramEditorInput diagramInput = (IDiagramEditorInput) ref.getEditorInput(); if (diagramInput.getDiagram().equals(diagram)) { boolean close = MessageDialog.openQuestion(activePage.getActivePart().getSite().getShell(), "Close subdiagram editor?", "The subdiagram is still open in another editor. Do you want to close it?"); if (close) { activePage.closeEditor(ref.getEditor(false), false); } return close; } } } catch (PartInitException e) { e.printStackTrace(); } } return true; }
Example 8
Source File: SaveAsRoutesAction.java From tesb-studio-se with Apache License 2.0 | 5 votes |
@Override public void run() { SaveAsRoutesWizard processWizard = new SaveAsRoutesWizard((JobEditorInput) editorPart.getEditorInput()); WizardDialog dlg = new WizardDialog(editorPart.getSite().getShell(), processWizard); if (dlg.open() == Window.OK) { try { // Set readonly to false since created routes will always be editable. JobEditorInput newRoutesEditorInput = new CamelProcessEditorInput(processWizard.getProcess(), true, true, false); IWorkbenchPage page = editorPart.getSite().getPage(); IRepositoryNode repositoryNode = RepositorySeekerManager.getInstance().searchRepoViewNode( newRoutesEditorInput.getItem().getProperty().getId(), false); newRoutesEditorInput.setRepositoryNode(repositoryNode); // close the old editor page.closeEditor(editorPart, false); // open the new editor, because at the same time, there will update the routes view page.openEditor(newRoutesEditorInput, CamelMultiPageTalendEditor.ID, true); } catch (Exception e) { MessageDialog.openError(editorPart.getSite().getShell(), "Error", "Routes could not be saved" + " : " + e.getMessage()); ExceptionHandler.process(e); } } }
Example 9
Source File: DiagramFileStore.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override protected void doClose() { DiagramEditor openedEditor = getOpenedEditor(); if (openedEditor != null) { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); activePage.closeEditor(openedEditor, false); } }
Example 10
Source File: CommonFunction.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * 关闭指定文件的编辑器 -- robert 2013-04-01 * 备注:这里面的方法,是不能获取 nattable 的实例,故,在处理 合并打开的情况时,是通过 vtd 进行解析 合并临时文件从而获取相关文件的 * @param iFileList */ public static void closePointEditor(List<IFile> iFileList){ Map<IFile, IEditorPart> openedIfileMap = new HashMap<IFile, IEditorPart>(); IEditorReference[] referenceArray = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences(); for(IEditorReference reference : referenceArray){ IEditorPart editor = reference.getEditor(true); IFile iFile = ((FileEditorInput)editor.getEditorInput()).getFile(); // 如果这是一个 nattable 编辑器 if (XLIFF_EDITOR_ID.equals(editor.getSite().getId())) { String iFilePath = iFile.getLocation().toOSString(); String extension = iFile.getFileExtension(); if ("hsxliff".equals(extension)) { openedIfileMap.put(iFile, editor); }else if ("xlp".equals(extension)) { // 这是合并打开的情况 // 开始解析这个合并打开临时文件,获取合并打开的文件。 VTDGen vg = new VTDGen(); if (vg.parseFile(iFilePath, true)) { VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); try { ap.selectXPath("/mergerFiles/mergerFile/@filePath"); int index = -1; while ((index = ap.evalXPath()) != -1) { String fileLC = vn.toString(index + 1); if (fileLC != null && !"".equals(fileLC)) { openedIfileMap.put(ResourceUtils.fileToIFile(fileLC), editor); } } } catch (Exception e) { e.printStackTrace(); } } } }else { // 其他情况,直接将文件丢进去就行了 openedIfileMap.put(iFile, editor); } IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); for(IFile curIfile : iFileList){ if (openedIfileMap.containsKey(curIfile)) { page.closeEditor(openedIfileMap.get(curIfile), false); } } } }
Example 11
Source File: CommonFunction.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * 关闭指定文件的编辑器 -- robert 2013-04-01 * 备注:这里面的方法,是不能获取 nattable 的实例,故,在处理 合并打开的情况时,是通过 vtd 进行解析 合并临时文件从而获取相关文件的 * @param iFileList */ public static void closePointEditor(List<IFile> iFileList){ Map<IFile, IEditorPart> openedIfileMap = new HashMap<IFile, IEditorPart>(); IEditorReference[] referenceArray = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences(); for(IEditorReference reference : referenceArray){ IEditorPart editor = reference.getEditor(true); IFile iFile = ((FileEditorInput)editor.getEditorInput()).getFile(); // 如果这是一个 nattable 编辑器 if (XLIFF_EDITOR_ID.equals(editor.getSite().getId())) { String iFilePath = iFile.getLocation().toOSString(); String extension = iFile.getFileExtension(); if ("hsxliff".equals(extension)) { openedIfileMap.put(iFile, editor); }else if ("xlp".equals(extension)) { // 这是合并打开的情况 // 开始解析这个合并打开临时文件,获取合并打开的文件。 VTDGen vg = new VTDGen(); if (vg.parseFile(iFilePath, true)) { VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); try { ap.selectXPath("/mergerFiles/mergerFile/@filePath"); int index = -1; while ((index = ap.evalXPath()) != -1) { String fileLC = vn.toString(index + 1); if (fileLC != null && !"".equals(fileLC)) { openedIfileMap.put(ResourceUtils.fileToIFile(fileLC), editor); } } } catch (Exception e) { e.printStackTrace(); } } } }else { // 其他情况,直接将文件丢进去就行了 openedIfileMap.put(iFile, editor); } IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); for(IFile curIfile : iFileList){ if (openedIfileMap.containsKey(curIfile)) { page.closeEditor(openedIfileMap.get(curIfile), false); } } } }
Example 12
Source File: EditorAPI.java From saros with GNU General Public License v2.0 | 3 votes |
/** * Closes the given editor part. If <code>save=true</code> is specified, the content of the editor * will be written to disk before it is closed. * * <p>Needs to be called from an UI thread. * * @param part the editor part to close * @param save whether to write the editor content to disk before closing it * @see IWorkbenchPage#closeEditor(IEditorPart, boolean) */ public static void closeEditor(IEditorPart part, boolean save) { IWorkbenchWindow window = getActiveWindow(); if (window == null) return; IWorkbenchPage page = window.getActivePage(); // Close AND let user decide if saving is necessary page.closeEditor(part, save); }