diff options
author | Eike Stepper | 2012-09-01 05:37:30 +0000 |
---|---|---|
committer | Eike Stepper | 2012-09-01 05:37:30 +0000 |
commit | 5d4333aa45cd54a2cbbb41f06bdaee76b9860aa4 (patch) | |
tree | 8adfededb78d33b875e566272c9b7897ac50581e | |
parent | 451f3f409934e97d4b3ad5c7b34adc7def90b380 (diff) | |
download | cdo-5d4333aa45cd54a2cbbb41f06bdaee76b9860aa4.tar.gz cdo-5d4333aa45cd54a2cbbb41f06bdaee76b9860aa4.tar.xz cdo-5d4333aa45cd54a2cbbb41f06bdaee76b9860aa4.zip |
[388567] [UI] Support CDOTextResource and CDOBinaryResource in the generic UI
https://bugs.eclipse.org/bugs/show_bug.cgi?id=388567
3 files changed, 149 insertions, 171 deletions
diff --git a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/OpenFileEditorAction.java b/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/OpenFileEditorAction.java deleted file mode 100644 index 56a28ab719..0000000000 --- a/plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/OpenFileEditorAction.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 - * Victor Roldan Betancort - maintenance - */ -package org.eclipse.emf.cdo.internal.ui.actions; - -import org.eclipse.emf.cdo.eresource.CDOResourceNode; -import org.eclipse.emf.cdo.internal.ui.messages.Messages; -import org.eclipse.emf.cdo.ui.CDOEditorUtil; -import org.eclipse.emf.cdo.view.CDOView; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.ui.IWorkbenchPage; - -/** - * @author Eike Stepper - */ -public final class OpenFileEditorAction extends ResourceNodeAction -{ - private static final String TITLE = Messages.getString("OpenFileEditorAction.0"); //$NON-NLS-1$ - - private static final String TOOL_TIP = Messages.getString("OpenFileEditorAction.1"); //$NON-NLS-1$ - - public OpenFileEditorAction(IWorkbenchPage page, CDOResourceNode resourceNode) - { - super(page, TITLE, TOOL_TIP, null, resourceNode); - } - - @Override - protected void doRun(IProgressMonitor progressMonitor) throws Exception - { - CDOView view = getResourceNode().cdoView(); - String resourcePath = getResourceNode().getPath(); - CDOEditorUtil.openEditor(getPage(), view, resourcePath); - } -} 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 7ee21afd0a..cb9316c714 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 @@ -4,21 +4,44 @@ * 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 * Victor Roldan Betancort - maintenance */ package org.eclipse.emf.cdo.internal.ui.actions; -import org.eclipse.emf.cdo.eresource.CDOResourceNode; +import org.eclipse.emf.cdo.common.lob.CDOClob; +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.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 */ @@ -28,16 +51,127 @@ public final class OpenResourceEditorAction extends ResourceNodeAction private static final String TOOL_TIP = Messages.getString("OpenResourceEditorAction.1"); //$NON-NLS-1$ - public OpenResourceEditorAction(IWorkbenchPage page, CDOResourceNode resourceNode) + private static final String FILE_TITLE = Messages.getString("OpenFileEditorAction.0"); //$NON-NLS-1$ + + private static final String FILE_TOOL_TIP = Messages.getString("OpenFileEditorAction.1"); //$NON-NLS-1$ + + public OpenResourceEditorAction(IWorkbenchPage page, CDOResourceLeaf resource) { - super(page, TITLE, TOOL_TIP, null, resourceNode); + super(page, resource instanceof CDOResource ? TITLE : FILE_TITLE, resource instanceof CDOResource ? TOOL_TIP + : FILE_TOOL_TIP, null, resource); } @Override protected void doRun(IProgressMonitor progressMonitor) throws Exception { - CDOView view = getResourceNode().cdoView(); - String resourcePath = getResourceNode().getPath(); - CDOEditorUtil.openEditor(getPage(), view, resourcePath); + final CDOResourceLeaf resource = (CDOResourceLeaf)getResourceNode(); + final CDOView view = resource.cdoView(); + final String resourcePath = resource.getPath(); + final IWorkbenchPage page = getPage(); + + if (resource instanceof CDOResource) + { + CDOEditorUtil.openEditor(page, view, resourcePath); + } + else if (resource instanceof CDOTextResource) + { + final IPath path = new Path(resourcePath); + + Display display = page.getWorkbenchWindow().getShell().getDisplay(); + display.asyncExec(new Runnable() + { + public void run() + { + 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); + } + } + }; + } + }; + + page.openEditor(input, "org.eclipse.ui.DefaultTextEditor"); + } + catch (Exception ex) + { + OM.LOG.error(ex); + } + } + }); + } } } 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 b5b6c2a18f..1a4f97d3fa 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,43 +10,25 @@ */ package org.eclipse.emf.cdo.internal.ui.views; -import org.eclipse.emf.cdo.common.lob.CDOClob; -import org.eclipse.emf.cdo.eresource.CDOResource; -import org.eclipse.emf.cdo.eresource.CDOTextResource; +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.internal.ui.bundle.OM; import org.eclipse.emf.cdo.session.CDOSession; -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.io.IORuntimeException; import org.eclipse.net4j.util.ui.views.ContainerItemProvider; import org.eclipse.net4j.util.ui.views.ContainerView; import org.eclipse.net4j.util.ui.views.IElementFilter; -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.Path; -import org.eclipse.core.runtime.Platform; import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; -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.IOException; -import java.io.InputStream; -import java.io.Reader; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -102,11 +84,11 @@ public class CDOSessionsView extends ContainerView @Override protected void doubleClicked(Object object) { - final IWorkbenchPage page = getSite().getPage(); + IWorkbenchPage page = getSite().getPage(); - if (object instanceof CDOResource) + if (object instanceof CDOResourceLeaf) { - CDOResource resource = (CDOResource)object; + CDOResourceLeaf resource = (CDOResourceLeaf)object; String path = resource.getPath(); String extension = new Path(path).getFileExtension(); @@ -117,105 +99,10 @@ public class CDOSessionsView extends ContainerView } else { - CDOEditorUtil.openEditor(page, resource.cdoView(), path); + OpenResourceEditorAction action = new OpenResourceEditorAction(page, resource); + action.run(); } } - else if (object instanceof CDOTextResource) - { - final CDOTextResource resource = (CDOTextResource)object; - final IPath path = new Path(resource.getPath()); - - Display display = page.getWorkbenchWindow().getShell().getDisplay(); - display.asyncExec(new Runnable() - { - public void run() - { - 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 = resource.getContents(); - Reader reader = clob.getContents(); - return new URIConverter.ReadableInputStream(reader); - } - catch (IOException ex) - { - throw new IORuntimeException(ex); - } - } - }; - } - }; - - page.openEditor(input, CDOEditorUtil.getEditorID()); - } - catch (Exception ex) - { - OM.LOG.error(ex); - } - } - }); - } else { super.doubleClicked(object); @@ -237,6 +124,6 @@ public class CDOSessionsView extends ContainerView */ public interface ResourceOpener { - public void openResource(IWorkbenchPage page, CDOResource resource); + public void openResource(IWorkbenchPage page, CDOResourceLeaf resource); } } |