diff options
author | Eike Stepper | 2015-02-09 19:48:12 +0000 |
---|---|---|
committer | Eike Stepper | 2015-02-18 14:41:11 +0000 |
commit | 9bcd1f30ff1774ff7e66c36ef8b200ef318a164c (patch) | |
tree | 942d3276a7df824dbe8c6fceef108060c58d23ad /plugins/org.eclipse.emf.cdo.ui | |
parent | a5244cfa65cf4b9bf8c9e53665842fe20261d265 (diff) | |
download | cdo-9bcd1f30ff1774ff7e66c36ef8b200ef318a164c.tar.gz cdo-9bcd1f30ff1774ff7e66c36ef8b200ef318a164c.tar.xz cdo-9bcd1f30ff1774ff7e66c36ef8b200ef318a164c.zip |
[458349] Consolidate UI
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=458349
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.ui')
7 files changed, 117 insertions, 303 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 226a66aec4..53b6eb4da2 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 @@ -18,54 +18,37 @@ import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPersistableElement; /** + * A text editor will consult {@link CDOLobStorage} for this input. + * * @author Eike Stepper */ public class CDOLobEditorInput extends PlatformObject implements IEditorInput { - // private static final String SCHEME = "cdo.lob"; - // - // private static final Map<CDOLobEditorInput, LobFileStore> fileStores = new WeakHashMap<CDOLobEditorInput, - // LobFileStore>(); - // - // private URI uri; - // - // public URI getURI() - // { - // return uri; - // } + private final CDOResourceLeaf resource; - private CDOResourceLeaf resource; + private final boolean commitOnSave; public CDOLobEditorInput(CDOResourceLeaf resource) { - this.resource = resource; + this(resource, false); + } - // try - // { - // 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) - // { - // throw WrappedException.wrap(ex); - // } - // - // synchronized (fileStores) - // { - // fileStores.remove(this); - // fileStores.put(this, null); - // } + public CDOLobEditorInput(CDOResourceLeaf resource, boolean commitOnSave) + { + this.resource = resource; + this.commitOnSave = commitOnSave; } - public CDOResourceLeaf getResource() + public final CDOResourceLeaf getResource() { return resource; } + public final boolean isCommitOnSave() + { + return commitOnSave; + } + public boolean exists() { return true; @@ -90,246 +73,4 @@ public class CDOLobEditorInput extends PlatformObject implements IEditorInput { return resource.getURI().toString(); } - - // @Override - // public int hashCode() - // { - // final int prime = 31; - // int result = 1; - // result = prime * result + (uri == null ? 0 : uri.hashCode()); - // return result; - // } - // - // @Override - // public boolean equals(Object obj) - // { - // if (this == obj) - // { - // return true; - // } - // - // if (obj == null) - // { - // return false; - // } - // - // if (!(obj instanceof CDOLobEditorInput)) - // { - // return false; - // } - // - // CDOLobEditorInput other = (CDOLobEditorInput)obj; - // if (uri == null) - // { - // if (other.uri != null) - // { - // return false; - // } - // } - // else if (!uri.equals(other.uri)) - // { - // return false; - // } - // - // return true; - // } - // - // /** - // * @author Eike Stepper - // */ - // public static class LobFileSystem extends FileSystem - // { - // @Override - // public IFileStore getStore(URI uri) - // { - // synchronized (fileStores) - // { - // for (Entry<CDOLobEditorInput, LobFileStore> entry : fileStores.entrySet()) - // { - // CDOLobEditorInput editorInput = entry.getKey(); - // if (uri.equals(editorInput.getURI())) - // { - // LobFileStore store = entry.getValue(); - // if (store == null) - // { - // store = createStore(uri, editorInput); - // fileStores.put(editorInput, store); - // } - // - // return store; - // } - // } - // } - // - // throw new IllegalStateException("No editor input is cached for " + uri); - // } - // - // protected LobFileStore createStore(URI uri, CDOLobEditorInput editorInput) - // { - // CDOResourceLeaf resource = editorInput.getResource(); - // return new LobFileStore(resource, uri); - // } - // } - // - // /** - // * @author Eike Stepper - // */ - // public static class LobFileStore extends FileStore - // { - // private static final String[] NO_CHILDREN = new String[0]; - // - // private CDOResourceLeaf resource; - // - // private final URI uri; - // - // private FileInfo info; - // - // public LobFileStore(CDOResourceLeaf resource, URI uri) - // { - // this.resource = resource; - // this.uri = uri; - // } - // - // @Override - // public URI toURI() - // { - // return uri; - // } - // - // @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 - // { - // if (resource instanceof CDOTextResource) - // { - // CDOTextResource textResource = (CDOTextResource)resource; - // CDOClob clob = textResource.getContents(); - // if (clob == null) - // { - // return new ByteArrayInputStream(new byte[0]); - // } - // - // Reader reader = clob.getContents(); - // CharArrayWriter writer = new CharArrayWriter(); - // IOUtil.copyCharacter(reader, writer); - // - // String encoding = getEncoding(textResource); - // byte[] bytes = writer.toString().getBytes(encoding); - // return new ByteArrayInputStream(bytes); - // } - // - // if (resource instanceof CDOBinaryResource) - // { - // 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); - // } - // - // ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - // ((CDOResource)resource).save(outputStream, null); - // 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 - // { - // return new ByteArrayOutputStream() - // { - // @Override - // public void close() throws IOException - // { - // if (resource instanceof CDOTextResource) - // { - // CDOTextResource textResource = (CDOTextResource)resource; - // String encoding = getEncoding(textResource); - // - // String string = toString(encoding); - // CDOClob clob = new CDOClob(new CharArrayReader(string.toCharArray())); - // textResource.setContents(clob); - // } - // else if (resource instanceof CDOBinaryResource) - // { - // byte[] bytes = toByteArray(); - // CDOBlob blob = new CDOBlob(new ByteArrayInputStream(bytes)); - // ((CDOBinaryResource)resource).setContents(blob); - // } - // } - // }; - // } - // - // @Override - // public String getName() - // { - // return resource.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 - // } - // - // private String getEncoding(CDOTextResource textResource) - // { - // String encoding = textResource.getEncoding(); - // if (encoding == null) - // { - // try - // { - // encoding = ResourcesPlugin.getWorkspace().getRoot().getDefaultCharset(); - // } - // catch (CoreException ex) - // { - // OM.LOG.error(ex); - // } - // } - // - // return encoding; - // } - // } } diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobStorage.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobStorage.java index 2615081fed..7ddc4dfd1f 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobStorage.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobStorage.java @@ -16,6 +16,8 @@ import org.eclipse.emf.cdo.eresource.CDOBinaryResource; 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.transaction.CDOTransaction; +import org.eclipse.emf.cdo.view.CDOView; import org.eclipse.net4j.util.StringUtil; import org.eclipse.net4j.util.WrappedException; @@ -95,7 +97,9 @@ public class CDOLobStorage extends AbstractDocumentProvider { if (element instanceof CDOLobEditorInput) { - CDOResourceLeaf resource = ((CDOLobEditorInput)element).getResource(); + CDOLobEditorInput editorInput = (CDOLobEditorInput)element; + + CDOResourceLeaf resource = editorInput.getResource(); String contents = document.get(); try @@ -112,6 +116,16 @@ public class CDOLobStorage extends AbstractDocumentProvider CDOBlob blob = new CDOBlob(new ByteArrayInputStream(bytes)); ((CDOBinaryResource)resource).setContents(blob); } + + if (editorInput.isCommitOnSave()) + { + CDOView view = resource.cdoView(); + if (view instanceof CDOTransaction) + { + CDOTransaction transaction = (CDOTransaction)view; + transaction.commit(); + } + } } catch (Exception ex) { diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOPropertyAdapterFactory.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOPropertyAdapterFactory.java index ade6f3e084..617022164a 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOPropertyAdapterFactory.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOPropertyAdapterFactory.java @@ -23,8 +23,12 @@ import org.eclipse.net4j.util.ui.AbstractPropertyAdapterFactory; import org.eclipse.net4j.util.ui.DefaultActionFilter; import org.eclipse.net4j.util.ui.DefaultPropertySource; +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.util.ResourceLocator; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.EMFEditPlugin; import org.eclipse.emf.edit.provider.ComposedAdapterFactory; +import org.eclipse.emf.edit.provider.IItemLabelProvider; import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; import org.eclipse.emf.edit.provider.IItemPropertySource; import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; @@ -34,6 +38,7 @@ import org.eclipse.ui.IActionFilter; import org.eclipse.ui.views.properties.IPropertySource; import org.eclipse.ui.views.properties.PropertyDescriptor; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -50,8 +55,6 @@ public class CDOPropertyAdapterFactory extends AbstractPropertyAdapterFactory private static final IActionFilter OBJECT_ACTION_FILTER = new DefaultActionFilter<EObject>(ObjectProperties.INSTANCE); - private static final String CATEGORY_EMF = "EMF"; //$NON-NLS-1$ - public CDOPropertyAdapterFactory() { } @@ -112,11 +115,12 @@ public class CDOPropertyAdapterFactory extends AbstractPropertyAdapterFactory continue; } + String category = getTypeText(adapterFactory, eObject); String id = "___EMF___" + propertyDescriptor.getId(eObject); String displayName = propertyDescriptor.getDisplayName(eObject); String description = propertyDescriptor.getDescription(eObject); - PropertyDescriptor descriptor = result.addDescriptor(CATEGORY_EMF, id, displayName, description); + PropertyDescriptor descriptor = result.addDescriptor(category, id, displayName, description); Object value = propertyDescriptor.getPropertyValue(eObject); propertyValues.put(id, value); @@ -173,4 +177,36 @@ public class CDOPropertyAdapterFactory extends AbstractPropertyAdapterFactory return super.createActionFilter(object); } + + public static String getTypeText(ComposedAdapterFactory adapterFactory, EObject eObject) + { + String typeKey = eObject.eClass().getName(); + List<Adapter> originalAdapters = new ArrayList<Adapter>(eObject.eAdapters()); + + try + { + return getResourceLocator(adapterFactory, eObject).getString("_UI_" + typeKey + "_type"); + } + catch (Exception ex) + { + //$FALL-THROUGH$ + } + finally + { + eObject.eAdapters().retainAll(originalAdapters); + } + + return typeKey; + } + + private static ResourceLocator getResourceLocator(ComposedAdapterFactory adapterFactory, EObject eObject) + { + Object adapter = adapterFactory.getRootAdapterFactory().adapt(eObject, IItemLabelProvider.class); + if (adapter instanceof ResourceLocator) + { + return (ResourceLocator)adapter; + } + + return EMFEditPlugin.INSTANCE; + } } diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/TransactionalBackgroundAction.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/TransactionalBackgroundAction.java index 4f2ea8ea92..4e3b5c483f 100644 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/TransactionalBackgroundAction.java +++ b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/TransactionalBackgroundAction.java @@ -13,7 +13,6 @@ package org.eclipse.emf.cdo.internal.ui.actions; import org.eclipse.emf.cdo.CDOObject; import org.eclipse.emf.cdo.common.commit.CDOCommitInfo; import org.eclipse.emf.cdo.internal.ui.messages.Messages; -import org.eclipse.emf.cdo.session.CDOSession; import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.view.CDOView; @@ -49,8 +48,7 @@ public abstract class TransactionalBackgroundAction extends LongRunningAction progressMonitor.beginTask(Messages.getString("TransactionalBackgroundAction_1"), 100); //$NON-NLS-1$ CDOView view = object.cdoView(); - CDOSession session = view.getSession(); - CDOTransaction transaction = session.openTransaction(view.getBranch()); + CDOTransaction transaction = view.getSession().openTransaction(view.getBranch()); OpenTransactionAction.configureTransaction(transaction); CDOObject transactionalObject = transaction.getObject(object); 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 c6c8baa853..e13e20e9bb 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 @@ -113,10 +113,7 @@ public class CDOSessionsView extends ContainerView { CDOResourceLeaf resource = (CDOResourceLeaf)object; - String name = resource.getName(); - String extension = new Path(name).getFileExtension(); - - ResourceOpener opener = resourceOpeners.get(extension); + ResourceOpener opener = getResourceOpener(resource); if (opener != null) { opener.openResource(page, resource); @@ -132,6 +129,17 @@ public class CDOSessionsView extends ContainerView super.doubleClicked(object); } + public static ResourceOpener getResourceOpener(CDOResourceLeaf resource) + { + String extension = new Path(resource.getName()).getFileExtension(); + return getResourceOpener(extension); + } + + public static ResourceOpener getResourceOpener(String resourceExtension) + { + return resourceOpeners.get(resourceExtension); + } + public static ResourceOpener registerResourceOpener(String resourceExtension, ResourceOpener opener) { return resourceOpeners.put(resourceExtension, opener); 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 4198c0affe..0f27ef4179 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 @@ -57,12 +57,15 @@ public final class CDOEditorUtil */ public static final String EDITOR_ID = "org.eclipse.emf.cdo.ui.CDOEditor"; //$NON-NLS-1$ + /** + * @since 4.4 + */ + public static final String TEXT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor"; + 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() @@ -96,12 +99,12 @@ public final class CDOEditorUtil /** * Creates a {@link CDOEditorInput} based on the given {@code input} that adapts to * the {@link IEditingDomainProvider} interface to provide a particular {@code editingDomain}. - * + * * @param input an editor input to copy * @param editingDomain the editing domain to associate with the editor input - * + * * @return the editing-domain-providing editor input - * + * * @since 4.3 */ public static CDOEditorInput createCDOEditorInputWithEditingDomain(CDOEditorInput input, EditingDomain editingDomain) @@ -113,14 +116,14 @@ public final class CDOEditorUtil /** * Creates a {@link CDOEditorInput} that adapts to the {@link IEditingDomainProvider} interface * to provide a particular {@code editingDomain}. - * + * * @param view the CDO view of the editor input * @param resourcePath the path to the resource to edit * @param viewOwned whether the opened editor should assume ownership of the {@code view} * @param editingDomain the editing domain to associate with the editor input - * + * * @return the editing-domain-providing editor input - * + * * @since 4.3 */ public static CDOEditorInput createCDOEditorInputWithEditingDomain(CDOView view, String resourcePath, @@ -317,11 +320,10 @@ public final class CDOEditorUtil } /** - * Returns an implementation of the IEditorInput interface. - * - * @since 4.2 + * @since 4.4 */ - public static IEditorInput createEditorInput(String editorID, CDOResourceLeaf resource, boolean viewOwned) + public static IEditorInput createEditorInput(String editorID, CDOResourceLeaf resource, boolean viewOwned, + boolean lobCommitOnSave) { if (resource instanceof CDOResource) { @@ -329,11 +331,21 @@ public final class CDOEditorUtil { CDOView view = resource.cdoView(); String path = resource.getPath(); - return createCDOEditorInput(view, path, viewOwned); + return createCDOEditorInput(view, path, lobCommitOnSave); } } - return new CDOLobEditorInput(resource); + return new CDOLobEditorInput(resource, lobCommitOnSave); + } + + /** + * Returns an implementation of the IEditorInput interface. + * + * @since 4.2 + */ + public static IEditorInput createEditorInput(String editorID, CDOResourceLeaf resource, boolean viewOwned) + { + return createEditorInput(editorID, resource, viewOwned, false); } /** 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 7b592ccb34..1354a016bc 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 @@ -82,6 +82,7 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.IEditorDescriptor; import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.IPropertyListener; import org.eclipse.ui.IWorkbenchPage; @@ -386,10 +387,14 @@ public class CDOItemProvider extends ContainerItemProvider<IContainer<Object>> if (obj instanceof CDOResourceLeaf) { String name = ((CDOResourceLeaf)obj).getName(); - Image image = getWorkbenchImage(name); - if (image != null) + IEditorDescriptor editorDescriptor = EDITOR_REGISTRY.getDefaultEditor(name); + if (editorDescriptor != null && !CDOEditorUtil.TEXT_EDITOR_ID.equals(editorDescriptor.getId())) { - return image; + Image image = getWorkbenchImage(name); + if (image != null) + { + return image; + } } if (obj instanceof CDOResource) |