Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime')
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/Messages.java2
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTEReferenceController.java206
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTPropertyEditorController.java57
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTStructuralFeatureController.java104
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/IBoundedValuesController.java19
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/IPropertyEditorController.java86
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/NullPropertyEditorController.java153
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/PropertyEditorController.java7
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/EMFTPropertyEditorControllerDescriptor.java3
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/NullPropertyEditorControllerDescriptor.java91
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/NullPropertyEditorControllerDescriptorFactory.java52
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/predefined/PredefinedControllerState.java3
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/messages.properties1
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/BooleanEMFModelHandler.java61
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFFeatureModelHandler.java787
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFStereotypeFeatureModelHandler.java75
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFUtils.java33
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EnumerationEMFModelHandler.java231
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EnumerationStereotypeModelHandler.java142
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/IEMFModelHandler.java119
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/ReferenceEMFModelHandler.java240
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/ReferenceStereotypeModelHandler.java13
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/StringEMFModelHandler.java268
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/StringStereotypeModelHandler.java152
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/TransactionUtil.java63
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/AbstractTablePropertyEditor.java497
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultiplePrimitiveTypedPropertyEditor.java100
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultiplePrimitiveTypedPropertyEditorValidator.java36
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultipleReferencePropertyEditor.java721
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultipleStructuralFeaturesPropertyEditor.java416
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/NullPropertyEditor.java100
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/NullPropertyEditorTypeValidator.java34
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/PropertyEditorService.java6
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/RadioBoxPropertyEditor.java7
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/descriptor/MultiplePrimitiveTypedPropertyEditorDescriptor.java53
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/descriptor/MultiplePrimitiveTypedPropertyEditorDescriptorFactory.java74
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/PropertyViewService.java6
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/ContainerDescriptor.java9
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/ExpandableContainerDescriptor.java2
-rw-r--r--plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/GroupContainerDescriptor.java2
40 files changed, 3942 insertions, 1089 deletions
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/Messages.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/Messages.java
index e43f544b846..2366c6d4d4b 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/Messages.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/Messages.java
@@ -27,6 +27,8 @@ public class Messages extends NLS {
/** Label for the Operation: Destroy operation */
public static String EMFTEReferenceController_DeleteElement_OperationLabel;
+ public static String ReferenceEMFModelHandler_Select_Values;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTEReferenceController.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTEReferenceController.java
index 96999237245..47c1a2f411d 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTEReferenceController.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTEReferenceController.java
@@ -31,10 +31,7 @@ import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
-import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelper;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
@@ -46,7 +43,8 @@ import org.eclipse.papyrus.core.utils.DisplayUtils;
import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.Messages;
import org.eclipse.papyrus.properties.runtime.modelhandler.emf.EMFFeatureModelHandler;
-import org.eclipse.papyrus.uml.service.creation.element.UMLTypeContext;
+import org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.service.edit.service.IElementEditService;
import org.eclipse.swt.widgets.Shell;
/**
@@ -227,27 +225,26 @@ public class EMFTEReferenceController extends EMFTStructuralFeatureController im
if(!(feature instanceof EReference)) {
return undoableOperations;
}
- IClientContext context;
+ //IClientContext context;
try {
- context = UMLTypeContext.getContext();
+ //context = UMLTypeContext.getContext();
+
+
// Use UML service creation context and look for element types that are possible types of
// the selected EReference
- IElementType[] featureTypes = ElementTypeRegistry.getInstance().getContainedTypes(eObject, (EReference)feature, context);
- if(featureTypes != null) {
- for(int i = 0; i < featureTypes.length; i++) {
- IElementType nextFeatureType = featureTypes[i];
-
- CreateElementRequest request = new CreateElementRequest(getEditingDomain(), eObject, nextFeatureType, (EReference)feature);
- request.setLabel(Messages.bind(Messages.EMFTEReferenceController_CreationOperationMenuLabel, nextFeatureType.getDisplayName()));
- ICommand command = nextFeatureType.getEditCommand(request);
- if(command.canExecute()) {
- // adds it to the list of command that can be
- // executed
- undoableOperations.add(command);
- }
+ List<IElementEditService> containedTypeServices = ElementEditServiceUtils.getEditServiceProvider().getContainedTypeEditServices(eObject, (EReference)feature);
+ for(IElementEditService service : containedTypeServices) {
+ CreateElementRequest request = new CreateElementRequest(getEditingDomain(), eObject, (IElementType)service.getAdapter(IElementType.class), (EReference)feature);
+ request.setLabel(Messages.bind(Messages.EMFTEReferenceController_CreationOperationMenuLabel, service.getDisplayName()));
+ ICommand command = service.getEditCommand(request);
+ if(command.canExecute()) {
+ // adds it to the list of command that can be
+ // executed
+ undoableOperations.add(command);
}
}
+
} catch (Exception e) {
Activator.log.error(e);
}
@@ -288,173 +285,18 @@ public class EMFTEReferenceController extends EMFTStructuralFeatureController im
return undoableOperation;
}
EObject eObject = getObjectsToEdit().get(0);
- IClientContext context;
- try {
- context = UMLTypeContext.getContext();
- IElementType type = ElementTypeRegistry.getInstance().getElementType(eObject, context);
- IEditHelper helper = type.getEditHelper();
- for(Object objectToDelete : objectsToDelete) {
- if(objectToDelete instanceof EObject) {
- DestroyElementRequest request = new DestroyElementRequest(getEditingDomain(), (EObject)objectToDelete, false);
- IUndoableOperation operation = helper.getEditCommand(request);
- if(operation != null && operation.canExecute()) {
- undoableOperation.add(operation);
- }
- } else {
- Activator.log.debug("the object to delete was not an EObject: " + objectToDelete);
- }
- }
- } catch (Exception e) {
- Activator.log.error(e);
- }
- return undoableOperation.reduce();
- }
-
- /**
- * {@inheritDoc}
- */
- public IUndoableOperation getMoveCurrentValuesOperation(List<Object> objects, int move) {
- IUndoableOperation undoableOperation = null;
- EClass eClass = retrieveEClass();
- if(eClass == null || getObjectsToEdit() == null || getObjectsToEdit().size() == 0 || !(getModelHandler() instanceof EMFFeatureModelHandler)) {
- return undoableOperation;
- }
- EObject eObject = getObjectsToEdit().get(0);
- // retrieve the current value (should be a list)
- EStructuralFeature feature = ((EMFFeatureModelHandler)getModelHandler()).getFeatureByName(eObject);
- Object currentValue = eObject.eGet(feature);
- if(currentValue instanceof List<?>) {
- @SuppressWarnings("unchecked")
- List<EObject> values = (List<EObject>)currentValue;
- List<EObject> copy = new ArrayList<EObject>(values);
- // make modification in copy list
- // check indices
- int min = copy.size();
- int max = 0;
-
- for(Object object : objects) {
- int index = copy.indexOf(object);
- if(index == -1) {
- Activator.log.debug("Impossible to find the index for object :" + object);
- }
- if(index < min) {
- min = index;
- }
- if(index > max) {
- max = index;
- }
- }
-
- // check that min and max are in the bounds of the list, with the
- // delta applied
- min += move;
- max += move;
- // check the bounds of the list
- if(min < 0) {
- Activator.log.debug("Trying to move up the elements, with a move which will cause an IndexOutOfBound exception");
- return undoableOperation;
- } else if(max >= copy.size()) {
- Activator.log.debug("Trying to move down the elements, with a move which will cause an IndexOutOfBound exception");
- return undoableOperation;
- }
-
- // now, do the move in the copy
- if(move < 0) {
- moveUpElementsInCollection(copy, objects, move);
- } else {
- moveDownElementsOperation(copy, objects, move);
- }
-
- // now, apply the new value
- IClientContext context;
- try {
- context = UMLTypeContext.getContext();
- IElementType type = ElementTypeRegistry.getInstance().getElementType(eObject, context);
- IEditHelper helper = type.getEditHelper();
-
- SetRequest request = new SetRequest(getEditingDomain(), eObject, feature, copy);
- IUndoableOperation operation = helper.getEditCommand(request);
+ for(Object objectToDelete : objectsToDelete) {
+ if(objectToDelete instanceof EObject) {
+ DestroyElementRequest request = new DestroyElementRequest(getEditingDomain(), (EObject)objectToDelete, false);
+ IUndoableOperation operation = ElementEditServiceUtils.getCommandProvider(objectToDelete).getEditCommand(request);
if(operation != null && operation.canExecute()) {
- undoableOperation = operation;
+ undoableOperation.add(operation);
}
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
-
- return undoableOperation;
- }
-
- /**
- * Moves the element in the specified list, when the elements are moved down
- * in the list
- *
- * @param modifiedElements
- * list of elements modified
- * @param objectsToMove
- * list of objects to move
- * @param move
- * delta for the move. should be positive integer
- */
- protected void moveDownElementsOperation(List<EObject> modifiedElements, List<Object> objectsToMove, int move) {
- // if moving down, starting from the end to move elements, assuming they
- // are in the increasing order by default
- Collections.reverse(objectsToMove);
- for(Object objectToMove : objectsToMove) {
- // retrieve index
- int index = modifiedElements.indexOf(objectToMove);
- // remove element
- modifiedElements.remove(index);
- // change index
- if(index == -1) {
- return;
- }
- index += move;
- // add the element to the new index
- modifiedElements.add(index, (EObject)objectToMove);
- }
- }
-
- /**
- * Moves the element in the specified list, when the elements are moved up
- * in the list
- *
- * @param modifiedElements
- * list of elements modified
- * @param objectsToMove
- * list of objects to move
- * @param move
- * delta for the move. should be positive integer
- */
- protected void moveUpElementsInCollection(List<EObject> modifiedElements, List<Object> objectsToMove, int move) {
- for(Object objectToMove : objectsToMove) {
- // retrieve index
- int index = modifiedElements.indexOf(objectToMove);
- // remove element
- modifiedElements.remove(index);
- // change index
- if(index == -1) {
- return;
+ } else {
+ Activator.log.debug("the object to delete was not an EObject: " + objectToDelete);
}
- index += move;
- // add the element to the new index
- modifiedElements.add(index, (EObject)objectToMove);
}
- }
- /**
- * {@inheritDoc}
- */
- public boolean canMoveValues() {
- EClass eClass = retrieveEClass();
- if(eClass == null || getObjectsToEdit() == null || getObjectsToEdit().size() == 0 || !(getModelHandler() instanceof EMFFeatureModelHandler)) {
- return false;
- }
- EObject eObject = getObjectsToEdit().get(0);
- EStructuralFeature feature = ((EMFFeatureModelHandler)getModelHandler()).getFeatureByName(eObject);
- if(feature == null) {
- return false;
- }
- return feature.isOrdered();
+ return undoableOperation.reduce();
}
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTPropertyEditorController.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTPropertyEditorController.java
index b802eaa091e..af859ac57e3 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTPropertyEditorController.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTPropertyEditorController.java
@@ -8,6 +8,7 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.controller;
@@ -18,9 +19,15 @@ import org.eclipse.core.commands.operations.OperationHistoryFactory;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.properties.runtime.modelhandler.emf.IEMFModelHandler;
+import org.eclipse.papyrus.properties.runtime.modelhandler.emf.TransactionUtil;
/**
@@ -29,9 +36,12 @@ import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCo
*/
public abstract class EMFTPropertyEditorController extends EMFPropertyEditorController {
- /** Transactional editing domain used to wirte into the model */
+ /** Transactional editing domain used to write into the model */
private TransactionalEditingDomain editingDomain;
+ /** model handler to interact with the model for this controller */
+ protected IEMFModelHandler modelHandler;
+
/**
* Constructor.
*/
@@ -40,12 +50,51 @@ public abstract class EMFTPropertyEditorController extends EMFPropertyEditorCont
}
/**
- * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.properties.runtime.controller.PropertyEditorController#updateModel()
+ *
*/
@Override
public void updateModel() {
+ CompositeCommand cc = new CompositeCommand("Set Value Command"); //$NON-NLS-1$
+ Object valueToSet = getEditorValue();
+ for(Object obj : this.objectToEdit) {
+ EObject elementToEdit = (EObject)obj;
+ //build the request
+ SetRequest[] req = null;
+ req = modelHandler.getSetRequest(getEditingDomain(), elementToEdit, valueToSet);
+ if(req == null) {
+ break;
+ }
+ org.eclipse.papyrus.service.edit.service.IElementEditService provider = org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils.getCommandProvider(elementToEdit);
+ if(provider != null) {
+
+ ICommand editCommand = null;
+ for(SetRequest current : req) {
+ editCommand = provider.getEditCommand(current);
+
+ if(editCommand != null && editCommand.canExecute()) {
+ cc.add(editCommand);
+ }
+ }
+ }
+
+ if(cc.canExecute() && !(TransactionUtil.isReadTransactionInProgress(getEditingDomain(), true, true))) {
+ try {
+ OperationHistoryFactory.getOperationHistory().execute(cc, new NullProgressMonitor(), null);
+ } catch (ExecutionException e) {
+ log.error(e);
+ }
+ return;
+ }
+ }
+
+ /*
+ * req was null, or the command was unexecutable
+ * Currently, the handler for stereotype return always null!
+ */
AbstractTransactionalCommand command = new EMFTControllerCommand();
- if(command.canExecute()) {
+ if(command.canExecute() && !(TransactionUtil.isReadTransactionInProgress(editingDomain, true, true))) {
try {
OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
} catch (ExecutionException e) {
@@ -82,7 +131,7 @@ public abstract class EMFTPropertyEditorController extends EMFPropertyEditorCont
* Creates the new EMFTControllerCommand.
*/
public EMFTControllerCommand() {
- super(editingDomain, "Editing Property", getWorkspaceFiles(getObjectsToEdit()));
+ super(editingDomain, "Editing Property", getWorkspaceFiles(getObjectsToEdit())); //$NON-NLS-1$
}
/**
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTStructuralFeatureController.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTStructuralFeatureController.java
index 7c970af4d1b..e7fd1dc0e83 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTStructuralFeatureController.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/EMFTStructuralFeatureController.java
@@ -8,25 +8,26 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.controller;
-import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.papyrus.core.utils.EditorUtils;
import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.controller.descriptor.EMFTPropertyEditorControllerDescriptor;
import org.eclipse.papyrus.properties.runtime.controller.descriptor.IPropertyEditorControllerDescriptor;
import org.eclipse.papyrus.properties.runtime.controller.predefined.PredefinedControllerDescriptor;
+import org.eclipse.papyrus.properties.runtime.modelhandler.emf.EMFUtils;
import org.eclipse.papyrus.properties.runtime.modelhandler.emf.IEMFModelHandler;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
import org.eclipse.swt.widgets.Composite;
@@ -41,10 +42,7 @@ public class EMFTStructuralFeatureController extends EMFTPropertyEditorControlle
private EMFTPropertyEditorControllerDescriptor descriptor;
/** identifier of the controller */
- public final static String ID = "emftStructuralFeatureController";
-
- /** model handler to interact with the model for this controller */
- protected IEMFModelHandler modelHandler;
+ public final static String ID = "emftStructuralFeatureController"; //$NON-NLS-1$
/**
* Creates a new EMFTStructuralFeatureController.
@@ -63,6 +61,7 @@ public class EMFTStructuralFeatureController extends EMFTPropertyEditorControlle
* @param descriptor
* the descriptor that realize specific configuration for this controller
*/
+ @Override
public IStatus initController(Composite parent, List<Object> objectsToEdit, IPropertyEditorControllerDescriptor descriptor) {
setParent(parent);
IPropertyEditorControllerDescriptor realDescriptor = descriptor;
@@ -75,27 +74,15 @@ public class EMFTStructuralFeatureController extends EMFTPropertyEditorControlle
if(realDescriptor instanceof EMFTPropertyEditorControllerDescriptor) {
this.descriptor = (EMFTPropertyEditorControllerDescriptor)realDescriptor;
} else {
- return new Status(IStatus.ERROR, Activator.ID, "impossible to adapt descriptor to an EMFTPropertyEditorControllerDescriptor");
+ return new Status(IStatus.ERROR, Activator.ID, "impossible to adapt descriptor to an EMFTPropertyEditorControllerDescriptor"); //$NON-NLS-1$
}
this.modelHandler = this.descriptor.getHandler();
setObjectsToEdit(objectsToEdit);
-
-
- TransactionalEditingDomain editingDomain = null;
- Iterator<Object> it2 = objectsToEdit.iterator();
- while(it2.hasNext() && editingDomain == null) {
- editingDomain = TransactionUtil.getEditingDomain(it2.next());
- }
-
- // if impossible to find editing domain this way: Tries the Papyrus service
- if(editingDomain == null) {
- editingDomain = EditorUtils.getTransactionalEditingDomain();
- }
-
+ TransactionalEditingDomain editingDomain = EMFUtils.getTransactionalEditingDomain(objectsToEdit);
if(editingDomain == null && !objectsToEdit.isEmpty()) {
- return new Status(IStatus.ERROR, Activator.ID, "impossible to find an editing domain for the controller.");
+ return new Status(IStatus.ERROR, Activator.ID, "impossible to find an editing domain for the controller."); //$NON-NLS-1$
}
setEditingDomain(editingDomain);
return Status.OK_STATUS;
@@ -224,4 +211,77 @@ public class EMFTStructuralFeatureController extends EMFTPropertyEditorControlle
// nothing to do here, as the adapter already knows the target
}
+ /**
+ * {@inheritDoc}
+ */
+ public IUndoableOperation getMoveCurrentValuesOperation(List<Integer> indexes, int delta) {
+ return getModelHandler().getMoveValueOperation(getObjectsToEdit(), indexes, getComposite(), delta);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canMoveValues(List<Integer> indexes, int delta) {
+ return getModelHandler().canCreateMoveValueOperation(getObjectsToEdit(), indexes, getComposite(), delta);
+ }
+
+ /**
+ * Retrieves the common metaclass for all selected objects
+ *
+ * @return the selected metaclass
+ *
+ */
+ protected EClass retrieveEClass() {
+ @SuppressWarnings("unchecked")
+ List<EObject> eObjects = (List<EObject>)getObjectsToEdit();
+ if(eObjects == null) {
+ return null;
+ } else if(eObjects.size() > 0) {
+ return eObjects.get(0).eClass();
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<IUndoableOperation> getCreateValueOperations() {
+ return getModelHandler().getCreateValueOperations(getObjectsToEdit(), getComposite());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreateValueOperations() {
+ return getModelHandler().canCreateValueOperations(getObjectsToEdit());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IUndoableOperation getDeleteValueOperation(List<Integer> indexes) {
+ return getModelHandler().getDeleteValueOperation(getObjectsToEdit(), getComposite(), indexes);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canDeleteValueOperation() {
+ return getModelHandler().canCreateDeleteValueOperation(getObjectsToEdit());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IUndoableOperation getEditValueOperation(int index, Composite parent, Object value) {
+ return getModelHandler().getEditValueOperation(getObjectsToEdit(), index, parent, value);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreateEditOperation(int index, Composite parent, Object value) {
+ return true;
+ }
+
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/IBoundedValuesController.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/IBoundedValuesController.java
index cc52a3a39bf..03e2376522a 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/IBoundedValuesController.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/IBoundedValuesController.java
@@ -13,7 +13,6 @@ package org.eclipse.papyrus.properties.runtime.controller;
import java.util.List;
-import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ViewerFilter;
@@ -33,24 +32,6 @@ public interface IBoundedValuesController extends ILabelProviderController {
public Object getAvailableValues();
/**
- * Moves the given list of Objects in the list
- *
- * @param objects
- * the list of objects to move
- * @param move
- * the delta for the index (0: stays at the same place, -1: everything move upper, +2: everything moves 2 index further)
- * @return the operation that moves the elements or <code>null</code>
- */
- public IUndoableOperation getMoveCurrentValuesOperation(List<Object> objects, int move);
-
- /**
- * Indicates if the values can be moved in the feature
- *
- * @return <code>true</code> if the values can be moved, else <code>false</code>
- */
- public boolean canMoveValues();
-
- /**
* Returns the list of current values
*
* @return the list of current values
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/IPropertyEditorController.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/IPropertyEditorController.java
index 11a55052f53..10c91bce6e8 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/IPropertyEditorController.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/IPropertyEditorController.java
@@ -13,10 +13,12 @@ package org.eclipse.papyrus.properties.runtime.controller;
import java.util.List;
+import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.papyrus.properties.runtime.controller.descriptor.IPropertyEditorControllerDescriptor;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
/**
@@ -60,8 +62,10 @@ public interface IPropertyEditorController {
*
* @param descriptor
* the image descriptor for the property editor
+ * @param widgetFactory
+ * widget factory used to create the content of the editor
*/
- public void createPropertyEditor(IPropertyEditorDescriptor descriptor);
+ public void createPropertyEditor(IPropertyEditorDescriptor descriptor, TabbedPropertySheetWidgetFactory widgetFactory);
/**
* Initialize the controller.
@@ -81,4 +85,84 @@ public interface IPropertyEditorController {
*/
public void refreshDisplay();
+ /**
+ * Moves the given list of Objects in the list
+ *
+ * @param indexes
+ * the indexes of objects to move
+ * @param move
+ * the delta for the index (0: stays at the same place, -1: everything move upper, +2: everything moves 2 index further)
+ * @return the operation that moves the elements or <code>null</code>
+ */
+ public IUndoableOperation getMoveCurrentValuesOperation(List<Integer> indexes, int move);
+
+ /**
+ * Indicates if the values can be moved in the feature
+ *
+ * @param indexes
+ * the indexes of objects to move
+ * @param move
+ * the delta for the index (0: stays at the same place, -1: everything move upper, +2: everything moves 2 index further)
+ * @return <code>true</code> if the values can be moved, else <code>false</code>
+ */
+ public boolean canMoveValues(List<Integer> indexes, int move);
+
+ /**
+ * Returns the operation to create a new value for this property
+ *
+ * @return the operation to create a new value for this property
+ */
+ public List<IUndoableOperation> getCreateValueOperations();
+
+ /**
+ * Returns <code>true</code> if the controller can create a new value for the property
+ *
+ * @return <code>true</code> if the controller can create a new value for the property
+ */
+ public boolean canCreateValueOperations();
+
+ /**
+ * Returns the operation to delete a value for this property
+ *
+ * @param indexes
+ * list of indexes for values to delete (not used in case of single valued proeprty)
+ * @return the operation to delete a value for this property
+ */
+ public IUndoableOperation getDeleteValueOperation(List<Integer> indexes);
+
+ /**
+ * Returns <code>true</code> if the controller can delete a value for the property
+ *
+ * @return <code>true</code> if the controller can delete a value for the property
+ */
+ public boolean canDeleteValueOperation();
+
+ /**
+ * Returns the operation to edit a value for this property
+ *
+ * @param index
+ * the index of the value to set
+ * @param parent
+ * the composite parent used for user interface
+ * @param value
+ * the value to set
+ *
+ * @return the operation to edit a value for this property
+ */
+ public IUndoableOperation getEditValueOperation(int index, Composite parent, Object value);
+
+ /**
+ * Returns <code>true</code> if the controller can edit a value for the property
+ *
+ * @param index
+ * the index of the value to set
+ * @param parent
+ * the composite parent used for user interface
+ * @param value
+ * the value to set
+ *
+ * @return <code>true</code> if the controller can edit a value for the property
+ */
+ public boolean canCreateEditOperation(int index, Composite parent, Object value);
+
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/NullPropertyEditorController.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/NullPropertyEditorController.java
new file mode 100644
index 00000000000..89a24d8111a
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/NullPropertyEditorController.java
@@ -0,0 +1,153 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.controller;
+
+import java.util.List;
+
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.papyrus.properties.runtime.controller.descriptor.IPropertyEditorControllerDescriptor;
+import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * Controller for Empty property editors, i.e. editors that are a simple Composite
+ */
+public class NullPropertyEditorController extends PropertyEditorController {
+
+ /** id of this controller */
+ public static final String ID = "nullPropertyEditorController";
+
+ /**
+ * {@inheritDoc}
+ */
+ public IUndoableOperation getMoveCurrentValuesOperation(List<Integer> indexes, int move) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canMoveValues(List<Integer> indexes, int move) {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<IUndoableOperation> getCreateValueOperations() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreateValueOperations() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IUndoableOperation getDeleteValueOperation(List<Integer> indexes) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canDeleteValueOperation() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IUndoableOperation getEditValueOperation(int index, Composite parent, Object value) {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreateEditOperation(int index, Composite parent, Object value) {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getDefaultLabel() {
+ return "";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected IStatus initPropertyEditor(IPropertyEditorDescriptor descriptor) {
+ return getPropertyEditor().init(descriptor);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IStatus initController(Composite parent, List<Object> objectsToEdit, IPropertyEditorControllerDescriptor descriptor) {
+ setParent(parent);
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setValueInModel(Object value) {
+ // Nothing to do
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object getValueToEdit() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void addListenersToModel() {
+ // Nothing to do
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void removeListenersFromModel() {
+ // Nothing to do
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void updateModel() {
+ // Nothing to do
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/PropertyEditorController.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/PropertyEditorController.java
index 843ea9d7d7a..372bad0d326 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/PropertyEditorController.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/PropertyEditorController.java
@@ -21,6 +21,7 @@ import org.eclipse.papyrus.properties.runtime.propertyeditor.PropertyEditorServi
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.services.IDisposable;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
/**
@@ -116,9 +117,11 @@ public abstract class PropertyEditorController implements IDisposable, IProperty
/**
* {@inheritDoc}
+ *
+ * @param widgetFactory
*/
- public void createPropertyEditor(IPropertyEditorDescriptor descriptor) {
- setPropertyEditor(PropertyEditorService.getInstance().createPropertyEditor(this, descriptor.getEditorId()));
+ public void createPropertyEditor(IPropertyEditorDescriptor descriptor, TabbedPropertySheetWidgetFactory widgetFactory) {
+ setPropertyEditor(PropertyEditorService.getInstance().createPropertyEditor(this, descriptor.getEditorId(), widgetFactory));
IStatus status = initPropertyEditor(descriptor);
if(IStatus.ERROR != status.getSeverity()) {
getPropertyEditor().createContent(getComposite());
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/EMFTPropertyEditorControllerDescriptor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/EMFTPropertyEditorControllerDescriptor.java
index 136631017fd..858fe8b4e2b 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/EMFTPropertyEditorControllerDescriptor.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/EMFTPropertyEditorControllerDescriptor.java
@@ -26,6 +26,7 @@ import org.eclipse.papyrus.properties.runtime.state.IState;
import org.eclipse.papyrus.properties.runtime.state.ITraversableModelElement;
import org.eclipse.papyrus.properties.runtime.view.constraints.IConstraintDescriptor;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -329,7 +330,7 @@ public class EMFTPropertyEditorControllerDescriptor implements IPropertyEditorCo
if(controller != null) {
// use the state to create this
- controller.createPropertyEditor(this.getDescriptor().getEditorDescriptor());
+ controller.createPropertyEditor(this.getDescriptor().getEditorDescriptor(), new TabbedPropertySheetWidgetFactory());
}
}
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/NullPropertyEditorControllerDescriptor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/NullPropertyEditorControllerDescriptor.java
new file mode 100644
index 00000000000..9d50b6b9f78
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/NullPropertyEditorControllerDescriptor.java
@@ -0,0 +1,91 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.controller.descriptor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.papyrus.properties.runtime.controller.NullPropertyEditorController;
+import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
+import org.eclipse.papyrus.properties.runtime.view.constraints.IConstraintDescriptor;
+import org.eclipse.swt.graphics.Image;
+
+
+/**
+ * Descriptor for {@link NullPropertyEditorController}
+ */
+public class NullPropertyEditorControllerDescriptor implements IPropertyEditorControllerDescriptor {
+
+ /** editor descriptor */
+ protected final IPropertyEditorDescriptor editorDescriptor;
+
+
+ /**
+ * Creates a new NullPropertyEditorControllerDescriptor.
+ *
+ * @param editorDescriptor
+ * the descriptor of the editor controller
+ */
+ public NullPropertyEditorControllerDescriptor(IPropertyEditorDescriptor editorDescriptor) {
+ this.editorDescriptor = editorDescriptor;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getText() {
+ return "NullController";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Image getImage() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean acceptMultiSelection() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getControllerID() {
+ return NullPropertyEditorController.ID;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IPropertyEditorDescriptor getEditorDescriptor() {
+ return editorDescriptor;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<IConstraintDescriptor> getConstraintDescriptors() {
+ return new ArrayList<IConstraintDescriptor>();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ControllerDescriptorState createState(boolean readOnly) {
+ return new ControllerDescriptorState(this, readOnly);
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/NullPropertyEditorControllerDescriptorFactory.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/NullPropertyEditorControllerDescriptorFactory.java
new file mode 100644
index 00000000000..8ce934a2474
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/descriptor/NullPropertyEditorControllerDescriptorFactory.java
@@ -0,0 +1,52 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.controller.descriptor;
+
+import org.eclipse.papyrus.properties.runtime.controller.NullPropertyEditorController;
+import org.eclipse.papyrus.properties.runtime.propertyeditor.PropertyEditorService;
+import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
+import org.osgi.framework.Bundle;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * Factory for {@link NullPropertyEditorController}.
+ */
+public class NullPropertyEditorControllerDescriptorFactory implements IPropertyEditorControllerDescriptorFactory {
+
+ /**
+ * {@inheritDoc}
+ */
+ public IPropertyEditorControllerDescriptor createDescriptor(Node controllerNode, Bundle bundle) {
+ // parse content of the node
+
+ IPropertyEditorDescriptor editorDescriptor = null;
+ NodeList children = controllerNode.getChildNodes();
+ for(int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if("editor".equals(child.getNodeName())) {
+ // retrieve editor id
+ if(child.hasAttributes()) {
+ Node editorIDNode = child.getAttributes().getNamedItem("id");
+ editorDescriptor = PropertyEditorService.getInstance().createPropertyEditorDescriptor(editorIDNode.getNodeValue(), child);
+ }
+
+ }
+ }
+
+ assert (editorDescriptor != null) : "impossible to create editor descriptor";
+
+ return new NullPropertyEditorControllerDescriptor(editorDescriptor);
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/predefined/PredefinedControllerState.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/predefined/PredefinedControllerState.java
index 1dd942d3624..24e131fa662 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/predefined/PredefinedControllerState.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/controller/predefined/PredefinedControllerState.java
@@ -19,6 +19,7 @@ import org.eclipse.papyrus.properties.runtime.controller.PropertyEditorControlle
import org.eclipse.papyrus.properties.runtime.controller.PropertyEditorControllerService;
import org.eclipse.papyrus.properties.runtime.controller.descriptor.ControllerDescriptorState;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -124,7 +125,7 @@ public class PredefinedControllerState extends ControllerDescriptorState {
if(controller != null) {
// use the state to create this
- controller.createPropertyEditor(this.getDescriptor().getEditorDescriptor());
+ controller.createPropertyEditor(this.getDescriptor().getEditorDescriptor(), new TabbedPropertySheetWidgetFactory());
}
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/messages.properties b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/messages.properties
index 3a890d0f76e..9a93214aa9f 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/messages.properties
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/messages.properties
@@ -1,2 +1,3 @@
EMFTEReferenceController_CreationOperationMenuLabel=Create a new {0}
EMFTEReferenceController_DeleteElement_OperationLabel=Delete elements
+ReferenceEMFModelHandler_Select_Values=Select Values
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/BooleanEMFModelHandler.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/BooleanEMFModelHandler.java
index 745a4c5c7c1..bc73a83321a 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/BooleanEMFModelHandler.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/BooleanEMFModelHandler.java
@@ -8,6 +8,7 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
@@ -16,6 +17,8 @@ import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IBoundedValuesPropertyEditorDescriptor;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
@@ -26,7 +29,7 @@ import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropert
public class BooleanEMFModelHandler extends EnumerationEMFModelHandler {
/** id of this model handler */
- public static final String ID = "Boolean";
+ public static final String ID = "Boolean"; //$NON-NLS-1$
/**
* Creates a new BooleanEMFModelHandler.
@@ -56,6 +59,7 @@ public class BooleanEMFModelHandler extends EnumerationEMFModelHandler {
/**
* {@inheritDoc}
*/
+ @SuppressWarnings("unchecked")
@Override
public void setValueInModel(EObject objectToEdit, Object newValue) {
EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
@@ -63,12 +67,22 @@ public class BooleanEMFModelHandler extends EnumerationEMFModelHandler {
return;
}
// remove value if result of the editor is empty
- if(newValue == null || newValue.equals("")) {
+ if(newValue == null || newValue.equals("")) { //$NON-NLS-1$
objectToEdit.eUnset(featureToEdit);
} else if(newValue instanceof String) {
objectToEdit.eSet(featureToEdit, Boolean.parseBoolean((String)newValue));
} else if(newValue instanceof Boolean) {
- objectToEdit.eSet(featureToEdit, (Boolean)newValue);
+ objectToEdit.eSet(featureToEdit, newValue);
+ } else if(newValue instanceof List<?>) {
+ List<Object> newValues = new ArrayList<Object>();
+ for(Object value : (List<Object>)newValue) {
+ if(value instanceof String) {
+ newValues.add(Boolean.parseBoolean((String)value));
+ } else if(value instanceof Boolean) {
+ newValues.add(value);
+ }
+ }
+ objectToEdit.eSet(featureToEdit, newValues);
}
}
@@ -89,23 +103,56 @@ public class BooleanEMFModelHandler extends EnumerationEMFModelHandler {
// check if there is an empty string at the beginning. there is one if the lower bound of the feature to edit equal 0
if(featureToEdit.getLowerBound() == 0) {
- values.add("");
+ values.add(""); //$NON-NLS-1$
}
- values.add("true");
- values.add("false");
+ values.add("true"); //$NON-NLS-1$
+ values.add("false"); //$NON-NLS-1$
if(descriptor instanceof IBoundedValuesPropertyEditorDescriptor) {
((IBoundedValuesPropertyEditorDescriptor)descriptor).setAvailableValues(values);
} else {
- Activator.log.error("Warning: " + descriptor + "could not be completed.", null);
+ Activator.log.debug("Warning: " + descriptor + "could not be completed."); //$NON-NLS-1$ //$NON-NLS-2$
}
}
/**
* {@inheritDoc}
*/
+ @Override
public String getId() {
return ID;
}
+ /**
+ *
+ * @param objectToEdit
+ * @param newValue
+ * @return
+ */
+ @Override
+ public SetRequest[] getSetRequest(TransactionalEditingDomain domain, EObject objectToEdit, Object newValue) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ // remove value if result of the editor is empty
+ if(newValue == null || newValue.equals("")) { //$NON-NLS-1$
+ return new SetRequest[]{ new SetRequest(domain, objectToEdit, featureToEdit, featureToEdit.getDefaultValue()) };
+ } else if(newValue instanceof String) {
+ return new SetRequest[]{ new SetRequest(domain, objectToEdit, featureToEdit, Boolean.parseBoolean((String)newValue)) };
+ } else if(newValue instanceof Boolean) {
+ return new SetRequest[]{ new SetRequest(domain, objectToEdit, featureToEdit, newValue) };
+ } else if(newValue instanceof List<?>) {
+ List<Object> newValues = new ArrayList<Object>();
+ for(Object value : (List<?>)newValue) {
+ if(value instanceof String) {
+ newValues.add(Boolean.parseBoolean((String)value));
+ } else if(value instanceof Boolean) {
+ newValues.add(value);
+ }
+ }
+ return new SetRequest[]{ new SetRequest(domain, objectToEdit, featureToEdit, newValues) };
+ }
+ return null;
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFFeatureModelHandler.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFFeatureModelHandler.java
index 1fccb65f77d..853da8ae2d2 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFFeatureModelHandler.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFFeatureModelHandler.java
@@ -8,24 +8,34 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.impl.BasicEObjectImpl;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.controller.EMFPropertyEditorController;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
/**
@@ -39,6 +49,12 @@ public abstract class EMFFeatureModelHandler implements IEMFModelHandler {
/** factory used by EMF objects */
protected AdapterFactory factory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+ /** value of unset new value index */
+ public static final int NEW_VALUE_NOT_SET_INDEX = -2;
+
+ /** value of single value property */
+ public static final int SINGLE_VALUE_PROPERTY_INDEX = -1;
+
/**
* Creates a new EMFFeatureModelHandler.
*
@@ -110,14 +126,14 @@ public abstract class EMFFeatureModelHandler implements IEMFModelHandler {
* {@inheritDoc}
*/
public String getText() {
- return "EMF Handler \"" + getId() + "\" -> " + getFeatureName();
+ return "EMF Handler \"" + getId() + "\" -> " + getFeatureName(); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
* {@inheritDoc}
*/
public Image getImage() {
- return Activator.getImage("/icons/ModelHandler.gif");
+ return Activator.getImage("/icons/ModelHandler.gif"); //$NON-NLS-1$
}
/**
@@ -133,23 +149,23 @@ public abstract class EMFFeatureModelHandler implements IEMFModelHandler {
public Object getAvailableValues(EObject eObject) {
EClass eClass = eObject.eClass();
if(eClass == null) {
- Activator.log.debug("problems during initialization, looking for availables values");
+ Activator.log.debug("problems during initialization, looking for availables values"); //$NON-NLS-1$
return null;
}
EStructuralFeature feature = getFeatureByName(eObject);
if(!(feature instanceof EReference)) {
- Activator.log.debug("feature is not a reference, looking for availables values: " + feature);
+ Activator.log.debug("feature is not a reference, looking for availables values: " + feature); //$NON-NLS-1$
return null;
}
IItemPropertySource itemPropertySource = (IItemPropertySource)factory.adapt(eObject, IItemPropertySource.class);
if(itemPropertySource == null) {
- Activator.log.debug("impossible to find item Property source for " + eObject);
+ Activator.log.debug("impossible to find item Property source for " + eObject); //$NON-NLS-1$
return null;
}
IItemPropertyDescriptor itemPropertyDescriptor = itemPropertySource.getPropertyDescriptor(eObject, feature);
if(itemPropertyDescriptor == null) {
- Activator.log.debug("impossible to find item Property descriptor for " + eObject + " and " + feature);
+ Activator.log.debug("impossible to find item Property descriptor for " + eObject + " and " + feature); //$NON-NLS-1$ //$NON-NLS-2$
return null;
}
return itemPropertyDescriptor.getChoiceOfValues(eObject);
@@ -170,7 +186,10 @@ public abstract class EMFFeatureModelHandler implements IEMFModelHandler {
for(EObject eObject : objects) {
EStructuralFeature feature = getFeatureByName(eObject);
if(notificationFeature.equals(feature)) {
- ((EObject)notification.getNewValue()).eAdapters().add(adapter);
+ Object newValue = notification.getNewValue();
+ if(newValue instanceof EObject) {
+ ((EObject)newValue).eAdapters().add(adapter);
+ }
// refresh the editors
adapter.refreshDisplay();
}
@@ -181,8 +200,10 @@ public abstract class EMFFeatureModelHandler implements IEMFModelHandler {
for(EObject eObject : objects) {
EStructuralFeature feature = getFeatureByName(eObject);
if(notificationFeature.equals(feature)) {
- for(EObject newValue : ((List<EObject>)notification.getNewValue())) {
- newValue.eAdapters().add(adapter);
+ for(Object newValue : ((List<Object>)notification.getNewValue())) {
+ if(newValue instanceof EObject) {
+ ((EObject)newValue).eAdapters().add(adapter);
+ }
}
// refresh the editors
adapter.refreshDisplay();
@@ -195,7 +216,11 @@ public abstract class EMFFeatureModelHandler implements IEMFModelHandler {
for(EObject eObject : objects) {
EStructuralFeature feature = getFeatureByName(eObject);
if(notificationFeature.equals(feature)) {
- ((EObject)notification.getOldValue()).eAdapters().remove(this);
+ Object oldValue = notification.getOldValue();
+ if(oldValue instanceof EObject) {
+ ((EObject)oldValue).eAdapters().remove(this);
+ }
+
// refresh the editors
adapter.refreshDisplay();
}
@@ -206,8 +231,10 @@ public abstract class EMFFeatureModelHandler implements IEMFModelHandler {
for(EObject eObject : objects) {
EStructuralFeature feature = getFeatureByName(eObject);
if(notificationFeature.equals(feature)) {
- for(EObject newValue : ((List<EObject>)notification.getOldValue())) {
- newValue.eAdapters().remove(adapter);
+ for(Object oldValue : ((List<Object>)notification.getOldValue())) {
+ if(oldValue instanceof EObject) {
+ ((EObject)oldValue).eAdapters().add(adapter);
+ }
}
// refresh the editors
adapter.refreshDisplay();
@@ -238,4 +265,740 @@ public abstract class EMFFeatureModelHandler implements IEMFModelHandler {
object.eAdapters().remove(controller);
}
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract List<IUndoableOperation> getCreateValueOperations(List<? extends EObject> objectsToEdit, Composite parent);
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreateValueOperations(List<? extends EObject> objectsToEdit) {
+ for(EObject objectToEdit : objectsToEdit) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return false;
+ }
+
+ if(!featureToEdit.isChangeable()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IUndoableOperation getDeleteValueOperation(List<? extends EObject> objectsToEdit, Composite parent, List<Integer> indexes) {
+ TransactionalEditingDomain editingDomain = EMFUtils.getTransactionalEditingDomain(objectsToEdit);
+ if(editingDomain == null) {
+ Activator.log.error("Impossible during creation operation to find the editing domain for objects: " + objectsToEdit, null); //$NON-NLS-1$
+ return null;
+ }
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Edit Value"); //$NON-NLS-1$
+ for(EObject objectToEdit : objectsToEdit) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ // DeleteStringValueOperation operation = new DeleteStringValueOperation(editingDomain, "Edit Value", objectToEdit, indexes, parent);
+ IUndoableOperation operation = getDeleteStringValueOperation(editingDomain, "Edit Value", objectToEdit, indexes, parent); //$NON-NLS-1$
+ if(operation != null) {
+ command.add(operation);
+ }
+ }
+ return command.reduce();
+ }
+
+ /**
+ * Returns the command to remove String values
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param string
+ * the name of the command
+ * @param objectToEdit
+ * the object to edit
+ * @param indexes
+ * the index of the element to remove
+ * @param parent
+ * the composite parent
+ * @return
+ * the command to remove String values
+ */
+ protected IUndoableOperation getDeleteStringValueOperation(TransactionalEditingDomain editingDomain, String string, EObject objectToEdit, List<Integer> indexes, Composite parent) {
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, string);
+ // get the feature to modify
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ Object newValue;
+ if(featureToEdit.getUpperBound() == 1) {
+ newValue = featureToEdit.getDefaultValue();
+ } else {
+ @SuppressWarnings("unchecked")
+ List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ for(int index : indexes) {
+ values.remove(index);
+ }
+ newValue = values;
+ }
+ SetRequest[] requests = getSetRequest(editingDomain, objectToEdit, newValue);
+ org.eclipse.papyrus.service.edit.service.IElementEditService provider = org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils.getCommandProvider(objectToEdit);
+ if(provider != null) {
+
+ ICommand editCommand = null;
+ for(SetRequest current : requests) {
+ editCommand = provider.getEditCommand(current);
+
+ if(editCommand != null && editCommand.canExecute()) {
+ command.add(editCommand);
+ }
+ }
+ }
+ return command;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreateDeleteValueOperation(List<? extends EObject> objectsToEdit) {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IUndoableOperation getEditValueOperation(List<? extends EObject> objectsToEdit, int index, Composite parent, Object value) {
+ TransactionalEditingDomain editingDomain = EMFUtils.getTransactionalEditingDomain(objectsToEdit);
+ if(editingDomain == null) {
+ Activator.log.error("Impossible during creation operation to find the editing domain for objects: " + objectsToEdit, null); //$NON-NLS-1$
+ return null;
+ }
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Edit Value"); //$NON-NLS-1$
+ for(EObject objectToEdit : objectsToEdit) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ // EditStringValueOperation operation = new EditStringValueOperation(editingDomain, "Edit Value", objectToEdit, index, parent, value);
+ IUndoableOperation operation = getEditStringValueOperation(editingDomain, "Edit Value", objectToEdit, index, parent, value); //$NON-NLS-1$
+ if(operation != null) {
+ command.add(operation);
+ }
+ }
+ return command.reduce();
+ }
+
+ /**
+ * Returns the Operation to edit the String value
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param string
+ * the name of the command
+ * @param objectToEdit
+ * the object to edit
+ * @param index
+ * the index of the String to edit
+ * @param parent
+ * the composite parent
+ * @param value
+ * the value to set
+ * @return
+ * the Operation to edit the String value
+ */
+ protected IUndoableOperation getEditStringValueOperation(TransactionalEditingDomain editingDomain, String string, EObject objectToEdit, int index, Composite parent, Object value) {
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, string);
+ // get the feature to modify
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ Object newValue;
+ if(featureToEdit.getUpperBound() == 1) {
+ newValue = value;
+ } else {
+ @SuppressWarnings("unchecked")
+ List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ values.set(index, value);
+ newValue = values;
+ }
+ SetRequest[] requests = getSetRequest(editingDomain, objectToEdit, newValue);
+ org.eclipse.papyrus.service.edit.service.IElementEditService provider = org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils.getCommandProvider(objectToEdit);
+ if(provider != null) {
+
+ ICommand editCommand = null;
+ for(SetRequest current : requests) {
+ editCommand = provider.getEditCommand(current);
+
+ if(editCommand != null && editCommand.canExecute()) {
+ command.add(editCommand);
+ }
+ }
+ }
+ return command;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreateEditValueOperation(List<? extends EObject> objectsToEdit) {
+ // try to retrieve editor for this property
+ // if one exists, return yes
+ // or try to open an inline-editor for simple values
+ return true;
+ }
+
+ /**
+ * Returns the feature ID
+ *
+ * @param feature
+ * the feature
+ * @param elementToEdit
+ * the element to edit
+ * @return
+ * the feature ID
+ */
+ protected int getFeatureID(EStructuralFeature feature, BasicEObjectImpl elementToEdit) {
+ return (elementToEdit).eDerivedStructuralFeatureID(feature);
+ }
+
+ /**
+ * Returns the structural feature of elementToEdit corresponding to this ID
+ *
+ * @param ID
+ * the ID of the feature
+ * @param elementToEdit
+ * the element to edit
+ * @return
+ * the structural feature of elementToEdit corresponding to this ID
+ */
+ protected EStructuralFeature getStructuralFeature(int ID, EObject elementToEdit) {
+ if(elementToEdit instanceof BasicEObjectImpl) {
+ EClass eClass = elementToEdit.eClass();
+ return eClass.getEStructuralFeature(ID);
+ }
+ return null;
+ }
+
+ // /**
+ // * Operation to edit a String value for the controlled property
+ // */
+ // protected class EditStringValueOperation extends AbstractTransactionalCommand {
+ //
+ // /** object to edit */
+ // protected final EObject objectToEdit;
+ //
+ // /** index of the value to edit */
+ // protected final int index;
+ //
+ // /** composite parent for the editor */
+ // protected final Composite parent;
+ //
+ // /** value to set */
+ // protected final Object value;
+ //
+ // /**
+ // * Initializes me with the editing domain, a label, transaction options, and
+ // * a list of {@link IFile}s that anticipate modifying when I am executed,
+ // * undone or redone.
+ // *
+ // * @param domain
+ // * the editing domain used to modify the model
+ // * @param label
+ // * my user-readable label, should never be <code>null</code>.
+ // * @param objectToEdit
+ // * object to edit
+ // * @param index
+ // * the index of the value to edit
+ // * @param parent
+ // * the graphical composite element
+ // * @param value
+ // */
+ // public EditStringValueOperation(TransactionalEditingDomain domain, String label, EObject objectToEdit, int index, Composite parent, Object value) {
+ // super(domain, (label == null) ? "" : label, null);
+ // this.objectToEdit = objectToEdit;
+ // this.index = index;
+ // this.parent = parent;
+ // this.value = value;
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // // get the feature to modify
+ // EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ // if(featureToEdit == null) {
+ // return CommandResult.newErrorCommandResult("Impossible to find the feature " + getFeatureName());
+ // }
+ // Object newValue;
+ // if(featureToEdit.getUpperBound() == 1) {
+ // newValue = value;
+ // } else {
+ // @SuppressWarnings("unchecked")
+ // List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ // values.set(index, value);
+ // newValue = values;
+ // }
+ // setValueInModel(objectToEdit, newValue);
+ // return CommandResult.newOKCommandResult();
+ // }
+ // }
+
+ // /**
+ // * Operation to edit a String value for the controlled property
+ // */
+ // protected class DeleteStringValueOperation extends AbstractTransactionalCommand {
+ //
+ // /** object to edit */
+ // protected final EObject objectToEdit;
+ //
+ // /** indexes of the value to delete */
+ // protected final List<Integer> indexes;
+ //
+ // /** composite parent for the editor */
+ // protected final Composite parent;
+ //
+ // /**
+ // * Initializes me with the editing domain, a label, transaction options, and
+ // * a list of {@link IFile}s that anticipate modifying when I am executed,
+ // * undone or redone.
+ // *
+ // * @param domain
+ // * the editing domain used to modify the model
+ // * @param label
+ // * my user-readable label, should never be <code>null</code>.
+ // * @param objectToEdit
+ // * object to edit
+ // * @param indexes
+ // * the indexes of the values to remove
+ // * @param parent
+ // * the graphical composite element
+ // */
+ // public DeleteStringValueOperation(TransactionalEditingDomain domain, String label, EObject objectToEdit, List<Integer> indexes, Composite parent) {
+ // super(domain, (label == null) ? "" : label, null);
+ // this.objectToEdit = objectToEdit;
+ // this.indexes = indexes;
+ // this.parent = parent;
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // // get the feature to modify
+ // EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ // if(featureToEdit == null) {
+ // return CommandResult.newErrorCommandResult("Impossible to find the feature " + getFeatureName());
+ // }
+ // Object newValue;
+ // if(featureToEdit.getUpperBound() == 1) {
+ // objectToEdit.eUnset(featureToEdit);
+ // } else {
+ // @SuppressWarnings("unchecked")
+ // List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ // for(int index : indexes) {
+ // values.remove(index);
+ // }
+ // newValue = values;
+ // setValueInModel(objectToEdit, newValue);
+ // }
+ // return CommandResult.newOKCommandResult();
+ // }
+ // }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IUndoableOperation getMoveValueOperation(List<? extends EObject> objectsToEdit, List<Integer> indexes, Composite parent, int delta) {
+ TransactionalEditingDomain editingDomain = EMFUtils.getTransactionalEditingDomain(objectsToEdit);
+ if(editingDomain == null) {
+ Activator.log.error("Impossible during move operation to find the editing domain for objects: " + objectsToEdit, null); //$NON-NLS-1$
+ return null;
+ }
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Move Values"); //$NON-NLS-1$
+ for(EObject objectToEdit : objectsToEdit) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ // MoveStringValueOperation operation = new MoveStringValueOperation(editingDomain, "Move Value", objectToEdit, indexes, parent, delta);
+ IUndoableOperation operation = getMoveStringValueOperation(editingDomain, "Move Value", objectToEdit, indexes, parent, delta); //$NON-NLS-1$
+ if(operation != null) {
+ command.add(operation);
+ }
+ }
+ return command.reduce();
+ }
+
+ /**
+ * Returns the command to move String values
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param string
+ * the name of the command
+ * @param objectToEdit
+ * the object to edit
+ * @param indexes
+ * the index of the elements to move
+ * @param parent
+ * the composite parent
+ * @param delta
+ * the delta
+ * @return
+ * the command to move String values
+ */
+ protected IUndoableOperation getMoveStringValueOperation(TransactionalEditingDomain editingDomain, String string, EObject objectToEdit, List<Integer> indexes, Composite parent, int delta) {
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, string);
+ if(canMoveStringValue(objectToEdit, indexes, delta)) {
+
+ EClass eClass = objectToEdit.eClass();
+ if(eClass == null) {
+ return null;
+ }
+ // retrieve the current value (should be a list)
+ EStructuralFeature feature = getFeatureByName(objectToEdit);
+ Object currentValue = objectToEdit.eGet(feature);
+ if(currentValue instanceof List<?>) {
+ @SuppressWarnings("unchecked")
+ List<Object> values = (List<Object>)currentValue;
+ List<Object> copy = new ArrayList<Object>(values);
+ // make modification in copy list
+ // check indices
+ int min = copy.size();
+ int max = 0;
+
+ for(int index : indexes) {
+ if(index < min) {
+ min = index;
+ }
+ if(index > max) {
+ max = index;
+ }
+ }
+
+ // check that min and max are in the bounds of the list, with the
+ // delta applied
+ min += delta;
+ max += delta;
+ // check the bounds of the list
+ if(min < 0) {
+ Activator.log.debug("Trying to move up the elements, with a move which will cause an IndexOutOfBound exception"); //$NON-NLS-1$
+ return null;
+ } else if(max >= copy.size()) {
+ Activator.log.debug("Trying to move down the elements, with a move which will cause an IndexOutOfBound exception"); //$NON-NLS-1$
+ return null;
+ }
+
+ // now, do the move in the copy
+ if(delta < 0) {
+ moveUpElementsInCollection(copy, indexes, delta);
+ } else {
+ moveDownElementsOperation(copy, indexes, delta);
+ }
+
+ // setValueInModel(objectToEdit, copy);
+ SetRequest[] requests = getSetRequest(editingDomain, objectToEdit, copy);
+ if(requests != null) {
+
+ org.eclipse.papyrus.service.edit.service.IElementEditService provider = org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils.getCommandProvider(objectToEdit);
+ if(provider != null) {
+
+ ICommand editCommand = null;
+ for(SetRequest current : requests) {
+ editCommand = provider.getEditCommand(current);
+
+ if(editCommand != null && editCommand.canExecute()) {
+ command.add(editCommand);
+ }
+ }
+ }
+ }
+ }
+ }
+ return command;
+ }
+
+ /**
+ * Tests if we can move values
+ *
+ * @param objectToEdit
+ * the object to edit
+ * @param indexes
+ * the indexes
+ * @param delta
+ * the delta
+ * @return
+ * <code>true</code> if we can move the values <code>false</code> if not
+ */
+ protected boolean canMoveStringValue(EObject objectToEdit, List<Integer> indexes, int delta) {
+ EClass eClass = objectToEdit.eClass();
+ if(eClass == null) {
+ return false;
+ }
+ // retrieve the current value (should be a list)
+ EStructuralFeature feature = getFeatureByName(objectToEdit);
+ Object currentValue = objectToEdit.eGet(feature);
+ if(currentValue instanceof List<?>) {
+ @SuppressWarnings("unchecked")
+ List<Object> values = (List<Object>)currentValue;
+ List<Object> copy = new ArrayList<Object>(values);
+ // make modification in copy list
+ // check indices
+ int min = copy.size();
+ int max = 0;
+
+ for(int index : indexes) {
+ if(index < min) {
+ min = index;
+ }
+ if(index > max) {
+ max = index;
+ }
+ }
+
+ // check that min and max are in the bounds of the list, with the
+ // delta applied
+ min += delta;
+ max += delta;
+ // check the bounds of the list
+ if(min < 0) {
+ return false;
+ } else if(max >= copy.size()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean canCreateMoveValueOperation(List<? extends EObject> objectsToEdit, List<Integer> indexes, Composite parent, int delta) {
+ TransactionalEditingDomain editingDomain = EMFUtils.getTransactionalEditingDomain(objectsToEdit);
+ if(editingDomain == null) {
+ Activator.log.error("Impossible during move operation to find the editing domain for objects: " + objectsToEdit, null); //$NON-NLS-1$
+ return false;
+ }
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Move Values"); //$NON-NLS-1$
+ for(EObject objectToEdit : objectsToEdit) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return false;
+ }
+ //MoveStringValueOperation operation = new MoveStringValueOperation(editingDomain, "Move Value", objectToEdit, indexes, parent, delta);
+ IUndoableOperation operation = getMoveStringValueOperation(editingDomain, "Move Value", objectToEdit, indexes, parent, delta); //$NON-NLS-1$
+ if(operation != null) {
+ command.add(operation);
+ }
+ }
+ return command.canExecute();
+ }
+
+ /**
+ * Moves the element in the specified list, when the elements are moved down
+ * in the list
+ *
+ * @param modifiedElements
+ * list of elements modified
+ * @param indexes
+ * list of indexes of objects to move
+ * @param move
+ * delta for the move. should be positive integer
+ */
+ protected void moveDownElementsOperation(List<Object> modifiedElements, List<Integer> indexes, int move) {
+ // if moving down, starting from the end to move elements, assuming they
+ // are in the increasing order by default
+ Collections.sort(indexes);
+ Collections.reverse(indexes);
+ for(int index : indexes) {
+ Object objectToMove = modifiedElements.get(index);
+ // remove element
+ modifiedElements.remove(index);
+ // change index
+ if(index == -1) {
+ return;
+ }
+ index += move;
+ // add the element to the new index
+ modifiedElements.add(index, objectToMove);
+ }
+ }
+
+ /**
+ * Moves the element in the specified list, when the elements are moved up
+ * in the list
+ *
+ * @param modifiedElements
+ * list of elements modified
+ * @param indexes
+ * list of indexes of objects to move
+ * @param move
+ * delta for the move. should be positive integer
+ */
+ protected void moveUpElementsInCollection(List<Object> modifiedElements, List<Integer> indexes, int move) {
+ Collections.sort(indexes);
+ for(int index : indexes) {
+ // retrieve index
+ Object objectToMove = modifiedElements.get(index);
+ // remove element
+ modifiedElements.remove(index);
+ // change index
+ if(index == -1) {
+ return;
+ }
+ index += move;
+ // add the element to the new index
+ modifiedElements.add(index, objectToMove);
+ }
+ }
+
+ // /**
+ // * Operation to edit a String value for the controlled property
+ // */
+ // protected class MoveStringValueOperation extends AbstractTransactionalCommand {
+ //
+ // /** object to edit */
+ // protected final EObject objectToEdit;
+ //
+ // /** indexes of the value to delete */
+ // protected final List<Integer> indexes;
+ //
+ // /** composite parent for the editor */
+ // protected final Composite parent;
+ //
+ // /** delta applied to all indexes */
+ // protected final int delta;
+ //
+ // /**
+ // * Initializes me with the editing domain, a label, transaction options, and
+ // * a list of {@link IFile}s that anticipate modifying when I am executed,
+ // * undone or redone.
+ // *
+ // * @param domain
+ // * the editing domain used to modify the model
+ // * @param label
+ // * my user-readable label, should never be <code>null</code>.
+ // * @param objectToEdit
+ // * object to edit
+ // * @param indexes
+ // * the indexes of the values to remove
+ // * @param parent
+ // * the graphical composite element
+ // * @param delta
+ // * the delta applied to all indexes
+ // */
+ // public MoveStringValueOperation(TransactionalEditingDomain domain, String label, EObject objectToEdit, List<Integer> indexes, Composite parent, int delta) {
+ // super(domain, (label == null) ? "" : label, null);
+ // this.objectToEdit = objectToEdit;
+ // this.indexes = indexes;
+ // this.parent = parent;
+ // this.delta = delta;
+ // }
+ //
+ // @Override
+ // public boolean canExecute() {
+ // EClass eClass = objectToEdit.eClass();
+ // if(eClass == null) {
+ // return false;
+ // }
+ // // retrieve the current value (should be a list)
+ // EStructuralFeature feature = getFeatureByName(objectToEdit);
+ // Object currentValue = objectToEdit.eGet(feature);
+ // if(currentValue instanceof List<?>) {
+ // @SuppressWarnings("unchecked")
+ // List<Object> values = (List<Object>)currentValue;
+ // List<Object> copy = new ArrayList<Object>(values);
+ // // make modification in copy list
+ // // check indices
+ // int min = copy.size();
+ // int max = 0;
+ //
+ // for(int index : indexes) {
+ // if(index < min) {
+ // min = index;
+ // }
+ // if(index > max) {
+ // max = index;
+ // }
+ // }
+ //
+ // // check that min and max are in the bounds of the list, with the
+ // // delta applied
+ // min += delta;
+ // max += delta;
+ // // check the bounds of the list
+ // if(min < 0) {
+ // return false;
+ // } else if(max >= copy.size()) {
+ // return false;
+ // }
+ // }
+ // return true;
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // EClass eClass = objectToEdit.eClass();
+ // if(eClass == null) {
+ // return CommandResult.newErrorCommandResult("Impossible to find the EClass for object: " + objectToEdit);
+ // }
+ // // retrieve the current value (should be a list)
+ // EStructuralFeature feature = getFeatureByName(objectToEdit);
+ // Object currentValue = objectToEdit.eGet(feature);
+ // if(currentValue instanceof List<?>) {
+ // @SuppressWarnings("unchecked")
+ // List<Object> values = (List<Object>)currentValue;
+ // List<Object> copy = new ArrayList<Object>(values);
+ // // make modification in copy list
+ // // check indices
+ // int min = copy.size();
+ // int max = 0;
+ //
+ // for(int index : indexes) {
+ // if(index < min) {
+ // min = index;
+ // }
+ // if(index > max) {
+ // max = index;
+ // }
+ // }
+ //
+ // // check that min and max are in the bounds of the list, with the
+ // // delta applied
+ // min += delta;
+ // max += delta;
+ // // check the bounds of the list
+ // if(min < 0) {
+ // Activator.log.debug("Trying to move up the elements, with a move which will cause an IndexOutOfBound exception");
+ // return CommandResult.newErrorCommandResult("Trying to move up the elements, with a move which will cause an IndexOutOfBound exception");
+ // } else if(max >= copy.size()) {
+ // Activator.log.debug("Trying to move down the elements, with a move which will cause an IndexOutOfBound exception");
+ // return CommandResult.newErrorCommandResult("Trying to move down the elements, with a move which will cause an IndexOutOfBound exception");
+ // }
+ //
+ // // now, do the move in the copy
+ // if(delta < 0) {
+ // moveUpElementsInCollection(copy, indexes, delta);
+ // } else {
+ // moveDownElementsOperation(copy, indexes, delta);
+ // }
+ //
+ // setValueInModel(objectToEdit, copy);
+ // }
+ //
+ // return CommandResult.newOKCommandResult();
+ // }
+ // }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFStereotypeFeatureModelHandler.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFStereotypeFeatureModelHandler.java
index 34369de6a02..fe5203e4774 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFStereotypeFeatureModelHandler.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFStereotypeFeatureModelHandler.java
@@ -8,9 +8,11 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.emf.ecore.EClass;
@@ -19,7 +21,10 @@ import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.papyrus.properties.runtime.Activator;
+import org.eclipse.papyrus.properties.runtime.controller.EMFPropertyEditorController;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;
@@ -36,6 +41,38 @@ public abstract class EMFStereotypeFeatureModelHandler extends EMFFeatureModelHa
private final String stereotypeName;
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addListenersToModel(List<? extends EObject> objectsToEdit, EMFPropertyEditorController controller) {
+ super.addListenersToModel(objectsToEdit, controller);
+ for(EObject object : objectsToEdit) {
+ if(object instanceof Element) {
+ Iterator<EObject> it = ((Element)object).getStereotypeApplications().iterator();
+ while(it.hasNext()) {
+ it.next().eAdapters().add(controller);
+ }
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void removeListenersFromModel(List<? extends EObject> objectsToEdit, EMFPropertyEditorController controller) {
+ super.removeListenersFromModel(objectsToEdit, controller);
+ for(EObject object : objectsToEdit) {
+ if(object instanceof Element) {
+ Iterator<EObject> it = ((Element)object).getStereotypeApplications().iterator();
+ while(it.hasNext()) {
+ it.next().eAdapters().remove(controller);
+ }
+ }
+ }
+ }
+
+ /**
* Creates a new EMFStereotypeFeatureModelHandler.
*
* @param stereotypeName
@@ -57,7 +94,7 @@ public abstract class EMFStereotypeFeatureModelHandler extends EMFFeatureModelHa
if(objectToEdit instanceof Element) {
return EMFUtils.getStereotypeFeatureByName((Element)objectToEdit, retrieveStereotype((Element)objectToEdit), getFeatureName());
}
- Activator.log.error("Impossible to cast into UML element: " + objectToEdit, null);
+ Activator.log.error("Impossible to cast into UML element: " + objectToEdit, null); //$NON-NLS-1$
return null;
}
@@ -68,23 +105,23 @@ public abstract class EMFStereotypeFeatureModelHandler extends EMFFeatureModelHa
public Object getAvailableValues(EObject eObject) {
EClass eClass = eObject.eClass();
if(eClass == null) {
- Activator.log.debug("problems during initialization, looking for availables values");
+ Activator.log.debug("problems during initialization, looking for availables values"); //$NON-NLS-1$
return null;
}
EStructuralFeature feature = getFeatureByName(eObject);
if(!(feature instanceof EReference)) {
- Activator.log.debug("feature is not a reference, looking for availables values: " + feature);
+ Activator.log.debug("feature is not a reference, looking for availables values: " + feature); //$NON-NLS-1$
return null;
}
IItemPropertySource itemPropertySource = (IItemPropertySource)factory.adapt(((Element)eObject).getStereotypeApplication(retrieveStereotype((Element)eObject)), IItemPropertySource.class);
if(itemPropertySource == null) {
- Activator.log.debug("impossible to find item Property source for " + retrieveStereotype((Element)eObject));
+ Activator.log.debug("impossible to find item Property source for " + retrieveStereotype((Element)eObject)); //$NON-NLS-1$
return null;
}
IItemPropertyDescriptor itemPropertyDescriptor = itemPropertySource.getPropertyDescriptor(retrieveStereotype((Element)eObject), feature);
if(itemPropertyDescriptor == null) {
- Activator.log.debug("impossible to find item Property descriptor for " + retrieveStereotype((Element)eObject) + " and " + feature);
+ Activator.log.debug("impossible to find item Property descriptor for " + retrieveStereotype((Element)eObject) + " and " + feature); //$NON-NLS-1$ //$NON-NLS-2$
return null;
}
return itemPropertyDescriptor.getChoiceOfValues(eObject);
@@ -96,7 +133,7 @@ public abstract class EMFStereotypeFeatureModelHandler extends EMFFeatureModelHa
@Override
public Object getValueToEdit(EObject objectToEdit) {
if(!(objectToEdit instanceof Element)) {
- Activator.log.warn("the object to edit is not a UML2 Element: " + objectToEdit);
+ Activator.log.warn("the object to edit is not a UML2 Element: " + objectToEdit); //$NON-NLS-1$
return null;
}
Element elementToEdit = (Element)objectToEdit;
@@ -104,7 +141,7 @@ public abstract class EMFStereotypeFeatureModelHandler extends EMFFeatureModelHa
if(stereotype != null) {
return getValueForElement(elementToEdit, stereotype);
} else {
- Activator.log.warn("Impossible to set value to the stereotype: " + stereotypeName + " on the element: " + elementToEdit);
+ Activator.log.warn("Impossible to get the stereotype: " + stereotypeName + " on the element: " + elementToEdit + " for feature " + getFeatureName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
return null;
}
@@ -128,7 +165,7 @@ public abstract class EMFStereotypeFeatureModelHandler extends EMFFeatureModelHa
@Override
public void setValueInModel(EObject objectToEdit, Object newValue) {
if(!(objectToEdit instanceof Element)) {
- Activator.log.warn("the object to edit is not a UML2 Element: " + objectToEdit);
+ Activator.log.warn("the object to edit is not a UML2 Element: " + objectToEdit); //$NON-NLS-1$
return;
}
Element elementToEdit = (Element)objectToEdit;
@@ -136,7 +173,7 @@ public abstract class EMFStereotypeFeatureModelHandler extends EMFFeatureModelHa
if(stereotype != null) {
setValueForElement(elementToEdit, stereotype, newValue);
} else {
- Activator.log.warn("Impossible to set value to the stereotype: " + stereotypeName + " on the element: " + elementToEdit);
+ Activator.log.warn("Impossible to set value to the stereotype: " + stereotypeName + " on the element: " + elementToEdit); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@@ -220,7 +257,7 @@ public abstract class EMFStereotypeFeatureModelHandler extends EMFFeatureModelHa
EObject firstObject = objectToEdit.get(0);
if(!(firstObject instanceof Element)) {
- Activator.log.warn("Object to edit should be a UML2 element: " + firstObject);
+ Activator.log.warn("Object to edit should be a UML2 element: " + firstObject); //$NON-NLS-1$
return null;
}
@@ -244,14 +281,30 @@ public abstract class EMFStereotypeFeatureModelHandler extends EMFFeatureModelHa
return property;
}
}
- Activator.log.warn("No feature fond with name:" + getFeatureName() + " for stereotype " + stereotypeName);
+ Activator.log.warn("No feature fond with name:" + getFeatureName() + " for stereotype " + stereotypeName); //$NON-NLS-1$ //$NON-NLS-2$
return null;
}
/**
* {@inheritDoc}
*/
+ @Override
public IEMFModelHandlerState createState(boolean readOnly) {
return new EMFStereotypeFeatureModelHandlerState(this, readOnly);
}
+
+ /**
+ *
+ * @see org.eclipse.papyrus.properties.runtime.modelhandler.emf.IEMFModelHandler#getSetRequest(org.eclipse.emf.transaction.TransactionalEditingDomain,
+ * org.eclipse.emf.ecore.EObject, java.lang.Object)
+ *
+ * @param domain
+ * @param objectToEdit
+ * @param newValue
+ * @return
+ */
+ public SetRequest[] getSetRequest(TransactionalEditingDomain domain, EObject objectToEdit, Object newValue) {
+ return null; //TODO
+ }
+
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFUtils.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFUtils.java
index 6c2b5fd9012..90ef012180e 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFUtils.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EMFUtils.java
@@ -11,9 +11,15 @@
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.papyrus.core.utils.EditorUtils;
import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.uml2.common.util.UML2Util;
import org.eclipse.uml2.uml.Element;
@@ -59,7 +65,8 @@ public class EMFUtils {
EObject eObject = elementToEdit.getStereotypeApplication(stereotype);
if(eObject == null) {
- throw new IllegalArgumentException(String.valueOf(stereotype));
+ Activator.log.error("Impossible to find stereotype application", null);
+ return null;
}
EClass eClass = eObject.eClass();
@@ -75,10 +82,32 @@ public class EMFUtils {
}
if(eStructuralFeature == null) {
- throw new IllegalArgumentException(String.valueOf(featureName));
+ Activator.log.error("Impossible to find structural feature", null);
+ return null;
}
return eStructuralFeature;
}
+ /**
+ * Returns the editing domain for a set of elements
+ *
+ * @param objects
+ * the objects from which the editing domain can be retrieved
+ * @return the editing domain found or <code>null</code>
+ */
+ public static TransactionalEditingDomain getTransactionalEditingDomain(List<? extends Object> objects) {
+ TransactionalEditingDomain editingDomain = null;
+ Iterator<? extends Object> it2 = objects.iterator();
+ while(it2.hasNext() && editingDomain == null) {
+ editingDomain = TransactionUtil.getEditingDomain(it2.next());
+ }
+
+ // if impossible to find editing domain this way: Tries the Papyrus service
+ if(editingDomain == null) {
+ editingDomain = EditorUtils.getTransactionalEditingDomain();
+ }
+ return editingDomain;
+ }
+
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EnumerationEMFModelHandler.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EnumerationEMFModelHandler.java
index a4169e0d84e..9c54bd305e9 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EnumerationEMFModelHandler.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EnumerationEMFModelHandler.java
@@ -8,20 +8,28 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IBoundedValuesPropertyEditorDescriptor;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
+import org.eclipse.swt.widgets.Composite;
/**
* Model Handler for enumeration
@@ -40,7 +48,7 @@ public class EnumerationEMFModelHandler extends EMFFeatureModelHandler {
/** id of this model handler */
- public static final String ID = "Enumeration";
+ public static final String ID = "Enumeration"; //$NON-NLS-1$
/**
* {@inheritDoc}
@@ -58,13 +66,14 @@ public class EnumerationEMFModelHandler extends EMFFeatureModelHandler {
/**
* {@inheritDoc}
*/
+ @Override
public void setValueInModel(EObject objectToEdit, Object newValue) {
EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
if(featureToEdit == null) {
return;
}
// remove value if result of the editor is empty
- if(newValue == null || newValue.equals("")) {
+ if(newValue == null || newValue.equals("")) { //$NON-NLS-1$
objectToEdit.eUnset(featureToEdit);
} else {
// retrieve the real value for the enumeration
@@ -81,6 +90,7 @@ public class EnumerationEMFModelHandler extends EMFFeatureModelHandler {
/**
* {@inheritDoc}
*/
+ @Override
public void completeEditorDescriptor(IPropertyEditorDescriptor descriptor, List<? extends EObject> objectToEdit) {
if(objectToEdit.size() < 1) {
return;
@@ -96,7 +106,7 @@ public class EnumerationEMFModelHandler extends EMFFeatureModelHandler {
// check if there is an empty string at the beginning. there is one if the lower bound of the feature to edit equal 0
if(featureToEdit.getLowerBound() == 0) {
- values.add("");
+ values.add(""); //$NON-NLS-1$
}
if(featureToEdit.getEType() instanceof EEnum) {
@@ -108,7 +118,7 @@ public class EnumerationEMFModelHandler extends EMFFeatureModelHandler {
if(descriptor instanceof IBoundedValuesPropertyEditorDescriptor) {
((IBoundedValuesPropertyEditorDescriptor)descriptor).setAvailableValues(values);
} else {
- Activator.log.warn("Warning: " + descriptor + "could not be completed.");
+ Activator.log.warn("Warning: " + descriptor + "could not be completed."); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@@ -118,4 +128,217 @@ public class EnumerationEMFModelHandler extends EMFFeatureModelHandler {
public String getId() {
return ID;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<IUndoableOperation> getCreateValueOperations(List<? extends EObject> objectsToEdit, Composite parent) {
+
+ List<IUndoableOperation> operations = new ArrayList<IUndoableOperation>(1);
+ TransactionalEditingDomain editingDomain = EMFUtils.getTransactionalEditingDomain(objectsToEdit);
+ if(editingDomain == null) {
+ Activator.log.error("Impossible during creation operation to find the editing domain for objects: " + objectsToEdit, null); //$NON-NLS-1$
+ return null;
+ }
+ int indexOfNewValue = NEW_VALUE_NOT_SET_INDEX;
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Create new Enumeration Value"); //$NON-NLS-1$
+ for(EObject objectToEdit : objectsToEdit) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ // CreateEnumerationValueOperation operation = new CreateEnumerationValueOperation(editingDomain, "Create new Enumeration Value", objectToEdit);
+ IUndoableOperation operation = getCreateEnumerationValueOperation(editingDomain, "Create new Enumeration Value", objectToEdit); //$NON-NLS-1$
+ if(operation != null) {
+ command.add(operation);
+ }
+ if(indexOfNewValue == NEW_VALUE_NOT_SET_INDEX) { // try to update
+ }
+ }
+
+ operations.add(command.reduce());
+
+ return operations;
+ }
+
+ /**
+ * Returns the command to edit the object
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param string
+ * the name of the command
+ * @param objectToEdit
+ * the object to edit
+ * @return
+ * the command to edit the object
+ */
+ protected IUndoableOperation getCreateEnumerationValueOperation(TransactionalEditingDomain editingDomain, String string, EObject objectToEdit) {
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, string);
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ Activator.log.error("Impossible to find the feature " + getFeatureName(), null); //$NON-NLS-1$
+ return command;
+ }
+
+ // create the value and add it to the feature
+ // if feature = simple valued => set
+ // if feature = multi valued => add at the end
+
+ Object newValue;
+ if(featureToEdit.getUpperBound() == 1) {
+ newValue = getInitialValue(objectToEdit);
+ } else {
+ @SuppressWarnings("unchecked")
+ List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ values.add(values.size(), getInitialValue(objectToEdit));
+ newValue = values;
+ }
+
+ SetRequest[] requests = getSetRequest(editingDomain, objectToEdit, newValue);
+ if(requests != null) {
+
+ org.eclipse.papyrus.service.edit.service.IElementEditService provider = org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils.getCommandProvider(objectToEdit);
+ if(provider != null) {
+
+ ICommand editCommand = null;
+ for(SetRequest current : requests) {
+ editCommand = provider.getEditCommand(current);
+
+ if(editCommand != null && editCommand.canExecute()) {
+ command.add(editCommand);
+ }
+ }
+ }
+ }
+ return command;
+ }
+
+ // /**
+ // * Operation to create a Enumeration value for the controlled property
+ // */
+ // protected class CreateEnumerationValueOperation extends AbstractTransactionalCommand {
+ //
+ // /** object to edit */
+ // protected final EObject objectToEdit;
+ //
+ // /** index of the value to add (-1 in case of single valued property) */
+ // private int indexOfNewValue = -2;
+ //
+ // /**
+ // * Initializes me with the editing domain, a label, transaction options, and
+ // * a list of {@link IFile}s that anticipate modifying when I am executed,
+ // * undone or redone.
+ // *
+ // * @param domain
+ // * the editing domain used to modify the model
+ // * @param label
+ // * my user-readable label, should never be <code>null</code>.
+ // * @param objectToEdit
+ // * the {@link EObject} to edit
+ // */
+ // public CreateEnumerationValueOperation(TransactionalEditingDomain domain, String label, EObject objectToEdit) {
+ // super(domain, (label == null) ? "" : label, null);
+ // this.objectToEdit = objectToEdit;
+ //
+ // EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ // if(featureToEdit.getUpperBound() == 1) {
+ // indexOfNewValue = -1;
+ // } else {
+ // @SuppressWarnings("unchecked")
+ // List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ // indexOfNewValue = values.size();
+ // }
+ // }
+ //
+ // /**
+ // * Returns the index at which the value will be added
+ // *
+ // * @return the index at which the value will be added
+ // */
+ // public int getIndexOfNewValue() {
+ // return indexOfNewValue;
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // // create the value and add it to the feature
+ // // if feature = simple valued => set
+ // // if feature = multi valued => add at the end
+ // EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ // if(featureToEdit == null) {
+ // return CommandResult.newErrorCommandResult("Impossible to find the feature " + getFeatureName());
+ // }
+ // Object newValue;
+ // if(featureToEdit.getUpperBound() == 1) {
+ // newValue = getInitialValue(objectToEdit);
+ // } else {
+ // @SuppressWarnings("unchecked")
+ // List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ // values.add(indexOfNewValue, getInitialValue(objectToEdit));
+ // newValue = values;
+ // }
+ // setValueInModel(objectToEdit, newValue);
+ // return CommandResult.newOKCommandResult();
+ // }
+ // }
+
+ /**
+ * Returns the initial value for a new value of the feature
+ *
+ * @param objectToEdit
+ * the object to edit
+ *
+ * @return the initial value, not <code>null</code>
+ */
+ public Object getInitialValue(EObject objectToEdit) {
+ String featureName = getFeatureName();
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit.getUpperBound() == 1) {
+ return featureName;
+ } else {
+ EClassifier eClassifier = featureToEdit.getEType();
+ if(eClassifier instanceof EEnum) {
+ return ((EEnum)eClassifier).getDefaultValue();
+ } else if(Boolean.TYPE.isAssignableFrom(eClassifier.getInstanceClass())) {
+ return Boolean.TRUE;
+ }
+ Activator.log.error("Impossible to find a default value", null); //$NON-NLS-1$
+ return null;
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.properties.runtime.modelhandler.emf.IEMFModelHandler#getSetRequest(org.eclipse.emf.transaction.TransactionalEditingDomain,
+ * org.eclipse.emf.ecore.EObject, java.lang.Object)
+ *
+ * @param domain
+ * @param objectToEdit
+ * @param newValue
+ * @return
+ */
+ public SetRequest[] getSetRequest(TransactionalEditingDomain domain, EObject objectToEdit, Object newValue) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ // remove value if result of the editor is empty
+ if(newValue == null || newValue.equals("")) { //$NON-NLS-1$
+ return new SetRequest[]{ new SetRequest(domain, objectToEdit, featureToEdit, featureToEdit.getDefaultValue()) };
+ } else {
+ // retrieve the real value for the enumeration
+ if(newValue instanceof String) {
+ EEnum type = (EEnum)featureToEdit.getEType();
+ EEnumLiteral literal = type.getEEnumLiteral((String)newValue);
+ Enumerator instance = literal.getInstance();
+ return new SetRequest[]{ new SetRequest(domain, objectToEdit, featureToEdit, instance) };
+ }
+ }
+ return null;
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EnumerationStereotypeModelHandler.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EnumerationStereotypeModelHandler.java
index 59407200889..929af46cd96 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EnumerationStereotypeModelHandler.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/EnumerationStereotypeModelHandler.java
@@ -14,11 +14,24 @@ package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IBoundedValuesPropertyEditorDescriptor;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Enumeration;
import org.eclipse.uml2.uml.EnumerationLiteral;
@@ -134,4 +147,133 @@ public class EnumerationStereotypeModelHandler extends EMFStereotypeFeatureModel
public String getId() {
return ID;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<IUndoableOperation> getCreateValueOperations(List<? extends EObject> objectsToEdit, Composite parent) {
+ List<IUndoableOperation> operations = new ArrayList<IUndoableOperation>(1);
+ TransactionalEditingDomain editingDomain = EMFUtils.getTransactionalEditingDomain(objectsToEdit);
+ if(editingDomain == null) {
+ Activator.log.error("Impossible during creation operation to find the editing domain for objects: " + objectsToEdit, null);
+ return null;
+ }
+ int indexOfNewValue = NEW_VALUE_NOT_SET_INDEX;
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Create new Enumeration Value");
+ for(EObject objectToEdit : objectsToEdit) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ CreateEnumerationStereotypeValueOperation operation = new CreateEnumerationStereotypeValueOperation(editingDomain, "Create new Enumeration Value", objectToEdit);
+ if(operation != null) {
+ command.add(operation);
+ }
+ if(indexOfNewValue == NEW_VALUE_NOT_SET_INDEX) { // try to update
+ indexOfNewValue = operation.getIndexOfNewValue();
+ }
+ }
+
+ operations.add(command.reduce());
+
+ return operations;
+ }
+
+ /**
+ * Operation to create a Enumeration value for the controlled property of a stererotype
+ */
+ protected class CreateEnumerationStereotypeValueOperation extends AbstractTransactionalCommand {
+
+ /** object to edit */
+ protected final EObject objectToEdit;
+
+ /** index of the value to add (-1 in case of single valued property) */
+ private int indexOfNewValue = -2;
+
+ /**
+ * Initializes me with the editing domain, a label, transaction options, and
+ * a list of {@link IFile}s that anticipate modifying when I am executed,
+ * undone or redone.
+ *
+ * @param domain
+ * the editing domain used to modify the model
+ * @param label
+ * my user-readable label, should never be <code>null</code>.
+ * @param objectToEdit
+ * the {@link EObject} to edit
+ */
+ public CreateEnumerationStereotypeValueOperation(TransactionalEditingDomain domain, String label, EObject objectToEdit) {
+ super(domain, (label == null) ? "" : label, null);
+ this.objectToEdit = objectToEdit;
+
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit.getUpperBound() == 1) {
+ indexOfNewValue = -1;
+ } else {
+ @SuppressWarnings("unchecked")
+ List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ indexOfNewValue = values.size();
+ }
+ }
+
+ /**
+ * Returns the index at which the value will be added
+ *
+ * @return the index at which the value will be added
+ */
+ public int getIndexOfNewValue() {
+ return indexOfNewValue;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // create the value and add it to the feature
+ // if feature = simple valued => set
+ // if feature = multi valued => add at the end
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return CommandResult.newErrorCommandResult("Impossible to find the feature " + getFeatureName());
+ }
+ Object newValue;
+ if(featureToEdit.getUpperBound() == 1) {
+ newValue = getInitialValue(objectToEdit);
+ } else {
+ @SuppressWarnings("unchecked")
+ List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ values.add(indexOfNewValue, getInitialValue(objectToEdit));
+ newValue = values;
+ }
+ setValueInModel(objectToEdit, newValue);
+ return CommandResult.newOKCommandResult();
+ }
+ }
+
+ /**
+ * Returns the initial value for a new value of the feature
+ *
+ * @param objectToEdit
+ * the object to edit
+ *
+ * @return the initial value, not <code>null</code>
+ */
+ public Object getInitialValue(EObject objectToEdit) {
+ String featureName = getFeatureName();
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit.getUpperBound() == 1) {
+ return featureName;
+ } else {
+ for(int suffix = 0; suffix < 1000; suffix++) {
+ EClassifier eClassifier = featureToEdit.getEType();
+ if(eClassifier instanceof EEnum) {
+ return ((EEnum)eClassifier).getDefaultValue();
+ }
+ }
+ Activator.log.error("Impossible to find a default value", null);
+ return null;
+ }
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/IEMFModelHandler.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/IEMFModelHandler.java
index 2d456ce2f2b..b42426d930e 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/IEMFModelHandler.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/IEMFModelHandler.java
@@ -8,16 +8,21 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
import java.util.List;
+import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
import org.eclipse.papyrus.properties.runtime.controller.EMFPropertyEditorController;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
import org.eclipse.papyrus.properties.runtime.view.IConfigurableDescriptor;
+import org.eclipse.swt.widgets.Composite;
/**
@@ -117,4 +122,118 @@ public interface IEMFModelHandler extends IConfigurableDescriptor {
* the controller which was using this model handler
*/
public void removeListenersFromModel(List<? extends EObject> objectsToEdit, EMFPropertyEditorController controller);
+
+ /**
+ * Returns the operation to create a new value for this property
+ *
+ * @param objectsToEdit
+ * the list of object to edit
+ * @param parent
+ * the composite parent, needed in case of user interaction
+ *
+ * @return the operation to create a new value for this property
+ */
+ public List<IUndoableOperation> getCreateValueOperations(List<? extends EObject> objectsToEdit, Composite parent);
+
+ /**
+ * Returns <code>true</code> if the controller can create a new value for the property
+ *
+ * @param objectsToEdit
+ * the list of object to edit
+ * @return <code>true</code> if the controller can create a new value for the property
+ */
+ public boolean canCreateValueOperations(List<? extends EObject> objectsToEdit);
+
+ /**
+ * Returns the operation to delete a value for this property
+ *
+ * @param objectsToEdit
+ * the list of object to edit
+ * @param parent
+ * the composite parent, needed in case of user interaction
+ * @param indexes
+ * list of indexes to delete
+ * @return the operation to delete a value for this property
+ *
+ */
+ public IUndoableOperation getDeleteValueOperation(List<? extends EObject> objectsToEdit, Composite parent, List<Integer> indexes);
+
+ /**
+ * Returns <code>true</code> if the controller can delete a value for the property
+ *
+ * @param objectsToEdit
+ * the list of object to edit
+ * @return <code>true</code> if the controller can delete a value for the property
+ */
+ public boolean canCreateDeleteValueOperation(List<? extends EObject> objectsToEdit);
+
+ /**
+ * Returns the operation to edit a value for this property
+ *
+ * @param objectsToEdit
+ * the list of object to edit
+ * @param index
+ * the index of the value to edit
+ * @param parent
+ * the parent for the editor
+ * @param value
+ * the value to set
+ * @return the operation to edit a value for this property
+ */
+ public IUndoableOperation getEditValueOperation(List<? extends EObject> objectsToEdit, int index, Composite parent, Object value);
+
+ /**
+ * Returns <code>true</code> if the controller can edit a value for the property
+ *
+ * @param objectsToEdit
+ * the list of object to edit
+ * @return <code>true</code> if the controller can edit a value for the property
+ */
+ public boolean canCreateEditValueOperation(List<? extends EObject> objectsToEdit);
+
+ /**
+ * Returns the operation to move a list of values for this property
+ *
+ * @param objectsToEdit
+ * the list of object to edit
+ * @param indexes
+ * the list of indexes to move
+ * @param parent
+ * the parent for the editor
+ * @param delta
+ * the delta applied to all moved objects
+ * @return the operation to edit a value for this property
+ */
+ public IUndoableOperation getMoveValueOperation(List<? extends EObject> objectsToEdit, List<Integer> indexes, Composite parent, int delta);
+
+ /**
+ * Returns <code>true</code> if the controller can move a set of values for the property
+ *
+ * @param objectsToEdit
+ * the list of object to edit
+ * @param indexes
+ * the list of indexes to move
+ * @param parent
+ * the parent for the editor
+ * @param delta
+ * the delta applied to all moved objects
+ * @return <code>true</code> if the controller can move a set of values for the property
+ */
+ public boolean canCreateMoveValueOperation(List<? extends EObject> objectsToEdit, List<Integer> indexes, Composite parent, int delta);
+
+
+
+ /**
+ * Returns a list of SetRequest for this object, or <code>null</code> if a request can't be created
+ *
+ * @param domain
+ * the transactional editing domain
+ * @param objectToEdit
+ * the object to edit
+ * @param newValue
+ * the new value for this object
+ * @return
+ * a list of SetRequest for this object, or <code>null</code> if a request can't be created
+ */
+ public SetRequest[] getSetRequest(TransactionalEditingDomain domain, EObject objectToEdit, Object newValue);
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/ReferenceEMFModelHandler.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/ReferenceEMFModelHandler.java
index 73f87186442..2b8f7f20f19 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/ReferenceEMFModelHandler.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/ReferenceEMFModelHandler.java
@@ -8,15 +8,38 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.papyrus.core.services.ServiceException;
+import org.eclipse.papyrus.core.utils.DisplayUtils;
import org.eclipse.papyrus.properties.runtime.Activator;
+import org.eclipse.papyrus.properties.runtime.Messages;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
+import org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.service.edit.service.IElementEditService;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.PlatformUI;
/**
@@ -35,11 +58,12 @@ public class ReferenceEMFModelHandler extends EMFFeatureModelHandler {
}
/** identifier fot this model handler */
- public static final String ID = "Reference";
+ public static final String ID = "Reference"; //$NON-NLS-1$
/**
* {@inheritDoc}
*/
+ @Override
public void setValueInModel(EObject objectToEdit, Object newValue) {
EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
if(featureToEdit == null) {
@@ -50,15 +74,15 @@ public class ReferenceEMFModelHandler extends EMFFeatureModelHandler {
} else if(newValue instanceof List<?>) {
objectToEdit.eSet(featureToEdit, newValue);
} else {
- Activator.log.error("impossible to set the new value", null);
+ Activator.log.error("impossible to set the new value", null); //$NON-NLS-1$
}
}
/**
* {@inheritDoc}
*/
+ @Override
public void completeEditorDescriptor(IPropertyEditorDescriptor descriptor, List<? extends EObject> objectToEdit) {
-
}
/**
@@ -67,4 +91,214 @@ public class ReferenceEMFModelHandler extends EMFFeatureModelHandler {
public String getId() {
return ID;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<IUndoableOperation> getCreateValueOperations(final List<? extends EObject> objectsToEdit, Composite parent) {
+ // checks the containment feature
+ EObject eObject = objectsToEdit.get(0);
+ EStructuralFeature feature = getFeatureByName(eObject);
+ if(!(feature instanceof EReference)) {
+ return new ArrayList<IUndoableOperation>();
+ }
+ // check containment feature
+
+ boolean isContainment = ((EReference)feature).isContainment();
+ if(isContainment) {
+ // retrieve the Eclass of the elements to edit
+ List<IUndoableOperation> undoableOperations = new ArrayList<IUndoableOperation>();
+ EClass eClass = eObject.eClass();
+ if(eClass == null) {
+ return undoableOperations;
+ }
+ // Use edit service and look for element types that are possible types of the selected EReference
+ List<IElementEditService> featureTypeServices;
+ try {
+ featureTypeServices = ElementEditServiceUtils.getEditServiceProvider().getContainedTypeEditServices(eObject, (EReference)feature);
+ } catch (ServiceException e) {
+ e.printStackTrace();
+ return undoableOperations;
+ }
+
+ for(IElementEditService featureTypeService : featureTypeServices) {
+ CreateElementRequest request = new CreateElementRequest(EMFUtils.getTransactionalEditingDomain(objectsToEdit), eObject, (IElementType)featureTypeService.getAdapter(IElementType.class), (EReference)feature);
+ request.setLabel(Messages.bind(Messages.EMFTEReferenceController_CreationOperationMenuLabel, featureTypeService.getDisplayName()));
+ ICommand command = featureTypeService.getEditCommand(request);
+ if(command.canExecute()) {
+ // adds it to the list of command that can be
+ // executed
+ undoableOperations.add(command);
+ }
+ }
+
+ return undoableOperations;
+ } else {
+
+ // IUndoableOperation operation = new FindReferenceCommand(EMFUtils.getTransactionalEditingDomain(objectsToEdit), "Find and Add references", objectsToEdit);
+ IUndoableOperation operation = getFindReferenceCommand(EMFUtils.getTransactionalEditingDomain(objectsToEdit), "Find and Add references", objectsToEdit); //$NON-NLS-1$
+ return Arrays.asList(operation);
+ }
+ }
+
+ /**
+ * Returns the command to find the reference
+ *
+ * @param transactionalEditingDomain
+ * the editing domain
+ * @param string
+ * the name of the command
+ * @param objectsToEdit
+ * the lists of objects to edit
+ * @return
+ * the command to find the reference
+ */
+ public IUndoableOperation getFindReferenceCommand(TransactionalEditingDomain transactionalEditingDomain, String string, List<? extends EObject> objectsToEdit) {
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(transactionalEditingDomain, string);
+ // checks the containment feature
+ EObject eObject = objectsToEdit.get(0);
+ EStructuralFeature feature = getFeatureByName(eObject);
+ if(!(feature instanceof EReference)) {
+ return command;
+ }
+
+ // pops up a window to ask for a new reference
+ Display display = Display.getCurrent();
+ if(display == null && PlatformUI.isWorkbenchRunning()) {
+ display = PlatformUI.getWorkbench().getDisplay();
+ }
+ display = (display != null) ? display : Display.getDefault();
+ EClassifier eclassifier = feature.getEType();
+ Object availableValues = getAvailableValues(eObject);
+ List<?> values = new ArrayList<Object>();
+ if(availableValues instanceof List<?>) {
+ values = (List<?>)availableValues;
+ } else if(availableValues instanceof Object[]) {
+ values = Arrays.asList(availableValues);
+ } else {
+ values = Arrays.asList(availableValues);
+ }
+
+ @SuppressWarnings("unchecked")
+ FeatureEditorDialog dialog = new FeatureEditorDialog(display.getActiveShell(), DisplayUtils.getLabelProvider(), eObject, eclassifier, (List<EObject>)eObject.eGet(feature), Messages.ReferenceEMFModelHandler_Select_Values, values, false, feature.isOrdered(), feature.isUnique());
+ // should select the current value by default
+ if(Dialog.OK == dialog.open()) {
+ @SuppressWarnings("unchecked")
+ List<EObject> currentValues = (List<EObject>)dialog.getResult();
+ SetRequest[] requests = getSetRequest(transactionalEditingDomain, eObject, currentValues);
+ if(requests != null) {
+
+ org.eclipse.papyrus.service.edit.service.IElementEditService provider = org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils.getCommandProvider(eObject);
+ if(provider != null) {
+
+ ICommand editCommand = null;
+ for(SetRequest current : requests) {
+ editCommand = provider.getEditCommand(current);
+
+ if(editCommand != null && editCommand.canExecute()) {
+ command.add(editCommand);
+ }
+ }
+ }
+ }
+ return command;
+ }
+
+ return command;
+ }
+
+ // /**
+ // * Command to create references.
+ // * Two cases:
+ // * - This is a containment reference, should create element.
+ // * - This is a simple reference, should only browse the model to get other elements
+ // */
+ // protected class FindReferenceCommand extends AbstractTransactionalCommand {
+ //
+ // /** list of objects to edit */
+ // protected final List<? extends EObject> objectsToEdit;
+ //
+ // /**
+ // * Creates a new FindReferenceCommand.
+ // *
+ // * @param domain
+ // * editing domain used to create or manipulate elements
+ // * @param label
+ // * the label of the command, used by UI.
+ // * @param objectsToEdit
+ // * the list of objects to edit
+ // */
+ // public FindReferenceCommand(TransactionalEditingDomain domain, String label, List<? extends EObject> objectsToEdit) {
+ // super(domain, label, null);
+ // this.objectsToEdit = objectsToEdit;
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ //
+ // // checks the containment feature
+ // EObject eObject = objectsToEdit.get(0);
+ // EStructuralFeature feature = getFeatureByName(eObject);
+ // if(!(feature instanceof EReference)) {
+ // return CommandResult.newErrorCommandResult("the feature " + getFeatureName() + " is not a reference");
+ // }
+ //
+ // // pops up a window to ask for a new reference
+ // Display display = Display.getCurrent();
+ // if(display == null && PlatformUI.isWorkbenchRunning()) {
+ // display = PlatformUI.getWorkbench().getDisplay();
+ // }
+ // display = (display != null) ? display : Display.getDefault();
+ // EClassifier eclassifier = feature.getEType();
+ // Object availableValues = getAvailableValues(eObject);
+ // List<?> values = new ArrayList<Object>();
+ // if(availableValues instanceof List<?>) {
+ // values = (List<?>)availableValues;
+ // } else if(availableValues instanceof Object[]) {
+ // values = Arrays.asList(availableValues);
+ // } else {
+ // values = Arrays.asList(availableValues);
+ // }
+ //
+ // @SuppressWarnings("unchecked")
+ // FeatureEditorDialog dialog = new FeatureEditorDialog(display.getActiveShell(), DisplayUtils.getLabelProvider(), eObject, eclassifier, (List<EObject>)eObject.eGet(feature), "Select Values", values, false, feature.isOrdered(), feature.isUnique());
+ // // should select the current value by default
+ // if(Dialog.OK == dialog.open()) {
+ // @SuppressWarnings("unchecked")
+ // List<EObject> currentValues = (List<EObject>)dialog.getResult();
+ // eObject.eSet(feature, currentValues);
+ // }
+ // return CommandResult.newOKCommandResult();
+ // }
+ // }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.properties.runtime.modelhandler.emf.IEMFModelHandler#getSetRequest(org.eclipse.emf.transaction.TransactionalEditingDomain,
+ * org.eclipse.emf.ecore.EObject, java.lang.Object)
+ *
+ * @param domain
+ * @param objectToEdit
+ * @param newValue
+ * @return
+ */
+ public SetRequest[] getSetRequest(TransactionalEditingDomain domain, EObject objectToEdit, Object newValue) {
+
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ if(newValue instanceof EObject || newValue == null) {
+ return new SetRequest[]{ new SetRequest(domain, objectToEdit, featureToEdit, newValue) };
+ } else if(newValue instanceof List<?>) {
+ return new SetRequest[]{ new SetRequest(domain, objectToEdit, featureToEdit, newValue) };
+ } else {
+ Activator.log.error("impossible to set the new value", null); //$NON-NLS-1$
+ }
+ return null;
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/ReferenceStereotypeModelHandler.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/ReferenceStereotypeModelHandler.java
index 8d5a5f1f248..a89463a0ec6 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/ReferenceStereotypeModelHandler.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/ReferenceStereotypeModelHandler.java
@@ -11,9 +11,13 @@
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
+import java.util.List;
+
+import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.properties.runtime.Activator;
+import org.eclipse.swt.widgets.Composite;
/**
@@ -57,4 +61,13 @@ public class ReferenceStereotypeModelHandler extends EMFStereotypeFeatureModelHa
public String getId() {
return ID;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<IUndoableOperation> getCreateValueOperations(List<? extends EObject> objectsToEdit, Composite parent) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/StringEMFModelHandler.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/StringEMFModelHandler.java
index 6df6c32c7ab..47b30bd4cfd 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/StringEMFModelHandler.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/StringEMFModelHandler.java
@@ -8,14 +8,24 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Vincent Lorenzo (CEA-LIST) vincent.lorenzo@cea.fr
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
+import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
+import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
+import org.eclipse.swt.widgets.Composite;
/**
@@ -24,7 +34,7 @@ import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropert
public class StringEMFModelHandler extends EMFFeatureModelHandler {
/** ID of this model handler */
- public static final String ID = "String";
+ public static final String ID = "String"; //$NON-NLS-1$
/**
* Creates a new StringEMFModelHandler.
@@ -39,17 +49,38 @@ public class StringEMFModelHandler extends EMFFeatureModelHandler {
/**
* {@inheritDoc}
*/
+ @Override
public void setValueInModel(EObject objectToEdit, Object newValue) {
EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
if(featureToEdit == null) {
return;
}
- objectToEdit.eSet(featureToEdit, newValue);
+
+ // check the type of the feature to set
+ EClassifier type = featureToEdit.getEType();
+ if(type == null) {
+ Activator.log.debug("Impossible to find the type of the feature: " + getFeatureName()); //$NON-NLS-1$
+ } else {
+ if(String.class.isAssignableFrom(type.getInstanceClass())) {
+ objectToEdit.eSet(featureToEdit, newValue);
+ } else if(Integer.TYPE.isAssignableFrom(type.getInstanceClass())) {
+ try {
+ int value = Integer.parseInt(newValue.toString());
+ objectToEdit.eSet(featureToEdit, value);
+ } catch (NumberFormatException e) {
+ Activator.log.debug(newValue + " can not be parsed as an integer"); //$NON-NLS-1$
+ }
+ } else {
+ Activator.log.error("Feature: " + getFeatureName() + ". Impossible to understand the value for the type: " + featureToEdit.getEType().getInstanceClass(), null); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
}
/**
* {@inheritDoc}
*/
+ @Override
public void completeEditorDescriptor(IPropertyEditorDescriptor descriptor, List<? extends EObject> objectToEdit) {
// nothing to do here
}
@@ -60,4 +91,237 @@ public class StringEMFModelHandler extends EMFFeatureModelHandler {
public String getId() {
return ID;
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<IUndoableOperation> getCreateValueOperations(List<? extends EObject> objectsToEdit, Composite parent) {
+ List<IUndoableOperation> operations = new ArrayList<IUndoableOperation>(1);
+ TransactionalEditingDomain editingDomain = EMFUtils.getTransactionalEditingDomain(objectsToEdit);
+ if(editingDomain == null) {
+ Activator.log.error("Impossible during creation operation to find the editing domain for objects: " + objectsToEdit, null); //$NON-NLS-1$
+ return null;
+ }
+ // int indexOfNewValue = NEW_VALUE_NOT_SET_INDEX;
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Create new String Values"); //$NON-NLS-1$
+ for(EObject objectToEdit : objectsToEdit) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ //CreateStringValueOperation operation = new CreateStringValueOperation(editingDomain, "Create new String Value", objectToEdit);
+ IUndoableOperation operation = getCreateStringValueCommand(editingDomain, "Create new String Value", objectToEdit); //$NON-NLS-1$
+ if(operation != null) {
+ command.add(operation);
+ }
+ // if(indexOfNewValue == NEW_VALUE_NOT_SET_INDEX) { // try to update
+ // indexOfNewValue = operation.getIndexOfNewValue();
+ // }
+ }
+
+ operations.add(command.reduce());
+
+ return operations;
+ }
+
+ /**
+ * Returns the command to create a string value
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param string
+ * the command's name
+ * @param objectToEdit
+ * the object to edit
+ * @return
+ * The command to create a string value
+ */
+ protected IUndoableOperation getCreateStringValueCommand(TransactionalEditingDomain editingDomain, String string, EObject objectToEdit) {
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, string);
+ int indexOfNewValue = -2;
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return command;
+ }
+ if(featureToEdit.getUpperBound() == 1) {
+ indexOfNewValue = -1;
+ } else {
+ @SuppressWarnings("unchecked")
+ List<Object> values = new ArrayList<Object>((List<Object>)objectToEdit.eGet(featureToEdit));
+ indexOfNewValue = values.size();
+ }
+
+ // create the value and add it to the feature
+ // if feature = simple valued => set
+ // if feature = multi valued => add at the end
+ Object newValue;
+ if(featureToEdit.getUpperBound() == 1) {
+ newValue = getInitialValue(objectToEdit);
+ } else {
+ @SuppressWarnings("unchecked")
+ List<Object> values = new ArrayList<Object>((List<Object>)objectToEdit.eGet(featureToEdit));
+ values.add(indexOfNewValue, getInitialValue(objectToEdit));
+ newValue = values;
+ }
+ SetRequest[] requests = getSetRequest(editingDomain, objectToEdit, newValue);
+ if(requests != null) {
+
+ org.eclipse.papyrus.service.edit.service.IElementEditService provider = org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils.getCommandProvider(objectToEdit);
+ if(provider != null) {
+
+ ICommand editCommand = null;
+ for(SetRequest current : requests) {
+ editCommand = provider.getEditCommand(current);
+
+ if(editCommand != null && editCommand.canExecute()) {
+ command.add(editCommand);
+ }
+ }
+ }
+ }
+ return command;
+ }
+
+ // /**
+ // * Operation to create a String value for the controlled property
+ // */
+ // protected class CreateStringValueOperation extends AbstractTransactionalCommand {
+ //
+ // /** object to edit */
+ // protected final EObject objectToEdit;
+ //
+ // /** index of the value to add (-1 in case of single valued property) */
+ // private int indexOfNewValue = -2;
+ //
+ // /**
+ // * Initializes me with the editing domain, a label, transaction options, and
+ // * a list of {@link IFile}s that anticipate modifying when I am executed,
+ // * undone or redone.
+ // *
+ // * @param domain
+ // * the editing domain used to modify the model
+ // * @param label
+ // * my user-readable label, should never be <code>null</code>.
+ // * @param objectToEdit
+ // * the {@link EObject} to edit
+ // */
+ // public CreateStringValueOperation(TransactionalEditingDomain domain, String label, EObject objectToEdit) {
+ // super(domain, (label == null) ? "" : label, null);
+ // this.objectToEdit = objectToEdit;
+ //
+ // EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ // if(featureToEdit.getUpperBound() == 1) {
+ // indexOfNewValue = -1;
+ // } else {
+ // @SuppressWarnings("unchecked")
+ // List<Object> values = new ArrayList<Object>((List<Object>)objectToEdit.eGet(featureToEdit));
+ // indexOfNewValue = values.size();
+ // }
+ // }
+ //
+ // /**
+ // * Returns the index at which the value will be added
+ // *
+ // * @return the index at which the value will be added
+ // */
+ // public int getIndexOfNewValue() {
+ // return indexOfNewValue;
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // // create the value and add it to the feature
+ // // if feature = simple valued => set
+ // // if feature = multi valued => add at the end
+ // EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ // if(featureToEdit == null) {
+ // return CommandResult.newErrorCommandResult("Impossible to find the feature " + getFeatureName());
+ // }
+ // Object newValue;
+ // if(featureToEdit.getUpperBound() == 1) {
+ // newValue = getInitialValue(objectToEdit);
+ // } else {
+ // @SuppressWarnings("unchecked")
+ // List<Object> values = new ArrayList<Object>((List<Object>)objectToEdit.eGet(featureToEdit));
+ // values.add(indexOfNewValue, getInitialValue(objectToEdit));
+ // newValue = values;
+ // }
+ // setValueInModel(objectToEdit, newValue);
+ // return CommandResult.newOKCommandResult();
+ // }
+ // }
+
+ /**
+ * Returns the initial value for a new value of the feature
+ *
+ * @param objectToEdit
+ * the object to edit
+ *
+ * @return the initial value, not <code>null</code>
+ */
+ public Object getInitialValue(EObject objectToEdit) {
+ String featureName = getFeatureName();
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit.getUpperBound() == 1) {
+ return featureName;
+ } else {
+ for(int suffix = 0; suffix < 1000; suffix++) {
+ String tmpName = featureName + suffix;
+ boolean found = false;
+ @SuppressWarnings("unchecked")
+ List<Object> values = new ArrayList<Object>((List<Object>)objectToEdit.eGet(featureToEdit));
+ for(Object value : values) {
+ if(tmpName.equals(value)) {
+ found = true;
+ }
+ }
+ if(!found) {
+ return tmpName;
+ }
+ }
+ return featureName;
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.properties.runtime.modelhandler.emf.IEMFModelHandler#getSetRequest(org.eclipse.emf.transaction.TransactionalEditingDomain,
+ * org.eclipse.emf.ecore.EObject, java.lang.Object)
+ *
+ * @param domain
+ * @param objectToEdit
+ * @param newValue
+ * @return
+ */
+ public SetRequest[] getSetRequest(TransactionalEditingDomain domain, EObject objectToEdit, Object newValue) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+
+ // check the type of the feature to set
+ EClassifier type = featureToEdit.getEType();
+ if(type == null) {
+ Activator.log.debug("Impossible to find the type of the feature: " + getFeatureName()); //$NON-NLS-1$
+ return null;
+ } else {
+ if(String.class.isAssignableFrom(type.getInstanceClass())) {
+ return new SetRequest[]{ new SetRequest(domain, objectToEdit, featureToEdit, newValue) };
+ } else if(Integer.TYPE.isAssignableFrom(type.getInstanceClass())) {
+ try {
+ int value = Integer.parseInt(newValue.toString());
+ return new SetRequest[]{ new SetRequest(domain, objectToEdit, featureToEdit, value) };
+ } catch (NumberFormatException e) {
+ Activator.log.debug(newValue + " can not be parsed as an integer"); //$NON-NLS-1$
+ }
+ } else {
+ Activator.log.error("Feature: " + getFeatureName() + ". Impossible to understand the value for the type: " + featureToEdit.getEType().getInstanceClass(), null); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ return null;
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/StringStereotypeModelHandler.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/StringStereotypeModelHandler.java
index befd5c32a86..70f4977ca3a 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/StringStereotypeModelHandler.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/StringStereotypeModelHandler.java
@@ -11,6 +11,23 @@
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
+import org.eclipse.papyrus.properties.runtime.Activator;
+import org.eclipse.swt.widgets.Composite;
+
/**
* Model Handler for String-typed stereotypes properties
@@ -39,4 +56,139 @@ public class StringStereotypeModelHandler extends EMFStereotypeFeatureModelHandl
return ID;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<IUndoableOperation> getCreateValueOperations(List<? extends EObject> objectsToEdit, Composite parent) {
+ List<IUndoableOperation> operations = new ArrayList<IUndoableOperation>(1);
+ TransactionalEditingDomain editingDomain = EMFUtils.getTransactionalEditingDomain(objectsToEdit);
+ if(editingDomain == null) {
+ Activator.log.error("Impossible during creation operation to find the editing domain for objects: " + objectsToEdit, null);
+ return null;
+ }
+ int indexOfNewValue = NEW_VALUE_NOT_SET_INDEX;
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Create new String Values");
+ for(EObject objectToEdit : objectsToEdit) {
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return null;
+ }
+ CreateStringStererotypeValueOperation operation = new CreateStringStererotypeValueOperation(editingDomain, "Create new String Value", objectToEdit);
+ if(operation != null) {
+ command.add(operation);
+ }
+ if(indexOfNewValue == NEW_VALUE_NOT_SET_INDEX) { // try to update
+ indexOfNewValue = operation.getIndexOfNewValue();
+ }
+ }
+
+ operations.add(command.reduce());
+
+ return operations;
+ }
+
+ /**
+ * Operation to create a String value for the controlled property of a stereotype
+ */
+ protected class CreateStringStererotypeValueOperation extends AbstractTransactionalCommand {
+
+ /** object to edit */
+ protected final EObject objectToEdit;
+
+ /** index of the value to add (-1 in case of single valued property) */
+ private int indexOfNewValue = -2;
+
+ /**
+ * Initializes me with the editing domain, a label, transaction options, and
+ * a list of {@link IFile}s that anticipate modifying when I am executed,
+ * undone or redone.
+ *
+ * @param domain
+ * the editing domain used to modify the model
+ * @param label
+ * my user-readable label, should never be <code>null</code>.
+ * @param objectToEdit
+ * the {@link EObject} to edit
+ */
+ public CreateStringStererotypeValueOperation(TransactionalEditingDomain domain, String label, EObject objectToEdit) {
+ super(domain, (label == null) ? "" : label, null);
+ this.objectToEdit = objectToEdit;
+
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit.getUpperBound() == 1) {
+ indexOfNewValue = -1;
+ } else {
+ @SuppressWarnings("unchecked")
+ List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ indexOfNewValue = values.size();
+ }
+ }
+
+ /**
+ * Returns the index at which the value will be added
+ *
+ * @return the index at which the value will be added
+ */
+ public int getIndexOfNewValue() {
+ return indexOfNewValue;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // create the value and add it to the feature
+ // if feature = simple valued => set
+ // if feature = multi valued => add at the end
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit == null) {
+ return CommandResult.newErrorCommandResult("Impossible to find the feature " + getFeatureName());
+ }
+ Object newValue;
+ if(featureToEdit.getUpperBound() == 1) {
+ newValue = getInitialValue(objectToEdit);
+ } else {
+ @SuppressWarnings("unchecked")
+ List<Object> values = (List<Object>)getValueToEdit(objectToEdit);
+ values.add(indexOfNewValue, getInitialValue(objectToEdit));
+ newValue = values;
+ }
+ setValueInModel(objectToEdit, newValue);
+ return CommandResult.newOKCommandResult();
+ }
+ }
+
+ /**
+ * Returns the initial value for a new value of the feature
+ *
+ * @param objectToEdit
+ * the object to edit
+ *
+ * @return the initial value, not <code>null</code>
+ */
+ public Object getInitialValue(EObject objectToEdit) {
+ String featureName = getFeatureName();
+ EStructuralFeature featureToEdit = getFeatureByName(objectToEdit);
+ if(featureToEdit.getUpperBound() == 1) {
+ return featureName;
+ } else {
+ for(int suffix = 0; suffix < 1000; suffix++) {
+ String tmpName = featureName + suffix;
+ boolean found = false;
+ @SuppressWarnings("unchecked")
+ List<Object> values = new ArrayList<Object>((List<Object>)getValueToEdit(objectToEdit));
+ for(Object value : values) {
+ if(tmpName.equals(value)) {
+ found = true;
+ }
+ }
+ if(!found) {
+ return tmpName;
+ }
+ }
+ return featureName;
+ }
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/TransactionUtil.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/TransactionUtil.java
new file mode 100644
index 00000000000..fd8b0f71007
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/modelhandler/emf/TransactionUtil.java
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.modelhandler.emf;
+
+import org.eclipse.emf.transaction.Transaction;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.impl.InternalTransaction;
+import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
+
+
+/**
+ * Utility class for transactions
+ */
+public class TransactionUtil {
+
+ /**
+ * Checks if the current active transaction is a Write transaction or not
+ * unprotected transaction are not considered write transaction
+ *
+ * @param internalEditingDomain
+ * the current internal editing domain, on which transaction are run
+ * @param includeUnprotected
+ * <code>boolean</code> value that if <code>true</code> will consider unprotected
+ * transactions when determining if a write transaction is in progress.
+ * @param otherThread
+ * <code>boolean</code> value that if <code>true</code>, will verify whether there is
+ * an active transaction only when on a different thread then the caller. This is useful to determine if a
+ * deadlock scenario will occur.
+ * @return <code>true</code> if the current active transaction is a write transaction
+ */
+ public static boolean isReadTransactionInProgress(TransactionalEditingDomain internalEditingDomain, boolean includeUnprotected, boolean otherThread) {
+ if(!(internalEditingDomain instanceof InternalTransactionalEditingDomain)) {
+ return false;
+ }
+
+ InternalTransaction transaction = ((InternalTransactionalEditingDomain)internalEditingDomain).getActiveTransaction();
+ if(transaction != null && transaction.isReadOnly()) {
+ if(includeUnprotected) {
+ Object unprotectedMode = transaction.getOptions().get(Transaction.OPTION_UNPROTECTED);
+ if(Boolean.FALSE.equals(unprotectedMode)) {
+ return false;
+ }
+ }
+
+ if(otherThread && Thread.currentThread() != transaction.getOwner())
+ return true;
+ else if(!otherThread) {
+ return true;
+ }
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/AbstractTablePropertyEditor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/AbstractTablePropertyEditor.java
new file mode 100644
index 00000000000..0565622d780
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/AbstractTablePropertyEditor.java
@@ -0,0 +1,497 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.propertyeditor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.core.commands.operations.OperationHistoryFactory;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.layout.TableColumnLayout;
+import org.eclipse.jface.viewers.ColumnWeightData;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.properties.runtime.Activator;
+import org.eclipse.papyrus.properties.runtime.controller.ILabelProviderController;
+import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.PlatformUI;
+
+
+/**
+ * Abstract class for all table editors
+ */
+public abstract class AbstractTablePropertyEditor extends AbstractPropertyEditor {
+
+ /** main composite created by this property editor */
+ protected Composite composite;
+
+ /** button to add a reference or modify existing one */
+ protected Button addButton;
+
+ /** button to remove reference */
+ protected Button removeButton;
+
+ /** table area that displays the values */
+ protected Table table;
+
+ /** viewer on the previous table */
+ protected TableViewer viewer;
+
+ /** current Value in the editor */
+ protected List<Object> currentValue;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Composite createContent(Composite parent) {
+ composite = getWidgetFactory().createComposite(parent, SWT.NONE);
+ int columnNu = getColumnNumber();
+ GridLayout layout = new GridLayout(columnNu, false);
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+ composite.setLayout(layout);
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
+ composite.setLayoutData(data);
+
+ // creates label. No TOP/DOWN/etc. position, always on top
+ createLabel(composite);
+
+ if(!getIsReadOnly()) {
+ // create Button area
+ addButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
+ addButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Add_12x12.gif")));
+ data = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ addButton.setLayoutData(data);
+ addButton.addMouseListener(new MouseListener() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseUp(MouseEvent e) {
+ performAddButtonPressed();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseDown(MouseEvent e) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseDoubleClick(MouseEvent e) {
+ }
+ });
+
+ removeButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
+ removeButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Delete_12x12.gif")));
+ data = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ removeButton.setLayoutData(data);
+ removeButton.addMouseListener(new MouseListener() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseUp(MouseEvent e) {
+ performRemoveButtonPressed();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseDown(MouseEvent e) {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseDoubleClick(MouseEvent e) {
+
+ }
+ });
+
+ if(getController().canMoveValues(new ArrayList<Integer>(), 0)) { // only checks if virtual elements can be moved, not real move, so a 0-delta is fine
+ Button upButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
+ upButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Up_12x12.gif")));
+ data = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ upButton.setLayoutData(data);
+ upButton.addMouseListener(new MouseListener() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseUp(MouseEvent e) {
+ performUpButtonPressed();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseDown(MouseEvent e) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseDoubleClick(MouseEvent e) {
+ }
+ });
+
+ Button downButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
+ downButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Down_12x12.gif")));
+ data = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ downButton.setLayoutData(data);
+ downButton.addMouseListener(new MouseListener() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseUp(MouseEvent e) {
+ performDownButtonPressed();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseDown(MouseEvent e) {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void mouseDoubleClick(MouseEvent e) {
+ }
+ });
+ }
+ }
+
+ Composite tableComposite = getWidgetFactory().createComposite(composite, SWT.NONE);
+ data = new GridData(SWT.FILL, SWT.FILL, true, true, columnNu, 1);
+ data.heightHint = 80;
+ data.widthHint = 200;
+ tableComposite.setLayoutData(data);
+ // creates table for the display of references
+ table = new Table(tableComposite, SWT.BORDER | SWT.MULTI);
+ viewer = new TableViewer(table);
+ TableColumnLayout tableLayout = new TableColumnLayout();
+ tableComposite.setLayout(tableLayout);
+ final TableViewerColumn tableViewerColumn = new TableViewerColumn(viewer, SWT.NONE);
+ TableColumn tableColumn = tableViewerColumn.getColumn();
+ tableLayout.setColumnData(tableColumn, new ColumnWeightData(100, 0, true));
+ tableColumn.setText("Value");
+ tableViewerColumn.setEditingSupport(createEditingSupport());
+ viewer.setUseHashlookup(true);
+ viewer.setContentProvider(new IStructuredContentProvider() {
+
+ /**
+ * {@inheritDoc}
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void dispose() {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object[] getElements(Object inputElement) {
+ if(inputElement instanceof List<?>) {
+ return ((List<?>)inputElement).toArray();
+ }
+ return new Object[0];
+ }
+ });
+
+ if(getController() instanceof ILabelProviderController) {
+ viewer.setLabelProvider(((ILabelProviderController)getController()).getEditorLabelProvider());
+ } else {
+ viewer.setLabelProvider(new LabelProvider());
+ }
+ viewer.getControl().setToolTipText(getTooltipText());
+ return composite;
+ }
+
+ /**
+ * Creates the editing support for the table viewer
+ *
+ * @return the editing support for the table viewer
+ */
+ protected abstract EditingSupport createEditingSupport();
+
+ /**
+ * performs the action handled by the "Add" button
+ */
+ protected void performAddButtonPressed() {
+ // pops up a window to ask for a new reference
+ Display display = Display.getCurrent();
+ if(display == null && PlatformUI.isWorkbenchRunning()) {
+ display = PlatformUI.getWorkbench().getDisplay();
+ }
+ display = (display != null) ? display : Display.getDefault();
+
+ List<IUndoableOperation> operations = getController().getCreateValueOperations();
+
+ // either one or more options
+ // in case there are several, open a sub-menu
+ // otherwise, execute the operation
+ if(operations == null || operations.isEmpty()) {
+ return;
+ }
+ if(operations.size() == 1) {
+ try {
+ OperationHistoryFactory.getOperationHistory().execute(operations.get(0), new NullProgressMonitor(), null);
+ } catch (ExecutionException e1) {
+ Activator.log.error(e1);
+ }
+ } else {
+ Menu menu = new Menu(addButton);
+ for(final IUndoableOperation operation : operations) {
+ MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setText(operation.getLabel());
+ item.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ try {
+ OperationHistoryFactory.getOperationHistory().execute(operation, new NullProgressMonitor(), null);
+ } catch (ExecutionException e1) {
+ Activator.log.error(e1);
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+
+ }
+ });
+ }
+ menu.setVisible(true);
+ }
+
+ // now select the new value added. Assumes this is the last one
+ int lastIndex = table.getItemCount() - 1;
+ table.select(lastIndex);
+
+ }
+
+ /**
+ * performs the action handled by the "Remove" button
+ */
+ protected void performRemoveButtonPressed() {
+ // use selection to remove element
+ // retrieve selected element(s)
+ IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
+ if(selection == null || selection.isEmpty()) {
+ // nothing selected.
+ return;
+ }
+
+ int[] selectedIndexes = table.getSelectionIndices();
+ Arrays.sort(selectedIndexes);
+ List<Integer> indexes = new ArrayList<Integer>();
+ for(int i = selectedIndexes.length - 1; i >= 0; i--) {
+ indexes.add(selectedIndexes[i]);
+ }
+ IUndoableOperation operation = getController().getDeleteValueOperation(indexes);
+ if(operation != null && operation.canExecute()) {
+ try {
+ OperationHistoryFactory.getOperationHistory().execute(operation, new NullProgressMonitor(), null);
+ } catch (ExecutionException e1) {
+ Activator.log.error(e1);
+ }
+ }
+ }
+
+ /**
+ * performs the action handled by the "Up" button
+ */
+ protected void performUpButtonPressed() {
+ int[] selectionIndices = table.getSelectionIndices();
+ final List<Integer> selectionList = new ArrayList<Integer>();
+ final List<Integer> newSelectionList = new ArrayList<Integer>();
+ for(int i : selectionIndices) {
+ selectionList.add(i);
+ newSelectionList.add(i - 1);
+ }
+ IUndoableOperation moveOperation = getController().getMoveCurrentValuesOperation(selectionList, -1);
+ if(moveOperation != null && moveOperation.canExecute()) {
+ try {
+ OperationHistoryFactory.getOperationHistory().execute(moveOperation, new NullProgressMonitor(), null);
+ // try to restore selection in the view
+ int[] newSelection = new int[newSelectionList.size()];
+ for(int i = 0; i < newSelectionList.size(); i++) {
+ newSelection[i] = newSelectionList.get(i);
+ }
+ table.select(newSelection);
+ } catch (ExecutionException e1) {
+ Activator.log.error(e1);
+ }
+ }
+ }
+
+ /**
+ * performs the action handled by the "Down" button
+ */
+ protected void performDownButtonPressed() {
+ // use selection to remove element
+ // retrieve selected element(s)
+ int[] selectionIndices = table.getSelectionIndices();
+ final List<Integer> selectionList = new ArrayList<Integer>();
+ final List<Integer> newSelectionList = new ArrayList<Integer>();
+ for(int i : selectionIndices) {
+ selectionList.add(i);
+ newSelectionList.add(i + 1);
+ }
+ IUndoableOperation moveOperation = getController().getMoveCurrentValuesOperation(selectionList, +1);
+ if(moveOperation != null && moveOperation.canExecute()) {
+ try {
+ OperationHistoryFactory.getOperationHistory().execute(moveOperation, new NullProgressMonitor(), null);
+ // try to restore selection in the view
+ int[] newSelection = new int[newSelectionList.size()];
+ for(int i = 0; i < newSelectionList.size(); i++) {
+ newSelection[i] = newSelectionList.get(i);
+ }
+ table.select(newSelection);
+ } catch (ExecutionException e1) {
+ Activator.log.error(e1);
+ }
+ }
+ }
+
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Control createLabel(Composite parent) {
+ GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
+ return createLabel(parent, data);
+ }
+
+ /**
+ * Returns the number of column for the composite
+ *
+ * @return the number of column for the composite
+ */
+ protected int getColumnNumber() {
+ if(getIsReadOnly()) {
+ return 1;
+ }
+ if(getController().canMoveValues(new ArrayList<Integer>(), 0)) {
+ return 5;
+ }
+ return 3;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void handleContentChanged() {
+ // this should tells the controller that the input has to be applied to the model
+ getController().updateModel();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IStatus init(IPropertyEditorDescriptor descriptor) {
+ setDescriptor(descriptor);
+ setTooltipText(descriptor.getTooltipText());
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<Object> getValue() {
+ return currentValue;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void setValue(Object valueToEdit) {
+ if(!isValid(table)) {
+ return;
+ }
+ if(valueToEdit instanceof List<?>) {
+ currentValue = (List<Object>)valueToEdit;
+ } else if(valueToEdit == null) {
+ currentValue = null;
+ } else {
+ Activator.log.error(valueToEdit + " is not a list of Object for current table: " + getDescriptor().getLabel(), null);
+ }
+ viewer.setInput((currentValue != null) ? currentValue : Collections.emptyList());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void dispose() {
+ if(isValid(composite)) {
+ composite.dispose();
+ composite = null;
+ setController(null);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isDisposed() {
+ if(composite == null) {
+ return true;
+ }
+ return composite.isDisposed();
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultiplePrimitiveTypedPropertyEditor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultiplePrimitiveTypedPropertyEditor.java
new file mode 100644
index 00000000000..d33186de1e5
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultiplePrimitiveTypedPropertyEditor.java
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.propertyeditor;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.core.commands.operations.OperationHistoryFactory;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ColumnViewer;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.papyrus.properties.runtime.Activator;
+
+
+/**
+ * Property editor for Primitive typed-properties
+ */
+public class MultiplePrimitiveTypedPropertyEditor extends AbstractTablePropertyEditor {
+
+ /** id of this editor */
+ public static final String ID = "org.eclipse.papyrus.properties.runtime.multiplePrimitiveTypedPropertyEditor";
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected EditingSupport createEditingSupport() {
+ return new StringEditingSupport(viewer);
+ }
+
+ /**
+ * Editing support for the viewer
+ */
+ protected class StringEditingSupport extends EditingSupport {
+
+ /**
+ * Creates a new StringEditingSupport.
+ *
+ * @param viewer
+ * the viewer in which this suport is added
+ */
+ public StringEditingSupport(ColumnViewer viewer) {
+ super(viewer);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ return new TextCellEditor(table);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Object getValue(Object element) {
+ return element;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void setValue(Object element, Object value) {
+ // retrieve the index of the element in the list of values
+ int index = viewer.getTable().getSelectionIndex();
+ // retrieves the operation to set the value
+ IUndoableOperation operation = getController().getEditValueOperation(index, table, value);
+ if(operation != null && operation.canExecute()) {
+ try {
+ OperationHistoryFactory.getOperationHistory().execute(operation, new NullProgressMonitor(), null);
+ } catch (ExecutionException e) {
+ Activator.log.error(e);
+ }
+ }
+ }
+
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultiplePrimitiveTypedPropertyEditorValidator.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultiplePrimitiveTypedPropertyEditorValidator.java
new file mode 100644
index 00000000000..5a355f9488b
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultiplePrimitiveTypedPropertyEditorValidator.java
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.propertyeditor;
+
+/**
+ * Validator for {@link MultiplePrimitiveTypedPropertyEditor}
+ */
+public class MultiplePrimitiveTypedPropertyEditorValidator implements IPropertyEditorTypeValidator {
+
+ /** editor fo which this validator is installed */
+ protected AbstractPropertyEditor editor;
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isValidForValue(Object valueToEdit) {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setPropertyEditor(AbstractPropertyEditor editor) {
+ this.editor = editor;
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultipleReferencePropertyEditor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultipleReferencePropertyEditor.java
index bdc78d15f09..8952f5c628a 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultipleReferencePropertyEditor.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultipleReferencePropertyEditor.java
@@ -11,347 +11,270 @@
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.propertyeditor;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.operations.IUndoableOperation;
-import org.eclipse.core.commands.operations.OperationHistoryFactory;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EClassifier;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.ui.celleditor.FeatureEditorDialog;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.properties.runtime.Activator;
-import org.eclipse.papyrus.properties.runtime.controller.EMFTStructuralFeatureController;
+import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.papyrus.properties.runtime.controller.IBoundedValuesController;
-import org.eclipse.papyrus.properties.runtime.controller.IWizardPropertyEditorController;
import org.eclipse.papyrus.properties.runtime.controller.PropertyEditorController;
-import org.eclipse.papyrus.properties.runtime.modelhandler.emf.EMFFeatureModelHandler;
-import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.ui.PlatformUI;
/**
* Property editor for references that have multiplicity [n..*]
*/
-public class MultipleReferencePropertyEditor extends AbstractPropertyEditor {
+public class MultipleReferencePropertyEditor extends AbstractTablePropertyEditor {
/** id of this editor */
public static final String ID = "org.eclipse.papyrus.properties.runtime.multipleReferencePropertyEditor";
- /** main composite created by this property editor */
- protected Composite composite;
-
- /** button to add a reference or modify existing one */
- protected Button addButton;
-
- /** button to remove reference */
- protected Button removeButton;
-
- /** table area that displays the reference name or toString */
- protected Table referenceArea;
-
- /** table area that displays the reference name or toString */
- protected TableViewer referencesViewer;
-
- /** current Value */
- protected List<EObject> currentValue;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Composite createContent(Composite parent) {
- composite = getWidgetFactory().createComposite(parent, SWT.NONE);
- int columnNu = getColumnNumber();
- GridLayout layout = new GridLayout(columnNu, false);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- composite.setLayout(layout);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
- composite.setLayoutData(data);
-
- // creates label. No TOP/DOWN/etc. position, always on top
- createLabel(composite);
-
- if(!getIsReadOnly()) {
- // create Button area
- addButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
- addButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Add_12x12.gif")));
- data = new GridData(SWT.FILL, SWT.CENTER, false, false);
- addButton.setLayoutData(data);
- addButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public void mouseUp(MouseEvent e) {
- // pops up a window to ask for a new reference
- Display display = Display.getCurrent();
- if(display == null && PlatformUI.isWorkbenchRunning()) {
- display = PlatformUI.getWorkbench().getDisplay();
- }
- display = (display != null) ? display : Display.getDefault();
-
- // FIXME: specific part to use with EMF properties... should be moved inside the controller ?!
- EObject eObject = ((EMFTStructuralFeatureController)getController()).getObjectsToEdit().get(0);
- EMFFeatureModelHandler handler = (EMFFeatureModelHandler)((EMFTStructuralFeatureController)getController()).getModelHandler();
- EStructuralFeature feature = handler.getFeatureByName(eObject);
- EClassifier eclassifier = feature.getEType();
- Object availableValues = ((IBoundedValuesController)getController()).getAvailableValues();
- List<?> values = new ArrayList<Object>();
- if(availableValues instanceof List<?>) {
- values = (List<?>)availableValues;
- } else if(availableValues instanceof Object[]) {
- values = Arrays.asList(availableValues);
- } else {
- values = Arrays.asList(availableValues);
- }
- FeatureEditorDialog dialog = new FeatureEditorDialog(display.getActiveShell(), ((IBoundedValuesController)getController()).getBrowserLabelProvider(), eObject, eclassifier, getValue(), "Select " + getController().getPropertyEditor().getDescriptor().getLabel(), values, false, feature.isOrdered(), feature.isUnique());
- // should select the current value by default
- if(Dialog.OK == dialog.open()) {
- currentValue = (List<EObject>)dialog.getResult();
- // now, apply the new value
- getController().updateModel();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
- });
-
- removeButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
- removeButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Delete_12x12.gif")));
- data = new GridData(SWT.FILL, SWT.CENTER, false, false);
- removeButton.setLayoutData(data);
- removeButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- public void mouseUp(MouseEvent e) {
- if(!(getController() instanceof IWizardPropertyEditorController)) {
- return;
- }
- // use selection to remove element
- // retrieve selected element(s)
- IStructuredSelection selection = (IStructuredSelection)referencesViewer.getSelection();
- if(selection == null || selection.isEmpty()) {
- // nothing selected.
- return;
- }
-
- // copy current value
- List<EObject> values = new ArrayList<EObject>(currentValue);
- // remove selected elements from values
- values.removeAll(selection.toList());
-
- currentValue = values;
- getController().updateModel();
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
-
- }
- });
-
- if(((IBoundedValuesController)getController()).canMoveValues()) {
- Button upButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
- upButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Up_12x12.gif")));
- data = new GridData(SWT.FILL, SWT.CENTER, false, false);
- upButton.setLayoutData(data);
- upButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- public void mouseUp(MouseEvent e) {
- // use selection to remove element
- // retrieve selected element(s)
- IStructuredSelection selection = (IStructuredSelection)referencesViewer.getSelection();
- if(selection == null || selection.isEmpty()) {
- // nothing selected.
- return;
- }
- @SuppressWarnings("unchecked")
- List<Object> selectedObjects = selection.toList();
- IUndoableOperation moveOperation = ((IBoundedValuesController)getController()).getMoveCurrentValuesOperation(selectedObjects, -1);
- if(moveOperation != null && moveOperation.canExecute()) {
- try {
- OperationHistoryFactory.getOperationHistory().execute(moveOperation, new NullProgressMonitor(), null);
- } catch (ExecutionException e1) {
- Activator.log.error(e1);
- } finally {
- // try to restore selection in the view
- referencesViewer.setSelection(selection, true);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
- });
-
- Button downButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
- downButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Down_12x12.gif")));
- data = new GridData(SWT.FILL, SWT.CENTER, false, false);
- downButton.setLayoutData(data);
- downButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- public void mouseUp(MouseEvent e) {
- // use selection to remove element
- // retrieve selected element(s)
- IStructuredSelection selection = (IStructuredSelection)referencesViewer.getSelection();
- if(selection == null || selection.isEmpty()) {
- // nothing selected.
- return;
- }
- @SuppressWarnings("unchecked")
- List<Object> selectedObjects = selection.toList();
- IUndoableOperation moveOperation = ((IBoundedValuesController)getController()).getMoveCurrentValuesOperation(selectedObjects, +1);
- if(moveOperation != null && moveOperation.canExecute()) {
- try {
- OperationHistoryFactory.getOperationHistory().execute(moveOperation, new NullProgressMonitor(), null);
- } catch (ExecutionException e1) {
- Activator.log.error(e1);
- } finally {
- // try to restore selection in the view
- referencesViewer.setSelection(selection, true);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
- });
- }
- }
-
- // creates table for the display of references
- referenceArea = new Table(composite, SWT.BORDER | SWT.MULTI);
- data = new GridData(SWT.FILL, SWT.FILL, true, true, columnNu, 1);
- data.heightHint = 80;
- referenceArea.setLayoutData(data);
- referencesViewer = new TableViewer(referenceArea);
- referencesViewer.setContentProvider(new IStructuredContentProvider() {
-
- /**
- * {@inheritDoc}
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getElements(Object inputElement) {
- if(inputElement instanceof List<?>) {
- return ((List<?>)inputElement).toArray();
- }
- return new Object[0];
- }
- });
- referencesViewer.setLabelProvider(((IBoundedValuesController)getController()).getEditorLabelProvider());
-
- referencesViewer.getControl().setToolTipText(getTooltipText());
-
- return composite;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Control createLabel(Composite parent) {
- GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
- return createLabel(parent, data);
- }
-
- /**
- * Returns the number of column for the composite
- *
- * @return the number of column for the composite
- */
- protected int getColumnNumber() {
- if(getIsReadOnly()) {
- return 1;
- }
- if(((IBoundedValuesController)getController()).canMoveValues()) {
- return 5;
- }
- return 3;
- }
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public Composite createContent(Composite parent) {
+ // composite = getWidgetFactory().createComposite(parent, SWT.NONE);
+ // int columnNu = getColumnNumber();
+ // GridLayout layout = new GridLayout(columnNu, false);
+ // layout.marginHeight = 0;
+ // layout.marginWidth = 0;
+ // composite.setLayout(layout);
+ // GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
+ // composite.setLayoutData(data);
+ //
+ // // creates label. No TOP/DOWN/etc. position, always on top
+ // createLabel(composite);
+ //
+ // if(!getIsReadOnly()) {
+ // // create Button area
+ // addButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
+ // addButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Add_12x12.gif")));
+ // data = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ // addButton.setLayoutData(data);
+ // addButton.addMouseListener(new MouseListener() {
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @SuppressWarnings("unchecked")
+ // public void mouseUp(MouseEvent e) {
+ // PER
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseDown(MouseEvent e) {
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseDoubleClick(MouseEvent e) {
+ // }
+ // });
+ //
+ // removeButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
+ // removeButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Delete_12x12.gif")));
+ // data = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ // removeButton.setLayoutData(data);
+ // removeButton.addMouseListener(new MouseListener() {
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseUp(MouseEvent e) {
+ // if(!(getController() instanceof IWizardPropertyEditorController)) {
+ // return;
+ // }
+ // // use selection to remove element
+ // // retrieve selected element(s)
+ // IStructuredSelection selection = (IStructuredSelection)referencesViewer.getSelection();
+ // if(selection == null || selection.isEmpty()) {
+ // // nothing selected.
+ // return;
+ // }
+ //
+ // // copy current value
+ // List<EObject> values = new ArrayList<EObject>(currentValue);
+ // // remove selected elements from values
+ // values.removeAll(selection.toList());
+ //
+ // currentValue = values;
+ // getController().updateModel();
+ //
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseDown(MouseEvent e) {
+ //
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseDoubleClick(MouseEvent e) {
+ //
+ // }
+ // });
+ //
+ // if(getController().canMoveValues(new ArrayList<Integer>(), 0)) { // only checks if elements can be moved, not real move, so a 0-delta is fine
+ // Button upButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
+ // upButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Up_12x12.gif")));
+ // data = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ // upButton.setLayoutData(data);
+ // upButton.addMouseListener(new MouseListener() {
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseUp(MouseEvent e) {
+ // int[] selectionIndices = referencesViewer.getTable().getSelectionIndices();
+ // final List<Integer> selectionList = new ArrayList<Integer>();
+ // final List<Integer> newSelectionList = new ArrayList<Integer>();
+ // for(int i : selectionIndices) {
+ // selectionList.add(i);
+ // newSelectionList.add(i - 1);
+ // }
+ // IUndoableOperation moveOperation = getController().getMoveCurrentValuesOperation(selectionList, -1);
+ // if(moveOperation != null && moveOperation.canExecute()) {
+ // try {
+ // OperationHistoryFactory.getOperationHistory().execute(moveOperation, new NullProgressMonitor(), null);
+ // // try to restore selection in the view
+ // int[] newSelection = new int[newSelectionList.size()];
+ // for(int i = 0; i < newSelectionList.size(); i++) {
+ // newSelection[i] = newSelectionList.get(i);
+ // }
+ // referencesViewer.getTable().select(newSelection);
+ // } catch (ExecutionException e1) {
+ // Activator.log.error(e1);
+ // }
+ // }
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseDown(MouseEvent e) {
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseDoubleClick(MouseEvent e) {
+ // }
+ // });
+ //
+ // Button downButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
+ // downButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Down_12x12.gif")));
+ // data = new GridData(SWT.FILL, SWT.CENTER, false, false);
+ // downButton.setLayoutData(data);
+ // downButton.addMouseListener(new MouseListener() {
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseUp(MouseEvent e) {
+ // // use selection to remove element
+ // // retrieve selected element(s)
+ // int[] selectionIndices = referencesViewer.getTable().getSelectionIndices();
+ // final List<Integer> selectionList = new ArrayList<Integer>();
+ // final List<Integer> newSelectionList = new ArrayList<Integer>();
+ // for(int i : selectionIndices) {
+ // selectionList.add(i);
+ // newSelectionList.add(i + 1);
+ // }
+ // IUndoableOperation moveOperation = getController().getMoveCurrentValuesOperation(selectionList, +1);
+ // if(moveOperation != null && moveOperation.canExecute()) {
+ // try {
+ // OperationHistoryFactory.getOperationHistory().execute(moveOperation, new NullProgressMonitor(), null);
+ // // try to restore selection in the view
+ // int[] newSelection = new int[newSelectionList.size()];
+ // for(int i = 0; i < newSelectionList.size(); i++) {
+ // newSelection[i] = newSelectionList.get(i);
+ // }
+ // referencesViewer.getTable().select(newSelection);
+ // } catch (ExecutionException e1) {
+ // Activator.log.error(e1);
+ // }
+ // }
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseDown(MouseEvent e) {
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void mouseDoubleClick(MouseEvent e) {
+ // }
+ // });
+ // }
+ // }
+ //
+ // // creates table for the display of references
+ // referenceArea = new Table(composite, SWT.BORDER | SWT.MULTI);
+ // data = new GridData(SWT.FILL, SWT.FILL, true, true, columnNu, 1);
+ // data.heightHint = 80;
+ // referenceArea.setLayoutData(data);
+ // referencesViewer = new TableViewer(referenceArea);
+ // referencesViewer.setContentProvider(new IStructuredContentProvider() {
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ //
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public void dispose() {
+ //
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // public Object[] getElements(Object inputElement) {
+ // if(inputElement instanceof List<?>) {
+ // return ((List<?>)inputElement).toArray();
+ // }
+ // return new Object[0];
+ // }
+ // });
+ // referencesViewer.setLabelProvider(((IBoundedValuesController)getController()).getEditorLabelProvider());
+ //
+ // referencesViewer.getControl().setToolTipText(getTooltipText());
+ //
+ // return composite;
+ // }
+
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected Control createLabel(Composite parent) {
+ // GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
+ // return createLabel(parent, data);
+ // }
+ //
+ // /**
+ // * Returns the number of column for the composite
+ // *
+ // * @return the number of column for the composite
+ // */
+ // protected int getColumnNumber() {
+ // if(getIsReadOnly()) {
+ // return 1;
+ // }
+ // if(getController().canMoveValues(new ArrayList<Integer>(), 0)) {
+ // return 5;
+ // }
+ // return 3;
+ // }
/**
* {@inheritDoc}
@@ -366,71 +289,79 @@ public class MultipleReferencePropertyEditor extends AbstractPropertyEditor {
* {@inheritDoc}
*/
@Override
- public void handleContentChanged() {
- // this should tells the controller that the input has to be applied to the model
- getController().updateModel();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public IStatus init(IPropertyEditorDescriptor descriptor) {
- setDescriptor(descriptor);
- setTooltipText(descriptor.getTooltipText());
- return Status.OK_STATUS;
+ protected EditingSupport createEditingSupport() {
+ return null;
}
- /**
- * {@inheritDoc}
- */
- @Override
- public List<EObject> getValue() {
- if(isValid(referenceArea)) {
- return currentValue;
- } else {
- Activator.log.error("trying to read the value of the reference area whereas the combo is disposed", null);
- }
- return Collections.emptyList();
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- @Override
- public void setValue(Object valueToEdit) {
- if(!isValid(referenceArea)) {
- return;
- }
- if(valueToEdit instanceof EList<?>) {
- currentValue = (EList<EObject>)valueToEdit;
- } else {
- Activator.log.error("Waiting for a list of EObject", null);
- }
- referencesViewer.setInput((valueToEdit != null) ? valueToEdit : Collections.emptyList());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dispose() {
- if(isValid(composite)) {
- composite.dispose();
- composite = null;
- setController(null);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isDisposed() {
- if(composite == null) {
- return true;
- }
- return composite.isDisposed();
- }
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public void handleContentChanged() {
+ // // this should tells the controller that the input has to be applied to the model
+ // getController().updateModel();
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public IStatus init(IPropertyEditorDescriptor descriptor) {
+ // setDescriptor(descriptor);
+ // setTooltipText(descriptor.getTooltipText());
+ // return Status.OK_STATUS;
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public List<EObject> getValue() {
+ // if(isValid(referenceArea)) {
+ // return currentValue;
+ // } else {
+ // Activator.log.error("trying to read the value of the reference area whereas the combo is disposed", null);
+ // }
+ // return Collections.emptyList();
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @SuppressWarnings("unchecked")
+ // @Override
+ // public void setValue(Object valueToEdit) {
+ // if(!isValid(referenceArea)) {
+ // return;
+ // }
+ // if(valueToEdit instanceof EList<?>) {
+ // currentValue = (EList<EObject>)valueToEdit;
+ // } else {
+ // Activator.log.error("Waiting for a list of EObject", null);
+ // }
+ // referencesViewer.setInput((valueToEdit != null) ? valueToEdit : Collections.emptyList());
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public void dispose() {
+ // if(isValid(composite)) {
+ // composite.dispose();
+ // composite = null;
+ // setController(null);
+ // }
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public boolean isDisposed() {
+ // if(composite == null) {
+ // return true;
+ // }
+ // return composite.isDisposed();
+ // }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultipleStructuralFeaturesPropertyEditor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultipleStructuralFeaturesPropertyEditor.java
index 94dce8fe954..fce45148016 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultipleStructuralFeaturesPropertyEditor.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/MultipleStructuralFeaturesPropertyEditor.java
@@ -11,432 +11,24 @@
*****************************************************************************/
package org.eclipse.papyrus.properties.runtime.propertyeditor;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
+import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.operations.IUndoableOperation;
-import org.eclipse.core.commands.operations.OperationHistoryFactory;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.properties.runtime.Activator;
-import org.eclipse.papyrus.properties.runtime.controller.IBoundedValuesController;
-import org.eclipse.papyrus.properties.runtime.controller.ILabelProviderController;
-import org.eclipse.papyrus.properties.runtime.controller.IWizardPropertyEditorController;
-import org.eclipse.papyrus.properties.runtime.controller.PropertyEditorController;
-import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.swt.widgets.Table;
/**
* Property editor for structural features that have multiplicity [n..*]
*/
-public class MultipleStructuralFeaturesPropertyEditor extends AbstractPropertyEditor {
+public class MultipleStructuralFeaturesPropertyEditor extends AbstractTablePropertyEditor {
/** id of this editor */
public static final String ID = "org.eclipse.papyrus.properties.runtime.multipleStructuralFeaturesPropertyEditor";
- /** main composite created by this property editor */
- protected Composite composite;
-
- /** button to add a reference or modify existing one */
- protected Button addButton;
-
- /** button to remove reference */
- protected Button removeButton;
-
- /** table area that displays the reference name or toString */
- protected Table referenceArea;
-
- /** table area that displays the reference name or toString */
- protected TableViewer referencesViewer;
-
- /** current Value */
- protected List<Object> currentValue;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Composite createContent(Composite parent) {
- composite = getWidgetFactory().createComposite(parent, SWT.NONE);
- int columnNu = getColumnNumber();
- GridLayout layout = new GridLayout(columnNu, false);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- composite.setLayout(layout);
- GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
- composite.setLayoutData(data);
-
- // creates label. No TOP/DOWN/etc. position, always on top
- createLabel(composite);
-
- if(!getIsReadOnly()) {
- // create Button area
- addButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
- addButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Add_12x12.gif")));
- data = new GridData(SWT.FILL, SWT.CENTER, false, false);
- addButton.setLayoutData(data);
- addButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- public void mouseUp(MouseEvent e) {
- // 2 possibilities:
- // we can create only one type of element, so the element is created, and then, a pop up dialog is displayed
- // several elements can be created (ex: nestedClassifiers for a class, we can create a class or an interface or any implementation of classifier
- if(getController() instanceof IWizardPropertyEditorController) {
- List<IUndoableOperation> availableCommands = ((IWizardPropertyEditorController)getController()).getAvailableCreationOperations();
- if(availableCommands.isEmpty()) {
- Activator.log.warn("no command was available to create elements for this view");
- return;
- } else if(availableCommands.size() == 1) {
- // only one command is available, create the element
- try {
- OperationHistoryFactory.getOperationHistory().execute(availableCommands.get(0), new NullProgressMonitor(), null);
- } catch (ExecutionException e1) {
- Activator.log.error(e1);
- }
- } else if(availableCommands.size() > 1) {
- Menu menu = new Menu(addButton);
- for(final IUndoableOperation operation : availableCommands) {
- MenuItem item = new MenuItem(menu, SWT.NONE);
- item.setText(operation.getLabel());
- item.addSelectionListener(new SelectionListener() {
-
- public void widgetSelected(SelectionEvent e) {
- try {
- OperationHistoryFactory.getOperationHistory().execute(operation, new NullProgressMonitor(), null);
- } catch (ExecutionException e1) {
- Activator.log.error(e1);
- }
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
-
- }
- });
- }
- menu.setVisible(true);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
- });
-
- removeButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
- removeButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Delete_12x12.gif")));
- data = new GridData(SWT.FILL, SWT.CENTER, false, false);
- removeButton.setLayoutData(data);
- removeButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public void mouseUp(MouseEvent e) {
- if(!(getController() instanceof IWizardPropertyEditorController)) {
- return;
- }
- // use selection to remove element
- // retrieve selected element(s)
- IStructuredSelection selection = (IStructuredSelection)referencesViewer.getSelection();
- if(selection == null || selection.isEmpty()) {
- // nothing selected.
- return;
- }
- List<Object> selectedObjects = selection.toList();
- IUndoableOperation deleteOperation = ((IWizardPropertyEditorController)getController()).getDeleteOperation(selectedObjects);
- if(deleteOperation != null && deleteOperation.canExecute()) {
- try {
- OperationHistoryFactory.getOperationHistory().execute(deleteOperation, new NullProgressMonitor(), null);
- } catch (ExecutionException e1) {
- Activator.log.error(e1);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
-
- }
- });
-
- if(((IBoundedValuesController)getController()).canMoveValues()) {
- Button upButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
- upButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Up_12x12.gif")));
- data = new GridData(SWT.FILL, SWT.CENTER, false, false);
- upButton.setLayoutData(data);
- upButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public void mouseUp(MouseEvent e) {
- // use selection to remove element
- // retrieve selected element(s)
- IStructuredSelection selection = (IStructuredSelection)referencesViewer.getSelection();
- if(selection == null || selection.isEmpty()) {
- // nothing selected.
- return;
- }
- List<Object> selectedObjects = selection.toList();
- IUndoableOperation moveOperation = ((IBoundedValuesController)getController()).getMoveCurrentValuesOperation(selectedObjects, -1);
- if(moveOperation != null && moveOperation.canExecute()) {
- try {
- OperationHistoryFactory.getOperationHistory().execute(moveOperation, new NullProgressMonitor(), null);
- } catch (ExecutionException e1) {
- Activator.log.error(e1);
- } finally {
- // try to restore selection in the view
- referencesViewer.setSelection(selection, true);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
- });
- }
-
- if(((IBoundedValuesController)getController()).canMoveValues()) {
- Button downButton = getWidgetFactory().createButton(composite, "", SWT.NONE);
- downButton.setImage(Activator.getImageFromDescriptor(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/Down_12x12.gif")));
- data = new GridData(SWT.FILL, SWT.CENTER, false, false);
- downButton.setLayoutData(data);
- downButton.addMouseListener(new MouseListener() {
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
- public void mouseUp(MouseEvent e) {
- // use selection to remove element
- // retrieve selected element(s)
- IStructuredSelection selection = (IStructuredSelection)referencesViewer.getSelection();
- if(selection == null || selection.isEmpty()) {
- // nothing selected.
- return;
- }
- List<Object> selectedObjects = selection.toList();
- IUndoableOperation moveOperation = ((IBoundedValuesController)getController()).getMoveCurrentValuesOperation(selectedObjects, +1);
- if(moveOperation != null && moveOperation.canExecute()) {
- try {
- OperationHistoryFactory.getOperationHistory().execute(moveOperation, new NullProgressMonitor(), null);
- } catch (ExecutionException e1) {
- Activator.log.error(e1);
- } finally {
- // try to restore selection in the view
- referencesViewer.setSelection(selection, true);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
- });
- }
- }
-
-
- // creates table for the display of references
- referenceArea = new Table(composite, SWT.BORDER | SWT.MULTI);
- data = new GridData(SWT.FILL, SWT.FILL, true, true, columnNu, 1);
- data.heightHint = 80;
- referenceArea.setLayoutData(data);
- referencesViewer = new TableViewer(referenceArea);
- referencesViewer.setContentProvider(new IStructuredContentProvider() {
-
- /**
- * {@inheritDoc}
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public void dispose() {
-
- }
-
- /**
- * {@inheritDoc}
- */
- public Object[] getElements(Object inputElement) {
- if(inputElement instanceof List<?>) {
- return ((List<?>)inputElement).toArray();
- }
- return new Object[0];
- }
- });
- referencesViewer.setLabelProvider(((ILabelProviderController)getController()).getEditorLabelProvider());
- referencesViewer.getControl().setToolTipText(getTooltipText());
- return composite;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Control createLabel(Composite parent) {
- GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
- return createLabel(parent, data);
- }
-
- /**
- * Returns the number of column for the composite
- *
- * @return the number of column for the composite
- */
- protected int getColumnNumber() {
- if(getIsReadOnly()) {
- return 1;
- }
- if(((IBoundedValuesController)getController()).canMoveValues()) {
- return 5;
- }
- return 3;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setController(PropertyEditorController controller) {
- assert (controller instanceof IBoundedValuesController) : "Controller should be a IboundedValuesController";
- super.setController(controller);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void handleContentChanged() {
- // this should tells the controller that the input has to be applied to the model
- getController().updateModel();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public IStatus init(IPropertyEditorDescriptor descriptor) {
- setDescriptor(descriptor);
- setTooltipText(descriptor.getTooltipText());
- return Status.OK_STATUS;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<Object> getValue() {
- if(isValid(referenceArea)) {
- return currentValue;
- } else {
- Activator.log.error("trying to read the value of the reference area whereas the combo is disposed", null);
- }
- return Collections.emptyList();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setValue(Object valueToEdit) {
- if(!isValid(referenceArea)) {
- return;
- }
- if(valueToEdit instanceof EList<?>) {
- currentValue = new ArrayList<Object>((EList<?>)valueToEdit);
- } else {
- Activator.log.error("Waiting for a list of EObject", null);
- }
- referencesViewer.setInput((valueToEdit != null) ? valueToEdit : Collections.emptyList());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void dispose() {
- if(isValid(composite)) {
- composite.dispose();
- composite = null;
- setController(null);
- }
- }
-
/**
* {@inheritDoc}
*/
@Override
- public boolean isDisposed() {
- if(composite == null) {
- return true;
- }
- return composite.isDisposed();
+ protected EditingSupport createEditingSupport() {
+ return null;
}
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/NullPropertyEditor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/NullPropertyEditor.java
new file mode 100644
index 00000000000..8a44e4a7c6d
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/NullPropertyEditor.java
@@ -0,0 +1,100 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.propertyeditor;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
+import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.PropertyEditorDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+
+/**
+ * Property editor that displays only a single Composite, no information
+ */
+public class NullPropertyEditor extends AbstractPropertyEditor {
+
+ /** main composite created by this property editor */
+ private Composite composite;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Composite createContent(Composite parent) {
+ composite = getWidgetFactory().createComposite(parent, SWT.NONE);
+ composite.setLayout(new GridLayout());
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
+ composite.setLayoutData(data);
+ return composite;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void handleContentChanged() {
+ // Nothing to do
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IStatus init(IPropertyEditorDescriptor descriptor) {
+ this.setDescriptor((PropertyEditorDescriptor)descriptor);
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object getValue() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setValue(Object valueToEdit) {
+ // Nothing to do
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void dispose() {
+ if(isValid(composite)) {
+ composite.dispose();
+ composite = null;
+ setController(null);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isDisposed() {
+ if(composite == null) {
+ return true;
+ }
+ return composite.isDisposed();
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/NullPropertyEditorTypeValidator.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/NullPropertyEditorTypeValidator.java
new file mode 100644
index 00000000000..2b0de412ec0
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/NullPropertyEditorTypeValidator.java
@@ -0,0 +1,34 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.propertyeditor;
+
+
+/**
+ * Validator which is always valid
+ */
+public class NullPropertyEditorTypeValidator implements IPropertyEditorTypeValidator {
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isValidForValue(Object valueToEdit) {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setPropertyEditor(AbstractPropertyEditor editor) {
+ // nothing here
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/PropertyEditorService.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/PropertyEditorService.java
index 2801f0f808c..4dbb56bc5a4 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/PropertyEditorService.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/PropertyEditorService.java
@@ -20,6 +20,7 @@ import org.eclipse.gmf.runtime.common.ui.services.util.ActivityFilterProviderDes
import org.eclipse.papyrus.properties.runtime.Activator;
import org.eclipse.papyrus.properties.runtime.controller.PropertyEditorController;
import org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor.IPropertyEditorDescriptor;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
import org.w3c.dom.Node;
@@ -63,11 +64,14 @@ public class PropertyEditorService extends Service {
* the controller that manages this editors
* @param id
* the identifier of the editor to create
+ * @param widgetFactory
+ * widget factory used to create the content of the editor
* @return the created property editor
*/
- public AbstractPropertyEditor createPropertyEditor(PropertyEditorController controller, String id) {
+ public AbstractPropertyEditor createPropertyEditor(PropertyEditorController controller, String id, TabbedPropertySheetWidgetFactory widgetFactory) {
Object result = executeUnique(ExecutionStrategy.REVERSE, new CreatePropertyEditorOperation(controller, id));
if(result instanceof AbstractPropertyEditor) {
+ ((AbstractPropertyEditor)result).setWidgetFactory(widgetFactory);
return (AbstractPropertyEditor)result;
}
Activator.log.error("impossible to create the editor using id " + id, null);
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/RadioBoxPropertyEditor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/RadioBoxPropertyEditor.java
index 3f2cecb547c..df663a61b6e 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/RadioBoxPropertyEditor.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/RadioBoxPropertyEditor.java
@@ -75,7 +75,12 @@ public class RadioBoxPropertyEditor extends AbstractPropertyEditor {
// create the set of radio-boxes. Does not know the size of the grid used for this editor
for(String value : values) {
Button button = getWidgetFactory().createButton(composite, (!value.equals("") ? value : "<Unset>"), SWT.RADIO);
- button.addSelectionListener(listener);
+ if(!getIsReadOnly()) {
+ button.setEnabled(true);
+ button.addSelectionListener(listener);
+ } else {
+ button.setEnabled(false);
+ }
buttons.add(button);
button.setToolTipText(getTooltipText());
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/descriptor/MultiplePrimitiveTypedPropertyEditorDescriptor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/descriptor/MultiplePrimitiveTypedPropertyEditorDescriptor.java
new file mode 100644
index 00000000000..a38f7d86ad8
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/descriptor/MultiplePrimitiveTypedPropertyEditorDescriptor.java
@@ -0,0 +1,53 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+
+/**
+ * Descriptor specific to the multi-valued primitive typed property editor
+ */
+public class MultiplePrimitiveTypedPropertyEditorDescriptor extends PropertyEditorDescriptor {
+
+ /**
+ * Creates a new MultiplePrimitiveTypedPropertyEditorDescriptor.
+ *
+ * @param editorId
+ * the unique identifier for this editor factory
+ * @param label
+ * the label for this property editor
+ * @param tooltipText
+ * the tooltip text for this property editor
+ */
+ public MultiplePrimitiveTypedPropertyEditorDescriptor(String editorId, String label, String tooltipText) {
+ super(editorId, label, tooltipText);
+ }
+
+ /**
+ * Creates a new MultiplePrimitiveTypedPropertyEditorDescriptor.
+ *
+ * @param editorId
+ * the unique identifier for this editor factory
+ * @param label
+ * the label for this property editor
+ * @param labelPosition
+ * the label position for this property editor
+ * @param tooltipText
+ * the tooltip text for this property editor
+ * @param imageDescriptor
+ * the icon for this property editor
+ */
+ public MultiplePrimitiveTypedPropertyEditorDescriptor(String editorId, String label, int labelPosition, String tooltipText, ImageDescriptor imageDescriptor) {
+ super(editorId, label, labelPosition, tooltipText, imageDescriptor);
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/descriptor/MultiplePrimitiveTypedPropertyEditorDescriptorFactory.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/descriptor/MultiplePrimitiveTypedPropertyEditorDescriptorFactory.java
new file mode 100644
index 00000000000..24359f46add
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/propertyeditor/descriptor/MultiplePrimitiveTypedPropertyEditorDescriptorFactory.java
@@ -0,0 +1,74 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.runtime.propertyeditor.descriptor;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.properties.runtime.Activator;
+import org.eclipse.swt.SWT;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Factory for multiple primitive typed property editor descriptors
+ */
+public class MultiplePrimitiveTypedPropertyEditorDescriptorFactory implements IPropertyEditorDescriptorFactory {
+
+ /**
+ * {@inheritDoc}
+ */
+ public IPropertyEditorDescriptor createEditorDescriptor(Node editorNode) {
+ String identifier = "";
+ String label = "";
+ String tooltipText = "";
+ int labelPosition = SWT.LEFT;
+ ImageDescriptor imageDescriptor = null;
+
+ // retrieve id, label, label position and tooltipText
+ NamedNodeMap attributes = editorNode.getAttributes();
+ if(attributes != null) {
+ for(int i = 0; i < attributes.getLength(); i++) {
+ Node attribute = attributes.item(i);
+ String nodeName = attribute.getNodeName();
+ if("label".equals(nodeName)) {
+ label = attribute.getNodeValue();
+ } else if("labelPosition".equals(nodeName)) {
+ labelPosition = Integer.parseInt(attribute.getNodeValue());
+ } else if("id".equals(nodeName)) {
+ identifier = attribute.getNodeValue();
+ } else if("tooltip".equals(nodeName)) {
+ tooltipText = attribute.getNodeValue();
+ }
+ }
+ }
+
+ // retrieve icon
+ NodeList children = editorNode.getChildNodes();
+ for(int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if("icon".equals(child.getNodeName())) {
+ NamedNodeMap iconAttributes = child.getAttributes();
+ if(iconAttributes != null) {
+ // retrieve plugin id and path
+ Node pluginIDNode = iconAttributes.getNamedItem("pluginID");
+ Node pathNode = iconAttributes.getNamedItem("path");
+ if(pluginIDNode != null && pathNode != null) {
+ imageDescriptor = Activator.imageDescriptorFromPlugin(pluginIDNode.getNodeValue(), pathNode.getNodeValue());
+ }
+ }
+ }
+ }
+
+ return new MultiplePrimitiveTypedPropertyEditorDescriptor(identifier, label, labelPosition, tooltipText, imageDescriptor);
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/PropertyViewService.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/PropertyViewService.java
index d586879dd10..fab2ca6d256 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/PropertyViewService.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/PropertyViewService.java
@@ -33,6 +33,7 @@ import org.eclipse.papyrus.properties.runtime.controller.descriptor.IPropertyEdi
import org.eclipse.papyrus.properties.runtime.dialogs.GetDialogDescriptorOperation;
import org.eclipse.papyrus.properties.runtime.dialogs.GetDialogDescriptorOperationById;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
/**
* Service to provide property views providers.
@@ -88,13 +89,14 @@ public class PropertyViewService extends Service implements IPreferenceChangeLis
* the composite parent for the property view
* @param controllerDescriptor
* the descriptor of the property editor controller
+ * @param widgetFactory
* @return the created controller for the property editor
*/
- public PropertyEditorController createPropertyEditorController(List<Object> objectsToEdit, Composite parent, IPropertyEditorControllerDescriptor controllerDescriptor) {
+ public PropertyEditorController createPropertyEditorController(List<Object> objectsToEdit, Composite parent, IPropertyEditorControllerDescriptor controllerDescriptor, TabbedPropertySheetWidgetFactory widgetFactory) {
PropertyEditorController controller = PropertyEditorControllerService.getInstance().createPropertyEditorController(objectsToEdit, parent, controllerDescriptor);
if(controller != null) {
- controller.createPropertyEditor(controllerDescriptor.getEditorDescriptor());
+ controller.createPropertyEditor(controllerDescriptor.getEditorDescriptor(), widgetFactory);
}
return controller;
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/ContainerDescriptor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/ContainerDescriptor.java
index 96ccb95fae4..0bb89a54c27 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/ContainerDescriptor.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/ContainerDescriptor.java
@@ -111,7 +111,7 @@ public class ContainerDescriptor extends AbstractContainerDescriptor {
getDescribedComposite().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
}
- controllers = updateControllers();
+ controllers = updateControllers(widgetFactory);
return controllers;
}
@@ -127,9 +127,12 @@ public class ContainerDescriptor extends AbstractContainerDescriptor {
/**
* Update controllers managed by this descriptor
*
+ * @param widgetFactory
+ * widget factory used to create content of the editors
+ *
* @return the list of update controllers
*/
- protected List<PropertyEditorController> updateControllers() {
+ protected List<PropertyEditorController> updateControllers(TabbedPropertySheetWidgetFactory widgetFactory) {
// clear and re-create the list of controllers
for(PropertyEditorController controller : controllers) {
controller.dispose();
@@ -145,7 +148,7 @@ public class ContainerDescriptor extends AbstractContainerDescriptor {
if(!parseFailed) {
// creates the content for the controllers
for(IPropertyEditorControllerDescriptor descriptor : getControllerDescriptors()) {
- controllers.add(PropertyViewService.getInstance().createPropertyEditorController(objectsToEdit, getPropertyEditorContainer(), descriptor));
+ controllers.add(PropertyViewService.getInstance().createPropertyEditorController(objectsToEdit, getPropertyEditorContainer(), descriptor, widgetFactory));
}
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/ExpandableContainerDescriptor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/ExpandableContainerDescriptor.java
index 36cf61ee91b..8d05553e402 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/ExpandableContainerDescriptor.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/ExpandableContainerDescriptor.java
@@ -98,7 +98,7 @@ public class ExpandableContainerDescriptor extends ContainerDescriptor {
getDescribedComposite().setClient(expandableContainer);
}
- controllers = updateControllers();
+ controllers = updateControllers(widgetFactory);
return controllers;
}
diff --git a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/GroupContainerDescriptor.java b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/GroupContainerDescriptor.java
index 047263fb20e..8ed50ae3793 100644
--- a/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/GroupContainerDescriptor.java
+++ b/plugins/core/org.eclipse.papyrus.properties.runtime/src/org/eclipse/papyrus/properties/runtime/view/content/GroupContainerDescriptor.java
@@ -89,7 +89,7 @@ public class GroupContainerDescriptor extends ContainerDescriptor {
getDescribedComposite().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
}
- controllers = updateControllers();
+ controllers = updateControllers(widgetFactory);
return controllers;
}

Back to the top