Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-09-01 19:54:55 +0000
committerEike Stepper2012-09-01 19:54:55 +0000
commitfbf08d198d4325231e970a4c13dea302650fc869 (patch)
tree18822cf1ccdb3d3e24fcafa3d719136bef873235 /plugins
parente60218226c5fd3f87651c55fd2908e06b325b574 (diff)
downloadcdo-fbf08d198d4325231e970a4c13dea302650fc869.tar.gz
cdo-fbf08d198d4325231e970a4c13dea302650fc869.tar.xz
cdo-fbf08d198d4325231e970a4c13dea302650fc869.zip
[388567] [UI] Support CDOTextResource and CDOBinaryResource in the generic UI
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388567
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/plugin.xml8
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/OpenResourceEditorAction.java110
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOLobEditorInput.java282
4 files changed, 298 insertions, 105 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF
index c58abe70b2..c28b19aced 100644
--- a/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.ui/META-INF/MANIFEST.MF
@@ -20,7 +20,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.net4j.util.ui;bundle-version="[3.0.0,4.0.0)";visibility:=reexport,
org.eclipse.emf.cdo;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
org.eclipse.emf.cdo.edit;bundle-version="[4.0.0,5.0.0)";visibility:=reexport,
- org.eclipse.emf.cdo.ui.shared;bundle-version="[4.0.0,5.0.0)"
+ org.eclipse.emf.cdo.ui.shared;bundle-version="[4.0.0,5.0.0)",
+ org.eclipse.core.filesystem;bundle-version="[1.3.0,2.0.0)";resolution:=optional
Export-Package: org.eclipse.emf.cdo.internal.ui;version="4.2.0";
x-friends:="org.eclipse.emf.cdo.ui.defs,
org.eclipse.emf.cdo.ui.ide,
diff --git a/plugins/org.eclipse.emf.cdo.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.ui/plugin.xml
index c79daf007c..bb5cfd27d5 100644
--- a/plugins/org.eclipse.emf.cdo.ui/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.ui/plugin.xml
@@ -145,4 +145,12 @@
</factory>
</extension>
+ <extension
+ id="org.eclipse.core.filesystem.cdo.workspace"
+ point="org.eclipse.core.filesystem.filesystems">
+ <filesystem scheme="cdo.lob">
+ <run class="org.eclipse.emf.cdo.internal.ui.views.CDOLobEditorInput$LobFileSystem"/>
+ </filesystem>
+ </extension>
+
</plugin>
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/OpenResourceEditorAction.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/OpenResourceEditorAction.java
index cb9316c714..092e9e8a09 100644
--- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/OpenResourceEditorAction.java
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/OpenResourceEditorAction.java
@@ -11,37 +11,20 @@
*/
package org.eclipse.emf.cdo.internal.ui.actions;
-import org.eclipse.emf.cdo.common.lob.CDOClob;
+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.internal.ui.messages.Messages;
+import org.eclipse.emf.cdo.internal.ui.views.CDOLobEditorInput;
import org.eclipse.emf.cdo.ui.CDOEditorUtil;
import org.eclipse.emf.cdo.view.CDOView;
-import org.eclipse.net4j.util.io.IORuntimeException;
-
-import org.eclipse.emf.ecore.resource.URIConverter;
-
-import org.eclipse.core.resources.IStorage;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbenchPage;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-
/**
* @author Eike Stepper
*/
@@ -65,18 +48,16 @@ public final class OpenResourceEditorAction extends ResourceNodeAction
protected void doRun(IProgressMonitor progressMonitor) throws Exception
{
final CDOResourceLeaf resource = (CDOResourceLeaf)getResourceNode();
- final CDOView view = resource.cdoView();
- final String resourcePath = resource.getPath();
final IWorkbenchPage page = getPage();
if (resource instanceof CDOResource)
{
+ CDOView view = resource.cdoView();
+ String resourcePath = resource.getPath();
CDOEditorUtil.openEditor(page, view, resourcePath);
}
- else if (resource instanceof CDOTextResource)
+ else if (resource instanceof CDOFileResource)
{
- final IPath path = new Path(resourcePath);
-
Display display = page.getWorkbenchWindow().getShell().getDisplay();
display.asyncExec(new Runnable()
{
@@ -84,86 +65,7 @@ public final class OpenResourceEditorAction extends ResourceNodeAction
{
try
{
- IEditorInput input = new IStorageEditorInput()
- {
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter)
- {
- System.out.println("IStorageEditorInput: " + adapter);
- return Platform.getAdapterManager().getAdapter(this, adapter);
- }
-
- public String getToolTipText()
- {
- return path.toString();
- }
-
- public IPersistableElement getPersistable()
- {
- return null;
- }
-
- public String getName()
- {
- return path.lastSegment();
- }
-
- public ImageDescriptor getImageDescriptor()
- {
- return null;
- }
-
- public boolean exists()
- {
- return true;
- }
-
- public IStorage getStorage() throws CoreException
- {
- return new IStorage()
- {
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter)
- {
- System.out.println("IStorage: " + adapter);
- return Platform.getAdapterManager().getAdapter(this, adapter);
- }
-
- public boolean isReadOnly()
- {
- return false;
- }
-
- public String getName()
- {
- return path.lastSegment();
- }
-
- public IPath getFullPath()
- {
- return path;
- }
-
- public InputStream getContents() throws CoreException
- {
- try
- {
- CDOClob clob = ((CDOTextResource)resource).getContents();
- if (clob == null)
- {
- return new ByteArrayInputStream(new byte[0]);
- }
-
- Reader reader = clob.getContents();
- return new URIConverter.ReadableInputStream(reader);
- }
- catch (IOException ex)
- {
- throw new IORuntimeException(ex);
- }
- }
- };
- }
- };
-
+ IEditorInput input = new CDOLobEditorInput((CDOFileResource<?>)resource);
page.openEditor(input, "org.eclipse.ui.DefaultTextEditor");
}
catch (Exception ex)
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOLobEditorInput.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOLobEditorInput.java
new file mode 100644
index 0000000000..93611eb639
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOLobEditorInput.java
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.internal.ui.views;
+
+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.CDOTextResource;
+
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.io.IORuntimeException;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.filesystem.provider.FileInfo;
+import org.eclipse.core.filesystem.provider.FileStore;
+import org.eclipse.core.filesystem.provider.FileSystem;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IURIEditorInput;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.CharArrayReader;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.WeakHashMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class CDOLobEditorInput extends PlatformObject implements IURIEditorInput
+{
+ private static final String SCHEME = "cdo.lob";
+
+ private static final Map<CDOLobEditorInput, URI> inputs = new WeakHashMap<CDOLobEditorInput, URI>();
+
+ private static int lastID;
+
+ private CDOFileResource<?> resource;
+
+ private URI uri;
+
+ public CDOLobEditorInput(CDOFileResource<?> resource)
+ {
+ this.resource = resource;
+
+ try
+ {
+ uri = new URI(SCHEME + "://" + ++lastID);
+ }
+ catch (URISyntaxException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+
+ synchronized (inputs)
+ {
+ inputs.put(this, uri);
+ }
+ }
+
+ public CDOFileResource<?> getResource()
+ {
+ return resource;
+ }
+
+ public boolean exists()
+ {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor()
+ {
+ return null;
+ }
+
+ public String getName()
+ {
+ return resource.getName();
+ }
+
+ public IPersistableElement getPersistable()
+ {
+ return null;
+ }
+
+ public String getToolTipText()
+ {
+ return resource.getPath();
+ }
+
+ public URI getURI()
+ {
+ return uri;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class LobFileSystem extends FileSystem
+ {
+ @Override
+ public IFileStore getStore(URI uri)
+ {
+ return new LobFileStore(uri);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class LobFileStore extends FileStore
+ {
+ private static final String[] NO_CHILDREN = new String[0];
+
+ private final URI uri;
+
+ private CDOFileResource<?> resource;
+
+ private FileInfo info;
+
+ public LobFileStore(URI uri)
+ {
+ this.uri = uri;
+ }
+
+ @Override
+ public URI toURI()
+ {
+ return uri;
+ }
+
+ private CDOFileResource<?> getResource()
+ {
+ if (resource == null)
+ {
+ synchronized (inputs)
+ {
+ for (Entry<CDOLobEditorInput, URI> entry : inputs.entrySet())
+ {
+ if (uri.equals(entry.getValue()))
+ {
+ resource = entry.getKey().getResource();
+ break;
+ }
+ }
+ }
+ }
+
+ return resource;
+ }
+
+ @Override
+ public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException
+ {
+ if (info == null)
+ {
+ info = new FileInfo(getName());
+ info.setLastModified(0L);
+ info.setExists(true);
+ info.setDirectory(false);
+ info.setLength(EFS.NONE);
+ info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
+ info.setAttribute(EFS.ATTRIBUTE_HIDDEN, false);
+ }
+
+ return info;
+ }
+
+ @Override
+ public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException
+ {
+ try
+ {
+ CDOFileResource<?> resource = getResource();
+ if (resource instanceof CDOTextResource)
+ {
+ CDOClob clob = ((CDOTextResource)resource).getContents();
+ if (clob == null)
+ {
+ return new ByteArrayInputStream(new byte[0]);
+ }
+
+ Reader reader = clob.getContents();
+ CharArrayWriter writer = new CharArrayWriter();
+ IOUtil.copyCharacter(reader, writer);
+
+ byte[] bytes = writer.toString().getBytes("UTF-8");
+ return new ByteArrayInputStream(bytes);
+ }
+
+ 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);
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ }
+
+ @Override
+ public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException
+ {
+ final CDOFileResource<?> resource = getResource();
+ return new ByteArrayOutputStream()
+ {
+ @Override
+ public void close() throws IOException
+ {
+ if (resource instanceof CDOTextResource)
+ {
+ String string = toString("UTF-8");
+ CDOClob clob = new CDOClob(new CharArrayReader(string.toCharArray()));
+ ((CDOTextResource)resource).setContents(clob);
+ }
+ else
+ {
+ byte[] bytes = toByteArray();
+ CDOBlob blob = new CDOBlob(new ByteArrayInputStream(bytes));
+ ((CDOBinaryResource)resource).setContents(blob);
+ }
+ }
+ };
+ }
+
+ @Override
+ public String getName()
+ {
+ return getResource().getName();
+ }
+
+ @Override
+ public IFileStore getParent()
+ {
+ return null; // This is a flat file system
+ }
+
+ @Override
+ public IFileStore getChild(String name)
+ {
+ return null; // This is a flat file system
+ }
+
+ @Override
+ public String[] childNames(int options, IProgressMonitor monitor) throws CoreException
+ {
+ return NO_CHILDREN; // This is a flat file system
+ }
+ }
+}

Back to the top