List of usage examples for org.eclipse.jdt.core IJavaModel getWorkspace
IWorkspace getWorkspace();
From source file:net.sf.j2s.ui.actions.UnitJavaScriptUtil.java
License:Open Source License
public static boolean openEditor(ICompilationUnit unit) { String relativePath = getRelativeJSPath(unit); IJavaModel javaModel = unit.getJavaModel(); File file = new File(javaModel.getResource().getLocation().toOSString(), relativePath); IFile[] files = javaModel.getWorkspace().getRoot() .findFilesForLocation(Path.fromPortableString(relativePath)); IEditorInput editorInput = null;/*from w w w . j a v a 2s . c o m*/ if (files != null && files.length != 0) { editorInput = new FileEditorInput(files[0]); try { Java2ScriptUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage() .openEditor(editorInput, getEditorID()); return true; } catch (PartInitException e) { e.printStackTrace(); } } else { IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(file.getParent())); fileStore = fileStore.getChild(file.getName()); if (!fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) { IWorkbenchWindow fWindow = Java2ScriptUIPlugin.getDefault().getWorkbench() .getActiveWorkbenchWindow(); IWorkbenchPage page = fWindow.getActivePage(); try { // Copy from IDE.openEditorOnFileStore IEditorInput input = getEditorInput(fileStore); String editorId = null; IEditorDescriptor descriptor; try { descriptor = IDE.getEditorDescriptor("java2script.txt"); // text editor if (descriptor != null) editorId = descriptor.getId(); } catch (PartInitException e) { } // open the editor on the file page.openEditor(input, editorId); return true; } catch (PartInitException e) { String msg = NLS.bind(IDEWorkbenchMessages.OpenLocalFileAction_message_errorOnOpen, fileStore.getName()); IDEWorkbenchPlugin.log(msg, e.getStatus()); MessageDialog.openError(fWindow.getShell(), IDEWorkbenchMessages.OpenLocalFileAction_title, msg); } } } return false; }