本文整理汇总了Java中org.eclipse.ui.ide.ResourceUtil类的典型用法代码示例。如果您正苦于以下问题:Java ResourceUtil类的具体用法?Java ResourceUtil怎么用?Java ResourceUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceUtil类属于org.eclipse.ui.ide包,在下文中一共展示了ResourceUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSeverity
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
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;
}
示例2: isMarkerChangeForThisEditor
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
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;
}
示例3: getPathFromInput
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
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;
}
}
示例4: getCurrentDb
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
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;
}
示例5: getTitleImage
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
@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;
}
示例6: getCurrentDocument
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
/**
* 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;
}
}
示例7: getFilePath
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
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());
}
}
示例8: execute
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
@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;
}
示例9: decorate
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
@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 + "]");
}
}
}
}
}
示例10: getCurrentCompilationUnit
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
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;
}
示例11: getContextResource
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
/**
* 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);
}
示例12: findSelection
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
@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;
}
示例13: execute
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
@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;
}
示例14: saveLastDb
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
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);
}
}
}
}
示例15: doSave
import org.eclipse.ui.ide.ResourceUtil; //导入依赖的package包/类
@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);
}
}