From 0f40832d925f63a5b4699f7753b4661d45f83b2c Mon Sep 17 00:00:00 2001
From: Eike Stepper
Date: Thu, 19 Feb 2015 07:57:06 +0100
Subject: [458349] Consolidate UI
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=458349---
plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml | 66 ++--
.../emf/cdo/explorer/ui/ObjectController.java | 298 -----------------
.../emf/cdo/explorer/ui/ObjectListController.java | 372 +++++++++++++++++++++
.../checkouts/CDOCheckoutDropAdapterAssistant.java | 10 +-
.../ui/checkouts/CDOCheckoutLabelDecorator.java | 3 +-
.../ui/checkouts/CDOCheckoutLabelProvider.java | 16 +-
.../ui/checkouts/CDOCheckoutNewActionProvider.java | 6 +-
.../checkouts/CDOCheckoutShowInActionProvider.java | 4 +-
.../explorer/ui/handlers/ObjectDeleteHandler.java | 10 +-
.../ui/handlers/WorkspaceRevertHandler.java | 10 +-
.../emf/cdo/explorer/CDOContentProvider.java | 20 ++
.../eclipse/emf/cdo/explorer/CDOExplorerUtil.java | 70 ++--
.../emf/cdo/explorer/checkouts/CDOCheckout.java | 19 +-
.../cdo/explorer/repositories/CDORepository.java | 6 +
.../explorer/checkouts/CDOCheckoutImpl.java | 5 -
.../explorer/checkouts/OfflineCDOCheckout.java | 10 +
.../explorer/checkouts/OnlineCDOCheckout.java | 10 +
.../explorer/repositories/CloneCDORepository.java | 15 +
.../explorer/repositories/LocalCDORepository.java | 15 +
.../explorer/repositories/RemoteCDORepository.java | 15 +
.../src/org/eclipse/net4j/util/AdapterUtil.java | 8 +
.../org/eclipse/net4j/util/collection/HashBag.java | 8 +-
22 files changed, 602 insertions(+), 394 deletions(-)
delete mode 100644 plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ObjectController.java
create mode 100644 plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ObjectListController.java
create mode 100644 plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/CDOContentProvider.java
(limited to 'plugins')
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml b/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml
index 439a7b4a5f..546b8770f0 100644
--- a/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.explorer.ui/plugin.xml
@@ -146,16 +146,16 @@
-
+
-
-
-
-
-
+
+
+
+
+
-
+
-
+
-
+
-
+
@@ -189,8 +189,8 @@
-
-
+
+
@@ -203,7 +203,7 @@
-
+
@@ -216,7 +216,7 @@
-
+
@@ -229,7 +229,7 @@
-
+
@@ -242,7 +242,7 @@
-
+
@@ -255,7 +255,7 @@
-
+
@@ -265,9 +265,9 @@
-
-
-
+
+
+
@@ -356,7 +356,7 @@
commandId="org.eclipse.ui.edit.delete">
-
+
@@ -365,7 +365,7 @@
commandId="org.eclipse.ui.edit.delete">
-
+
@@ -374,7 +374,7 @@
commandId="org.eclipse.ui.edit.delete">
-
+
@@ -426,7 +426,7 @@
-
+
@@ -492,7 +492,7 @@
-
+
@@ -506,7 +506,7 @@
-
+
@@ -520,7 +520,7 @@
-
+
@@ -539,7 +539,7 @@
-
+
@@ -557,7 +557,7 @@
-
+
@@ -574,7 +574,7 @@
-
+
@@ -595,7 +595,7 @@
-
+
@@ -612,7 +612,7 @@
-
+
@@ -629,7 +629,7 @@
-
+
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ObjectController.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ObjectController.java
deleted file mode 100644
index e19cd1e71e..0000000000
--- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ObjectController.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * Copyright (c) 2004-2014 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;
-
-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.explorer.ui.checkouts.CDOCheckoutLabelProvider;
-
-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.viewers.CheckboxTreeViewer;
-import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.graphics.Image;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * @author Eike Stepper
- */
-public class ObjectController
-{
- private final List wrappers = new ArrayList();
-
- private final CDOCheckout checkout;
-
- public ObjectController(CDOCheckout checkout)
- {
- this.checkout = checkout;
- }
-
- public final CDOCheckout getCheckout()
- {
- return checkout;
- }
-
- public final EObject getObject(Object wrapper)
- {
- if (wrapper instanceof Wrapper)
- {
- return ((Wrapper)wrapper).getObject();
- }
-
- return null;
- }
-
- public final void addObject(EObject object, boolean delete)
- {
- wrappers.add(new Wrapper(object, delete));
- }
-
- public void configure(final TreeViewer treeViewer)
- {
- final LabelProvider labelProvider = new LabelProvider();
-
- treeViewer.setContentProvider(new ContentProvider());
- treeViewer.setLabelProvider(new DecoratingStyledCellLabelProvider(labelProvider, new LabelDecorator(), null));
- treeViewer.setInput(wrappers);
-
- treeViewer.getControl().getDisplay().asyncExec(new Runnable()
- {
- public void run()
- {
- configureAsync(treeViewer, labelProvider);
- }
- });
- }
-
- @SuppressWarnings("deprecation")
- protected void configureAsync(final TreeViewer treeViewer, final LabelProvider labelProvider)
- {
- if (treeViewer instanceof CheckboxTreeViewer)
- {
- CheckboxTreeViewer checkboxTreeViewer = (CheckboxTreeViewer)treeViewer;
- checkboxTreeViewer.setAllChecked(true);
- }
-
- new Job("Compute paths")
- {
- @Override
- protected IStatus run(IProgressMonitor monitor)
- {
- updateWrappers(treeViewer, labelProvider);
- return Status.OK_STATUS;
- }
- }.schedule();
- }
-
- protected void updateWrappers(final TreeViewer treeViewer, final LabelProvider labelProvider)
- {
- for (Wrapper wrapper : wrappers)
- {
- try
- {
- if (wrapper.computePath(checkout, labelProvider))
- {
- ViewerUtil.update(treeViewer, wrapper);
- }
- }
- catch (Exception ex)
- {
- //$FALL-THROUGH$
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class Wrapper
- {
- private final EObject object;
-
- private final boolean delete;
-
- private String path;
-
- public Wrapper(EObject object, boolean delete)
- {
- this.object = object;
- this.delete = delete;
- }
-
- public final EObject getObject()
- {
- return object;
- }
-
- public final boolean isDelete()
- {
- return delete;
- }
-
- public final String getPath()
- {
- return path;
- }
-
- public boolean computePath(CDOCheckout checkout, LabelProvider labelProvider)
- {
- LinkedList nodes = CDOExplorerUtil.getPath(object);
- if (nodes != null)
- {
- nodes.removeLast();
-
- StringBuilder builder = new StringBuilder();
- boolean first = true;
-
- for (EObject node : nodes)
- {
- builder.append('/');
-
- if (first)
- {
- builder.append(checkout.getLabel());
- first = false;
- }
- else
- {
- builder.append(labelProvider.getText(node));
- }
- }
-
- path = builder.toString();
- return true;
- }
-
- return false;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private final class ContentProvider implements ITreeContentProvider
- {
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
- {
- }
-
- public void dispose()
- {
- }
-
- public Object[] getElements(Object element)
- {
- return wrappers.toArray();
- }
-
- public Object getParent(Object element)
- {
- return null;
- }
-
- public Object[] getChildren(Object element)
- {
- return getElements(element);
- }
-
- public boolean hasChildren(Object element)
- {
- return element == wrappers && !wrappers.isEmpty();
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class LabelProvider extends CDOCheckoutLabelProvider
- {
- public LabelProvider()
- {
- }
-
- @Override
- public Image getImage(Object element)
- {
- if (element instanceof Wrapper)
- {
- Wrapper wrapper = (Wrapper)element;
- return super.getImage(wrapper.getObject());
- }
-
- return super.getImage(element);
- }
-
- @Override
- public String getText(Object element)
- {
- if (element instanceof Wrapper)
- {
- Wrapper wrapper = (Wrapper)element;
- return super.getText(wrapper.getObject());
- }
-
- return super.getText(element);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class LabelDecorator extends BaseLabelDecorator
- {
- private static final Image DELETE_OVERLAY_IMAGE = OM.getImage("icons/delete_ovr.gif");
-
- @Override
- public Image decorateImage(Image image, Object element)
- {
- if (element instanceof Wrapper)
- {
- Wrapper wrapper = (Wrapper)element;
- if (wrapper.isDelete())
- {
- return OM.getOverlayImage(image, DELETE_OVERLAY_IMAGE, 9, 0);
- }
- }
-
- return super.decorateImage(image, element);
- }
-
- @Override
- public String decorateText(String text, Object element)
- {
- if (element instanceof Wrapper)
- {
- Wrapper wrapper = (Wrapper)element;
- String path = wrapper.getPath();
- if (path != null)
- {
- text = path + "/" + text;
- }
-
- return text;
- }
-
- return super.decorateText(text, element);
- }
- }
-
-}
diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ObjectListController.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ObjectListController.java
new file mode 100644
index 0000000000..86298c6c9e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/ObjectListController.java
@@ -0,0 +1,372 @@
+/*
+ * Copyright (c) 2004-2014 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;
+
+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.explorer.ui.checkouts.CDOCheckoutLabelProvider;
+
+import org.eclipse.net4j.util.ui.views.ItemProvider;
+
+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.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Control;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * @author Eike Stepper
+ */
+public class ObjectListController
+{
+ private final LabelProvider labelProvider = new LabelProvider();
+
+ private final AtomicBoolean refreshing = new AtomicBoolean();
+
+ private final List wrappers = new ArrayList();
+
+ private final CDOCheckout checkout;
+
+ public ObjectListController(CDOCheckout checkout)
+ {
+ this.checkout = checkout;
+ }
+
+ public final CDOCheckout getCheckout()
+ {
+ return checkout;
+ }
+
+ public final EObject getObject(Object wrapper)
+ {
+ if (wrapper instanceof Wrapper)
+ {
+ return ((Wrapper)wrapper).getObject();
+ }
+
+ return null;
+ }
+
+ public final void addObject(EObject object, boolean delete)
+ {
+ String name = labelProvider.getSuperText(object);
+ wrappers.add(new Wrapper(object, delete, name));
+ }
+
+ public void configure(final TreeViewer treeViewer)
+ {
+ treeViewer.setContentProvider(new ContentProvider());
+ treeViewer.setLabelProvider(new DecoratingStyledCellLabelProvider(labelProvider, new LabelDecorator(), null));
+ treeViewer.setInput(wrappers);
+
+ treeViewer.getControl().getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ configureAsync(treeViewer, labelProvider);
+ }
+ });
+ }
+
+ @SuppressWarnings("deprecation")
+ protected void configureAsync(final TreeViewer treeViewer, final LabelProvider labelProvider)
+ {
+ if (treeViewer instanceof CheckboxTreeViewer)
+ {
+ CheckboxTreeViewer checkboxTreeViewer = (CheckboxTreeViewer)treeViewer;
+ checkboxTreeViewer.setAllChecked(true);
+ }
+
+ new Job("Compute paths")
+ {
+ @Override
+ protected IStatus run(IProgressMonitor monitor)
+ {
+ updateWrappers(treeViewer, labelProvider);
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+ }
+
+ protected void updateWrappers(final TreeViewer treeViewer, final LabelProvider labelProvider)
+ {
+ for (Wrapper wrapper : wrappers)
+ {
+ try
+ {
+ boolean hasPath;
+ synchronized (wrappers)
+ {
+ hasPath = wrapper.computePath(checkout, labelProvider);
+ }
+
+ if (hasPath)
+ {
+ refresh(treeViewer);
+ }
+ }
+ catch (Exception ex)
+ {
+ //$FALL-THROUGH$
+ }
+ }
+ }
+
+ private void refresh(final TreeViewer treeViewer)
+ {
+ if (!refreshing.getAndSet(true))
+ {
+ Control control = treeViewer.getControl();
+ if (!control.isDisposed())
+ {
+ control.getDisplay().asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ refreshing.set(false);
+ treeViewer.refresh(wrappers);
+ }
+ });
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class Wrapper implements Comparable
+ {
+ private final EObject object;
+
+ private final boolean delete;
+
+ private final String name;
+
+ private String path;
+
+ public Wrapper(EObject object, boolean delete, String name)
+ {
+ this.object = object;
+ this.delete = delete;
+ this.name = name;
+ }
+
+ public final EObject getObject()
+ {
+ return object;
+ }
+
+ public final boolean isDelete()
+ {
+ return delete;
+ }
+
+ public final String getPath()
+ {
+ return path;
+ }
+
+ public final String getName()
+ {
+ return name;
+ }
+
+ public boolean computePath(CDOCheckout checkout, LabelProvider labelProvider)
+ {
+ LinkedList