Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-17 04:21:12 +0000
committerEike Stepper2012-09-17 04:21:12 +0000
commite8539fb3937305a12d648f7eb85952a11e7d71e1 (patch)
tree5daa8abd6d31aeed8d9841e8620b1de829ce1764 /plugins
parent94e9d7dccf553650b9f0f8c5858087962a9445c7 (diff)
downloadcdo-e8539fb3937305a12d648f7eb85952a11e7d71e1.tar.gz
cdo-e8539fb3937305a12d648f7eb85952a11e7d71e1.tar.xz
cdo-e8539fb3937305a12d648f7eb85952a11e7d71e1.zip
Provide better CDOEditorUtil.openEditor() mechansim
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobEditorInput.java58
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java299
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEditorUtil.java226
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java178
4 files changed, 441 insertions, 320 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobEditorInput.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobEditorInput.java
index 5dc7c0cf2e..07f85e40e6 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobEditorInput.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobEditorInput.java
@@ -13,9 +13,11 @@ package org.eclipse.emf.cdo.internal.ui;
import org.eclipse.emf.cdo.common.lob.CDOBlob;
import org.eclipse.emf.cdo.common.lob.CDOClob;
import org.eclipse.emf.cdo.eresource.CDOBinaryResource;
-import org.eclipse.emf.cdo.eresource.CDOFileResource;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.CDOResourceLeaf;
import org.eclipse.emf.cdo.eresource.CDOTextResource;
import org.eclipse.emf.cdo.internal.ui.bundle.OM;
+import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.io.IORuntimeException;
@@ -58,19 +60,22 @@ public class CDOLobEditorInput extends PlatformObject implements IURIEditorInput
private static final Map<CDOLobEditorInput, LobFileStore> fileStores = new WeakHashMap<CDOLobEditorInput, LobFileStore>();
- private static int lastID;
-
- private CDOFileResource<?> resource;
+ private CDOResourceLeaf resource;
private URI uri;
- public CDOLobEditorInput(CDOFileResource<?> resource)
+ public CDOLobEditorInput(CDOResourceLeaf resource)
{
this.resource = resource;
try
{
- uri = new URI(SCHEME + "://" + ++lastID);
+ CDOView view = resource.cdoView();
+ org.eclipse.emf.common.util.URI resourceURI = resource.getURI();
+ String path = resourceURI.authority() + "/" + resourceURI.path() + "?session=" + view.getSessionID() + "&view="
+ + view.getViewID();
+
+ uri = new URI(SCHEME + "://" + path);
}
catch (URISyntaxException ex)
{
@@ -79,11 +84,12 @@ public class CDOLobEditorInput extends PlatformObject implements IURIEditorInput
synchronized (fileStores)
{
+ fileStores.remove(this);
fileStores.put(this, null);
}
}
- public CDOFileResource<?> getResource()
+ public CDOResourceLeaf getResource()
{
return resource;
}
@@ -110,7 +116,7 @@ public class CDOLobEditorInput extends PlatformObject implements IURIEditorInput
public String getToolTipText()
{
- return resource.getPath();
+ return resource.getURI().toString();
}
public URI getURI()
@@ -123,7 +129,7 @@ public class CDOLobEditorInput extends PlatformObject implements IURIEditorInput
{
final int prime = 31;
int result = 1;
- result = prime * result + (resource == null ? 0 : resource.hashCode());
+ result = prime * result + (uri == null ? 0 : uri.hashCode());
return result;
}
@@ -146,14 +152,14 @@ public class CDOLobEditorInput extends PlatformObject implements IURIEditorInput
}
CDOLobEditorInput other = (CDOLobEditorInput)obj;
- if (resource == null)
+ if (uri == null)
{
- if (other.resource != null)
+ if (other.uri != null)
{
return false;
}
}
- else if (!resource.equals(other.resource))
+ else if (!uri.equals(other.uri))
{
return false;
}
@@ -193,7 +199,7 @@ public class CDOLobEditorInput extends PlatformObject implements IURIEditorInput
protected LobFileStore createStore(URI uri, CDOLobEditorInput editorInput)
{
- CDOFileResource<?> resource = editorInput.getResource();
+ CDOResourceLeaf resource = editorInput.getResource();
return new LobFileStore(resource, uri);
}
}
@@ -205,13 +211,13 @@ public class CDOLobEditorInput extends PlatformObject implements IURIEditorInput
{
private static final String[] NO_CHILDREN = new String[0];
- private CDOFileResource<?> resource;
+ private CDOResourceLeaf resource;
private final URI uri;
private FileInfo info;
- public LobFileStore(CDOFileResource<?> resource, URI uri)
+ public LobFileStore(CDOResourceLeaf resource, URI uri)
{
this.resource = resource;
this.uri = uri;
@@ -263,16 +269,24 @@ public class CDOLobEditorInput extends PlatformObject implements IURIEditorInput
return new ByteArrayInputStream(bytes);
}
- CDOBlob blob = ((CDOBinaryResource)resource).getContents();
- if (blob == null)
+ if (resource instanceof CDOBinaryResource)
{
- return new ByteArrayInputStream(new byte[0]);
+ CDOBlob blob = ((CDOBinaryResource)resource).getContents();
+ if (blob == null)
+ {
+ return new ByteArrayInputStream(new byte[0]);
+ }
+
+ InputStream inputStream = blob.getContents();
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ IOUtil.copy(inputStream, outputStream);
+
+ byte[] bytes = outputStream.toByteArray();
+ return new ByteArrayInputStream(bytes);
}
- InputStream inputStream = blob.getContents();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- IOUtil.copy(inputStream, outputStream);
-
+ ((CDOResource)resource).save(outputStream, null);
byte[] bytes = outputStream.toByteArray();
return new ByteArrayInputStream(bytes);
}
@@ -299,7 +313,7 @@ public class CDOLobEditorInput extends PlatformObject implements IURIEditorInput
CDOClob clob = new CDOClob(new CharArrayReader(string.toCharArray()));
textResource.setContents(clob);
}
- else
+ else if (resource instanceof CDOBinaryResource)
{
byte[] bytes = toByteArray();
CDOBlob blob = new CDOBlob(new ByteArrayInputStream(bytes));
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java
index 0a55d8cda0..e73f480fb2 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java
@@ -10,23 +10,27 @@
*/
package org.eclipse.emf.cdo.internal.ui.views;
+import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceLeaf;
-import org.eclipse.emf.cdo.internal.ui.actions.OpenResourceEditorAction;
import org.eclipse.emf.cdo.internal.ui.actions.OpenSessionAction;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.transfer.ui.TransferDropAdapter;
+import org.eclipse.emf.cdo.ui.CDOEditorUtil;
import org.eclipse.emf.cdo.ui.CDOItemProvider;
import org.eclipse.net4j.util.container.IContainer;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
+import org.eclipse.net4j.util.ui.views.ContainerNameSorter;
import org.eclipse.net4j.util.ui.views.ContainerView;
import org.eclipse.net4j.util.ui.views.IElementFilter;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchPage;
@@ -64,6 +68,35 @@ public class CDOSessionsView extends ContainerView
}
@Override
+ protected ViewerSorter createViewerSorter()
+ {
+ return new ContainerNameSorter()
+ {
+ @Override
+ public int compare(Viewer viewer, Object e1, Object e2)
+ {
+ if (e1 instanceof CDOResourceFolder)
+ {
+ if (e2 instanceof CDOResourceLeaf)
+ {
+ return -1;
+ }
+ }
+
+ if (e1 instanceof CDOResourceLeaf)
+ {
+ if (e2 instanceof CDOResourceFolder)
+ {
+ return 1;
+ }
+ }
+
+ return super.compare(viewer, e1, e2);
+ }
+ };
+ }
+
+ @Override
protected IManagedContainer getContainer()
{
return IPluginContainer.INSTANCE;
@@ -96,9 +129,10 @@ public class CDOSessionsView extends ContainerView
if (object instanceof CDOResourceLeaf)
{
CDOResourceLeaf resource = (CDOResourceLeaf)object;
- String path = resource.getPath();
- String extension = new Path(path).getFileExtension();
+ String name = resource.getName();
+ String extension = new Path(name).getFileExtension();
+
ResourceOpener opener = resourceOpeners.get(extension);
if (opener != null)
{
@@ -106,8 +140,7 @@ public class CDOSessionsView extends ContainerView
}
else
{
- OpenResourceEditorAction action = new OpenResourceEditorAction(page, resource);
- action.run();
+ CDOEditorUtil.openEditor(page, resource);
}
}
else
@@ -133,260 +166,4 @@ public class CDOSessionsView extends ContainerView
{
public void openResource(IWorkbenchPage page, CDOResourceLeaf resource);
}
-
- // /**
- // * @author Eike Stepper
- // */
- // public static class CDOResourceDropAdapter extends DNDDropAdapter<Object>
- // {
- // public static final Transfer[] TRANSFERS = { ResourceTransfer.getInstance(), FileTransfer.getInstance() };
- //
- // protected CDOResourceDropAdapter(StructuredViewer viewer)
- // {
- // super(TRANSFERS, viewer);
- // }
- //
- // @Override
- // protected boolean validateTarget(Object target, int operation)
- // {
- // if (getTargetResourceNode(target) != null)
- // {
- // overrideOperation(DND.DROP_COPY);
- // return true;
- // }
- //
- // return false;
- // }
- //
- // @Override
- // protected boolean performDrop(Object data, Object target)
- // {
- // CDOResourceNode container = getTargetResourceNode(target);
- // String containerPath = container.getPath();
- //
- // List<Source> sources = Source.getSources((Object[])data);
- // for (Source source : sources)
- // {
- // // System.out.println(source.getName() + " --> " + originalOperation);
- // }
- //
- // return true;
- // }
- //
- // protected CDOResourceNode getTargetResourceNode(Object target)
- // {
- // if (target instanceof CDOTransaction)
- // {
- // return ((CDOTransaction)target).getRootResource();
- // }
- //
- // if (target instanceof CDOResourceFolder)
- // {
- // return (CDOResourceFolder)target;
- // }
- //
- // return null;
- // }
- //
- // public static CDOResourceDropAdapter support(StructuredViewer viewer)
- // {
- // CDOResourceDropAdapter dropAdapter = new CDOResourceDropAdapter(viewer);
- // viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT, TRANSFERS, dropAdapter);
- // return dropAdapter;
- // }
- //
- // /**
- // * @author Eike Stepper
- // */
- // public static abstract class Source
- // {
- // public abstract String getName();
- //
- // public abstract String getPath();
- //
- // public abstract boolean isDirectory();
- //
- // public final InputStream getInputStream() throws IOException
- // {
- // checkNotDirectory();
- // return openInputStream();
- // }
- //
- // public final OutputStream getOutputStream() throws IOException
- // {
- // checkNotDirectory();
- // return openOutputStream();
- // }
- //
- // protected abstract InputStream openInputStream() throws IOException;
- //
- // protected abstract OutputStream openOutputStream() throws IOException;
- //
- // private void checkNotDirectory() throws IOException
- // {
- // if (isDirectory())
- // {
- // throw new IOException("Not supported for directories");
- // }
- // }
- //
- // public static Source getSource(Object data)
- // {
- // if (data instanceof IResource)
- // {
- // IResource resource = (IResource)data;
- // return new ResourceSource(resource);
- // }
- //
- // if (data instanceof String)
- // {
- // File file = new File((String)data);
- // return new FileSource(file);
- // }
- //
- // return null;
- // }
- //
- // public static List<Source> getSources(Object[] data)
- // {
- // List<Source> sources = new ArrayList<Source>();
- //
- // String commonPath = null;
- // for (int i = 0; i < data.length; i++)
- // {
- // Object element = data[i];
- // Source source = getSource(element);
- // if (source != null && !source.isDirectory())
- // {
- // String path = source.getPath();
- // if (commonPath == null)
- // {
- // commonPath = path;
- // }
- // else
- // {
- // if (!commonPath.equals(path))
- // {
- // return new ArrayList<Source>();
- // }
- // }
- //
- // sources.add(source);
- // }
- // }
- //
- // return sources;
- // }
- //
- // /**
- // * @author Eike Stepper
- // */
- // private static class ResourceSource extends Source
- // {
- // private IResource resource;
- //
- // public ResourceSource(IResource resource)
- // {
- // this.resource = resource;
- // }
- //
- // @Override
- // public String getName()
- // {
- // return resource.getName();
- // }
- //
- // @Override
- // public String getPath()
- // {
- // return resource.getParent().getFullPath().toString();
- // }
- //
- // @Override
- // public boolean isDirectory()
- // {
- // return resource instanceof org.eclipse.core.resources.IContainer;
- // }
- //
- // @Override
- // protected InputStream openInputStream() throws IOException
- // {
- // try
- // {
- // return ((IFile)resource).getContents();
- // }
- // catch (CoreException ex)
- // {
- // throw new IOException(ex);
- // }
- // }
- //
- // @Override
- // protected OutputStream openOutputStream() throws IOException
- // {
- // return new ByteArrayOutputStream()
- // {
- // @Override
- // public void close() throws IOException
- // {
- // if (resource.exists())
- // {
- // try
- // {
- // ((IFile)resource).setContents(new ByteArrayInputStream(toByteArray()), true, true, null);
- // }
- // catch (CoreException ex)
- // {
- // throw new IOException(ex);
- // }
- // }
- // }
- // };
- // }
- // }
- //
- // /**
- // * @author Eike Stepper
- // */
- // private static class FileSource extends Source
- // {
- // private File file;
- //
- // public FileSource(File file)
- // {
- // this.file = file;
- // }
- //
- // @Override
- // public String getName()
- // {
- // return file.getName();
- // }
- //
- // @Override
- // public String getPath()
- // {
- // return file.getParentFile().getPath();
- // }
- //
- // @Override
- // public boolean isDirectory()
- // {
- // return file.isDirectory();
- // }
- //
- // @Override
- // protected InputStream openInputStream() throws IOException
- // {
- // return new FileInputStream(file);
- // }
- //
- // @Override
- // protected OutputStream openOutputStream() throws IOException
- // {
- // return new FileOutputStream(file);
- // }
- // }
- // }
- // }
}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEditorUtil.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEditorUtil.java
index d76ee6cd65..5f6a4c8850 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEditorUtil.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEditorUtil.java
@@ -11,22 +11,34 @@
*/
package org.eclipse.emf.cdo.ui;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.CDOResourceLeaf;
import org.eclipse.emf.cdo.internal.ui.CDOEditorInputImpl;
+import org.eclipse.emf.cdo.internal.ui.CDOLobEditorInput;
import org.eclipse.emf.cdo.internal.ui.bundle.OM;
import org.eclipse.emf.cdo.internal.ui.editor.CDOEditor;
import org.eclipse.emf.cdo.view.CDOView;
import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
/**
* Some utility methods to cope with CDOEditor and CDOEditorInput
@@ -41,6 +53,12 @@ public final class CDOEditorUtil
*/
public static final String EDITOR_ID = "org.eclipse.emf.cdo.ui.CDOEditor"; //$NON-NLS-1$
+ private static final IEditorRegistry EDITOR_REGISTRY = PlatformUI.getWorkbench().getEditorRegistry();
+
+ private static final Map<CDOResourceLeaf, String> EDITOR_OVERRIDES = new WeakHashMap<CDOResourceLeaf, String>();
+
+ private static final String TEXT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor";
+
private static String editorID = EDITOR_ID;
private CDOEditorUtil()
@@ -64,7 +82,7 @@ public final class CDOEditorUtil
}
/**
- * Returns an implementation of CDOEditorInput interface
+ * Returns an implementation of the CDOEditorInput interface.
*/
public static CDOEditorInput createCDOEditorInput(CDOView view, String resourcePath, boolean viewOwned)
{
@@ -75,7 +93,7 @@ public final class CDOEditorUtil
* Opens the specified resource in CDOEditor
*
* @param page
- * The page in which the editor will be open
+ * The page in which the editor will be opened
* @param view
* the CDOView that will be used to access the resource
* @param resourcePath
@@ -98,8 +116,8 @@ public final class CDOEditorUtil
}
else
{
- IEditorInput input = CDOEditorUtil.createCDOEditorInput(view, resourcePath, false);
- page.openEditor(input, CDOEditorUtil.getEditorID());
+ IEditorInput input = createCDOEditorInput(view, resourcePath, false);
+ page.openEditor(input, editorID);
}
}
catch (Exception ex)
@@ -128,7 +146,7 @@ public final class CDOEditorUtil
{
try
{
- if (ObjectUtil.equals(editorReference.getId(), CDOEditorUtil.getEditorID()))
+ if (ObjectUtil.equals(editorReference.getId(), editorID))
{
IEditorInput editorInput = editorReference.getEditorInput();
if (editorInput instanceof CDOEditorInput)
@@ -154,6 +172,157 @@ public final class CDOEditorUtil
}
/**
+ * @since 4.2
+ */
+ public static void populateMenu(IMenuManager manager, CDOResourceLeaf resource, IWorkbenchPage page)
+ {
+ String effectiveEditorID = getEffectiveEditorID(resource);
+ manager.add(new OpenEditorAction(page, effectiveEditorID, resource, false));
+
+ String[] editorIDs = getAllEditorIDs(resource);
+ if (editorIDs.length > 1 || editorIDs.length == 1 && !editorIDs[0].equals(effectiveEditorID))
+ {
+ MenuManager subMenu = new MenuManager("Open With");
+ manager.add(subMenu);
+
+ for (String id : editorIDs)
+ {
+ OpenEditorAction action = new OpenEditorAction(page, id, resource, true);
+ subMenu.add(action);
+ if (id.equals(effectiveEditorID))
+ {
+ action.setChecked(true);
+ }
+ }
+ }
+ }
+
+ /**
+ * @since 4.2
+ */
+ public static String getEffectiveEditorID(CDOResourceLeaf resource)
+ {
+ String editorID = EDITOR_OVERRIDES.get(resource);
+ if (editorID != null)
+ {
+ return editorID;
+ }
+
+ if (resource instanceof CDOResource)
+ {
+ return EDITOR_ID;
+ }
+
+ String name = resource.getName();
+ IEditorDescriptor editorDescriptor = EDITOR_REGISTRY.getDefaultEditor(name);
+ if (editorDescriptor != null)
+ {
+ return editorDescriptor.getId();
+ }
+
+ return TEXT_EDITOR_ID;
+ }
+
+ /**
+ * @since 4.2
+ */
+ public static String[] getAllEditorIDs(CDOResourceLeaf resource)
+ {
+ List<String> editorIDs = new ArrayList<String>();
+ if (resource instanceof CDOResource)
+ {
+ editorIDs.add(EDITOR_ID);
+ }
+
+ String name = resource.getName();
+ for (IEditorDescriptor editorDescriptor : EDITOR_REGISTRY.getEditors(name))
+ {
+ editorIDs.add(editorDescriptor.getId());
+ }
+
+ if (!editorIDs.contains(TEXT_EDITOR_ID))
+ {
+ editorIDs.add(TEXT_EDITOR_ID);
+ }
+
+ Collections.sort(editorIDs);
+ return editorIDs.toArray(new String[editorIDs.size()]);
+ }
+
+ /**
+ * Returns an implementation of the IEditorInput interface.
+ *
+ * @since 4.2
+ */
+ public static IEditorInput createEditorInput(String editorID, CDOResourceLeaf resource, boolean viewOwned)
+ {
+ if (resource instanceof CDOResource)
+ {
+ if (EDITOR_ID.equals(editorID))
+ {
+ CDOView view = resource.cdoView();
+ String path = resource.getPath();
+ return createCDOEditorInput(view, path, viewOwned);
+ }
+ }
+
+ return new CDOLobEditorInput(resource);
+ }
+
+ /**
+ * Returns an implementation of the IEditorInput interface.
+ *
+ * @since 4.2
+ */
+ public static IEditorInput createEditorInput(String editorID, CDOResourceLeaf resource)
+ {
+ return createEditorInput(editorID, resource, false);
+ }
+
+ /**
+ * Opens the specified resource in CDOEditor
+ *
+ * @param page
+ * The page in which the editor will be opened
+ * @since 4.2
+ */
+ public static void openEditor(IWorkbenchPage page, CDOResourceLeaf resource)
+ {
+ String editorID = CDOEditorUtil.getEffectiveEditorID(resource);
+ if (editorID != null)
+ {
+ openEditor(page, editorID, resource);
+ }
+ }
+
+ /**
+ * Opens the specified resource in CDOEditor
+ *
+ * @param page
+ * The page in which the editor will be opened
+ * @since 4.2
+ */
+ public static void openEditor(final IWorkbenchPage page, final String editorID, final CDOResourceLeaf resource)
+ {
+ Display display = page.getWorkbenchWindow().getShell().getDisplay();
+ display.asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ IEditorInput editorInput = createEditorInput(editorID, resource);
+ page.openEditor(editorInput, editorID);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ });
+ }
+
+ /**
* Refreshes all editor's viewers that are using certain CDOView.
*
* @param page
@@ -173,4 +342,51 @@ public final class CDOEditorUtil
}
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ private static class OpenEditorAction extends Action
+ {
+ private IWorkbenchPage page;
+
+ private String editorID;
+
+ private CDOResourceLeaf resource;
+
+ private boolean overrideOnRun;
+
+ public OpenEditorAction(IWorkbenchPage page, String editorID, CDOResourceLeaf resource, boolean overrideOnRun)
+ {
+ this.page = page;
+ this.editorID = editorID;
+ this.resource = resource;
+ this.overrideOnRun = overrideOnRun;
+
+ IEditorDescriptor editorDescriptor = EDITOR_REGISTRY.findEditor(editorID);
+ String label = editorDescriptor.getLabel();
+ if (overrideOnRun)
+ {
+ setText(label);
+ }
+ else
+ {
+ setText("Open With " + label);
+ }
+
+ setImageDescriptor(editorDescriptor.getImageDescriptor());
+ setToolTipText("Open the " + label + " editor on this resource");
+ }
+
+ @Override
+ public void run()
+ {
+ if (overrideOnRun)
+ {
+ EDITOR_OVERRIDES.put(resource, editorID);
+ }
+
+ openEditor(page, editorID, resource);
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java
index 52d7ccae30..d521edbe5c 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java
@@ -20,13 +20,14 @@ import org.eclipse.emf.cdo.common.model.CDOPackageUnit.Type;
import org.eclipse.emf.cdo.eresource.CDOBinaryResource;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
+import org.eclipse.emf.cdo.eresource.CDOResourceLeaf;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.eresource.CDOTextResource;
import org.eclipse.emf.cdo.internal.ui.actions.CloseSessionAction;
import org.eclipse.emf.cdo.internal.ui.actions.CloseViewAction;
import org.eclipse.emf.cdo.internal.ui.actions.CommitTransactionAction;
import org.eclipse.emf.cdo.internal.ui.actions.CreateBranchAction;
-import org.eclipse.emf.cdo.internal.ui.actions.CreateResourceNodeAction;
+import org.eclipse.emf.cdo.internal.ui.actions.NewResourceNodeAction;
import org.eclipse.emf.cdo.internal.ui.actions.DisableViewDurabilityAction;
import org.eclipse.emf.cdo.internal.ui.actions.EnableViewDurabilityAction;
import org.eclipse.emf.cdo.internal.ui.actions.ExportResourceAction;
@@ -35,10 +36,8 @@ import org.eclipse.emf.cdo.internal.ui.actions.LoadResourceAction;
import org.eclipse.emf.cdo.internal.ui.actions.ManagePackagesAction;
import org.eclipse.emf.cdo.internal.ui.actions.OpenAuditAction;
import org.eclipse.emf.cdo.internal.ui.actions.OpenDurableViewAction;
-import org.eclipse.emf.cdo.internal.ui.actions.OpenResourceEditorAction;
import org.eclipse.emf.cdo.internal.ui.actions.OpenTransactionAction;
import org.eclipse.emf.cdo.internal.ui.actions.OpenViewAction;
-import org.eclipse.emf.cdo.internal.ui.actions.OpenViewEditorAction;
import org.eclipse.emf.cdo.internal.ui.actions.RegisterFilesystemPackagesAction;
import org.eclipse.emf.cdo.internal.ui.actions.RegisterSinglePackageAction;
import org.eclipse.emf.cdo.internal.ui.actions.RegisterWorkspacePackagesAction;
@@ -69,10 +68,16 @@ import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.resource.LocalResourceManager;
+import org.eclipse.jface.resource.ResourceManager;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IEditorRegistry;
+import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
import java.util.ArrayList;
import java.util.Collections;
@@ -94,6 +99,12 @@ import java.util.List;
*/
public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
{
+ private static final IEditorRegistry EDITOR_REGISTRY = PlatformUI.getWorkbench().getEditorRegistry();
+
+ private IPropertyListener editorRegistryListener;
+
+ private ResourceManager resourceManager;
+
private IWorkbenchPage page;
public CDOItemProvider(IWorkbenchPage page, IElementFilter rootElementFilter)
@@ -108,6 +119,24 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
}
@Override
+ public void dispose()
+ {
+ if (editorRegistryListener != null)
+ {
+ EDITOR_REGISTRY.removePropertyListener(editorRegistryListener);
+ resourceManager = null;
+ }
+
+ if (resourceManager != null)
+ {
+ resourceManager.dispose();
+ resourceManager = null;
+ }
+
+ super.dispose();
+ }
+
+ @Override
public Object[] getChildren(Object element)
{
if (element instanceof CDOBranchManager)
@@ -235,25 +264,69 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
if (obj instanceof CDOResourceFolder)
{
- return SharedIcons.getImage(SharedIcons.OBJ_RESOURCE_FOLDER);
+ return SharedIcons.getImage(SharedIcons.OBJ_FOLDER);
}
- if (obj instanceof CDOResource)
+ if (obj instanceof CDOResourceLeaf)
{
- return SharedIcons.getImage(SharedIcons.OBJ_RESOURCE);
+ String name = ((CDOResourceLeaf)obj).getName();
+ Image image = getWorkbenchImage(name);
+ if (image != null)
+ {
+ return image;
+ }
+
+ if (obj instanceof CDOResource)
+ {
+ return SharedIcons.getImage(SharedIcons.OBJ_RESOURCE);
+ }
+
+ if (obj instanceof CDOTextResource)
+ {
+ return SharedIcons.getImage(SharedIcons.OBJ_TEXT_RESOURCE);
+ }
+
+ if (obj instanceof CDOBinaryResource)
+ {
+ return SharedIcons.getImage(SharedIcons.OBJ_BINARY_RESOURCE);
+ }
}
- if (obj instanceof CDOTextResource)
+ return super.getImage(obj);
+ }
+
+ /**
+ * @since 4.2
+ */
+ protected Image getWorkbenchImage(String name)
+ {
+ ImageDescriptor imageDescriptor = EDITOR_REGISTRY.getImageDescriptor(name);
+ if (imageDescriptor != null)
{
- return SharedIcons.getImage(SharedIcons.OBJ_TEXT_RESOURCE);
+ if (editorRegistryListener == null)
+ {
+ editorRegistryListener = new EditorRegistryListener(this);
+ EDITOR_REGISTRY.addPropertyListener(editorRegistryListener);
+ }
+
+ ResourceManager resourceManager = getResourceManager();
+ return (Image)resourceManager.get(imageDescriptor);
}
- if (obj instanceof CDOBinaryResource)
+ return null;
+ }
+
+ /**
+ * @since 4.2
+ */
+ protected ResourceManager getResourceManager()
+ {
+ if (resourceManager == null)
{
- return SharedIcons.getImage(SharedIcons.OBJ_BINARY_RESOURCE);
+ resourceManager = new LocalResourceManager(JFaceResources.getResources());
}
- return super.getImage(obj);
+ return resourceManager;
}
@Override
@@ -274,7 +347,6 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
@Override
protected void fillContextMenu(IMenuManager manager, ITreeSelection selection)
{
- super.fillContextMenu(manager, selection);
if (selection.size() == 1)
{
Object object = selection.getFirstElement();
@@ -290,19 +362,14 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
{
fillResourceFolder(manager, (CDOResourceFolder)object);
}
- else if (object instanceof CDOResource)
+ else if (object instanceof CDOResourceLeaf)
{
- fillResource(manager, (CDOResource)object);
- }
- else if (object instanceof CDOTextResource)
- {
- fillTextResource(manager, (CDOTextResource)object);
- }
- else if (object instanceof CDOBinaryResource)
- {
- fillBinaryResource(manager, (CDOBinaryResource)object);
+ fillResourceLeaf(manager, object);
}
}
+
+ manager.add(new Separator());
+ super.fillContextMenu(manager, selection);
}
/**
@@ -313,11 +380,32 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
}
/**
+ * @since 4.2
+ */
+ protected void fillResourceLeaf(IMenuManager manager, Object object)
+ {
+ CDOEditorUtil.populateMenu(manager, (CDOResourceLeaf)object, page);
+
+ if (object instanceof CDOResource)
+ {
+ fillResource(manager, (CDOResource)object);
+ }
+ else if (object instanceof CDOTextResource)
+ {
+ fillTextResource(manager, (CDOTextResource)object);
+ }
+ else if (object instanceof CDOBinaryResource)
+ {
+ fillBinaryResource(manager, (CDOBinaryResource)object);
+ }
+ }
+
+ /**
* @since 3.0
*/
protected void fillResource(IMenuManager manager, CDOResource resource)
{
- manager.add(new OpenResourceEditorAction(page, resource));
+ // manager.add(new OpenResourceEditorAction(page, resource));
}
/**
@@ -325,7 +413,7 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
*/
protected void fillTextResource(IMenuManager manager, CDOTextResource resource)
{
- manager.add(new OpenResourceEditorAction(page, resource));
+ // manager.add(new OpenResourceEditorAction(page, resource));
}
/**
@@ -333,7 +421,7 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
*/
protected void fillBinaryResource(IMenuManager manager, CDOBinaryResource resource)
{
- manager.add(new OpenResourceEditorAction(page, resource));
+ // manager.add(new OpenResourceEditorAction(page, resource));
}
/**
@@ -420,19 +508,23 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
*/
protected void fillView(IMenuManager manager, CDOView view)
{
- manager.add(new OpenViewEditorAction(page, view));
+ if (!view.isReadOnly())
+ {
+ CDOResource rootResource = view.getRootResource();
+ manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.FOLDER));
+ manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.MODEL));
+ manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.TEXT));
+ manager.add(new NewResourceNodeAction(this, page, view, rootResource, NewResourceNodeAction.Type.BINARY));
+ }
+
+ manager.add(new Separator());
manager.add(new LoadResourceAction(page, view));
manager.add(new ExportResourceAction(page, view));
- manager.add(new Separator());
if (!view.isReadOnly())
{
- CDOResource rootResource = view.getRootResource();
- manager.add(new CreateResourceNodeAction(this, page, view, rootResource, CreateResourceNodeAction.Type.FOLDER));
- manager.add(new CreateResourceNodeAction(this, page, view, rootResource, CreateResourceNodeAction.Type.MODEL));
- manager.add(new CreateResourceNodeAction(this, page, view, rootResource, CreateResourceNodeAction.Type.TEXT));
- manager.add(new CreateResourceNodeAction(this, page, view, rootResource, CreateResourceNodeAction.Type.BINARY));
manager.add(new ImportResourceAction(page, view));
+ manager.add(new Separator());
manager.add(new CommitTransactionAction(page, view));
manager.add(new RollbackTransactionAction(page, view));
}
@@ -528,4 +620,26 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>>
return SharedIcons.getImage(SharedIcons.OBJ_EDITOR);
}
+
+ /**
+ * @author Eike Stepper
+ * @since 4.2
+ */
+ protected static class EditorRegistryListener implements IPropertyListener
+ {
+ private CDOItemProvider itemProvider;
+
+ public EditorRegistryListener(CDOItemProvider itemProvider)
+ {
+ this.itemProvider = itemProvider;
+ }
+
+ public void propertyChanged(Object source, int propId)
+ {
+ if (propId == IEditorRegistry.PROP_CONTENTS)
+ {
+ itemProvider.fireLabelProviderChanged();
+ }
+ }
+ }
}

Back to the top