/** * Returns the opened file of the currently active editor. * * Returns null if no editor is open. */ private static IFile getActiveEditorFile() { IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor(); if (null == activeEditor) { return null; } IEditorInput input = activeEditor.getEditorInput(); if (input instanceof FileEditorInput) { return ((FileEditorInput) input).getFile(); } else { return null; } }
@Override public IStructuredSelection findSelection(final IEditorInput input) { final IStructuredSelection selection = super.findSelection(input); if (null == selection || selection.isEmpty() && input instanceof XtextReadonlyEditorInput) { try { final IStorage storage = ((XtextReadonlyEditorInput) input).getStorage(); if (storage instanceof URIBasedStorage) { final URI uri = ((URIBasedStorage) storage).getURI(); if (uri.isFile()) { final File file = new File(uri.toFileString()); if (file.exists() && file.isFile()) { final Node node = getResourceNode(file); if (null != node) { return new StructuredSelection(node); } } } } } catch (final CoreException e) { LOGGER.error("Error while extracting storage from read-only Xtext editor input.", e); return EMPTY; } } return selection; }
/** * Provides input so that the Project Explorer can locate the editor's input in its tree. */ @Override public ShowInContext getShowInContext() { IEditorInput editorInput = getEditorInput(); if (editorInput instanceof FileEditorInput) { FileEditorInput fei = (FileEditorInput) getEditorInput(); return new ShowInContext(fei.getFile(), null); } else if (editorInput instanceof XtextReadonlyEditorInput) { XtextReadonlyEditorInput readOnlyEditorInput = (XtextReadonlyEditorInput) editorInput; IStorage storage; try { storage = readOnlyEditorInput.getStorage(); return new ShowInContext(storage.getFullPath(), null); } catch (CoreException e) { // Do nothing } } return new ShowInContext(null, null); }
/** * Gets the default {@link IEditorInput} for the given {@link Object}. * * @param element * the {@link Object} * @return the default {@link IEditorInput} for the given {@link Object} if any, <code>null</code> * otherwise */ public static IEditorInput getEditorInput(Object element) { final IEditorInput res; if (element instanceof EObject) { Resource resource = ((EObject)element).eResource(); if (resource != null) { res = getEditorInputFromURI(resource.getURI()); } else { res = null; } } else if (element instanceof DSLBreakpoint) { res = getEditorInputFromURI(((DSLBreakpoint)element).getURI().trimFragment()); } else { res = null; } return res; }
public void closeConnectorEditors() { IWorkbenchPage activePage = PlatformUI .getWorkbench() .getActiveWorkbenchWindow() .getActivePage(); if (activePage != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof ConnectorEditorInput)) { if (((ConnectorEditorInput)editorInput).is(getObject())) activePage.closeEditor(editorRef.getEditor(false),true); } } catch(PartInitException e) { ConvertigoPlugin.logException(e, "Error while retrieving the connector editor '" + editorRef.getName() + "'"); } } } }
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { super.init(site, input); if (site == null) { return; } IWorkbenchPage page = site.getPage(); if (page == null) { return; } // workaround to show action set for block mode etc. // https://www.eclipse.org/forums/index.php/t/366630/ page.showActionSet("org.eclipse.ui.edit.text.actionSet.presentation"); }
@Override public void runWithObject(Object object) throws Exception { String editorId = getAssociatedEditorId(object); if (editorId == null) { return; } IEditorInput input = getAssociatedEditorInput(editorId, object); if (input == null) { return; } String pageId = getAssociatedEditorPageId(editorId, object); try { open(object, input, editorId, pageId); } catch (Exception e) { throw new Exception(getOpenErrorMessage(object, input, editorId, e), e); } }
public boolean canRun() { InputType inputType = getInputType(); if (inputType.isStructuredSelection()) { IStructuredSelection structuredSelection = getCurrentStructuredSelection(); if (canRunWithStructuredSelection(structuredSelection)) { return true; } } else if (inputType.isEditorInput()) { IEditorPart editor = getActiveEditor(); IEditorInput editorInput = (editor != null) ? editor.getEditorInput() : null; if (canRunWithEditorInput(editorInput)) { return true; } } else if (canRunWithNothing()) { return true; } return false; }
private void closeComponentFileEditor(final IFile file) { try { IWorkbenchPage activePage = PlatformUI .getWorkbench() .getActiveWorkbenchWindow() .getActivePage(); for (IEditorReference editorReference : activePage.getEditorReferences()) { IEditorInput editorInput = editorReference.getEditorInput(); if (editorInput instanceof ComponentFileEditorInput) { ComponentFileEditorInput cfei = (ComponentFileEditorInput) editorInput; if (cfei.getFile().equals(file)) { activePage.closeEditor(editorReference.getEditor(false), true); return; } } } } catch (Exception e) { } }
@Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { if (!(input instanceof ProjectEditorInput)) { throw new PartInitException(Messages.ProjectEditorDiffer_error_bad_input_type); } ProjectEditorInput in = (ProjectEditorInput) input; Exception ex = in.getError(); if (ex != null) { throw new PartInitException(in.getError().getLocalizedMessage(), ex); } setInput(input); setSite(site); setPartName(in.getName()); proj = new PgDbProject(in.getProject()); sp = new ProjectEditorSelectionProvider(proj.getProject()); // message box if(!site.getPage().getPerspective().getId().equals(PERSPECTIVE.MAIN)){ askPerspectiveChange(site); } getSite().setSelectionProvider(sp); }
private IEditorPart getConnectorEditor(IWorkbenchPage activePage, Connector connector) { IEditorPart editorPart = null; if (activePage != null) { if (connector != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof ConnectorEditorInput)) { if (((ConnectorEditorInput)editorInput).is(connector)) { editorPart = editorRef.getEditor(false); break; } } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the connector editor '" + editorRef.getName() + "'"); } } } } return editorPart; }
public static void handleOpen ( final IWorkbenchPage page, final ISelection selection ) { final MultiStatus status = new MultiStatus ( Activator.PLUGIN_ID, 0, "Open editor", null ); final IEditorInput[] inputs = EditorHelper.createInput ( selection ); for ( final IEditorInput input : inputs ) { try { if ( input instanceof ConfigurationEditorInput ) { page.openEditor ( input, MultiConfigurationEditor.EDITOR_ID, true ); } else if ( input instanceof FactoryEditorInput ) { page.openEditor ( input, FactoryEditor.EDITOR_ID, true ); } } catch ( final PartInitException e ) { status.add ( e.getStatus () ); } } }
/** * Gets the jscript editor associated with given transaction. * !!MUST BE CALLED IN A UI-THREAD!! * @return IEditorPart : the found jscript editor or null */ public IEditorPart getJscriptTransactionEditor(Transaction transaction) { IEditorPart editorPart = null; IWorkbenchPage activePage = getActivePage(); if (activePage != null) { if (transaction != null) { IEditorReference[] editorRefs = activePage.getEditorReferences(); for (int i=0;i<editorRefs.length;i++) { IEditorReference editorRef = (IEditorReference)editorRefs[i]; try { IEditorInput editorInput = editorRef.getEditorInput(); if ((editorInput != null) && (editorInput instanceof JscriptTransactionEditorInput)) { if (((JscriptTransactionEditorInput)editorInput).transaction.equals(transaction)) { editorPart = editorRef.getEditor(false); break; } } } catch(PartInitException e) { //ConvertigoPlugin.logException(e, "Error while retrieving the jscript transaction editor '" + editorRef.getName() + "'"); } } } } return editorPart; }
@Override protected void createContainerControls(Composite parent, int nColumns) { super.createContainerControls(parent, nColumns); Text text = (Text) parent.getChildren()[1]; text.setEditable(false); IEditorInput editorInput = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor().getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput; IProject project = fileEditorInput.getFile().getProject(); if (project != null) { IFolder srcFolder = project.getFolder("src/main/java"); if (srcFolder != null && srcFolder.exists()) { text.setText(project.getName() + "/" + srcFolder.getProjectRelativePath().toString()); } } Button button = (Button) parent.getChildren()[2]; button.setEnabled(false); } }
private void enableRunningGraphResource(IEditorInput editorInput, String partName) { IFileEditorInput input = (IFileEditorInput)editorInput ; IFile fileJob = input.getFile(); IPath xmlFileIPath =new Path(input.getFile().getFullPath().toOSString().replace(".job", ".xml")); IFile fileXml = ResourcesPlugin.getWorkspace().getRoot().getFile(xmlFileIPath); ResourceAttributes attributes = new ResourceAttributes(); attributes.setReadOnly(false); attributes.setExecutable(true); try { if(fileJob.exists()){ fileJob.setResourceAttributes(attributes); } if(fileXml.exists()){ fileXml.setResourceAttributes(attributes); } } catch (CoreException e) { logger.error("Unable to enable locked job resources",e); } }
@Override public void init ( final IEditorSite site, final IEditorInput input ) throws PartInitException { setSite ( site ); setInput ( input ); final IFileEditorInput fileInput = AdapterHelper.adapt ( input, IFileEditorInput.class ); if ( fileInput != null ) { this.loader = new FileLoader ( fileInput ); setContentDescription ( fileInput.getName () ); setPartName ( fileInput.getName () ); } if ( this.loader == null ) { throw new PartInitException ( "Invalid editor input. Unable to load data" ); } }
@Override public void launch(IEditorPart editor, String mode) { try { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFile selectObj = ((IFileEditorInput) editorInput).getFile(); launchFile(selectObj, mode); } else { showDialogNotImplemented(editor.getClass().getName()); } } catch (CoreException e) { System.out.println(e.getLocalizedMessage() + "\n"); } }
/** * This is called during startup. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void init(IEditorSite site, IEditorInput editorInput) { setSite(site); setInputWithNotify(editorInput); setPartName(editorInput.getName()); site.setSelectionProvider(this); site.getPage().addPartListener(partListener); ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener, IResourceChangeEvent.POST_CHANGE); }
private boolean isEditorForResource(IEditorReference editorRef, IResource resource) { final IFile manifest = resource.getProject().getFile(N4MF_MANIFEST); if (!manifest.exists()) { return false; } try { final IEditorInput input = editorRef.getEditorInput(); if (input instanceof IFileEditorInput) { return ((IFileEditorInput) input).getFile().equals(manifest); } } catch (final PartInitException e) { LOGGER.warn("Error while trying to get editor input for editor reference: " + editorRef, e); } return false; }
public static IFile getFile(ITextEditor textEditor) { IEditorInput input = textEditor.getEditorInput(); if (input instanceof IFileEditorInput) { return ((IFileEditorInput) input).getFile(); } return null; }
/** * Derives a location URI as expected by {@link TestDiscoveryHelper#collectTests(URI...)} from an editor. */ public static final URI getLocationForEditor(IEditorPart editor) { final IEditorInput input = editor.getEditorInput(); if (input instanceof IFileEditorInput) return getLocationForEditorInput((IFileEditorInput) input); return null; }
@Override public void launch(IEditorPart editor, String mode) { IEditorInput editorInput = editor.getEditorInput(); if (editorInput instanceof IFileEditorInput) { IFile selectObj = ((IFileEditorInput) editorInput).getFile(); launchFile(selectObj, mode); } else { showDialogNotImplemented(editor.getClass().getName()); } }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void doSaveAs(URI uri, IEditorInput editorInput) { (editingDomain.getResourceSet().getResources().get(0)).setURI(uri); setInputWithNotify(editorInput); setPartName(editorInput.getName()); IProgressMonitor progressMonitor = getActionBars().getStatusLineManager() != null ? getActionBars().getStatusLineManager().getProgressMonitor() : new NullProgressMonitor(); doSave(progressMonitor); }
@Override public Object execute ( final ExecutionEvent event ) throws ExecutionException { final MultiStatus ms = new MultiStatus ( Activator.PLUGIN_ID, 0, "Opening preview", null ); for ( final IFile file : SelectionHelper.iterable ( getSelection (), IFile.class ) ) { final IEditorInput input = new FileEditorInput ( file ); try { getActivePage ().openEditor ( input, PreviewEditorImpl.EDITOR_ID, true, IWorkbenchPage.MATCH_ID ); } catch ( final PartInitException e ) { ms.add ( e.getStatus () ); } } if ( !ms.isOK () ) { final IStatus[] childs = ms.getChildren (); if ( childs.length < 2 ) { StatusManager.getManager ().handle ( childs[0], StatusManager.SHOW ); } else { StatusManager.getManager ().handle ( ms, StatusManager.SHOW ); } } return null; }
/** * Obtains an editor that may edits the contents of a file. * @param file the file * @return the editor of the file, or <code>null</code> if none */ public static IEditorPart getEditor(IFile file) { IEditorInput input = new FileEditorInput(file); IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); for (IWorkbenchWindow window : windows) { IWorkbenchPage[] pages = window.getPages(); for (IWorkbenchPage page : pages) { IEditorPart part = page.findEditor(input); return part; } } return null; }
/** * Records the file open operation when the editor is instantiated. * @param site the editor site * @param input the editor input * @exception PartInitException if this editor was not initialized successfully */ @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { super.init(site, input); if (historyManager == null) { historyManager = HistoryManager.getInstance(); historyManager.start(this); historyManager.recordFileOpenOperation(getInputFile(), getSourceCode()); } }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); if (activeWorkbenchWindow == null) { return null; } IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); if (activePage == null) { return null; } IEditorPart editor = activePage.getActiveEditor(); if (editor == null) { return null; } IEditorInput input = editor.getEditorInput(); if (input == null || ! (input instanceof FileEditorInput)) { return null; } IFile file = ((FileEditorInput) input).getFile(); if (file != null && file.getType() == IResource.FILE && file.getFileExtension().equals("java")) { utils = new ProjectUtils(file.getProject()); if (utils.isGluonMobileProject()) { ISelection selection = HandlerUtil.getCurrentSelection(event); Display.getDefault().asyncExec(() -> new JCode(utils, selection, (JavaEditor) editor)); } } return null; }
public static void removeLinterErrors(IEditorPart editor) { if (editor == null) { return; } IEditorInput input = editor.getEditorInput(); if (input == null) { return; } IResource editorResource = input.getAdapter(IResource.class); if (editorResource == null) { return; } linterMarkerHelper.removeMarkers(editorResource); }
@Override public IEditorInput getEditorInput(Object element) { if (element instanceof EObject) { EObject eObject = (EObject) element; EObject target = eObject; Resource res = eObject.eResource(); if(res != null && res.getResourceSet() != null) { MelangeResourceImpl mr = null; for(Resource candidate : res.getResourceSet().getResources()) { if(candidate instanceof MelangeResourceImpl) { mr = (MelangeResourceImpl) candidate; break; } } if(mr != null) { String uriFragment = res.getURIFragment(eObject); target = mr.getWrappedResource().getEObject(uriFragment); } } Resource r = eObject.eResource(); if (r instanceof XtextResource) { URI uri = target.eResource().getURI(); if(uri.toPlatformString(true) != null){ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true))); IFileEditorInput input = new FileEditorInput(file); return input; } } else { //Default return getPresentation().getEditorInput(eObject); } } return null; }
/** * Gets the current project from active graph. * * @return the current project from active graph */ private static IProject getCurrentProjectFromActiveGraph() { IEditorInput editorInput=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput(); if(editorInput instanceof IFileEditorInput){ return ((IFileEditorInput)editorInput).getFile().getProject(); } return null; }
@Override public IEditorInput getEditorInput(Object element) { final IEditorInput res; if (element instanceof MSE && ((MSE) element).getCaller() != null) { res = super.getEditorInput(((MSE) element).getCaller()); } else { res = super.getEditorInput(element); } return res; }
@Override public String getEditorId(IEditorInput input, Object element) { final String res; if (element instanceof MSE && ((MSE) element).getCaller() != null) { res = super.getEditorId(input, ((MSE) element).getCaller()); } else { res = super.getEditorId(input, element); } return res; }
/** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void doSaveAs ( URI uri, IEditorInput editorInput ) { ( editingDomain.getResourceSet ().getResources ().get ( 0 ) ).setURI ( uri ); setInputWithNotify ( editorInput ); setPartName ( editorInput.getName () ); IProgressMonitor progressMonitor = getActionBars ().getStatusLineManager () != null ? getActionBars ().getStatusLineManager ().getProgressMonitor () : new NullProgressMonitor (); doSave ( progressMonitor ); }