Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2013-03-05 17:15:31 +0000
committercletavernie2013-03-05 17:15:31 +0000
commit6fba62a50bf139c4584bba1dbca40ba307865d33 (patch)
tree888842f81a76457684d2908c7413ae648cf50c1f /plugins/views/modelexplorer
parent2b3f54be65436eb1edd5fe299ce6172ad23bb020 (diff)
downloadorg.eclipse.papyrus-6fba62a50bf139c4584bba1dbca40ba307865d33.tar.gz
org.eclipse.papyrus-6fba62a50bf139c4584bba1dbca40ba307865d33.tar.xz
org.eclipse.papyrus-6fba62a50bf139c4584bba1dbca40ba307865d33.zip
290952: [CDO] Support for CDO model repository
https://bugs.eclipse.org/bugs/show_bug.cgi?id=290952 Merged the cdo_kepler branch to the trunk (r9967 -> r10355)
Diffstat (limited to 'plugins/views/modelexplorer')
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/DecoratingLabelProviderWTooltips.java26
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java5
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractCommandHandler.java108
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java3
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java2
5 files changed, 93 insertions, 51 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/DecoratingLabelProviderWTooltips.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/DecoratingLabelProviderWTooltips.java
index 020ad9522ce..f24278ca987 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/DecoratingLabelProviderWTooltips.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/DecoratingLabelProviderWTooltips.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
+ * Copyright (c) 2010, 2013 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - don't rely on IMarker changes to refresh Model Explorer labels (CDO)
*
* History:
* Renamed from MoDiscoLabelProviderWTooltips - fix for bug 371905
@@ -17,10 +18,13 @@
package org.eclipse.papyrus.views.modelexplorer;
import java.util.List;
+import java.util.Observable;
+import java.util.Observer;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProviderChangedEvent;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.services.decoration.DecorationService;
@@ -34,7 +38,7 @@ import org.eclipse.ui.internal.navigator.NavigatorDecoratingLabelProvider;
/**
* A LabelProvider with support for decorations
*/
-public class DecoratingLabelProviderWTooltips extends NavigatorDecoratingLabelProvider {
+public class DecoratingLabelProviderWTooltips extends NavigatorDecoratingLabelProvider implements Observer {
private DecorationService decorationService;
@@ -42,12 +46,30 @@ public class DecoratingLabelProviderWTooltips extends NavigatorDecoratingLabelPr
super(labelProvider);
try {
this.decorationService = servicesRegistry.getService(DecorationService.class);
+ this.decorationService.addListener(this);
} catch (ServiceException ex) {
Activator.log.error(ex);
}
}
@Override
+ public void dispose() {
+ try {
+ if (decorationService != null) {
+ decorationService.deleteListener(this);
+ }
+ } finally {
+ super.dispose();
+ }
+ }
+
+ public void update(Observable o, Object arg) {
+ if ((decorationService != null) && (o == decorationService)) {
+ fireLabelProviderChanged(new LabelProviderChangedEvent(this));
+ }
+ }
+
+ @Override
public String getToolTipText(Object element) {
if(decorationService == null) {
return null;
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
index 8689ea97bb3..bb87ea9fa8e 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
@@ -1,5 +1,5 @@
/*****************************************************************************
-= * Copyright (c) 2010 CEA LIST.
+= * Copyright (c) 2010, 2013 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - post refreshes for transaction commit asynchronously (CDO)
*
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer;
@@ -455,7 +456,7 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
return;
}
lastTrans = curTrans;
- PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
/**
* {@inheritDoc}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractCommandHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractCommandHandler.java
index 69a87837902..5f02f0ed78e 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractCommandHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/AbstractCommandHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
+ * Copyright (c) 2010, 2013 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -11,25 +11,30 @@
*
* Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
* Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
+ * Christian W. Damus (CEA) - Refactoring package/profile import/apply UI for CDO
+ *
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer.handler;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtilsForActionHandlers;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForHandlers;
import org.eclipse.papyrus.views.modelexplorer.Activator;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
/**
* <pre>
@@ -44,6 +49,8 @@ import org.eclipse.ui.PlatformUI;
*/
public abstract class AbstractCommandHandler extends AbstractModelExplorerHandler {
+ private List<?> selection = Collections.EMPTY_LIST;
+
/**
* <pre>
*
@@ -56,6 +63,10 @@ public abstract class AbstractCommandHandler extends AbstractModelExplorerHandle
*/
protected abstract Command getCommand();
+ protected List<?> getSelection() {
+ return selection;
+ }
+
/**
* <pre>
* Get the selected element, the first selected element if several are selected or null
@@ -69,23 +80,19 @@ public abstract class AbstractCommandHandler extends AbstractModelExplorerHandle
EObject eObject = null;
// Get current selection
- IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- Object selection = (activeWorkbenchWindow != null) ? activeWorkbenchWindow.getSelectionService().getSelection() : null;
+ List<?> selection = getSelection();
// Treat non-null selected object (try to adapt and return EObject)
- if(selection != null) {
+ if (!selection.isEmpty()) {
// Get first element if the selection is an IStructuredSelection
- if(selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection)selection;
- selection = structuredSelection.getFirstElement();
- }
+ Object first = selection.get(0);
- if(selection instanceof IAdaptable) {
- selection = ((IAdaptable)selection).getAdapter(EObject.class);
+ if (first instanceof IAdaptable) {
+ first = ((IAdaptable)first).getAdapter(EObject.class);
}
- EObject businessObject = EMFHelper.getEObject(selection);
+ EObject businessObject = EMFHelper.getEObject(first);
if(businessObject != null) {
eObject = businessObject;
}
@@ -111,34 +118,18 @@ public abstract class AbstractCommandHandler extends AbstractModelExplorerHandle
List<EObject> selectedEObjects = new ArrayList<EObject>();
// Get current selection
- IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- Object selection = (activeWorkbenchWindow != null) ? activeWorkbenchWindow.getSelectionService().getSelection() : null;
+ Collection<?> selection = getSelection();
// Treat non-null selected object (try to adapt and return EObject)
- if(selection != null) {
+ if (!selection.isEmpty()) {
// Parse current selection
- if(selection instanceof IStructuredSelection) {
- IStructuredSelection structuredSelection = (IStructuredSelection)selection;
- for(Object current : structuredSelection.toArray()) {
- // Adapt current selection to EObject
- EObject selectedEObject = EMFHelper.getEObject(current);
- //we avoid to add null element in the list!
- if(selectedEObject != null) {
- selectedEObjects.add(selectedEObject);
- }
- }
- } else { // Not a IStructuredSelection
+ for (Object current : selection) {
// Adapt current selection to EObject
- EObject selectedElement = null;
- if(selection instanceof IAdaptable) {
- selectedElement = (EObject)((IAdaptable)selection).getAdapter(EObject.class);
- }
- if(selectedElement == null) {
- selectedElement = (EObject)Platform.getAdapterManager().getAdapter(selection, EObject.class);
- }
- if(selectedElement != null) { //we avoid to add null element in the list!
- selectedEObjects.add(selectedElement);
+ EObject selectedEObject = EMFHelper.getEObject(current);
+ if (selectedEObject != null) {
+ //we avoid to add null element in the list!
+ selectedEObjects.add(selectedEObject);
}
}
}
@@ -156,21 +147,48 @@ public abstract class AbstractCommandHandler extends AbstractModelExplorerHandle
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
- ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain().getCommandStack().execute(getCommand());
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ this.selection = (selection instanceof IStructuredSelection)
+ ? ((IStructuredSelection) selection).toList()
+ : Collections.EMPTY_LIST;
+
+ ServiceUtilsForHandlers.getInstance()
+ .getTransactionalEditingDomain(event).getCommandStack()
+ .execute(getCommand());
} catch (ServiceException e) {
Activator.log.error("Unexpected error while executing command.", e); //$NON-NLS-1$
+ } finally {
+ // clear the selection
+ this.selection = Collections.EMPTY_LIST;
}
return null;
}
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isEnabled() {
+ protected boolean computeEnabled() {
+ boolean result = false;
+
Command command = getCommand();
- return command != null && getCommand().canExecute();
+ if (command != null) {
+ result = getCommand().canExecute();
+ command.dispose();
+ }
+
+ return result;
}
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ if (evaluationContext instanceof IEvaluationContext) {
+ Object selection = ((IEvaluationContext) evaluationContext).getDefaultVariable();
+ if (selection instanceof Collection<?>) {
+ this.selection = (selection instanceof List<?>)
+ ? (List<?>) selection
+ : new java.util.ArrayList<Object>((Collection<?>) selection);
+ setBaseEnabled(computeEnabled());
+ this.selection = Collections.EMPTY_LIST;
+ }
+ }
+ super.setEnabled(evaluationContext);
+ }
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java
index 997f9056a5f..83961d6d626 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java
@@ -38,8 +38,9 @@ public class CutHandler extends AbstractCommandHandler {
List<EObject> selection = getSelectedElements();
return CutToClipboardCommand.create(getEditingDomain(), selection);
}
+
@Override
- public boolean isEnabled() {
+ protected boolean computeEnabled() {
//done explicitly inorder to desactivate it.
return false;
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java
index d658577dc31..3582d482420 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/DeleteCommandHandler.java
@@ -110,7 +110,7 @@ public class DeleteCommandHandler extends AbstractCommandHandler implements IHan
* {@inheritDoc}
*/
@Override
- public boolean isEnabled() {
+ protected boolean computeEnabled() {
//we need to test if selected element is not a meta-class
List<EObject> selectedElements = getSelectedElements();

Back to the top