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 nodes = CDOExplorerUtil.getPath(object); + if (nodes != null) + { + nodes.removeLast(); + + StringBuilder builder = new StringBuilder(); + boolean first = true; + + for (Object 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; + } + + public int compareTo(Wrapper o) + { + return toString().compareTo(o.toString()); + } + + @Override + public String toString() + { + if (path != null) + { + return path + name; + } + + return name; + } + } + + /** + * @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) + { + if (element == wrappers) + { + Object[] result = wrappers.toArray(); + + synchronized (wrappers) + { + Arrays.sort(result); + } + + return result; + } + + return ItemProvider.NO_ELEMENTS; + } + + 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 wrapper.getName(); + } + + return getSuperText(element); + } + + public String getSuperText(Object element) + { + 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/checkouts/CDOCheckoutDropAdapterAssistant.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutDropAdapterAssistant.java index b25f0a9ceb..a9676713b4 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutDropAdapterAssistant.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutDropAdapterAssistant.java @@ -20,6 +20,7 @@ import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout.ObjectType; import org.eclipse.emf.cdo.explorer.ui.bundle.OM; import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.net4j.util.AdapterUtil; import org.eclipse.net4j.util.ObjectUtil; import org.eclipse.emf.common.util.EList; @@ -125,9 +126,10 @@ public class CDOCheckoutDropAdapterAssistant extends CommonDropAdapterAssistant for (Iterator it = selection.iterator(); it.hasNext();) { Object object = it.next(); - if (object instanceof EObject) + + EObject eObject = AdapterUtil.adapt(object, EObject.class); + if (eObject != null) { - EObject eObject = (EObject)object; ObjectType objectType = ObjectType.valueFor(eObject); if (objectType == null || objectType == ObjectType.Root) { @@ -211,13 +213,13 @@ public class CDOCheckoutDropAdapterAssistant extends CommonDropAdapterAssistant } } - LinkedList path = CDOExplorerUtil.getPath(target); + LinkedList path = CDOExplorerUtil.getPath(target); if (path == null) { return false; } - Set targetPath = new HashSet(path); + Set targetPath = new HashSet(path); for (EObject object : objects) { diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelDecorator.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelDecorator.java index 3279ed29a0..989d67eca4 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelDecorator.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutLabelDecorator.java @@ -15,7 +15,6 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchPoint; import org.eclipse.emf.cdo.common.util.CDOCommonUtil; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; import org.eclipse.emf.cdo.explorer.ui.BaseLabelDecorator; -import org.eclipse.emf.cdo.internal.explorer.checkouts.OfflineCDOCheckout; /** * @author Eike Stepper @@ -58,7 +57,7 @@ public class CDOCheckoutLabelDecorator extends BaseLabelDecorator text += " " + CDOCommonUtil.formatTimeStamp(timeStamp); } - if (checkout instanceof OfflineCDOCheckout) + if (checkout.isOffline()) { if (checkout.isDirty()) { 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 2ba6fe0028..fdf774ce70 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 @@ -49,6 +49,8 @@ public class CDOCheckoutLabelProvider extends AdapterFactoryLabelProvider implem private static final Image CHECKOUT_CLOSED_IMAGE = OM.getImage("icons/checkout_closed.gif"); + private static final Image FOLDER_IMAGE = OM.getImage("icons/CDOResourceFolder.gif"); + private static final Image ERROR_IMAGE = PlatformUI.getWorkbench().getSharedImages() .getImage(ISharedImages.IMG_OBJS_ERROR_TSK); @@ -115,7 +117,14 @@ public class CDOCheckoutLabelProvider extends AdapterFactoryLabelProvider implem try { - return resourceNode.getName(); + String name = resourceNode.getName(); + if (name == null) + { + // This must be the root resource. + return ""; + } + + return name; } catch (Exception ex) { @@ -156,6 +165,11 @@ public class CDOCheckoutLabelProvider extends AdapterFactoryLabelProvider implem if (element instanceof CDOResourceLeaf) { String name = ((CDOResourceLeaf)element).getName(); + if (name == null) + { + // This must be the root resource. + return FOLDER_IMAGE; + } IEditorDescriptor editorDescriptor = EDITOR_REGISTRY.getDefaultEditor(name); if (editorDescriptor != null && !CDOEditorUtil.TEXT_EDITOR_ID.equals(editorDescriptor.getId())) 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 1fd0b961be..a77c9e1d8e 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 @@ -238,13 +238,13 @@ public class CDOCheckoutNewActionProvider extends CommonActionProvider implement } } - private void selectObject(final EObject object) + private void selectObject(final Object object) { viewer.getControl().getDisplay().asyncExec(new Runnable() { public void run() { - LinkedList path = new LinkedList(); + LinkedList path = new LinkedList(); CDOCheckout checkout = CDOExplorerUtil.walkUp(object, path); if (checkout != null) { @@ -253,7 +253,7 @@ public class CDOCheckoutNewActionProvider extends CommonActionProvider implement path.removeFirst(); path.removeLast(); - for (EObject object : path) + for (Object object : path) { viewer.setExpandedState(object, true); } diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutShowInActionProvider.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutShowInActionProvider.java index bca3668e09..d9bd4ad235 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutShowInActionProvider.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/checkouts/CDOCheckoutShowInActionProvider.java @@ -95,7 +95,7 @@ public class CDOCheckoutShowInActionProvider extends CommonActionProvider final CDORepository repository = (CDORepository)selectedElement; if (repository.isConnected()) { - if (repository instanceof LocalCDORepository) + if (repository.isLocal()) { LocalCDORepository localRepository = (LocalCDORepository)repository; @@ -138,7 +138,7 @@ public class CDOCheckoutShowInActionProvider extends CommonActionProvider CDOCheckout checkout = (CDOCheckout)selectedElement; if (checkout.isOpen()) { - if (checkout instanceof OfflineCDOCheckout) + if (checkout.isOffline()) { OfflineCDOCheckout offlineCheckout = (OfflineCDOCheckout)checkout; diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/ObjectDeleteHandler.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/ObjectDeleteHandler.java index ce3d560298..25fc3346ba 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/ObjectDeleteHandler.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/ObjectDeleteHandler.java @@ -11,7 +11,7 @@ package org.eclipse.emf.cdo.explorer.ui.handlers; import org.eclipse.emf.cdo.explorer.checkouts.CDOCheckout; -import org.eclipse.emf.cdo.explorer.ui.ObjectController; +import org.eclipse.emf.cdo.explorer.ui.ObjectListController; import org.eclipse.emf.cdo.explorer.ui.bundle.OM; import org.eclipse.emf.ecore.EObject; @@ -106,21 +106,21 @@ public class ObjectDeleteHandler extends AbstractObjectHandler containerGridLayout.marginHeight = 10; container.setLayout(containerGridLayout); - final ObjectController objectController = new ObjectController(checkout); + final ObjectListController objectListController = new ObjectListController(checkout); for (EObject object : objects) { - objectController.addObject(object, false); + objectListController.addObject(object, true); } final CheckboxTreeViewer treeViewer = new CheckboxTreeViewer(container); treeViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - objectController.configure(treeViewer); + objectListController.configure(treeViewer); treeViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { - EObject object = objectController.getObject(event.getElement()); + EObject object = objectListController.getObject(event.getElement()); if (event.getChecked()) { objects.add(object); diff --git a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/WorkspaceRevertHandler.java b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/WorkspaceRevertHandler.java index 69ee6859c7..4222601340 100644 --- a/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/WorkspaceRevertHandler.java +++ b/plugins/org.eclipse.emf.cdo.explorer.ui/src/org/eclipse/emf/cdo/explorer/ui/handlers/WorkspaceRevertHandler.java @@ -14,7 +14,7 @@ import org.eclipse.emf.cdo.CDOObject; import org.eclipse.emf.cdo.common.commit.CDOChangeSetData; import org.eclipse.emf.cdo.common.revision.CDOIDAndVersion; import org.eclipse.emf.cdo.common.revision.CDORevisionKey; -import org.eclipse.emf.cdo.explorer.ui.ObjectController; +import org.eclipse.emf.cdo.explorer.ui.ObjectListController; import org.eclipse.emf.cdo.explorer.ui.bundle.OM; import org.eclipse.emf.cdo.internal.explorer.checkouts.OfflineCDOCheckout; import org.eclipse.emf.cdo.spi.workspace.InternalCDOWorkspace; @@ -182,24 +182,24 @@ public class WorkspaceRevertHandler extends AbstractBaseHandler getPath(EObject object) + public static LinkedList getPath(Object object) { - LinkedList path = new LinkedList(); + LinkedList path = new LinkedList(); if (walkUp(object, path) != null) { return path; @@ -92,7 +105,7 @@ public final class CDOExplorerUtil return null; } - public static CDOCheckout walkUp(EObject object, LinkedList path) + public static CDOCheckout walkUp(Object object, LinkedList path) { while (object != null) { @@ -101,10 +114,15 @@ public final class CDOExplorerUtil path.addFirst(object); } - Adapter adapter = EcoreUtil.getAdapter(object.eAdapters(), CDOCheckout.class); - if (adapter != null) + if (object instanceof EObject) { - return (CDOCheckout)adapter; + EObject eObject = (EObject)object; + + Adapter adapter = EcoreUtil.getAdapter(eObject.eAdapters(), CDOCheckout.class); + if (adapter != null) + { + return (CDOCheckout)adapter; + } } object = getParent(object); 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 f5a9a1add3..7854f45ca4 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 @@ -20,6 +20,8 @@ import org.eclipse.emf.cdo.explorer.repositories.CDORepository; import org.eclipse.emf.cdo.transaction.CDOTransaction; import org.eclipse.emf.cdo.view.CDOView; +import org.eclipse.net4j.util.AdapterUtil; + import org.eclipse.emf.ecore.EObject; /** @@ -34,6 +36,10 @@ public interface CDOCheckout extends CDOExplorerElement, CDOTimeProvider public static final String TYPE_OFFLINE = "offline"; + public boolean isOffline(); + + public boolean isOnline(); + public CDORepository getRepository(); public int getBranchID(); @@ -93,16 +99,17 @@ public interface CDOCheckout extends CDOExplorerElement, CDOTimeProvider { Root, Folder, File, Resource, Object; - public static ObjectType valueFor(Object rootObject) + public static ObjectType valueFor(Object object) { - if (rootObject instanceof CDOResourceFolder) + if (AdapterUtil.adapts(object, CDOResourceFolder.class)) { return ObjectType.Folder; } - if (rootObject instanceof CDOResource) + CDOResource resource = AdapterUtil.adapt(object, CDOResource.class); + if (resource != null) { - if (((CDOResource)rootObject).isRoot()) + if (resource.isRoot()) { return ObjectType.Root; } @@ -110,12 +117,12 @@ public interface CDOCheckout extends CDOExplorerElement, CDOTimeProvider return ObjectType.Resource; } - if (rootObject instanceof CDOFileResource) + if (AdapterUtil.adapts(object, CDOFileResource.class)) { return ObjectType.File; } - if (rootObject != null) + if (AdapterUtil.adapts(object, EObject.class)) { return ObjectType.Object; } diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepository.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepository.java index e5c198bc30..8ed522ce9d 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepository.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/explorer/repositories/CDORepository.java @@ -33,6 +33,12 @@ public interface CDORepository extends CDOExplorerElement, IContainer public static final String TYPE_LOCAL = "local"; + public boolean isRemote(); + + public boolean isClone(); + + public boolean isLocal(); + public String getConnectorType(); public String getConnectorDescription(); 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 b572991202..618496f3d9 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 @@ -395,11 +395,6 @@ public abstract class CDOCheckoutImpl extends AbstractElement implements CDOChec { return view; } - - if (adapter == EObject.class) - { - return rootObject; - } } return super.getAdapter(adapter); diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java index a01eb122bf..8af1be14c4 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OfflineCDOCheckout.java @@ -64,6 +64,16 @@ public class OfflineCDOCheckout extends CDOCheckoutImpl { } + public boolean isOffline() + { + return true; + } + + public boolean isOnline() + { + return false; + } + public final CDOWorkspace getWorkspace() { return workspace; diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OnlineCDOCheckout.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OnlineCDOCheckout.java index b7ad201f93..bdd3d5fbe8 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OnlineCDOCheckout.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/checkouts/OnlineCDOCheckout.java @@ -24,6 +24,16 @@ public class OnlineCDOCheckout extends CDOCheckoutImpl { } + public boolean isOffline() + { + return false; + } + + public boolean isOnline() + { + return true; + } + public final boolean isDirty() { return false; diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CloneCDORepository.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CloneCDORepository.java index 104749bf81..6e7a2ba9c4 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CloneCDORepository.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/CloneCDORepository.java @@ -71,6 +71,21 @@ public class CloneCDORepository extends CDORepositoryImpl { } + public boolean isRemote() + { + return false; + } + + public boolean isClone() + { + return true; + } + + public boolean isLocal() + { + return false; + } + public final String getConnectorType() { return "jvm"; diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/LocalCDORepository.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/LocalCDORepository.java index 7307be6288..34d30c94a0 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/LocalCDORepository.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/LocalCDORepository.java @@ -62,6 +62,21 @@ public class LocalCDORepository extends CDORepositoryImpl { } + public boolean isRemote() + { + return false; + } + + public boolean isClone() + { + return false; + } + + public boolean isLocal() + { + return true; + } + public final String getConnectorType() { return "jvm"; diff --git a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/RemoteCDORepository.java b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/RemoteCDORepository.java index 910c3b9bb7..322b608984 100644 --- a/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/RemoteCDORepository.java +++ b/plugins/org.eclipse.emf.cdo.explorer/src/org/eclipse/emf/cdo/internal/explorer/repositories/RemoteCDORepository.java @@ -30,6 +30,21 @@ public class RemoteCDORepository extends CDORepositoryImpl { } + public boolean isRemote() + { + return true; + } + + public boolean isClone() + { + return false; + } + + public boolean isLocal() + { + return false; + } + public final String getConnectorType() { return connectorType; diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/AdapterUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/AdapterUtil.java index 8a6636d088..363d7a2be8 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/AdapterUtil.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/AdapterUtil.java @@ -22,6 +22,14 @@ public final class AdapterUtil { } + /** + * @since 3.5 + */ + public static boolean adapts(Object object, Class type) + { + return adapt(object, type, true) != null; + } + public static TYPE adapt(Object object, Class type) { return adapt(object, type, true); diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HashBag.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HashBag.java index 87e15147e7..77f23f1b33 100644 --- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HashBag.java +++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/collection/HashBag.java @@ -21,7 +21,7 @@ import java.util.Set; */ public final class HashBag implements Set { - private Map map; + private Map map; public HashBag() { @@ -38,7 +38,7 @@ public final class HashBag implements Set map = new HashMap(initialCapacity); } - public HashBag(Map m) + public HashBag(Map m) { map = new HashMap(m); } @@ -67,7 +67,7 @@ public final class HashBag implements Set */ public boolean add(T o, int count) { - HashBag.Counter counter = map.get(o); + Counter counter = map.get(o); if (counter == null) { counter = new Counter(count); @@ -124,7 +124,7 @@ public final class HashBag implements Set */ public boolean remove(Object o, int count) { - HashBag.Counter counter = map.get(o); + Counter counter = map.get(o); if (counter == null) { return false; -- cgit v1.2.3