private int getSeverity() { IEditorInput editorInput = getEditorInput(); if (editorInput == null) { return IMarker.SEVERITY_INFO; } try { final IResource resource = ResourceUtil.getResource(editorInput); if (resource == null) { return IMarker.SEVERITY_INFO; } int severity = resource.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); return severity; } catch (CoreException e) { // Might be a project that is not open } return IMarker.SEVERITY_INFO; }
private boolean isMarkerChangeForThisEditor(IResourceChangeEvent event) { IResource resource = ResourceUtil.getResource(getEditorInput()); if (resource == null) { return false; } IPath path = resource.getFullPath(); if (path == null) { return false; } IResourceDelta eventDelta = event.getDelta(); if (eventDelta == null) { return false; } IResourceDelta delta = eventDelta.findMember(path); if (delta == null) { return false; } boolean isMarkerChangeForThisResource = (delta.getFlags() & IResourceDelta.MARKERS) != 0; return isMarkerChangeForThisResource; }
public static String getPathFromInput(IEditorInput in) { IResource res = ResourceUtil.getResource(in); if (res != null) { try { if (res.getProject().hasNature(NATURE.ID)) { return res.getLocation().toOSString(); } } catch (CoreException ex) { Log.log(Log.LOG_WARNING, "Nature error", ex); //$NON-NLS-1$ } } if (in instanceof IURIEditorInput) { return Paths.get(((IURIEditorInput) in).getURI()).toString(); } else { return null; } }
public DbInfo getCurrentDb() { if (currentDB != null) { return currentDB; } IResource res = ResourceUtil.getResource(getEditorInput()); if (res != null) { IEclipsePreferences prefs = PgDbProject.getPrefs(res.getProject()); if (prefs != null) { List<DbInfo> lastStore = DbInfo.preferenceToStore( prefs.get(PROJ_PREF.LAST_DB_STORE_EDITOR, "")); //$NON-NLS-1$ if (!lastStore.isEmpty()) { return lastStore.get(0); } } } return null; }
@Override public Image getTitleImage() { Image image = super.getTitleImage(); try { IEditorInput input = getEditorInput(); IResource file = ResourceUtil.getResource(input); if (input.exists() && file != null && file.findMarkers(MARKER.ERROR, false, IResource.DEPTH_ZERO).length > 0) { if (errorTitleImage == null) { errorTitleImage = new DecorationOverlayIcon(image, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( ISharedImages.IMG_DEC_FIELD_ERROR), IDecoration.BOTTOM_LEFT) .createImage(); } return errorTitleImage; } } catch (CoreException e) { Log.log(e); } return image; }
/** * Returns {@link IDocument} in the open editor, or null if the editor * is not open. */ static IDocument getCurrentDocument(IFile file) { try { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); IEditorPart editorPart = ResourceUtil.findEditor(activePage, file); if (editorPart != null) { IDocument document = editorPart.getAdapter(IDocument.class); return document; } return null; } catch (IllegalStateException ex) { //If workbench does not exist return null; } }
private IPath getFilePath(ITextEditor textEditor) { IEditorInput editorInput = textEditor.getEditorInput(); IFile file = ResourceUtil.getFile(editorInput); File localFile = null; if (file != null) { localFile = file.getLocation().toFile(); } else if (editorInput instanceof FileStoreEditorInput) { FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput; URI uri = fileStoreEditorInput.getURI(); IFileStore location = EFS.getLocalFileSystem().getStore(uri); try { localFile = location.toLocalFile(EFS.NONE, null); } catch (CoreException e) { // ignore } } if (localFile == null) { return null; } else { return Path.fromOSString(localFile.toString()); } }
@Override public Object execute( ExecutionEvent event ) { IEditorInput editorInput = HandlerUtil.getActiveEditorInput( event ); IFile resource = ResourceUtil.getFile( editorInput ); if( resource != null ) { if( resource.isAccessible() ) { deleteResource( HandlerUtil.getActiveWorkbenchWindow( event ), resource ); } } else { File file = getFile( editorInput ); IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow( event ); if( file != null && prompter.confirmDelete( workbenchWindow, file )) { deleteFile( workbenchWindow, file ); } } return null; }
@Override public void decorate(Object element, IDecoration decoration) { final IResource resource = ResourceUtil.getResource(element); if (resource != null && resource.getType() != ROOT) { final CodenvyProvider provider = (CodenvyProvider)getProvider(resource.getProject(), CodenvyProvider.PROVIDER_ID); if (provider != null) { final CodenvyMetaResource metaResource = (CodenvyMetaResource)getAdapter(resource, CodenvyMetaResource.class, true); if (metaResource != null && metaResource.isTracked()) { decoration.addOverlay(trackedImageDescriptor); if (resource.getType() == PROJECT) { decoration.addSuffix(" [codenvy: " + provider.getProjectMetadata().url + "]"); } } } } }
public static ICompilationUnit getCurrentCompilationUnit() { IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage().getActiveEditor(); if (activeEditor == null) { return null; } IFile file = (IFile) ResourceUtil.getFile(activeEditor.getEditorInput()); if (file == null) { return null; } IJavaElement element = JavaCore.create(file); if (!(element instanceof ICompilationUnit) || !element.exists()) { return null; } return (ICompilationUnit) element; }
/** * Attempts to guess the most relevant resource for the current workbench state */ public static IResource getContextResource() { IWorkbenchPage page = getActivePage(); if (page == null) { return null; } final ISelection selection = page.getSelection(); if (selection instanceof IStructuredSelection) { final IStructuredSelection ss = (IStructuredSelection) selection; if (!ss.isEmpty()) { final Object obj = ss.getFirstElement(); if (obj instanceof IResource) { return (IResource) obj; } } } IEditorPart editor = page.getActiveEditor(); if (editor == null) { return null; } IEditorInput editorInput = editor.getEditorInput(); return ResourceUtil.getResource(editorInput); }
@Override public IStructuredSelection findSelection(IEditorInput input) { IFile file = ResourceUtil.getFile(input); if (file != null) { return new StructuredSelection(file); } IFileStore fileStore = (IFileStore) input.getAdapter(IFileStore.class); if (fileStore == null && input instanceof FileStoreEditorInput) { URI uri = ((FileStoreEditorInput)input).getURI(); try { fileStore = EFS.getStore(uri); } catch (CoreException e) { } } if (fileStore != null) { return new StructuredSelection(fileStore); } return StructuredSelection.EMPTY; }
@Override public Object execute(ExecutionEvent event) { SQLEditor editor = (SQLEditor) HandlerUtil.getActiveEditor(event); DbInfo dbInfo = editor.getCurrentDb(); if (dbInfo == null){ ExceptionNotifier.notifyDefault(Messages.sqlScriptDialog_script_select_storage, null); return null; } String text = editor.getEditorText(); if (text.trim().isEmpty()) { ExceptionNotifier.notifyDefault(Messages.QuickUpdate_empty_script, null); return null; } IFile file = ResourceUtil.getFile(editor.getEditorInput()); editor.doSave(new NullProgressMonitor()); byte[] textSnapshot; try { textSnapshot = text.getBytes(file.getCharset()); } catch (UnsupportedEncodingException | CoreException e) { ExceptionNotifier.notifyDefault(Messages.QuickUpdate_error_charset, e); return null; } QuickUpdateJob quickUpdateJob = new QuickUpdateJob(file, dbInfo, textSnapshot, editor); quickUpdateJob.setUser(true); quickUpdateJob.schedule(); editor.saveLastDb(dbInfo); return null; }
public static void saveLastDb(DbInfo lastDb, IEditorInput inputForProject) { IResource res = ResourceUtil.getResource(inputForProject); if (res != null) { IEclipsePreferences prefs = PgDbProject.getPrefs(res.getProject()); if (prefs != null) { prefs.put(PROJ_PREF.LAST_DB_STORE_EDITOR, lastDb.toString()); try { prefs.flush(); } catch (BackingStoreException ex) { Log.log(ex); } } } }
@Override public void doSave(IProgressMonitor progressMonitor) { super.doSave(progressMonitor); IResource res = ResourceUtil.getResource(getEditorInput()); try { if (res == null || !PgUIDumpLoader.isInProject(res)) { refreshParser(getParser(), res, progressMonitor); } } catch (Exception ex) { Log.log(ex); } }
private PgDbParser initParser() throws InterruptedException, IOException, CoreException { IEditorInput in = getEditorInput(); IResource res = ResourceUtil.getResource(in); if (res != null && PgUIDumpLoader.isInProject(res)) { return PgDbParser.getParser(res.getProject()); } PgDbParser parser = new PgDbParser(); if (refreshParser(parser, res, null)) { return parser; } throw new PartInitException("Unknown editor input: " + in); //$NON-NLS-1$ }
@Override public void resourceChanged(IResourceChangeEvent event) { IResource file = ResourceUtil.getResource(getEditorInput()); IResourceDelta delta = event.getDelta(); if (delta != null && file != null) { IResourceDelta child = delta.findMember(file.getFullPath()); if (child != null && (child.getFlags() & IResourceDelta.MARKERS) != 0) { UiSync.exec(parentComposite, () -> { if (!parentComposite.isDisposed()) { firePropertyChange(IWorkbenchPart.PROP_TITLE); } }); } } }
@Override protected String getFilePath() { IEditorPart editor; editor = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor(); String result = null; final IFile file = ResourceUtil.getFile(editor.getEditorInput()); result = file.getLocation().makeAbsolute().toOSString(); return result; }
@Override public String getFilePath() { IEditorPart editor; editor = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage() .getActiveEditor(); String result = null; final IFile file = ResourceUtil.getFile(editor.getEditorInput()); result = file.getLocation().makeAbsolute().toOSString(); return result; }
static ITextViewer getViewer(IFile file) { IWorkbench workbench = PlatformUI.getWorkbench(); IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage(); IEditorPart editorPart = ResourceUtil.findEditor(activePage, file); ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class); if (target instanceof ITextViewer) { return (ITextViewer) target; } return null; }
private static IResource getWorkspaceResource(IWorkbenchPart part) { ITextEditor textEditor = getTextEditor(part); if (textEditor == null) { return null; } IEditorInput editorInput = textEditor.getEditorInput(); IFile file = ResourceUtil.getFile(editorInput); return file; }
private void addWorkspacePath(Map<String, String> properties, ITextEditor textEditor) { IEditorInput editorInput = textEditor.getEditorInput(); IFile file = ResourceUtil.getFile(editorInput); if (file == null) { return; } putIfAbsent(properties, PROP_WORKSPACE_PATH, file.getFullPath().toPortableString()); putIfAbsent(properties, PROP_PROJECT_NAME, file.getProject().getName()); }
private void updatePageModel() { String text = getText(); if (text == null) text = ""; IResource resource = ResourceUtil.getResource(getEditorInput()); pageModel.updateModel(resource, text); pageDirty = false; }
public IXtextDocument getXtextDocument(IResource resource) { IXtextDocument result = XtextDocumentUtil.get(resource); if(result == null) { IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); try { IFile file = ResourceUtil.getFile(resource); IEditorInput input = new FileEditorInput(file); page.openEditor(input, getEditorId()); } catch (PartInitException e) { return null; } } return XtextDocumentUtil.get(resource); }
private static IFile extractFileFromSelection( IStructuredSelection selection ) { IFile result = null; if( selection.size() == 1 ) { result = ResourceUtil.getFile( selection.getFirstElement() ); } return result; }
private static boolean isEnabled( IEvaluationContext evaluationContext ) { Object variable = evaluationContext.getVariable( ISources.ACTIVE_EDITOR_INPUT_NAME ); boolean result = false; if( variable instanceof IEditorInput ) { IEditorInput editorInput = ( IEditorInput )variable; result = ResourceUtil.getFile( editorInput ) != null || getFile( editorInput ) != null; } return result; }
private IPath querySaveAsFilePath() { SaveAsDialog dialog = new SaveAsDialog( getSite().getShell() ); IEditorInput editorInput = getEditorInput(); IFile originalFile = ResourceUtil.getFile( editorInput ); if( originalFile != null ) { dialog.setOriginalFile( originalFile ); } else { dialog.setOriginalName( editorInput.getName() ); } int dialogResult = dialog.open(); return dialogResult == Window.OK ? dialog.getResult() : null; }
public IStructuredSelection findSelection(IEditorInput input) { IJavaElement element= JavaUI.getEditorInputJavaElement(input); if (element == null) { IFile file = ResourceUtil.getFile(input); if (file != null) { element= JavaCore.create(file); } } return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY; }
/** * 释放编辑器,同时释放其他相关资源。 * @see org.eclipse.ui.part.WorkbenchPart#dispose() */ public void dispose() { // 当该编辑器被释放资源时,检查该编辑器是否被保存,并且是否是同时打开多个文件,若成立,则删除合并打开所产生的临时文件--robert 2012-03-30 if (!isStore && isMultiFile()) { try { IEditorInput input = getEditorInput(); IProject multiProject = ResourceUtil.getResource(input).getProject(); ResourceUtil.getResource(input).delete(true, null); multiProject.refreshLocal(IResource.DEPTH_INFINITE, null); CommonFunction.refreshHistoryWhenDelete(input); } catch (CoreException e) { LOGGER.error("", e); e.printStackTrace(); } } if (titleImage != null && !titleImage.isDisposed()) { titleImage.dispose(); titleImage = null; } if (table != null && !table.isDisposed()) { table.dispose(); table = null; } if (statusLineImage != null && !statusLineImage.isDisposed()) { statusLineImage.dispose(); statusLineImage = null; } handler = null; JFaceResources.getFontRegistry().removeListener(fFontPropertyChangeListener); NattableUtil.getInstance(this).releaseResource(); super.dispose(); System.gc(); }
public IStructuredSelection findSelection(IEditorInput anInput) { IFile file = ResourceUtil.getFile(anInput); if (file != null) { return new StructuredSelection(file); } return StructuredSelection.EMPTY; }
public Object execute(ExecutionEvent event) throws ExecutionException { IEditorPart editor = HandlerUtil.getActiveEditor(event); if (editor == null) { return false; } IEditorInput input = editor.getEditorInput(); IFile file = ResourceUtil.getFile(input); shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(); if (file == null) { MessageDialog.openInformation(shell, "提示", "未找当前编辑器打开的文件资源。"); } else { String fileExtension = file.getFileExtension(); if (fileExtension != null && "xlf".equalsIgnoreCase(fileExtension)) { ConverterViewModel model = getConverterViewModel(file); if (model != null) { model.convert(); } } else if (fileExtension != null && "xlp".equalsIgnoreCase(fileExtension)) { if (file.exists()) { IFolder xliffFolder = file.getProject().getFolder(Constant.FOLDER_XLIFF); if (xliffFolder.exists()) { ArrayList<IFile> files = new ArrayList<IFile>(); try { getChildFiles(xliffFolder, "xlf", files); } catch (CoreException e) { throw new ExecutionException(e.getMessage(), e); } previewFiles(files); } else { MessageDialog.openWarning(shell, "提示", "未找到系统默认的 XLIFF 文件夹!"); } } } else { MessageDialog.openInformation(shell, "提示", "当前编辑器打开的文件不是一个合法的 XLIFF 文件。"); } } return null; }
/** {@inheritDoc} */ @Override protected void createActions() { super.createActions(); selectionActions.add(registerAction(new OpenSpecificationAction(this))); selectionActions.add(registerAction(new ReferenceProjectSearchAction( this, ResourceUtil.getFile(getEditorInput())))); selectionActions.add(registerAction(new ReferenceWorkspaceSearchAction( this))); selectionActions.add(registerAction(new CopyAction(this))); selectionActions.add(registerAction(new CutAction(this))); selectionActions.add(registerAction(new PowerDeleteAction(this))); selectionActions.add(registerAction(new InvertConditionAction(this))); selectionActions .add(registerAction(new SourceEdgeVisibilityAction(this))); selectionActions.add(registerAction(new ExtractBlockAction(this))); selectionActions.add(registerAction(new LayoutAction(this))); selectionActions.add(registerAction(new VerticalAlignAction(this))); selectionActions.add(registerAction(new HorizontalAlignAction(this))); selectionActions.add(registerAction(new ExposeInterfaceWizardAction( this))); selectionActions .add(registerAction(new ParameterRenameRefactoringAction(this))); registerAction(new PasteAction(this)); }
@Override public void launch(IEditorPart editor, String mode) { IFile file = ResourceUtil.getFile(editor.getEditorInput()); if (file != null) { IProject project = file.getProject(); launch(project); } else{ showEmptyError("Unable to determine the project to launch for from the editor."); } }