Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/GenericAttributeObservable.java')
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/GenericAttributeObservable.java55
1 files changed, 28 insertions, 27 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/GenericAttributeObservable.java b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/GenericAttributeObservable.java
index 7c7a084f2de..7af07b75af8 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/GenericAttributeObservable.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/GenericAttributeObservable.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* 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
@@ -28,9 +28,9 @@ import org.eclipse.emf.edit.domain.EditingDomain;
* An observable value for manipulating reflective properties
* (Based on a key/value pair). The modifications are based on EMF
* commands.
- *
+ *
* @see GenericAttributeModelElement
- *
+ *
* @author Camille Letavernier
*/
public class GenericAttributeObservable extends AbstractObservableValue {
@@ -50,23 +50,23 @@ public class GenericAttributeObservable extends AbstractObservableValue {
private String propertyPath;
/**
- *
+ *
* Constructor.
- *
+ *
* @param source
- * The EObject being edited
+ * The EObject being edited
* @param domain
- * The Editing domain on which the commands will be executed
+ * The Editing domain on which the commands will be executed
* @param createIn
- * The Feature in which the value will be set
+ * The Feature in which the value will be set
* @param createFrom
- * The Factory used to instantiate the new value
+ * The Factory used to instantiate the new value
* @param createAsValue
- * The EClass that will be instantiated for the new value, if it is an attribute
+ * The EClass that will be instantiated for the new value, if it is an attribute
* @param createAsReference
- * The EClass that will be instantiated for the new value, if it is a reference
+ * The EClass that will be instantiated for the new value, if it is a reference
* @param propertyPath
- * The value of the "name" attribute (Which is the "key" of the property)
+ * The value of the "name" attribute (Which is the "key" of the property)
*/
public GenericAttributeObservable(EObject source, EditingDomain domain, EStructuralFeature createIn, EFactory createFrom, EClass createAsValue, EClass createAsReference, String propertyPath) {
this.source = source;
@@ -78,6 +78,7 @@ public class GenericAttributeObservable extends AbstractObservableValue {
this.propertyPath = propertyPath;
}
+ @Override
public Object getValueType() {
return Object.class;
}
@@ -85,7 +86,7 @@ public class GenericAttributeObservable extends AbstractObservableValue {
@Override
protected Object doGetValue() {
EObject attribute = findAttribute();
- if(attribute == null) {
+ if (attribute == null) {
return null;
}
Object result = attribute.eGet(attribute.eClass().getEStructuralFeature("value")); //$NON-NLS-1$
@@ -95,15 +96,15 @@ public class GenericAttributeObservable extends AbstractObservableValue {
/**
* Browse the existing attributes in the given feature, and returns the
* one with the same name, if it exists, or null otherwise.
- *
+ *
* @return The attribute being edited, if it already exists, or null otherwise
*/
@SuppressWarnings("unchecked")
protected EObject findAttribute() {
- EList<? extends EObject> allAttributes = (EList<? extends EObject>)source.eGet(createIn);
- for(EObject attribute : allAttributes) {
- if(createAsValue.isInstance(attribute) || createAsReference.isInstance(attribute)) {
- if(attribute.eGet(attribute.eClass().getEStructuralFeature("name")).equals(propertyPath)) { //$NON-NLS-1$
+ EList<? extends EObject> allAttributes = (EList<? extends EObject>) source.eGet(createIn);
+ for (EObject attribute : allAttributes) {
+ if (createAsValue.isInstance(attribute) || createAsReference.isInstance(attribute)) {
+ if (attribute.eGet(attribute.eClass().getEStructuralFeature("name")).equals(propertyPath)) { //$NON-NLS-1$
return attribute;
}
}
@@ -116,34 +117,34 @@ public class GenericAttributeObservable extends AbstractObservableValue {
public void doSetValue(final Object value) {
final Object oldValue = doGetValue();
- if(value != null && value.equals(oldValue)) {
+ if (value != null && value.equals(oldValue)) {
return;
}
EObject attribute = findAttribute();
- EList<? extends EObject> collection = (EList<? extends EObject>)source.eGet(createIn);
+ EList<? extends EObject> collection = (EList<? extends EObject>) source.eGet(createIn);
CompoundCommand command = new CompoundCommand(String.format("Set %s value", propertyPath)) {
@Override
public boolean prepare() {
- //Only test the first command's canExecute(), as the following ones depend on the execution of the first one
- //Can we use a StrictCompoundCommand here ?
- if(commandList.isEmpty()) {
+ // Only test the first command's canExecute(), as the following ones depend on the execution of the first one
+ // Can we use a StrictCompoundCommand here ?
+ if (commandList.isEmpty()) {
return true;
}
return commandList.get(0).canExecute();
}
};
- if(value == null || value.equals("")) { //$NON-NLS-1$
- if(attribute != null) {
+ if (value == null || value.equals("")) { //$NON-NLS-1$
+ if (attribute != null) {
RemoveCommand rCommand = new RemoveCommand(domain, collection, attribute);
command.append(rCommand);
}
} else {
- if(attribute == null) {
- if(value instanceof String) {
+ if (attribute == null) {
+ if (value instanceof String) {
attribute = createFrom.create(createAsValue);
} else {
attribute = createFrom.create(createAsReference);

Back to the top