It's all about the answers!

Ask a question

Need to open files from the workspace already loaded...would also require to access history of files


Atul Kumar (1871929) | asked May 30 '14, 2:25 a.m.
edited May 30 '14, 6:28 a.m.
For my application, I need to open files programmatically from the workspace already loaded.

What is the starting point for that ?

To be specific,
a. I need to open workspace files (from my view) which should be editable
b. Need to open Compare editor with N-1 version on the right (read-only) and current workspace version (editable) on the left (like it is done while merging.)

One answer



permanent link
Atul Kumar (1871929) | answered Nov 24 '14, 3:36 a.m.
Here's the implementation for opening local-workspace's file:

 public static IFile openLocalFile(final Shell shell, final IWorkbenchPage page, IShareable shareable, boolean open) {
        try {          
        Object adapter = shareable.getAdapter(IResource.class);
        if (adapter instanceof IResource) {
            IResource resource = (IResource) adapter;
            IFile file = (IFile) resource;
            if(open) {
                openFileWithDefaultEditor(page, file);
            }
            return file;
        } else {
            URI uri = URIUtil.toURI((IPath) shareable.getFullPath().getAdapter(IPath.class));
            String editorId = null;
            try {
                IEditorDescriptor desc = IDE.getEditorDescriptor(shareable.getLocalPath().getName());
                if (desc != null) {
                    editorId = desc.getId();
                }
            } catch (PartInitException e) {
                StatusUtil.log(UiPlugin.PLUGIN_ID, e);
            }
            if (editorId == null) {
                editorId = EditorsUI.DEFAULT_TEXT_EDITOR_ID;
            }
            try {
                if(open) {                    
                    IDE.openEditor(page, uri, editorId, true);
                }
            } catch (PartInitException e) {
                StatusUtil.log(UiPlugin.PLUGIN_ID, e);
            }
        }
        return null;
    }

Your answer


Register or to post your answer.