Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2015-02-09 19:48:12 +0000
committerEike Stepper2015-02-18 14:41:11 +0000
commit9bcd1f30ff1774ff7e66c36ef8b200ef318a164c (patch)
tree942d3276a7df824dbe8c6fceef108060c58d23ad /plugins
parenta5244cfa65cf4b9bf8c9e53665842fe20261d265 (diff)
downloadcdo-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')
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml28
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java91
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelProvider.java101
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutNewActionProvider.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutOpenActionProvider.java473
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/wizards/NewWizardPage.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractElement.java13
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractManager.java53
-rw-r--r--plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java53
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobEditorInput.java291
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOLobStorage.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/CDOPropertyAdapterFactory.java42
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/actions/TransactionalBackgroundAction.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/internal/ui/views/CDOSessionsView.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOEditorUtil.java40
-rw-r--r--plugins/org.eclipse.emf.cdo.ui/src/org/eclipse/emf/cdo/ui/CDOItemProvider.java11
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java46
18 files changed, 934 insertions, 356 deletions
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml
index ddfd3ad453..76ce132e54 100644
--- a/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml
@@ -158,6 +158,34 @@
<test property="org.eclipse.emf.cdo.explorer.checkout.state" value="Open"/>
</and>
<instanceof value="org.eclipse.emf.cdo.eresource.CDOResourceFolder"/>
+ <and>
+ <instanceof
+ value="org.eclipse.emf.ecore.EObject">
+ </instanceof>
+ <not>
+ <instanceof
+ value="org.eclipse.emf.cdo.eresource.CDOBinaryResource">
+ </instanceof>
+ </not>
+ <not>
+ <instanceof
+ value="org.eclipse.emf.cdo.eresource.CDOTextResource">
+ </instanceof>
+ </not>
+ </and>
+ </or>
+ </enablement>
+ </actionProvider>
+ <actionProvider
+ class="org.eclipse.emf.cdo.explorer.ui.checkouts.CDOCheckoutOpenActionProvider"
+ id="org.eclipse.emf.cdo.explorer.ui.checkouts.OpenWithActions">
+ <enablement>
+ <or>
+ <and>
+ <instanceof value="org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout"/>
+ <test property="org.eclipse.emf.cdo.explorer.checkout.state" value="Open"/>
+ </and>
+ <instanceof value="org.eclipse.emf.cdo.eresource.CDOResourceFolder"/>
<instanceof value="org.eclipse.emf.ecore.EObject"/>
</or>
</enablement>
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java
index 9543ae101e..dcfbf0708b 100644
--- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java
+++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutContentProvider.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDOList;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionManager;
+import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.explorer.CDOExplorerManager;
import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
@@ -63,6 +64,15 @@ import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IViewReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonViewer;
+import org.eclipse.ui.part.IPage;
+import org.eclipse.ui.views.properties.PropertySheet;
+import org.eclipse.ui.views.properties.PropertySheetPage;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -107,13 +117,74 @@ public class CDOCheckoutContentProvider extends AdapterFactoryContentProvider im
{
ViewerUtil.expand(viewer, checkout, true);
}
+
+ updatePropertySheetPage(checkout);
}
else if (event instanceof CDOExplorerManager.ElementChangedEvent)
{
CDOExplorerManager.ElementChangedEvent e = (CDOExplorerManager.ElementChangedEvent)event;
Object changedElement = e.getChangedElement();
ViewerUtil.update(viewer, changedElement);
+ updatePropertySheetPage(changedElement);
+ }
+ }
+
+ private void updatePropertySheetPage(final Object element)
+ {
+ IWorkbenchPage workbenchPage = getWorkbenchPage();
+
+ PropertySheet propertySheet = getPropertySheet(workbenchPage);
+ if (propertySheet != null)
+ {
+ final IPage currentPage = propertySheet.getCurrentPage();
+ if (currentPage instanceof PropertySheetPage || currentPage instanceof TabbedPropertySheetPage)
+ {
+ viewer.getControl().getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ if (selection.size() == 1)
+ {
+ for (Object object : selection.toArray())
+ {
+ if (object == element)
+ {
+ if (currentPage instanceof PropertySheetPage)
+ {
+ ((PropertySheetPage)currentPage).refresh();
+ }
+ else if (currentPage instanceof TabbedPropertySheetPage)
+ {
+ ((TabbedPropertySheetPage)currentPage).refresh();
+ }
+
+ return;
+ }
+ }
+ }
+ }
+ });
+ }
+ }
+ }
+
+ private PropertySheet getPropertySheet(IWorkbenchPage workbenchPage)
+ {
+ for (IViewReference viewReference : workbenchPage.getViewReferences())
+ {
+ if ("org.eclipse.ui.views.PropertySheet".equals(viewReference.getId()))
+ {
+ IViewPart view = viewReference.getView(false);
+ if (view instanceof PropertySheet)
+ {
+ return (PropertySheet)view;
+
+ }
+ }
}
+
+ return null;
}
};
@@ -530,10 +601,30 @@ public class CDOCheckoutContentProvider extends AdapterFactoryContentProvider im
ViewerUtil.expand(viewer, checkout, true);
}
}
+ else if (element instanceof CDOResourceFolder)
+ {
+ // Do nothing special.
+ }
+ else if (element instanceof EObject)
+ {
+ EObject eObject = (EObject)element;
+ CDOCheckoutOpenActionProvider.openEditor(getWorkbenchPage(), eObject, null);
+ }
}
}
}
+ private IWorkbenchPage getWorkbenchPage()
+ {
+ if (viewer instanceof CommonViewer)
+ {
+ CommonViewer commonViewer = (CommonViewer)viewer;
+ return commonViewer.getCommonNavigator().getSite().getPage();
+ }
+
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ }
+
private static InternalCDOObject getCDOObject(EObject eObject)
{
if (eObject instanceof InternalCDOObject)
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelProvider.java
index ad2a3ce576..686aceb411 100644
--- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelProvider.java
+++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelProvider.java
@@ -10,20 +10,31 @@
*/
package org.eclipse.emf.cdo.explorer.ui.checkouts;
+import org.eclipse.emf.cdo.eresource.CDOResourceLeaf;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.cdo.explorer.ui.ViewerUtil;
import org.eclipse.emf.cdo.explorer.ui.bundle.OM;
import org.eclipse.emf.cdo.internal.ui.editor.CDOEditor;
+import org.eclipse.emf.cdo.transfer.CDOTransferElement;
+import org.eclipse.emf.cdo.ui.CDOEditorUtil;
import org.eclipse.net4j.util.ui.views.ContainerItemProvider;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+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.IColorProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.swt.graphics.Color;
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.ISharedImages;
import org.eclipse.ui.PlatformUI;
@@ -39,8 +50,14 @@ public class CDOCheckoutLabelProvider extends AdapterFactoryLabelProvider implem
private static final Image ERROR_IMAGE = PlatformUI.getWorkbench().getSharedImages()
.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
+ private static final IEditorRegistry EDITOR_REGISTRY = PlatformUI.getWorkbench().getEditorRegistry();
+
private final ComposedAdapterFactory adapterFactory;
+ private IPropertyListener editorRegistryListener;
+
+ private ResourceManager resourceManager;
+
public CDOCheckoutLabelProvider()
{
super(null);
@@ -52,6 +69,18 @@ public class CDOCheckoutLabelProvider extends AdapterFactoryLabelProvider implem
@Override
public void dispose()
{
+ if (editorRegistryListener != null)
+ {
+ EDITOR_REGISTRY.removePropertyListener(editorRegistryListener);
+ resourceManager = null;
+ }
+
+ if (resourceManager != null)
+ {
+ resourceManager.dispose();
+ resourceManager = null;
+ }
+
super.dispose();
// Must come after super.dispose().
@@ -59,6 +88,17 @@ public class CDOCheckoutLabelProvider extends AdapterFactoryLabelProvider implem
}
@Override
+ public Color getForeground(Object object)
+ {
+ if (object instanceof ViewerUtil.Pending)
+ {
+ return ContainerItemProvider.PENDING_COLOR;
+ }
+
+ return super.getForeground(object);
+ }
+
+ @Override
public String getText(Object element)
{
if (element instanceof CDOCheckout)
@@ -111,22 +151,73 @@ public class CDOCheckoutLabelProvider extends AdapterFactoryLabelProvider implem
try
{
+ if (element instanceof CDOResourceLeaf)
+ {
+ String name = ((CDOResourceLeaf)element).getName();
+
+ IEditorDescriptor editorDescriptor = EDITOR_REGISTRY.getDefaultEditor(name);
+ if (editorDescriptor != null && !CDOEditorUtil.TEXT_EDITOR_ID.equals(editorDescriptor.getId()))
+ {
+ Image image = getWorkbenchImage(name);
+ if (image != null)
+ {
+ return image;
+ }
+ }
+ }
+
return super.getImage(element);
}
catch (Exception ex)
{
+ ex.printStackTrace();
return ERROR_IMAGE;
}
}
- @Override
- public Color getForeground(Object object)
+ protected Image getWorkbenchImage(String name)
{
- if (object instanceof ViewerUtil.Pending)
+ ImageDescriptor imageDescriptor = EDITOR_REGISTRY.getImageDescriptor(name);
+ if (imageDescriptor != null)
{
- return ContainerItemProvider.PENDING_COLOR;
+ if (editorRegistryListener == null)
+ {
+ editorRegistryListener = new EditorRegistryListener();
+ EDITOR_REGISTRY.addPropertyListener(editorRegistryListener);
+ }
+
+ ResourceManager resourceManager = getResourceManager();
+ return (Image)resourceManager.get(imageDescriptor);
}
- return super.getForeground(object);
+ return null;
+ }
+
+ protected ResourceManager getResourceManager()
+ {
+ if (resourceManager == null)
+ {
+ resourceManager = new LocalResourceManager(JFaceResources.getResources());
+ }
+
+ return resourceManager;
+ }
+
+ /**
+ * A {@link IPropertyListener listener} on the platform's {@link IEditorRegistry editor registry} that fires {@link LabelProviderChangedEvent label events}
+ * from the associated {@link #getItemProvider() item provider} when {@link CDOTransferElement element} labels need to be updated.
+ *
+ * @author Eike Stepper
+ * @since 4.2
+ */
+ protected class EditorRegistryListener implements IPropertyListener
+ {
+ public void propertyChanged(Object source, int propId)
+ {
+ if (propId == IEditorRegistry.PROP_CONTENTS)
+ {
+ fireLabelProviderChanged();
+ }
+ }
}
}
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutNewActionProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutNewActionProvider.java
index e7d53d6eb6..cbc0278155 100644
--- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutNewActionProvider.java
+++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutNewActionProvider.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.explorer.ui.checkouts;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.cdo.internal.ui.actions.TransactionalBackgroundAction;
@@ -176,6 +177,10 @@ public class CDOCheckoutNewActionProvider extends CommonActionProvider implement
{
fillNewRootActions(submenu, (CDOResource)selectedObject);
}
+ else if (selectedObject instanceof CDOResourceNode)
+ {
+ // CDOResourceFolder contributions have already been added by newWizardActionGroup.
+ }
else if (selectedObject instanceof EObject)
{
fillNewChildActions(submenu, (EObject)selectedObject);
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutOpenActionProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutOpenActionProvider.java
new file mode 100644
index 0000000000..614b9d1bb0
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutOpenActionProvider.java
@@ -0,0 +1,473 @@
+/*
+ * Copyright (c) 2009-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.explorer.ui.checkouts;
+
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
+import org.eclipse.emf.cdo.eresource.CDOResourceLeaf;
+import org.eclipse.emf.cdo.explorer.CDOExplorerUtil;
+import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
+import org.eclipse.emf.cdo.explorer.ui.bundle.OM;
+import org.eclipse.emf.cdo.internal.ui.actions.OpenTransactionAction;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.ui.CDOEditorUtil;
+import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.net4j.util.collection.Pair;
+import org.eclipse.net4j.util.ui.UIUtil;
+
+import org.eclipse.emf.ecore.EObject;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.GroupMarker;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IPageListener;
+import org.eclipse.ui.IPartListener2;
+import org.eclipse.ui.IWindowListener;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartReference;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.navigator.CommonActionProvider;
+import org.eclipse.ui.navigator.ICommonActionConstants;
+import org.eclipse.ui.navigator.ICommonActionExtensionSite;
+import org.eclipse.ui.navigator.ICommonMenuConstants;
+import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class CDOCheckoutOpenActionProvider extends CommonActionProvider
+{
+ private static final Map<IEditorPart, Pair<CDOView, Pair<CDOResourceLeaf, String>>> VIEWS = new HashMap<IEditorPart, Pair<CDOView, Pair<CDOResourceLeaf, String>>>();
+
+ private static final Map<Pair<CDOResourceLeaf, String>, Object> EDITORS = new HashMap<Pair<CDOResourceLeaf, String>, Object>();
+
+ private static final Object EDITOR_OPENING = new Object();
+
+ private static final IPartListener2 PART_LISTENER = new IPartListener2()
+ {
+ public void partOpened(IWorkbenchPartReference partRef)
+ {
+ }
+
+ public void partClosed(IWorkbenchPartReference partRef)
+ {
+ IWorkbenchPart part = partRef.getPart(false);
+ if (part != null)
+ {
+ Pair<CDOView, Pair<CDOResourceLeaf, String>> pair;
+ synchronized (VIEWS)
+ {
+ pair = VIEWS.remove(part);
+ }
+
+ if (pair != null)
+ {
+ CDOView view = pair.getElement1();
+ view.close();
+
+ Pair<CDOResourceLeaf, String> key = pair.getElement2();
+ synchronized (EDITORS)
+ {
+ EDITORS.remove(key);
+ }
+ }
+ }
+ }
+
+ public void partVisible(IWorkbenchPartReference partRef)
+ {
+ // Do nothing
+ }
+
+ public void partHidden(IWorkbenchPartReference partRef)
+ {
+ // Do nothing
+ }
+
+ public void partActivated(IWorkbenchPartReference partRef)
+ {
+ // Do nothing
+ }
+
+ public void partDeactivated(IWorkbenchPartReference partRef)
+ {
+ // Do nothing
+ }
+
+ public void partBroughtToTop(IWorkbenchPartReference partRef)
+ {
+ // Do nothing
+ }
+
+ public void partInputChanged(IWorkbenchPartReference partRef)
+ {
+ // Do nothing
+ }
+ };
+
+ private static final IPageListener PAGE_LISTENER = new IPageListener()
+ {
+ public void pageOpened(IWorkbenchPage page)
+ {
+ page.addPartListener(PART_LISTENER);
+ }
+
+ public void pageClosed(IWorkbenchPage page)
+ {
+ page.removePartListener(PART_LISTENER);
+ }
+
+ public void pageActivated(IWorkbenchPage page)
+ {
+ // Do nothing
+ }
+ };
+
+ private static final IWindowListener WINDOW_LISTENER = new IWindowListener()
+ {
+ public void windowOpened(IWorkbenchWindow window)
+ {
+ window.addPageListener(PAGE_LISTENER);
+ }
+
+ public void windowClosed(IWorkbenchWindow window)
+ {
+ window.removePageListener(PAGE_LISTENER);
+ }
+
+ public void windowActivated(IWorkbenchWindow window)
+ {
+ // Do nothing
+ }
+
+ public void windowDeactivated(IWorkbenchWindow window)
+ {
+ // Do nothing
+ }
+ };
+
+ static
+ {
+ IWorkbench workbench = UIUtil.getWorkbench();
+ for (IWorkbenchWindow window : workbench.getWorkbenchWindows())
+ {
+ window.addPageListener(PAGE_LISTENER);
+
+ for (IWorkbenchPage page : window.getPages())
+ {
+ page.addPartListener(PART_LISTENER);
+ }
+ }
+
+ workbench.addWindowListener(WINDOW_LISTENER);
+ }
+
+ private ICommonViewerWorkbenchSite viewSite;
+
+ private OpenFileAction openFileAction;
+
+ @Override
+ public void init(ICommonActionExtensionSite aConfig)
+ {
+ if (aConfig.getViewSite() instanceof ICommonViewerWorkbenchSite)
+ {
+ viewSite = (ICommonViewerWorkbenchSite)aConfig.getViewSite();
+ openFileAction = new OpenFileAction(viewSite.getPage());
+ }
+ }
+
+ @Override
+ public void fillActionBars(IActionBars actionBars)
+ {
+ if (viewSite == null)
+ {
+ return;
+ }
+
+ Object selectedElement = getSelectedElement();
+
+ openFileAction.selectionChanged(selectedElement);
+ if (openFileAction.isEnabled())
+ {
+ actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, openFileAction);
+ }
+ }
+
+ @Override
+ public void fillContextMenu(IMenuManager menu)
+ {
+ if (viewSite == null)
+ {
+ return;
+ }
+
+ Object selectedElement = getSelectedElement();
+
+ openFileAction.selectionChanged(selectedElement);
+ if (openFileAction.isEnabled())
+ {
+ menu.insertAfter(ICommonMenuConstants.GROUP_OPEN, openFileAction);
+ addOpenWithMenu(menu, selectedElement);
+ }
+ }
+
+ private Object getSelectedElement()
+ {
+ IStructuredSelection selection = (IStructuredSelection)getContext().getSelection();
+ if (selection.size() == 1)
+ {
+ return selection.getFirstElement();
+ }
+
+ return null;
+ }
+
+ private void addOpenWithMenu(IMenuManager menu, Object selectedElement)
+ {
+ EObject openableElement = getOpenableElement(selectedElement);
+ if (openableElement == null)
+ {
+ return;
+ }
+
+ CDOObject cdoObject = CDOUtil.getCDOObject(openableElement);
+ CDOResourceLeaf resourceLeaf = getResourceLeaf(cdoObject);
+ if (resourceLeaf == null)
+ {
+ return;
+ }
+
+ String[] editorIDs = CDOEditorUtil.getAllEditorIDs(resourceLeaf);
+ if (editorIDs.length == 0)
+ {
+ return;
+ }
+
+ IMenuManager submenu = new MenuManager("Open With", ICommonMenuConstants.GROUP_OPEN_WITH);
+ submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_TOP));
+
+ for (String editorID : editorIDs)
+ {
+ OpenFileAction action = new OpenFileAction(viewSite.getPage(), resourceLeaf, editorID);
+ submenu.add(action);
+ }
+
+ submenu.add(new GroupMarker(ICommonMenuConstants.GROUP_ADDITIONS));
+ menu.appendToGroup(ICommonMenuConstants.GROUP_OPEN_WITH, submenu);
+ }
+
+ private static EObject getOpenableElement(Object element)
+ {
+ if (element instanceof EObject)
+ {
+ EObject eObject = (EObject)element;
+ CDOCheckout checkout = CDOExplorerUtil.getCheckout(eObject);
+ if (checkout != null && !(eObject instanceof CDOResourceFolder))
+ {
+ return eObject;
+ }
+ }
+
+ return null;
+ }
+
+ private static CDOResourceLeaf getResourceLeaf(CDOObject cdoObject)
+ {
+ if (cdoObject instanceof CDOResourceLeaf)
+ {
+ return (CDOResourceLeaf)cdoObject;
+ }
+
+ if (cdoObject instanceof CDOResourceFolder)
+ {
+ return null;
+ }
+
+ return cdoObject.cdoResource();
+ }
+
+ private static void openEditor(final IWorkbenchPage page, final CDOObject object, final CDOResourceLeaf resourceLeaf,
+ final String editorID, final Pair<CDOResourceLeaf, String> key)
+ {
+ new Job("Open")
+ {
+ @Override
+ protected IStatus run(IProgressMonitor monitor)
+ {
+ CDOView view = object.cdoView();
+ final CDOTransaction transaction = view.getSession().openTransaction(view.getBranch());
+ OpenTransactionAction.configureTransaction(transaction);
+
+ CDOResourceLeaf transactionalLeaf = transaction.getObject(resourceLeaf);
+ final IEditorInput editorInput = CDOEditorUtil.createEditorInput(editorID, transactionalLeaf, false, true);
+
+ final IWorkbenchWindow workbenchWindow = page.getWorkbenchWindow();
+ Display display = workbenchWindow.getShell().getDisplay();
+
+ display.asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ IEditorPart editor = page.openEditor(editorInput, editorID);
+ if (editor != null)
+ {
+ synchronized (EDITORS)
+ {
+ EDITORS.put(key, editor);
+ }
+
+ synchronized (VIEWS)
+ {
+ VIEWS.put(editor, Pair.create((CDOView)transaction, key));
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ });
+
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ }
+
+ public static void openEditor(IWorkbenchPage page, EObject object, String editorID)
+ {
+ if (page == null)
+ {
+ page = UIUtil.getActiveWorkbenchPage();
+ }
+
+ if (object == null)
+ {
+ throw new IllegalArgumentException("object is null");
+ }
+
+ CDOObject cdoObject = CDOUtil.getCDOObject(object);
+ CDOResourceLeaf resourceLeaf = getResourceLeaf(cdoObject);
+ if (resourceLeaf == null)
+ {
+ return;
+ }
+
+ if (editorID == null)
+ {
+ CDOCheckout checkout = CDOExplorerUtil.getCheckout(object);
+ if (checkout != null)
+ {
+ editorID = checkout.getEditorID(cdoObject.cdoID());
+ }
+ }
+
+ if (editorID == null)
+ {
+ editorID = CDOEditorUtil.getEffectiveEditorID(resourceLeaf);
+ }
+
+ Pair<CDOResourceLeaf, String> key = Pair.create(resourceLeaf, editorID);
+
+ synchronized (EDITORS)
+ {
+ Object editor = EDITORS.get(key);
+ if (editor != null)
+ {
+ if (editor != EDITOR_OPENING)
+ {
+ page.activate((IEditorPart)editor);
+ }
+
+ return;
+ }
+
+ EDITORS.put(key, EDITOR_OPENING);
+ }
+
+ openEditor(page, cdoObject, resourceLeaf, editorID, key);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static class OpenFileAction extends Action
+ {
+ public static final String ID = OM.BUNDLE_ID + ".OpenFileAction"; //$NON-NLS-1$
+
+ private final IWorkbenchPage page;
+
+ private EObject openableElement;
+
+ private String editorID;
+
+ public OpenFileAction(IWorkbenchPage page)
+ {
+ this(page, null, null);
+ }
+
+ public OpenFileAction(IWorkbenchPage page, EObject openableElement, String editorID)
+ {
+ super();
+ setId(ID);
+
+ this.page = page;
+ this.openableElement = openableElement;
+ this.editorID = editorID;
+
+ if (editorID != null)
+ {
+ IEditorDescriptor editorDescriptor = PlatformUI.getWorkbench().getEditorRegistry().findEditor(editorID);
+ setText(editorDescriptor.getLabel());
+ setImageDescriptor(editorDescriptor.getImageDescriptor());
+ }
+ else
+ {
+ setText("Open");
+ }
+
+ setToolTipText("Edit this resource");
+ }
+
+ public void selectionChanged(Object selectedElement)
+ {
+ openableElement = getOpenableElement(selectedElement);
+ setEnabled(openableElement != null);
+ }
+
+ @Override
+ public void run()
+ {
+ openEditor(page, openableElement, editorID);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/wizards/NewWizardPage.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/wizards/NewWizardPage.java
index 72ab82a03f..a0ea83ed85 100644
--- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/wizards/NewWizardPage.java
+++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/wizards/NewWizardPage.java
@@ -204,6 +204,9 @@ public class NewWizardPage extends WizardPage
revealParent();
validate();
+
+ nameText.setFocus();
+ nameText.selectAll();
}
});
}
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java
index be889197bd..19ca489296 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/checkouts/CDOCheckout.java
@@ -59,6 +59,10 @@ public interface CDOCheckout extends CDOExplorerElement, CDOTimeProvider
public RootType getRootType();
+ public String getEditorID(CDOID objectID);
+
+ public void setEditorID(CDOID objectID, String editorID);
+
/**
* @author Eike Stepper
*/
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractElement.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractElement.java
index dee08c3040..62f64314fd 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractElement.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractElement.java
@@ -199,19 +199,24 @@ public abstract class AbstractElement extends Notifier implements CDOExplorerEle
public void save()
{
- folder.mkdirs();
-
Properties properties = new Properties();
collectProperties(properties);
+ saveProperties(PROPERTIES_FILE, properties);
+ }
+
+ protected final void saveProperties(String fileName, Properties properties)
+ {
OutputStream out = null;
try
{
- File file = new File(folder, PROPERTIES_FILE);
+ folder.mkdirs();
+
+ File file = new File(folder, fileName);
out = new FileOutputStream(file);
- properties.store(out, getClass().getSimpleName());
+ properties.store(out, getClass().getSimpleName() + fileName);
}
catch (IOException ex)
{
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractManager.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractManager.java
index d14052bedd..511e44aba4 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractManager.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/AbstractManager.java
@@ -97,28 +97,10 @@ public abstract class AbstractManager<T extends CDOExplorerElement> extends SetC
private void readElement(File folder)
{
- File file = new File(folder, AbstractElement.PROPERTIES_FILE);
- if (file.isFile())
+ Properties properties = loadProperties(folder, AbstractElement.PROPERTIES_FILE);
+ if (properties != null)
{
- FileInputStream in = null;
-
- try
- {
- in = new FileInputStream(file);
-
- Properties properties = new Properties();
- properties.load(in);
-
- addElement(folder, properties);
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- }
- finally
- {
- IOUtil.close(in);
- }
+ addElement(folder, properties);
}
}
@@ -142,6 +124,35 @@ public abstract class AbstractManager<T extends CDOExplorerElement> extends SetC
fireEvent(new ElementChangedImpl(this, changedElement));
}
+ public static Properties loadProperties(File folder, String fileName)
+ {
+ File file = new File(folder, fileName);
+ if (file.isFile())
+ {
+ FileInputStream in = null;
+
+ try
+ {
+ in = new FileInputStream(file);
+
+ Properties properties = new Properties();
+ properties.load(in);
+
+ return properties;
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ finally
+ {
+ IOUtil.close(in);
+ }
+ }
+
+ return null;
+ }
+
/**
* @author Eike Stepper
*/
diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java
index a7e5ad004b..ea54ff0851 100644
--- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java
+++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/CDOCheckoutImpl.java
@@ -17,11 +17,13 @@ import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout;
import org.eclipse.emf.cdo.explorer.repositories.CDORepository;
import org.eclipse.emf.cdo.internal.explorer.AbstractElement;
+import org.eclipse.emf.cdo.internal.explorer.AbstractManager;
import org.eclipse.emf.cdo.internal.explorer.bundle.OM;
import org.eclipse.emf.cdo.internal.explorer.repositories.CDORepositoryImpl;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.view.CDOView;
+import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
@@ -30,13 +32,19 @@ import org.eclipse.net4j.util.lifecycle.ILifecycleEvent.Kind;
import org.eclipse.emf.ecore.EObject;
import java.io.File;
+import java.util.Map;
import java.util.Properties;
+import java.util.WeakHashMap;
/**
* @author Eike Stepper
*/
public abstract class CDOCheckoutImpl extends AbstractElement implements CDOCheckout
{
+ public static final String EDITORS_FILE = "_editors";
+
+ private final Map<CDOID, String> editorIDs = new WeakHashMap<CDOID, String>();
+
private final IListener viewListener = new IListener()
{
public void notifyEvent(IEvent event)
@@ -253,6 +261,51 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec
return null;
}
+ public String getEditorID(CDOID objectID)
+ {
+ synchronized (editorIDs)
+ {
+ String editorID = editorIDs.get(objectID);
+ if (editorID != null)
+ {
+ return editorID;
+ }
+
+ Properties properties = AbstractManager.loadProperties(getFolder(), EDITORS_FILE);
+ if (properties != null)
+ {
+ String idString = getCDOIDString(objectID);
+ return properties.getProperty(idString);
+ }
+
+ return null;
+ }
+ }
+
+ public void setEditorID(CDOID objectID, String editorID)
+ {
+ synchronized (editorIDs)
+ {
+ String exisingEditorID = editorIDs.get(objectID);
+ if (ObjectUtil.equals(exisingEditorID, editorID))
+ {
+ return;
+ }
+
+ Properties properties = AbstractManager.loadProperties(getFolder(), EDITORS_FILE);
+ if (properties == null)
+ {
+ properties = new Properties();
+ }
+
+ String idString = getCDOIDString(objectID);
+ properties.put(idString, editorID);
+
+ saveProperties(EDITORS_FILE, properties);
+ editorIDs.put(objectID, editorID);
+ }
+ }
+
@Override
public void delete(boolean deleteContents)
{
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)
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java
index 0b22c222a4..5623d61299 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java
@@ -196,6 +196,29 @@ public final class StringUtil
return builder.toString();
}
+ public static String cap(String str)
+ {
+ if (str == null || str.length() == 0)
+ {
+ return str;
+ }
+
+ char first = str.charAt(0);
+ if (Character.isUpperCase(first))
+ {
+ return str;
+ }
+
+ if (str.length() == 1)
+ {
+ return str.toUpperCase();
+ }
+
+ StringBuilder builder = new StringBuilder(str);
+ builder.setCharAt(0, Character.toUpperCase(first));
+ return builder.toString();
+ }
+
/**
* @since 2.0
*/
@@ -223,29 +246,6 @@ public final class StringUtil
return builder.toString();
}
- public static String cap(String str)
- {
- if (str == null || str.length() == 0)
- {
- return str;
- }
-
- char first = str.charAt(0);
- if (Character.isUpperCase(first))
- {
- return str;
- }
-
- if (str.length() == 1)
- {
- return str.toUpperCase();
- }
-
- StringBuilder builder = new StringBuilder(str);
- builder.setCharAt(0, Character.toUpperCase(first));
- return builder.toString();
- }
-
public static String uncap(String str)
{
if (str == null || str.length() == 0)

Back to the top