Java Code Examples for org.eclipse.ui.ide.IDE#openEditor()
The following examples show how to use
org.eclipse.ui.ide.IDE#openEditor() .
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: LanguageSpecificURIEditorOpener.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) { Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator(); if (storages != null && storages.hasNext()) { try { IStorage storage = storages.next().getFirst(); IEditorInput editorInput = EditorUtils.createEditorInput(storage); IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage(); final IEditorPart editor = IDE.openEditor(activePage, editorInput, getEditorId()); selectAndReveal(editor, uri, crossReference, indexInList, select); return EditorUtils.getXtextEditor(editor); } catch (WrappedException e) { logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause()); } catch (PartInitException partInitException) { logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException); } } return null; }
Example 2
Source File: BusinessObjectModelFileStore.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override protected IWorkbenchPart doOpen() { try { BusinessDataModelEditor openedEditor = getOpenedEditor(); if (openedEditor != null) { if (openedEditor.setActiveContribution(BusinessDataModelEditorContribution.ID)) { openedEditor.getSite().getPage().activate(openedEditor); return openedEditor; } openedEditor.close(true); } openedEditor = (BusinessDataModelEditor) IDE.openEditor(getActivePage(), getResource()); openedEditor.setActiveContribution(BusinessDataModelEditorContribution.ID); openedEditor.getSite().getPage().activate(openedEditor); return openedEditor; } catch (final PartInitException e) { throw new RuntimeException("Failed to open bdm", e); } }
Example 3
Source File: EditorUtil.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * Open a file in an editor and return the opened editor part.<br> * This method will try to open the file in an internal editor, unless there is no editor descriptor assigned to * that file type. * * @param file * @return The {@link IEditorPart} that was created when the file was opened; Return null in case of an error */ public static IEditorPart openInEditor(File file) { // NOTE: Moved from PHP's EditorUtils if (file == null) { IdeLog.logError(CommonEditorPlugin.getDefault(), "Error open a file in the editor", new IllegalArgumentException("file is null")); //$NON-NLS-1$ //$NON-NLS-2$ return null; } try { URI uri = file.toURI(); IEditorDescriptor desc = getEditorDescriptor(uri); String editorId = (desc == null) ? IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID : desc.getId(); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); return IDE.openEditor(page, uri, editorId, true); } catch (Exception e) { IdeLog.logError(CommonEditorPlugin.getDefault(), "Error open a file in the editor", e); //$NON-NLS-1$ } return null; }
Example 4
Source File: TestXML.java From wildwebdeveloper with Eclipse Public License 2.0 | 6 votes |
@Test public void testXSDFile() throws Exception { final IFile file = project.getFile("blah.xsd"); file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("a<"); assertTrue("Diagnostic not published", new DisplayHelper() { @Override protected boolean condition() { try { return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; } catch (CoreException e) { return false; } } }.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000)); }
Example 5
Source File: PlatformPluginAwareEditorOpener.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * If a platform plugin URI is given, a read-only Xtext editor is opened and returned. {@inheritDoc} * * @see {@link org.eclipse.emf.common.util.URI#isPlatformPlugin()} */ @Override public IEditorPart open(final URI uri, final EReference crossReference, final int indexInList, final boolean select) { IEditorPart result = super.open(uri, crossReference, indexInList, select); if (result == null && (uri.isPlatformPlugin() || OSGI_RESOURCE_URL_PROTOCOL.equals(uri.scheme()))) { final IModelLocation modelLocation = getModelLocation(uri.trimFragment()); if (modelLocation != null) { PlatformPluginStorage storage = new PlatformPluginStorage(modelLocation); IEditorInput editorInput = new XtextReadonlyEditorInput(storage); IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage(); try { IEditorPart editor = IDE.openEditor(activePage, editorInput, editorID); selectAndReveal(editor, uri, crossReference, indexInList, select); return EditorUtils.getXtextEditor(editor); } catch (WrappedException e) { LOG.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause()); //$NON-NLS-1$ //$NON-NLS-2$ } catch (PartInitException partInitException) { LOG.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException); //$NON-NLS-1$ //$NON-NLS-2$ } } } return result; }
Example 6
Source File: TestLanguageServers.java From wildwebdeveloper with Eclipse Public License 2.0 | 6 votes |
@Test public void testCSSFile() throws Exception { final IFile file = project.getFile("blah.css"); file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("FAIL"); assertTrue("Diagnostic not published", new DisplayHelper() { @Override protected boolean condition() { try { return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; } catch (CoreException e) { return false; } } }.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000)); }
Example 7
Source File: KickStartNewProjectAction.java From solidity-ide with Eclipse Public License 1.0 | 6 votes |
@Override public void run(IIntroSite site, Properties params) { WorkspaceModifyOperation op = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { IProject project = createProject(monitor); createExample(project); } }; try { PlatformUI.getWorkbench().getProgressService().run(true, true, op); final IIntroManager introManager = PlatformUI.getWorkbench().getIntroManager(); IIntroPart part = introManager.getIntro(); introManager.closeIntro(part); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IDE.openEditor(page, ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("hello-world/greeter.sol"))); } catch (Exception e) { e.printStackTrace(); } }
Example 8
Source File: TestLanguageServers.java From wildwebdeveloper with Eclipse Public License 2.0 | 6 votes |
@Test public void testJSONFile() throws Exception { final IFile file = project.getFile("blah.json"); file.create(new ByteArrayInputStream("FAIL".getBytes()), true, null); ITextEditor editor = (ITextEditor) IDE .openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("ERROR"); assertTrue("Diagnostic not published", new DisplayHelper() { @Override protected boolean condition() { try { return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; } catch (CoreException e) { return false; } } }.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000)); }
Example 9
Source File: TestLanguageServers.java From wildwebdeveloper with Eclipse Public License 2.0 | 6 votes |
@Test public void testJSXFile() throws Exception { final IFile file = project.getFile("blah.jsx"); file.create(new ByteArrayInputStream("ERROR".getBytes()), true, null); ITextEditor editor = (ITextEditor) IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file); editor.getDocumentProvider().getDocument(editor.getEditorInput()).set("a<"); assertTrue("Diagnostic not published", new DisplayHelper() { @Override protected boolean condition() { try { return file.findMarkers("org.eclipse.lsp4e.diagnostic", true, IResource.DEPTH_ZERO).length != 0; } catch (CoreException e) { return false; } } }.waitForCondition(PlatformUI.getWorkbench().getDisplay(), 5000)); }
Example 10
Source File: PyOpenResourceAction.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Overridden to open the given files with the match provided by the platform. */ @Override protected void openFiles(List<IFile> filesSelected) { for (IFile f : filesSelected) { CorePlugin.markAsPyDevFileIfDetected(f); try { IDE.openEditor(page, f); } catch (PartInitException e) { Log.log(e); } } }
Example 11
Source File: XSDFileStore.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override protected IWorkbenchPart doOpen() { try { return IDE.openEditor(getActivePage(), getResource()); } catch (PartInitException e) { BonitaStudioLog.error(e); } return null; }
Example 12
Source File: TestSyntaxHighlighting.java From corrosion with Eclipse Public License 2.0 | 5 votes |
@Test public void testManifestSyntaxHighlighting() throws CoreException, IOException { IFile rustFile = getProject(BASIC_PROJECT_NAME).getFile("Cargo.toml"); TextEditor editor = (TextEditor) IDE.openEditor( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), rustFile, "org.eclipse.ui.genericeditor.GenericEditor"); StyledText editorTextWidget = (StyledText) editor.getAdapter(Control.class); new DisplayHelper() { @Override protected boolean condition() { return editorTextWidget.getStyleRanges().length > 1; } }.waitForCondition(editorTextWidget.getDisplay(), 4000); Assert.assertTrue("There should be multiple styles in editor", editorTextWidget.getStyleRanges().length > 1); }
Example 13
Source File: TestIDEIntegration.java From corrosion with Eclipse Public License 2.0 | 5 votes |
@Test public void testManifestEditorAssociation() throws IOException, CoreException { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart editor = null; editor = IDE.openEditor(activePage, getProject(BASIC_PROJECT_NAME).getFile("Cargo.toml")); Assert.assertTrue(editor instanceof ExtensionBasedTextEditor); }
Example 14
Source File: EditorOpener.java From txtUML with Eclipse Public License 1.0 | 5 votes |
/** * Opens an editor for the file * @param diFile A file in the project * @return The EditorPart of the editor * @throws PartInitException */ public static final IMultiDiagramEditor openPapyrusEditor(final IFile diFile){ IMultiDiagramEditor ed = null; IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if(page != null) { try { IEditorInput editorInput = new FileEditorInput(diFile); ed = (IMultiDiagramEditor) IDE.openEditor(page, editorInput, PapyrusEditorId, true); } catch (PartInitException e) { Dialogs.errorMsgb(null, null, e); } } return ed; }
Example 15
Source File: TestIDEIntegration.java From corrosion with Eclipse Public License 2.0 | 5 votes |
@Test public void testRustEditorAssociation() throws IOException, CoreException { IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); IEditorPart editor = null; editor = IDE.openEditor(activePage, getProject(BASIC_PROJECT_NAME).getFolder("src").getFile("main.rs")); Assert.assertTrue(editor instanceof ExtensionBasedTextEditor); }
Example 16
Source File: PyOpenExternalAction.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override protected void openFiles(PythonpathTreeNode[] pythonPathFilesSelected) { for (PythonpathTreeNode n : pythonPathFilesSelected) { try { IDE.openEditor(page, EditorInputFactory.create(n.file, false), IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); } catch (PartInitException e) { Log.log(e); } } }
Example 17
Source File: PyOpenExternalAction.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Overridden to open the given files with the match provided by the platform. */ @Override protected void openFiles(List<IFile> filesSelected) { for (IFile f : filesSelected) { try { IDE.openEditor(page, f, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); } catch (PartInitException e) { Log.log(e); } } }
Example 18
Source File: ExampleModelOpener.java From statecharts with Eclipse Public License 1.0 | 4 votes |
protected void openExampleReadme(IProject project) throws PartInitException { IResource indexFile = project.findMember(ExampleData.DESC_FILE); if (indexFile != null) { IDE.openEditor(getPage(), (IFile) indexFile, true); } }
Example 19
Source File: CompositeQuickfixTest.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Test public void testTextualMultiModification() { try { StringConcatenation _builder = new StringConcatenation(); _builder.append("lowercase_a {}"); _builder.newLine(); _builder.append("lowercase_b {}"); _builder.newLine(); _builder.append("lowercase_c {}"); _builder.newLine(); _builder.append("lowercase_d {}"); _builder.newLine(); _builder.append("lowercase_e {}"); _builder.newLine(); _builder.append("lowercase_f {}"); _builder.newLine(); final IFile resource = this.dslFile(_builder); IEditorPart _openEditor = IDE.openEditor(AbstractWorkbenchTest.getActivePage(), resource); final XtextEditor xtextEditor = ((XtextEditor) _openEditor); final IMarker[] markers = this.getMarkers(resource); StringConcatenation _builder_1 = new StringConcatenation(); _builder_1.append("<0<lowercase_a>0> {}"); _builder_1.newLine(); _builder_1.append("<1<lowercase_b>1> {}"); _builder_1.newLine(); _builder_1.append("<2<lowercase_c>2> {}"); _builder_1.newLine(); _builder_1.append("<3<lowercase_d>3> {}"); _builder_1.newLine(); _builder_1.append("<4<lowercase_e>4> {}"); _builder_1.newLine(); _builder_1.append("<5<lowercase_f>5> {}"); _builder_1.newLine(); _builder_1.append("--------------------"); _builder_1.newLine(); _builder_1.append("0: message=lowercase"); _builder_1.newLine(); _builder_1.append("1: message=lowercase"); _builder_1.newLine(); _builder_1.append("2: message=lowercase"); _builder_1.newLine(); _builder_1.append("3: message=lowercase"); _builder_1.newLine(); _builder_1.append("4: message=lowercase"); _builder_1.newLine(); _builder_1.append("5: message=lowercase"); _builder_1.newLine(); this.assertContentsAndMarkers(resource, markers, _builder_1); this.applyQuickfixOnMultipleMarkers(markers); xtextEditor.doSave(null); StringConcatenation _builder_2 = new StringConcatenation(); _builder_2.append("LOWERCASE_A_LOWERCASE_A {}"); _builder_2.newLine(); _builder_2.append("LOWERCASE_B_LOWERCASE_B {}"); _builder_2.newLine(); _builder_2.append("LOWERCASE_C_LOWERCASE_C {}"); _builder_2.newLine(); _builder_2.append("LOWERCASE_D_LOWERCASE_D {}"); _builder_2.newLine(); _builder_2.append("LOWERCASE_E_LOWERCASE_E {}"); _builder_2.newLine(); _builder_2.append("LOWERCASE_F_LOWERCASE_F {}"); _builder_2.newLine(); _builder_2.append("--------------------------"); _builder_2.newLine(); _builder_2.append("(no markers found)"); _builder_2.newLine(); this.assertContentsAndMarkers(resource, _builder_2); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 20
Source File: XSLBasedGenerator.java From CogniCrypt with Eclipse Public License 2.0 | 4 votes |
@Override public boolean generateCodeTemplates(final Configuration chosenConfig, final String pathToAdditionalResources) { try { // Check whether directories and templates/model exist final File configFile = chosenConfig.persistConf(); if (!configFile.exists()) { Activator.getDefault().logError(Constants.FilesDoNotExistErrorMessage); return false; } final String srcPath = this.project.getProjectPath() + Constants.innerFileSeparator + this.project.getSourcePath(); String temporaryOutputFile = srcPath + Constants.CodeGenerationCallFile; // If Output.java exists create OutputTemp.java final Path path = Paths.get(temporaryOutputFile); boolean tempFlag; if (Files.exists(path)) { final StringBuilder sb = new StringBuilder(temporaryOutputFile); sb.insert(temporaryOutputFile.length() - 5, Constants.TempSuffix); temporaryOutputFile = sb.toString(); Activator.getDefault().logInfo(Constants.CreateOutputTemp); tempFlag = true; } else { Activator.getDefault().logInfo(Constants.CreateOutput); tempFlag = false; } // Perform actual transformation by calling XSLT processor. transform(configFile, temporaryOutputFile); if (!Activator.getDefault().getPreferenceStore().getBoolean(Constants.PERSIST_CONFIG)) { chosenConfig.deleteConfFromDisk(); } // Trim Output.java FileUtils.trimFile(temporaryOutputFile); // Add additional resources like jar files if (!addAdditionalFiles(pathToAdditionalResources)) { return false; } for (final String customProvider : chosenConfig.getProviders()) { if (!addAddtionalFile(CodeGenUtils.getResourceFromWithin(Constants.providerPath + "/" + customProvider + Constants.JAR))) { return false; } } if (targetFile != null && this.project.equals(targetFile.getProject())) { Activator.getDefault().logInfo(Constants.OpenFile + targetFile.getName()); if (FileUtils.checkFileForString(targetFile.getRawLocation().toOSString(), Constants.AuthorTag)) { Activator.getDefault().logInfo(Constants.ContainsAuthorTag + targetFile.getName()); insertCallCodeIntoFile(temporaryOutputFile, true, true, tempFlag); removeCryptoPackageIfEmpty(); } else { Activator.getDefault().logInfo(Constants.ContainsNotAuthorTag + targetFile.getName()); insertCallCodeIntoFile(temporaryOutputFile, true, false, tempFlag); removeCryptoPackageIfEmpty(); } } else { if (tempFlag) { Activator.getDefault().logInfo(Constants.CloseFile); insertCallCodeIntoFile(temporaryOutputFile, false, false, tempFlag); removeCryptoPackageIfEmpty(); } this.project.refresh(); final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final IFile outputFile = this.project.getIFile(temporaryOutputFile); final IEditorPart editor = IDE.openEditor(page, outputFile); cleanUpProject(editor); } this.project.refresh(); } catch (TransformerException | IOException | CoreException | BadLocationException e) { Activator.getDefault().logError(e, Constants.CodeGenerationErrorMessage); return false; } return true; }