Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/core/org.eclipse.papyrus.properties/src/org/eclipse')
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/Activator.java8
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/constraints/AbstractConstraint.java3
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/constraints/JavaInstanceOf.java47
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/EcorePropertyEditorFactory.java108
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/EditionDialog.java10
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/PropertyEditorFactory.java38
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/EMFObservableList.java117
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservable.java32
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservableList.java172
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservableValue.java28
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/PapyrusObservableList.java309
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/PapyrusObservableValue.java86
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/messages/Messages.java6
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/messages/messages.properties3
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/AbstractModelElement.java13
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/CompositeModelElement.java28
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/DataSource.java10
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/EMFModelElement.java17
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/ModelElement.java17
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/preferences/Preferences.java2
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/ConfigurationManager.java4
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/DefaultConstraintEngine.java14
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/DefaultDisplayEngine.java2
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/StereotypeModelElement.java39
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/util/EMFHelper.java51
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/util/Util.java8
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/AbstractPropertyEditor.java98
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/EnumRadio.java2
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/InvalidWidget.java4
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiInteger.java5
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiReference.java8
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiString.java10
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/ReferenceDialog.java32
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/StringFileSelector.java63
-rw-r--r--plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/xwt/XWTTabDescriptor.java2
35 files changed, 827 insertions, 569 deletions
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/Activator.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/Activator.java
index ae4c5100334..849a4ea2e30 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/Activator.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/Activator.java
@@ -107,7 +107,7 @@ public class Activator extends AbstractUIPlugin {
*/
public Image getImage(String pluginId, String path) {
final ImageRegistry registry = getImageRegistry();
- String key = pluginId + "/" + path;
+ String key = pluginId + "/" + path; //$NON-NLS-1$
Image image = registry.get(key);
if(image == null) {
registry.put(key, AbstractUIPlugin.imageDescriptorFromPlugin(pluginId, path));
@@ -125,11 +125,11 @@ public class Activator extends AbstractUIPlugin {
* The Image at the given location, or null if none was found
*/
public Image getImageFromPlugin(String imagePath) {
- if(imagePath.startsWith("/")) {
+ if(imagePath.startsWith("/")) { //$NON-NLS-1$
String pluginId, path;
imagePath = imagePath.substring(1, imagePath.length());
- pluginId = imagePath.substring(0, imagePath.indexOf("/"));
- path = imagePath.substring(imagePath.indexOf("/"), imagePath.length());
+ pluginId = imagePath.substring(0, imagePath.indexOf("/")); //$NON-NLS-1$
+ path = imagePath.substring(imagePath.indexOf("/"), imagePath.length()); //$NON-NLS-1$
return getImage(pluginId, path);
} else {
return getImage(imagePath);
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/constraints/AbstractConstraint.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/constraints/AbstractConstraint.java
index 5e8188fade9..e0742b4afa7 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/constraints/AbstractConstraint.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/constraints/AbstractConstraint.java
@@ -62,9 +62,6 @@ public abstract class AbstractConstraint implements Constraint {
}
}
- if(descriptor.getOverriddenConstraints().contains(constraint.getDescriptor()))
- return true;
-
return false;
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/constraints/JavaInstanceOf.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/constraints/JavaInstanceOf.java
new file mode 100644
index 00000000000..6c2e6c0f88b
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/constraints/JavaInstanceOf.java
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.constraints;
+
+import org.eclipse.papyrus.properties.contexts.ConfigProperty;
+import org.eclipse.papyrus.properties.contexts.ConstraintDescriptor;
+import org.eclipse.papyrus.properties.contexts.ValueProperty;
+import org.eclipse.papyrus.properties.util.ClassLoader;
+
+public class JavaInstanceOf extends AbstractConstraint {
+
+ private Class<?> clazz;
+
+ @Override
+ public void setConstraintDescriptor(ConstraintDescriptor descriptor) {
+ super.setConstraintDescriptor(descriptor);
+ ClassLoader loader = new ClassLoader();
+ for(ConfigProperty property : descriptor.getProperties()) {
+ if(property.getName().equals("class") && property instanceof ValueProperty) { //$NON-NLS-1$
+ clazz = loader.loadClass(((ValueProperty)property).getValue());
+ }
+ }
+ }
+
+ public boolean match(Object selection) {
+ if(clazz == null) {
+ return false;
+ }
+
+ return clazz.isInstance(selection);
+ }
+
+ @Override
+ protected boolean equivalent(Constraint constraint) {
+ return false; //TODO
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/EcorePropertyEditorFactory.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/EcorePropertyEditorFactory.java
index d49dda52b21..755aebb477a 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/EcorePropertyEditorFactory.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/EcorePropertyEditorFactory.java
@@ -12,10 +12,23 @@
package org.eclipse.papyrus.properties.creation;
import java.util.Collection;
+import java.util.List;
import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.papyrus.properties.Activator;
+import org.eclipse.papyrus.properties.messages.Messages;
+import org.eclipse.papyrus.properties.util.EMFHelper;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.events.MenuListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
/**
@@ -29,12 +42,20 @@ import org.eclipse.papyrus.properties.Activator;
*/
public class EcorePropertyEditorFactory extends PropertyEditorFactory {
+ private EClass type;
+
private EClass eClass;
private String nsUri;
private String className;
+ private boolean menuVisible = false;
+
+ public EcorePropertyEditorFactory(EClass type) {
+ this.type = type;
+ }
+
/**
*
* Constructor.
@@ -44,18 +65,19 @@ public class EcorePropertyEditorFactory extends PropertyEditorFactory {
}
- /**
+ /*
* Creates a new EcorePropertyEditorFactory. The given EClass is used to instantiate
* a new EObject when the {@link #createObject} method is called.
* Constructor.
*
* @param eClass
+ *
+ * public EcorePropertyEditorFactory(EClass eClass) {
+ * this.eClass = eClass;
+ * this.nsUri = eClass.getEPackage().getNsURI();
+ * this.className = eClass.getName();
+ * }
*/
- public EcorePropertyEditorFactory(EClass eClass) {
- this.eClass = eClass;
- this.nsUri = eClass.getEPackage().getNsURI();
- this.className = eClass.getName();
- }
/**
* @return the nsUri of the EClass used by this factory to instantiate new EObjects
@@ -114,8 +136,76 @@ public class EcorePropertyEditorFactory extends PropertyEditorFactory {
}
@Override
- public Object createObject() {
- return eClass.getEPackage().getEFactoryInstance().create(eClass);
+ public Object createObject(Control widget) {
+ EClass eClass = chooseEClass(widget);
+ if(eClass == null) {
+ return null;
+ }
+
+ EObject instance = eClass.getEPackage().getEFactoryInstance().create(eClass);
+ return super.createObject(widget, instance);
+ }
+
+ private EClass chooseEClass(Control widget) {
+ if(eClass != null) {
+ return eClass;
+ }
+
+ List<EClass> availableClasses = EMFHelper.getSubclassesOf(type, true);
+
+ System.out.println(availableClasses);
+
+ final Menu menu = new Menu(widget);
+ for(EClass eClass : availableClasses) {
+ final MenuItem item = new MenuItem(menu, SWT.NONE);
+ item.setText(eClass.getName());
+ item.setData("eClass", eClass); //$NON-NLS-1$
+ item.addSelectionListener(new SelectionListener() {
+
+ public void widgetSelected(SelectionEvent e) {
+ EcorePropertyEditorFactory.this.eClass = (EClass)item.getData("eClass"); //$NON-NLS-1$
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // Nothing
+ }
+
+ });
+ }
+
+ menu.addMenuListener(new MenuListener() {
+
+ public void menuHidden(MenuEvent e) {
+ menuVisible = false;
+ }
+
+ public void menuShown(MenuEvent e) {
+ //Nothing
+ }
+
+ });
+
+ menu.setVisible(true);
+ menuVisible = true;
+
+ //The menu is blocking the thread
+ Display display = widget.getDisplay();
+ while(menu.isVisible()) {
+ try {
+ if(!display.readAndDispatch()) {
+ display.sleep();
+ }
+ } catch (Throwable ex) {
+ Activator.log.error(ex);
+ }
+ }
+ if(!display.isDisposed())
+ display.update();
+
+ EClass eClass = this.eClass;
+ this.eClass = null;
+
+ return eClass;
}
@Override
@@ -125,6 +215,6 @@ public class EcorePropertyEditorFactory extends PropertyEditorFactory {
@Override
public String getCreationDialogTitle() {
- return "Create a new " + className;
+ return Messages.EcorePropertyEditorFactory_CreateANew + className;
}
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/EditionDialog.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/EditionDialog.java
index 70e6be32a95..4ec2e3d03c4 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/EditionDialog.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/EditionDialog.java
@@ -20,6 +20,7 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.papyrus.properties.Activator;
import org.eclipse.papyrus.properties.contexts.Section;
import org.eclipse.papyrus.properties.contexts.View;
+import org.eclipse.papyrus.properties.messages.Messages;
import org.eclipse.papyrus.properties.runtime.DefaultDisplayEngine;
import org.eclipse.papyrus.properties.runtime.DisplayEngine;
import org.eclipse.papyrus.properties.xwt.XWTSection;
@@ -59,9 +60,9 @@ public class EditionDialog extends SelectionDialog {
@Override
public void create() {
- setTitle("Create a new Element");
+ setTitle(Messages.EditionDialog_CreateANewElement);
super.create();
- getShell().setImage(Activator.getDefault().getImage("org.eclipse.papyrus.widgets", "/icons/papyrus.png")); //$NON-NLS-1$
+ getShell().setImage(Activator.getDefault().getImage("org.eclipse.papyrus.widgets", "/icons/papyrus.png")); //$NON-NLS-1$ //$NON-NLS-2$
getShell().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
@@ -109,11 +110,6 @@ public class EditionDialog extends SelectionDialog {
getShell().setSize(600, 400);
for(View view : views) {
-
- // if(getShell().getText() == null || getShell().getText().equals("")) {
- // getShell().setText(view.getName());
- // }
-
for(Section section : view.getSections()) {
XWTSection xwtSection = new XWTSection(section, view, display);
sections.add(xwtSection);
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/PropertyEditorFactory.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/PropertyEditorFactory.java
index d89730ffc14..a583aeee874 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/PropertyEditorFactory.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/creation/PropertyEditorFactory.java
@@ -18,6 +18,7 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.properties.contexts.View;
+import org.eclipse.papyrus.properties.messages.Messages;
import org.eclipse.papyrus.properties.runtime.ConfigurationManager;
import org.eclipse.papyrus.properties.runtime.ConstraintEngine;
import org.eclipse.papyrus.widgets.creation.ReferenceValueFactory;
@@ -46,10 +47,25 @@ public class PropertyEditorFactory implements ReferenceValueFactory {
}
/**
- * {@inheritDoc}
+ * Return a null value. Implementors should override when object creation
+ * needs to be supported. Implementors may rely on {@link #createObject(Control, Object)}
+ *
+ * @see org.eclipse.papyrus.widgets.creation.ReferenceValueFactory#createObject(org.eclipse.swt.widgets.Control)
+ * @see #createObject(org.eclipse.swt.widgets.Control, Object)
+ *
+ * @param widget
+ * The widget from which this method is called. May be used to retrieve the current shell
+ * @return
+ * The newly created object
*/
public Object createObject(Control widget) {
- Object source = createObject();
+ return null;
+ }
+
+ /**
+ * Facility
+ */
+ protected Object createObject(Control widget, Object source) {
if(source == null)
return null;
@@ -97,7 +113,7 @@ public class PropertyEditorFactory implements ReferenceValueFactory {
* @param source
* The object to edit
*/
- public void edit(Control widget, Object source) {
+ public Object edit(Control widget, Object source) {
IStructuredSelection selection = new StructuredSelection(source);
ConstraintEngine constraintEngine = ConfigurationManager.instance.constraintEngine;
@@ -110,24 +126,14 @@ public class PropertyEditorFactory implements ReferenceValueFactory {
dialog.open();
}
- }
- /**
- * Creates a new empty instance. The instance will then be edited through
- * the matching property view, if any.
- * Subclasses should override this method if canCreateObject returns true
- *
- * @return
- * The newly created object
- */
- protected Object createObject() {
- return null;
+ return source;
}
/**
* The standard Property Editor Factory cannot instantiate new objects.
* However, subclasses may override this method to return true if they
- * implement {@link #createObject()}
+ * implement {@link #createObject(Control)}
*
* @see org.eclipse.papyrus.widgets.creation.ReferenceValueFactory#canCreateObject()
*
@@ -146,6 +152,6 @@ public class PropertyEditorFactory implements ReferenceValueFactory {
* @see #createObject()
*/
public String getCreationDialogTitle() {
- return "Create a new element";
+ return Messages.PropertyEditorFactory_CreateANewElement;
}
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/EMFObservableList.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/EMFObservableList.java
index b5ee83788e8..e9af039ee91 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/EMFObservableList.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/EMFObservableList.java
@@ -15,7 +15,6 @@ import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
-import org.eclipse.core.databinding.observable.list.ListDiff;
import org.eclipse.core.databinding.observable.list.ObservableList;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
@@ -40,7 +39,7 @@ import org.eclipse.papyrus.widgets.editors.ICommitListener;
public class EMFObservableList extends ObservableList implements ICommitListener {
/**
- * The list of commands that haven't been executed
+ * The list of commands that haven't been executed yet
*/
protected List<Command> commands = new LinkedList<Command>();
@@ -94,6 +93,10 @@ public class EMFObservableList extends ObservableList implements ICommitListener
*/
public void commit(AbstractEditor editor) {
+ if(commands.isEmpty()) {
+ return;
+ }
+
CompoundCommand compoundCommand = new CompoundCommand() {
@Override
@@ -142,11 +145,6 @@ public class EMFObservableList extends ObservableList implements ICommitListener
commands.clear();
}
- @Override
- protected void fireListChange(ListDiff diff) {
- super.fireListChange(diff);
- }
-
/**
* Refresh the cached list by copying the real list
*/
@@ -158,7 +156,7 @@ public class EMFObservableList extends ObservableList implements ICommitListener
@Override
public void add(int index, Object value) {
- Command command = AddCommand.create(editingDomain, source, feature, value, index);
+ Command command = getAddCommand(index, value);
commands.add(command);
wrappedList.add(index, value);
@@ -167,7 +165,7 @@ public class EMFObservableList extends ObservableList implements ICommitListener
@Override
public void clear() {
- Command command = RemoveCommand.create(editingDomain, source, feature, new LinkedList<Object>(wrappedList));
+ Command command = getClearCommand();
commands.add(command);
wrappedList.clear();
@@ -176,7 +174,7 @@ public class EMFObservableList extends ObservableList implements ICommitListener
@Override
public boolean add(Object o) {
- Command command = AddCommand.create(editingDomain, source, feature, o);
+ Command command = getAddCommand(o);
commands.add(command);
boolean result = wrappedList.add(o);
@@ -186,7 +184,7 @@ public class EMFObservableList extends ObservableList implements ICommitListener
@Override
public boolean remove(Object o) {
- Command command = RemoveCommand.create(editingDomain, source, feature, o);
+ Command command = getRemoveCommand(o);
commands.add(command);
@@ -197,7 +195,7 @@ public class EMFObservableList extends ObservableList implements ICommitListener
@Override
public boolean addAll(Collection c) {
- Command command = AddCommand.create(editingDomain, source, feature, c);
+ Command command = getAddAllCommand(c);
commands.add(command);
boolean result = wrappedList.addAll(c);
@@ -207,7 +205,7 @@ public class EMFObservableList extends ObservableList implements ICommitListener
@Override
public boolean addAll(int index, Collection c) {
- Command command = AddCommand.create(editingDomain, source, feature, c, index);
+ Command command = getAddAllCommand(index, c);
commands.add(command);
boolean result = wrappedList.addAll(index, c);
@@ -217,7 +215,7 @@ public class EMFObservableList extends ObservableList implements ICommitListener
@Override
public boolean removeAll(Collection c) {
- Command command = RemoveCommand.create(editingDomain, source, feature, c);
+ Command command = getRemoveCommand(c);
commands.add(command);
boolean result = wrappedList.removeAll(c);
@@ -227,17 +225,8 @@ public class EMFObservableList extends ObservableList implements ICommitListener
@Override
public boolean retainAll(Collection c) {
- List<Object> objectsToRemove = new LinkedList<Object>();
- for(Object object : c) {
- if(!contains(object)) {
- objectsToRemove.add(object);
- }
- }
- if(!objectsToRemove.isEmpty()) {
- Command command = RemoveCommand.create(editingDomain, source, feature, objectsToRemove);
- commands.add(command);
-
- }
+ Command command = getRetainAllCommand(c);
+ commands.add(command);
boolean result = wrappedList.retainAll(c);
fireListChange(null);
@@ -246,7 +235,7 @@ public class EMFObservableList extends ObservableList implements ICommitListener
@Override
public Object set(int index, Object element) {
- Command command = SetCommand.create(editingDomain, source, feature, element, index);
+ Command command = getSetCommand(index, element);
commands.add(command);
Object result = wrappedList.set(index, element);
@@ -256,18 +245,13 @@ public class EMFObservableList extends ObservableList implements ICommitListener
@Override
public Object move(int oldIndex, int newIndex) {
- Object value = get(oldIndex);
- if(value != null) {
- Command remove = RemoveCommand.create(editingDomain, source, feature, value);
- Command add = AddCommand.create(editingDomain, source, feature, value, newIndex);
- commands.add(remove);
- commands.add(add);
+ commands.addAll(getMoveCommands(oldIndex, newIndex));
- wrappedList.remove(oldIndex);
- wrappedList.add(newIndex, value);
+ Object value = get(oldIndex);
+ wrappedList.remove(oldIndex);
+ wrappedList.add(newIndex, value);
- fireListChange(null);
- }
+ fireListChange(null);
return value;
}
@@ -276,7 +260,7 @@ public class EMFObservableList extends ObservableList implements ICommitListener
public Object remove(int index) {
Object value = get(index);
if(value != null) {
- Command command = RemoveCommand.create(editingDomain, source, feature, value);
+ Command command = getRemoveCommand(index);
commands.add(command);
}
@@ -285,4 +269,63 @@ public class EMFObservableList extends ObservableList implements ICommitListener
return result;
}
+ protected Command getAddCommand(int index, Object value) {
+ return AddCommand.create(editingDomain, source, feature, value, index);
+ }
+
+ protected Command getAddCommand(Object value) {
+ return AddCommand.create(editingDomain, source, feature, value);
+ }
+
+ protected Command getAddAllCommand(Collection<?> values) {
+ return AddCommand.create(editingDomain, source, feature, values);
+ }
+
+ protected Command getAddAllCommand(int index, Collection<?> values) {
+ return AddCommand.create(editingDomain, source, feature, values, index);
+ }
+
+ protected Command getClearCommand() {
+ return getRemoveAllCommand(new LinkedList<Object>(wrappedList));
+ }
+
+ protected Command getRemoveCommand(int index) {
+ Object value = get(index);
+ return getRemoveCommand(value);
+ }
+
+ protected Command getRemoveCommand(Object value) {
+ return RemoveCommand.create(editingDomain, source, feature, value);
+ }
+
+ protected Command getRemoveAllCommand(Collection<?> values) {
+ return RemoveCommand.create(editingDomain, source, feature, values);
+ }
+
+ protected List<Command> getMoveCommands(int oldIndex, int newIndex) {
+ Object value = get(oldIndex);
+ List<Command> commands = new LinkedList<Command>();
+ commands.add(getRemoveCommand(value));
+ commands.add(getAddCommand(newIndex, value));
+ return commands;
+ }
+
+ protected Command getRetainAllCommand(Collection<?> values) {
+ List<Object> objectsToRemove = new LinkedList<Object>();
+ for(Object object : values) {
+ if(!contains(object)) {
+ objectsToRemove.add(object);
+ }
+ }
+ if(!objectsToRemove.isEmpty()) {
+ return getRemoveAllCommand(objectsToRemove);
+ } else {
+ return null;
+ }
+ }
+
+ protected Command getSetCommand(int index, Object value) {
+ return SetCommand.create(editingDomain, source, feature, value, index);
+ }
+
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservable.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservable.java
new file mode 100644
index 00000000000..e045dc677f9
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservable.java
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.databinding;
+
+import org.eclipse.core.databinding.observable.IObservable;
+
+/**
+ * An interface for Composite IObservables
+ *
+ * @author Camille Letavernier
+ */
+public interface MultipleObservable extends IObservable {
+
+ /**
+ * Adds an IObservable to this composite Observable
+ *
+ * @param observable
+ * The IObservable to add
+ * @return
+ * true if the observable has been successfully added, false otherwise
+ */
+ public boolean add(IObservable observable);
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservableList.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservableList.java
new file mode 100644
index 00000000000..70b41640c93
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservableList.java
@@ -0,0 +1,172 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.databinding;
+
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.databinding.observable.IObservable;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.ObservableList;
+import org.eclipse.papyrus.widgets.editors.AbstractEditor;
+import org.eclipse.papyrus.widgets.editors.ICommitListener;
+
+//TODO : Implement the getters
+//The list may be either the union or the intersection of all sublists
+//Union : allows the "remove" and "removeAll" on a group of lists (Even if one of the sublists doesn't contain the given element)
+//Intersection : Closer to the behavior of the CompositeValue (The current value is displayed only if it is shared by all elements)
+//The Union is probably a better solution
+//Simple solution : bind read operations to the first sub-list
+
+/**
+ * A Composite ObservableList. Modifications are forwarded to each sublist
+ * The read operations are not supported. This list behaves as if it were empty
+ *
+ * @author Camille Letavernier
+ */
+public class MultipleObservableList extends ObservableList implements ICommitListener, MultipleObservable {
+
+ List<IObservableList> observableLists = new LinkedList<IObservableList>();
+
+ public MultipleObservableList() {
+ super(new LinkedList<Object>(), Object.class);
+ }
+
+ @Override
+ public void add(int index, Object element) {
+ for(IObservableList observableList : observableLists) {
+ observableList.add(index, element);
+ }
+ }
+
+ @Override
+ public void clear() {
+ for(IObservableList observableList : observableLists) {
+ observableList.clear();
+ }
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ boolean contains = false;
+
+ for(IObservableList observableList : observableLists) {
+ if(observableList.contains(o)) {
+ contains = true;
+ } else {
+ return false;
+ }
+ }
+
+ return contains;
+ }
+
+ @Override
+ public boolean add(Object o) {
+ for(IObservableList observableList : observableLists) {
+ observableList.add(o);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ for(IObservableList observableList : observableLists) {
+ observableList.remove(o);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean containsAll(Collection c) {
+ boolean containsAll = false;
+ for(IObservableList observableList : observableLists) {
+ containsAll = containsAll && observableList.containsAll(c);
+ }
+ return containsAll;
+ }
+
+ @Override
+ public boolean addAll(Collection c) {
+ for(IObservableList observableList : observableLists) {
+ observableList.addAll(c);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean addAll(int index, Collection c) {
+ for(IObservableList observableList : observableLists) {
+ observableList.addAll(index, c);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean removeAll(Collection c) {
+ for(IObservableList observableList : observableLists) {
+ observableList.removeAll(c);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean retainAll(Collection c) {
+ for(IObservableList observableList : observableLists) {
+ observableList.retainAll(c);
+ }
+ return true;
+ }
+
+ @Override
+ public Object set(int index, Object element) {
+ for(IObservableList observableList : observableLists) {
+ observableList.set(index, element);
+ }
+ return null;
+ }
+
+ @Override
+ public Object move(int oldIndex, int newIndex) {
+ for(IObservableList observableList : observableLists) {
+ observableList.move(oldIndex, newIndex);
+ }
+ return null;
+ }
+
+ @Override
+ public Object remove(int index) {
+ for(IObservableList observableList : observableLists) {
+ observableList.remove(index);
+ }
+ return null;
+ }
+
+ public void commit(AbstractEditor editor) {
+ for(IObservableList observableList : observableLists) {
+ if(observableList instanceof ICommitListener) {
+ ((ICommitListener)observableList).commit(editor);
+ }
+ }
+ }
+
+ public boolean add(IObservable observable) {
+ if(observable instanceof IObservableList) {
+ observableLists.add((IObservableList)observable);
+ return true;
+ }
+
+ return false;
+ }
+
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservableValue.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservableValue.java
index 5638aaf9cd2..0f8b56062ef 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservableValue.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/MultipleObservableValue.java
@@ -15,6 +15,7 @@ import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
+import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
@@ -27,18 +28,7 @@ import org.eclipse.core.databinding.observable.value.IObservableValue;
*
* All sub-elements will be edited at the same time, with the same value.
*/
-public class MultipleObservableValue extends AbstractObservableValue {
-
- /**
- *
- * Constructs an instance of MultipleObservableValue with a single sub-element
- *
- * @param observable
- *
- */
- public MultipleObservableValue(IObservableValue observable) {
- observableValues.add(observable);
- }
+public class MultipleObservableValue extends AbstractObservableValue implements MultipleObservable {
/**
*
@@ -135,14 +125,12 @@ public class MultipleObservableValue extends AbstractObservableValue {
}
}
- /**
- * Adds an observableValue to the list of sub-elements
- *
- * @param observableValue
- * The observableValue to add
- */
- public void addObservable(IObservableValue observableValue) {
- observableValues.add(observableValue);
+ public boolean add(IObservable observable) {
+ if(observable instanceof MultipleObservableValue) {
+ observableValues.add((IObservableValue)observable);
+ return true;
+ }
+ return false;
}
private List<IObservableValue> observableValues = new LinkedList<IObservableValue>();
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/PapyrusObservableList.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/PapyrusObservableList.java
deleted file mode 100644
index 08a5c7fafa0..00000000000
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/PapyrusObservableList.java
+++ /dev/null
@@ -1,309 +0,0 @@
-/*****************************************************************************
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.properties.databinding;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.core.databinding.observable.Realm;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.databinding.EObjectObservableList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
-import org.eclipse.papyrus.diagram.common.command.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.properties.Activator;
-import org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.service.edit.service.IElementEditService;
-
-/**
- * An ObservableList used to edit collections of EObjects through
- * Papyrus commands
- *
- * @author Camille Letavernier
- *
- */
-@SuppressWarnings({ "unchecked", "rawtypes" })
-public class PapyrusObservableList extends EObjectObservableList {
-
- private EditingDomain domain;
-
- /**
- * Constructor.
- *
- * @param eObject
- * The EObject to edit
- * @param eStructuralFeature
- * The structural feature to edit
- * @param domain
- * The editing domain on which the commands will be executed
- */
- public PapyrusObservableList(EObject eObject, EStructuralFeature eStructuralFeature, EditingDomain domain) {
- super(eObject, eStructuralFeature);
- this.domain = domain;
- }
-
- /**
- *
- * Constructor.
- *
- * @param realm
- * @param eObject
- * The EObject to edit
- * @param eStructuralFeature
- * The structural feature to edit
- * @param domain
- * The editing domain on which the commands will be executed
- */
- public PapyrusObservableList(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature, EditingDomain domain) {
- super(realm, eObject, eStructuralFeature);
- this.domain = domain;
- }
-
- @Override
- public void add(int index, Object value) {
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- List<Object> values = new LinkedList<Object>(this);
- values.add(index, value);
- SetRequest request = new SetRequest(eObject, eStructuralFeature, values);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- }
-
- @Override
- public void clear() {
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- SetRequest request = new SetRequest(eObject, eStructuralFeature, Collections.EMPTY_LIST);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- }
-
- @Override
- public boolean add(Object o) {
- boolean result = false;
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- List<Object> values = new LinkedList<Object>(this);
- result = values.add(o);
- SetRequest request = new SetRequest(eObject, eStructuralFeature, values);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- return result;
- }
-
- @Override
- public boolean remove(Object o) {
- boolean result = false;
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- List<Object> values = new LinkedList<Object>(this);
- result = values.remove(o);
- SetRequest request = new SetRequest(eObject, eStructuralFeature, values);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- return result;
- }
-
- @Override
- public boolean addAll(Collection c) {
- boolean result = false;
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- List<Object> values = new LinkedList<Object>(this);
- result = values.addAll(c);
-
- SetRequest request = new SetRequest(eObject, eStructuralFeature, values);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- return result;
- }
-
- @Override
- public boolean addAll(int index, Collection c) {
- boolean result = false;
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- List<Object> values = new LinkedList<Object>(this);
- result = values.addAll(index, c);
- SetRequest request = new SetRequest(eObject, eStructuralFeature, values);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- return result;
- }
-
- @Override
- public boolean removeAll(Collection c) {
- boolean result = false;
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- List<Object> values = new LinkedList<Object>(this);
- result = values.removeAll(c);
- SetRequest request = new SetRequest(eObject, eStructuralFeature, values);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- return result;
- }
-
- @Override
- public boolean retainAll(Collection c) {
- List<Object> objectsToRemove = new LinkedList<Object>();
- for(Object object : c) {
- if(!contains(object)) {
- objectsToRemove.add(object);
- }
- }
-
- boolean result = false;
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- List<Object> values = new LinkedList<Object>(this);
- result = values.removeAll(objectsToRemove);
- SetRequest request = new SetRequest(eObject, eStructuralFeature, values);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- return result;
- }
-
- @Override
- public Object set(int index, Object element) {
- Object result = null;
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- List<Object> values = new LinkedList<Object>(this);
- result = values.set(index, element);
- SetRequest request = new SetRequest(eObject, eStructuralFeature, values);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- return result;
- }
-
- @Override
- public Object move(int oldIndex, int newIndex) {
- Object result = null;
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- List<Object> values = new LinkedList<Object>(this);
- result = values.remove(oldIndex);
- values.add(newIndex, result);
- SetRequest request = new SetRequest(eObject, eStructuralFeature, values);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- return result;
- }
-
- @Override
- public Object remove(int index) {
- Object result = null;
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- List<Object> values = new LinkedList<Object>(this);
- result = values.remove(index);
- SetRequest request = new SetRequest(eObject, eStructuralFeature, values);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- return result;
- }
-}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/PapyrusObservableValue.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/PapyrusObservableValue.java
deleted file mode 100644
index 3f2277de714..00000000000
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/databinding/PapyrusObservableValue.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*****************************************************************************
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.properties.databinding;
-
-import org.eclipse.core.databinding.observable.Realm;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.databinding.EObjectObservableValue;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
-import org.eclipse.papyrus.diagram.common.command.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.properties.Activator;
-import org.eclipse.papyrus.service.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.service.edit.service.IElementEditService;
-
-/**
- * An ObservableValue used to edit EObject properties through
- * Papyrus commands
- *
- * @author Camille Letavernier
- *
- */
-public class PapyrusObservableValue extends EObjectObservableValue {
-
- private EditingDomain domain;
-
- /**
- *
- * Constructor.
- *
- * @param eObject
- * The EObject to edit
- * @param eStructuralFeature
- * The structural feature to edit
- * @param domain
- * The editing domain on which the commands will be executed
- */
- public PapyrusObservableValue(EObject eObject, EStructuralFeature eStructuralFeature, EditingDomain domain) {
- this(Realm.getDefault(), eObject, eStructuralFeature, domain);
- }
-
- /**
- *
- * Constructor.
- *
- * @param realm
- * @param eObject
- * The EObject to edit
- * @param eStructuralFeature
- * The structural feature to edit
- * @param domain
- * The editing domain on which the commands will be executed
- */
- public PapyrusObservableValue(Realm realm, EObject eObject, EStructuralFeature eStructuralFeature, EditingDomain domain) {
- super(realm, eObject, eStructuralFeature);
- this.domain = domain;
- }
-
- @Override
- protected void doSetValue(Object value) {
- try {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getObserved());
- if(provider != null) {
- SetRequest request = new SetRequest(eObject, eStructuralFeature, value);
- ICommand createGMFCommand = provider.getEditCommand(request);
-
- Command emfCommand = new GMFtoEMFCommandWrapper(createGMFCommand);
-
- domain.getCommandStack().execute(emfCommand);
- }
- } catch (Exception ex) {
- Activator.log.error(ex);
- }
- }
-}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/messages/Messages.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/messages/Messages.java
index cd0991a1898..e2156f041e6 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/messages/Messages.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/messages/Messages.java
@@ -17,11 +17,17 @@ public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.papyrus.properties.messages.messages"; //$NON-NLS-1$
+ public static String EcorePropertyEditorFactory_CreateANew;
+
+ public static String EditionDialog_CreateANewElement;
+
public static String Preferences_Contexts;
public static String Preferences_Custom;
public static String Preferences_Plugin;
+
+ public static String PropertyEditorFactory_CreateANewElement;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/messages/messages.properties b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/messages/messages.properties
index 31132838baf..2cbbfb20f7e 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/messages/messages.properties
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/messages/messages.properties
@@ -1,3 +1,6 @@
+EcorePropertyEditorFactory_CreateANew=Create a new
+EditionDialog_CreateANewElement=Create a new Element
Preferences_Contexts=Contexts :
Preferences_Custom=custom
Preferences_Plugin=plugin
+PropertyEditorFactory_CreateANewElement=Create a new element
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/AbstractModelElement.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/AbstractModelElement.java
index 42460c5598f..9c128b088af 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/AbstractModelElement.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/AbstractModelElement.java
@@ -13,7 +13,9 @@ package org.eclipse.papyrus.properties.modelelement;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.papyrus.properties.contexts.Property;
+import org.eclipse.papyrus.properties.creation.PropertyEditorFactory;
import org.eclipse.papyrus.properties.runtime.ConfigurationManager;
+import org.eclipse.papyrus.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.widgets.providers.EmptyContentProvider;
import org.eclipse.papyrus.widgets.providers.IStaticContentProvider;
@@ -63,4 +65,15 @@ public abstract class AbstractModelElement implements ModelElement {
return ConfigurationManager.instance.getProperty(propertyPath, dataSource.getView().getContext());
}
+ /**
+ * @see org.eclipse.papyrus.properties.modelelement.ModelElement#getValueFactory(java.lang.String)
+ *
+ * @param propertyPath
+ * @return a default factory based on the property view configuration to
+ * edit objects, as if they were selected in an editor
+ */
+ public ReferenceValueFactory getValueFactory(String propertyPath) {
+ return new PropertyEditorFactory();
+ }
+
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/CompositeModelElement.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/CompositeModelElement.java
index 5a9bebbf5a8..d889468bdde 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/CompositeModelElement.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/CompositeModelElement.java
@@ -14,8 +14,10 @@ package org.eclipse.papyrus.properties.modelelement;
import java.util.LinkedList;
import java.util.List;
+import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.papyrus.properties.databinding.MultipleObservable;
import org.eclipse.papyrus.properties.databinding.MultipleObservableValue;
import org.eclipse.papyrus.widgets.providers.EmptyContentProvider;
import org.eclipse.papyrus.widgets.providers.IStaticContentProvider;
@@ -32,12 +34,30 @@ import org.eclipse.papyrus.widgets.providers.IStaticContentProvider;
*/
public class CompositeModelElement extends AbstractModelElement {
- public IObservableValue getObservable(String propertyPath) {
- MultipleObservableValue observableValue = new MultipleObservableValue();
+ public IObservable getObservable(String propertyPath) {
+
+ MultipleObservable observableComposite = null;
+
for(ModelElement element : elements) {
- observableValue.addObservable((IObservableValue)element.getObservable(propertyPath));
+ IObservable observable = element.getObservable(propertyPath);
+
+ if(observableComposite == null) {
+ if(observable instanceof IObservableValue) {
+ observableComposite = new MultipleObservableValue();
+ } else {
+ return null; //The support for CompositeObservableList is too complicated.
+ //There are too many non-trivial choices (Union or Intersection display,
+ //unadapted behavior of MultipleValueEditors, ...)
+ //observableComposite = new MultipleObservableList();
+ }
+ }
+
+ if(!observableComposite.add(observable)) {
+ return null;
+ }
}
- return observableValue;
+
+ return observableComposite;
}
/**
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/DataSource.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/DataSource.java
index 327d4cbedec..34b75fc4347 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/DataSource.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/DataSource.java
@@ -25,6 +25,7 @@ import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.properties.Activator;
import org.eclipse.papyrus.properties.contexts.View;
+import org.eclipse.papyrus.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.widgets.providers.EmptyContentProvider;
import org.eclipse.papyrus.widgets.providers.IStaticContentProvider;
@@ -72,7 +73,7 @@ public class DataSource implements IChangeListener {
this.selection = selection;
}
- private ModelElement getModelElement(String propertyPath) {
+ public ModelElement getModelElement(String propertyPath) {
//ConfigurationManager.instance.getProperty(propertyPath)
String key = propertyPath.substring(0, propertyPath.lastIndexOf(":")); //$NON-NLS-1$
ModelElement element = elements.get(key);
@@ -253,4 +254,11 @@ public class DataSource implements IChangeListener {
return false;
return element.forceRefresh(getLocalPropertyPath(propertyPath));
}
+
+ public ReferenceValueFactory getValueFactory(String propertyPath) {
+ ModelElement element = getModelElement(propertyPath);
+ if(element == null)
+ return null;
+ return element.getValueFactory(getLocalPropertyPath(propertyPath));
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/EMFModelElement.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/EMFModelElement.java
index df7da8b9916..4ddfcd09dfd 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/EMFModelElement.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/EMFModelElement.java
@@ -25,11 +25,13 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.papyrus.properties.Activator;
+import org.eclipse.papyrus.properties.creation.EcorePropertyEditorFactory;
import org.eclipse.papyrus.properties.databinding.EMFObservableList;
import org.eclipse.papyrus.properties.databinding.EMFObservableValue;
import org.eclipse.papyrus.properties.providers.EMFObjectLabelProvider;
import org.eclipse.papyrus.properties.providers.EcoreEnumeratorContentProvider;
import org.eclipse.papyrus.properties.providers.EcoreReferenceContentProvider;
+import org.eclipse.papyrus.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.widgets.providers.EmptyContentProvider;
import org.eclipse.papyrus.widgets.providers.IStaticContentProvider;
@@ -238,4 +240,19 @@ public class EMFModelElement extends AbstractModelElement {
return false;
return feature.isDerived();
}
+
+ @Override
+ public ReferenceValueFactory getValueFactory(String propertyPath) {
+ EStructuralFeature feature = getFeature(propertyPath);
+ if(feature != null) {
+ if(feature instanceof EReference) {
+ EReference reference = (EReference)feature;
+ if(reference.isContainment()) {
+ return new EcorePropertyEditorFactory(reference.getEReferenceType());
+ }
+ }
+ }
+
+ return super.getValueFactory(propertyPath);
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/ModelElement.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/ModelElement.java
index 5a45c5cf9c4..cfb6234eb00 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/ModelElement.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/modelelement/ModelElement.java
@@ -13,6 +13,7 @@ package org.eclipse.papyrus.properties.modelelement;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.papyrus.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.widgets.providers.EmptyContentProvider;
import org.eclipse.papyrus.widgets.providers.IStaticContentProvider;
@@ -103,7 +104,21 @@ public interface ModelElement {
* @param localPropertyPath
* @return
*/
- public boolean forceRefresh(String localPropertyPath);
+ public boolean forceRefresh(String propertyPath);
+ /**
+ * Sets the DataSource associated to this model element
+ *
+ * @param source
+ * The DataSource to associate to this model element
+ */
public void setDataSource(DataSource source);
+
+ /**
+ * @return the default factory used to handle operations such as object
+ * creation or edition, or null if these operations are not supported.
+ * This factory will typically be used by Multiple value editors, to
+ * create or edit a single entry.
+ */
+ public ReferenceValueFactory getValueFactory(String propertyPath);
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/preferences/Preferences.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/preferences/Preferences.java
index d4aa7febed4..4ba54b910bc 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/preferences/Preferences.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/preferences/Preferences.java
@@ -105,7 +105,7 @@ public class Preferences extends PreferencePage implements IWorkbenchPreferenceP
}
private String getLabel(Context context) {
- return context.getName() + " (" + (ConfigurationManager.instance.isPlugin(context) ? Messages.Preferences_Plugin : Messages.Preferences_Custom) + ")"; //$NON-NLS-1$ //$NON-NLS-4$
+ return context.getName() + " (" + (ConfigurationManager.instance.isPlugin(context) ? Messages.Preferences_Plugin : Messages.Preferences_Custom) + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-4$
}
private final ContextState contextState = new ContextState();
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/ConfigurationManager.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/ConfigurationManager.java
index 1fccebbf64a..5c38237789d 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/ConfigurationManager.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/ConfigurationManager.java
@@ -566,8 +566,8 @@ public class ConfigurationManager {
}
public Property getProperty(String propertyPath, Context context) {
- String elementName = propertyPath.substring(0, propertyPath.lastIndexOf(":"));
- String propertyName = propertyPath.substring(propertyPath.lastIndexOf(":") + 1, propertyPath.length());
+ String elementName = propertyPath.substring(0, propertyPath.lastIndexOf(":")); //$NON-NLS-1$
+ String propertyName = propertyPath.substring(propertyPath.lastIndexOf(":") + 1, propertyPath.length()); //$NON-NLS-1$
Set<DataContextElement> elements = new HashSet<DataContextElement>();
Collection<Context> allContexts;
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/DefaultConstraintEngine.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/DefaultConstraintEngine.java
index 74290988069..754d62b9f5f 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/DefaultConstraintEngine.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/DefaultConstraintEngine.java
@@ -55,7 +55,7 @@ public class DefaultConstraintEngine implements ConstraintEngine {
constraint.setConstraintDescriptor(descriptor);
constraints.add(constraint);
} catch (Exception ex) {
- Activator.log.error(ex);
+ Activator.log.error("Cannot load constraint " + descriptor.getName(), ex); //$NON-NLS-1$
}
}
}
@@ -103,9 +103,9 @@ public class DefaultConstraintEngine implements ConstraintEngine {
}
}
- //Activator.log.debug("Filtered Constraints : " + matchedConstraints); //$NON-NLS-1$
+ Activator.log.warn("Filtered Constraints : " + matchedConstraints); //$NON-NLS-1$
resolveConstraintConflicts(matchedConstraints);
- Activator.log.debug("Filtered Constraints : " + matchedConstraints); //$NON-NLS-1$
+ Activator.log.warn("Filtered Constraints : " + matchedConstraints); //$NON-NLS-1$
return matchedConstraints;
}
@@ -117,8 +117,14 @@ public class DefaultConstraintEngine implements ConstraintEngine {
if(c == c2)
continue;
- if(c.overrides(c2)) {
+ if(c.getDescriptor().getOverriddenConstraints().contains(c2.getDescriptor())) {
matchedConstraints.remove(c2);
+ continue;
+ }
+
+ if(c2.getDescriptor().isOverrideable() && c.overrides(c2)) {
+ matchedConstraints.remove(c2);
+ continue;
}
}
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/DefaultDisplayEngine.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/DefaultDisplayEngine.java
index cb90073821b..a2d1227823c 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/DefaultDisplayEngine.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/DefaultDisplayEngine.java
@@ -183,7 +183,7 @@ public class DefaultDisplayEngine implements DisplayEngine {
Context context = (Context)tab.eContainer();
if(context.eResource() == null) {
context = ConfigurationManager.instance.getContext(context.getName());
- Activator.log.warn("No resource for Context : " + context + " ; refreshing the model"); //$NON-NLS-1$
+ Activator.log.warn("No resource for Context : " + context + " ; refreshing the model"); //$NON-NLS-1$ //$NON-NLS-2$
}
URI sectionURI = URI.createURI(section.getSectionFile());
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/StereotypeModelElement.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/StereotypeModelElement.java
deleted file mode 100644
index c0fe0be2e0c..00000000000
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/runtime/StereotypeModelElement.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*****************************************************************************
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.properties.runtime;
-
-import org.eclipse.core.databinding.observable.IObservable;
-import org.eclipse.emf.databinding.FeaturePath;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.papyrus.properties.databinding.PapyrusObservableList;
-import org.eclipse.papyrus.properties.databinding.PapyrusObservableValue;
-import org.eclipse.papyrus.properties.modelelement.EMFModelElement;
-
-public class StereotypeModelElement extends EMFModelElement {
-
- public StereotypeModelElement(EObject source, EditingDomain domain) {
- super(source, domain);
- }
-
- @Override
- public IObservable getObservable(String propertyPath) {
- FeaturePath featurePath = getFeaturePath(propertyPath);
- EStructuralFeature feature = getFeature(featurePath);
- if(feature.getUpperBound() != 1) {
- return new PapyrusObservableList(getSource(featurePath), feature, domain);
- }
-
- return new PapyrusObservableValue(getSource(featurePath), feature, domain);
- }
-}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/util/EMFHelper.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/util/EMFHelper.java
index ebc651e7e88..9de810f7c68 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/util/EMFHelper.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/util/EMFHelper.java
@@ -12,6 +12,7 @@
package org.eclipse.papyrus.properties.util;
import java.io.IOException;
+import java.util.LinkedList;
import java.util.List;
import org.eclipse.core.runtime.IAdaptable;
@@ -203,5 +204,55 @@ public class EMFHelper {
return null;
}
+ /**
+ * Return the root package containing the given package, or the package
+ * itself if it is already the root
+ *
+ * @param ePackage
+ * @return
+ */
+ public static EPackage getRootPackage(EPackage ePackage) {
+ if(ePackage.getESuperPackage() == null) {
+ return ePackage;
+ }
+ return getRootPackage(ePackage.getESuperPackage());
+ }
+
+
+ /**
+ * Return the list of Concrete (ie. non-abstract) that are subtypes
+ * of the given EClass
+ *
+ * @param type
+ * @return
+ */
+ public static List<EClass> getSubclassesOf(EClass type, boolean concreteClassesOnly) {
+ List<EClass> result = new LinkedList<EClass>();
+ if(concreteClassesOnly || !type.isAbstract()) {
+ result.add(type);
+ }
+
+ EPackage ePackage = getRootPackage(type.getEPackage());
+ getSubclassesOf(type, ePackage, result, concreteClassesOnly);
+ return result;
+ }
+
+ private static void getSubclassesOf(EClass type, EPackage fromPackage, List<EClass> result, boolean concreteClassesOnly) {
+ for(EClassifier classifier : fromPackage.getEClassifiers()) {
+ if(classifier instanceof EClass) {
+ EClass eClass = (EClass)classifier;
+ if(eClass.getEAllSuperTypes().contains(type)) {
+ if(concreteClassesOnly || !eClass.isAbstract()) {
+ result.add(eClass);
+ }
+ }
+ }
+ }
+
+ for(EPackage subPackage : fromPackage.getESubpackages()) {
+ getSubclassesOf(type, subPackage, result, concreteClassesOnly);
+ }
+ }
+
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/util/Util.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/util/Util.java
index f7e620af964..d1325223e08 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/util/Util.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/util/Util.java
@@ -222,14 +222,14 @@ public class Util {
return string.trim();
}
- String[] stringChunks = string.split("\n|\r|\r\n|\n\r");
+ String[] stringChunks = string.split("\n|\r|\r\n|\n\r"); //$NON-NLS-1$
List<String> chunks = new LinkedList<String>();
for(String chunk : stringChunks) {
chunk = chunk.trim();
if(chunk.length() > maxCharPerLine) {
- Matcher matcher = Pattern.compile("(.{0," + maxCharPerLine + "}\\b\\p{Punct}?)").matcher(chunk);
+ Matcher matcher = Pattern.compile("(.{0," + maxCharPerLine + "}\\b\\p{Punct}?)").matcher(chunk); //$NON-NLS-1$ //$NON-NLS-2$
while(matcher.find()) {
String group = matcher.group(1);
chunks.add(group);
@@ -239,9 +239,9 @@ public class Util {
}
}
- String result = "";
+ String result = ""; //$NON-NLS-1$
for(String chunk : chunks) {
- result += chunk.trim() + "\n";
+ result += chunk.trim() + "\n"; //$NON-NLS-1$
}
return result.trim();
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/AbstractPropertyEditor.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/AbstractPropertyEditor.java
index 8941d171336..0efc3b45c38 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/AbstractPropertyEditor.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/AbstractPropertyEditor.java
@@ -15,6 +15,7 @@ import org.eclipse.core.databinding.observable.ChangeEvent;
import org.eclipse.core.databinding.observable.IChangeListener;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.papyrus.properties.Activator;
import org.eclipse.papyrus.properties.contexts.Context;
import org.eclipse.papyrus.properties.contexts.Property;
import org.eclipse.papyrus.properties.modelelement.DataSource;
@@ -71,6 +72,11 @@ public abstract class AbstractPropertyEditor implements IChangeListener {
*/
protected IObservableValue observableValue;
+ /**
+ * Indicates if the editor's label should be displayed
+ */
+ protected boolean showLabel = true;
+
public static int descriptionMaxCharPerLine = 200;
/**
@@ -161,15 +167,25 @@ public abstract class AbstractPropertyEditor implements IChangeListener {
valueEditor.setModelObservable(inputObservableValue);
}
- AbstractEditor editor = getEditor();
- if(editor != null)
- editor.setReadOnly(isReadOnly);
+ applyReadOnly(isReadOnly);
if(input.forceRefresh(propertyPath)) {
input.addChangeListener(this);
}
}
+ /**
+ * Applies the readOnly state to the editor
+ *
+ * @param readOnly
+ * Indicates if this widget should be read-only
+ */
+ protected void applyReadOnly(boolean readOnly) {
+ AbstractEditor editor = getEditor();
+ if(editor != null)
+ editor.setReadOnly(readOnly);
+ }
+
public void handleChange(ChangeEvent event) {
AbstractEditor editor = getEditor();
if(editor != null) {
@@ -200,10 +216,12 @@ public abstract class AbstractPropertyEditor implements IChangeListener {
label += " *"; //$NON-NLS-1$
}
- if(valueEditor != null) {
- valueEditor.setLabel(label);
- } else if(listEditor != null) {
- listEditor.setLabel(label);
+ if(showLabel) {
+ if(valueEditor != null) {
+ valueEditor.setLabel(label);
+ } else if(listEditor != null) {
+ listEditor.setLabel(label);
+ }
}
}
@@ -236,7 +254,7 @@ public abstract class AbstractPropertyEditor implements IChangeListener {
*/
protected String getLabel() {
Property property = getModelProperty();
- if(property == null || property.getLabel() == null || property.getLabel().trim().equals(""))
+ if(property == null || property.getLabel() == null || property.getLabel().trim().equals("")) //$NON-NLS-1$
return Util.getLabel(getLocalPropertyPath());
return property.getLabel();
@@ -247,12 +265,12 @@ public abstract class AbstractPropertyEditor implements IChangeListener {
* The description is the widget's ToolTipText
*/
protected void updateDescription() {
- String description = "";
+ String description = ""; //$NON-NLS-1$
Property property = getModelProperty();
if(property != null)
description = property.getDescription();
- if(description == null || description.trim().equals("")) {
+ if(description == null || description.trim().equals("")) { //$NON-NLS-1$
return;
}
@@ -312,8 +330,13 @@ public abstract class AbstractPropertyEditor implements IChangeListener {
* available
*/
protected IObservableList getInputObservableList() {
- if(observableList == null)
- observableList = (IObservableList)input.getObservable(propertyPath);
+ if(observableList == null) {
+ try {
+ observableList = (IObservableList)input.getObservable(propertyPath);
+ } catch (Exception ex) {
+ Activator.log.error("Cannot find a valid IObservable for " + propertyPath, ex); //$NON-NLS-1$
+ }
+ }
return observableList;
}
@@ -323,8 +346,13 @@ public abstract class AbstractPropertyEditor implements IChangeListener {
* available
*/
protected IObservableValue getInputObservableValue() {
- if(observableValue == null)
- observableValue = (IObservableValue)input.getObservable(propertyPath);
+ if(observableValue == null) {
+ try {
+ observableValue = (IObservableValue)input.getObservable(propertyPath);
+ } catch (Exception ex) {
+ Activator.log.error("Cannot find a valid IObservable for " + propertyPath, ex); //$NON-NLS-1$
+ }
+ }
return observableValue;
}
@@ -335,4 +363,46 @@ public abstract class AbstractPropertyEditor implements IChangeListener {
protected String getLocalPropertyPath() {
return propertyPath.substring(propertyPath.lastIndexOf(":") + 1); //$NON-NLS-1$
}
+
+ /**
+ * Sets the editor's Layout Data
+ *
+ * @param data
+ */
+ public void setLayoutData(Object data) {
+ if(getEditor() != null)
+ getEditor().setLayoutData(data);
+ }
+
+ /**
+ * Returns the editor's Layout Data
+ *
+ * @param data
+ * @return
+ */
+ public Object getLayoutData() {
+ return getEditor() == null ? null : getEditor().getLayoutData();
+ }
+
+ /**
+ * Indicates whether the editor's label should be displayed or not
+ *
+ * @param showLabel
+ */
+ public void setShowLabel(boolean showLabel) {
+ AbstractEditor editor = getEditor();
+ this.showLabel = showLabel;
+ if(editor != null) {
+ editor.setDisplayLabel(showLabel);
+ }
+ }
+
+ /**
+ * Indicates whether the editor's label is displayed or not
+ *
+ * @return
+ */
+ public boolean getShowLabel() {
+ return this.showLabel;
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/EnumRadio.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/EnumRadio.java
index f387e6b045f..ad3e86c202f 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/EnumRadio.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/EnumRadio.java
@@ -55,7 +55,7 @@ public class EnumRadio extends AbstractPropertyEditor {
@Override
protected void doBinding() {
- enumRadio.setProviders(input.getContentProvider(propertyPath), null);
+ enumRadio.setProviders(input.getContentProvider(propertyPath), input.getLabelProvider(propertyPath));
super.doBinding();
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/InvalidWidget.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/InvalidWidget.java
index 5de9ec0ef8b..d7c3f968a77 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/InvalidWidget.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/InvalidWidget.java
@@ -38,8 +38,8 @@ public class InvalidWidget extends AbstractPropertyEditor {
StringLabel editor = new StringLabel(parent, style);
setEditor(editor);
- editor.getValueLabel().setText("Property view Error : invalid widget type");
- editor.getValueLabel().setImage(Activator.getDefault().getImage("icons/error.gif"));
+ editor.getValueLabel().setText("Property view Error : invalid widget type"); //$NON-NLS-1$
+ editor.getValueLabel().setImage(Activator.getDefault().getImage("icons/error.gif")); //$NON-NLS-1$
}
@Override
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiInteger.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiInteger.java
index dcdfd7d854f..3a271a4985e 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiInteger.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiInteger.java
@@ -11,6 +11,7 @@
*****************************************************************************/
package org.eclipse.papyrus.properties.widgets;
+import org.eclipse.papyrus.widgets.editors.ICommitListener;
import org.eclipse.papyrus.widgets.editors.MultipleIntegerEditor;
import org.eclipse.swt.widgets.Composite;
@@ -46,6 +47,10 @@ public class MultiInteger extends AbstractPropertyEditor {
editor.setOrdered(input.isOrdered(propertyPath));
editor.setUnique(input.isUnique(propertyPath));
+ if(getInputObservableList() instanceof ICommitListener) {
+ editor.addCommitListener((ICommitListener)getInputObservableList());
+ }
+
super.doBinding();
}
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiReference.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiReference.java
index b26e6169c06..3b206804e24 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiReference.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiReference.java
@@ -12,7 +12,6 @@
package org.eclipse.papyrus.properties.widgets;
import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.papyrus.properties.creation.PropertyEditorFactory;
import org.eclipse.papyrus.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.widgets.editors.ICommitListener;
import org.eclipse.papyrus.widgets.editors.MultipleReferenceEditor;
@@ -48,8 +47,6 @@ public class MultiReference extends AbstractPropertyEditor {
*/
public MultiReference(Composite parent, int style) {
editor = new MultipleReferenceEditor(parent, style);
- factory = new PropertyEditorFactory();
- editor.setFactory(factory);
super.setEditor(editor);
}
@@ -65,6 +62,11 @@ public class MultiReference extends AbstractPropertyEditor {
editor.setProviders(contentProvider, labelProvider);
editor.setOrdered(input.isOrdered(propertyPath));
editor.setUnique(input.isUnique(propertyPath));
+ if(factory == null) {
+ editor.setFactory(input.getValueFactory(propertyPath));
+ } else {
+ editor.setFactory(factory);
+ }
super.doBinding();
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiString.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiString.java
index db01d12f452..1e5a96aac50 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiString.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/MultiString.java
@@ -11,6 +11,8 @@
*****************************************************************************/
package org.eclipse.papyrus.properties.widgets;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.papyrus.widgets.editors.ICommitListener;
import org.eclipse.papyrus.widgets.editors.MultipleStringEditor;
import org.eclipse.swt.widgets.Composite;
@@ -46,6 +48,14 @@ public class MultiString extends AbstractPropertyEditor {
editor.setOrdered(input.isOrdered(propertyPath));
editor.setUnique(input.isUnique(propertyPath));
+ if(getInputObservableList() instanceof ICommitListener) {
+ editor.addCommitListener((ICommitListener)getInputObservableList());
+ }
+
super.doBinding();
}
+
+ public ListViewer getViewer() {
+ return editor.getViewer();
+ }
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/ReferenceDialog.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/ReferenceDialog.java
index 82574fd6813..b6bcd805bf3 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/ReferenceDialog.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/ReferenceDialog.java
@@ -11,6 +11,7 @@
*****************************************************************************/
package org.eclipse.papyrus.properties.widgets;
+import org.eclipse.papyrus.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.widgets.providers.IStaticContentProvider;
import org.eclipse.swt.widgets.Composite;
@@ -29,6 +30,12 @@ public class ReferenceDialog extends AbstractPropertyEditor {
protected org.eclipse.papyrus.widgets.editors.ReferenceDialog editor;
/**
+ * The ValueFactory used to create or edit Objects directly from
+ * this editor
+ */
+ protected ReferenceValueFactory factory;
+
+ /**
* Constructor.
*
* @param parent
@@ -46,7 +53,32 @@ public class ReferenceDialog extends AbstractPropertyEditor {
IStaticContentProvider provider = input.getContentProvider(propertyPath);
editor.setLabelProvider(input.getLabelProvider(propertyPath));
editor.setContentProvider(provider);
+ if(factory == null) { //Use the default factory from the DataSource
+ editor.setValueFactory(input.getValueFactory(propertyPath));
+ } else { //Use the factory explicitly specified
+ editor.setValueFactory(factory);
+ }
+
super.doBinding();
}
+ /**
+ * Sets the ValueFactory used to create or edit Objects directly from
+ * this editor
+ *
+ * @param factory
+ */
+ public void setFactory(ReferenceValueFactory factory) {
+ this.factory = factory;
+ editor.setValueFactory(factory);
+ }
+
+ /**
+ * @return The ValueFactory used to create or edit Objects directly from
+ * this editor
+ */
+ public ReferenceValueFactory getFactory() {
+ return factory;
+ }
+
}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/StringFileSelector.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/StringFileSelector.java
new file mode 100644
index 00000000000..5bdf5dfa422
--- /dev/null
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/widgets/StringFileSelector.java
@@ -0,0 +1,63 @@
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.properties.widgets;
+
+import org.eclipse.swt.widgets.Composite;
+
+
+public class StringFileSelector extends AbstractPropertyEditor {
+
+ protected org.eclipse.papyrus.widgets.editors.StringFileSelector selector;
+
+ protected String[] filterExtensions, filterNames;
+
+ protected boolean allowWorkspace = true, allowFileSystem = true;
+
+ public StringFileSelector(Composite parent, int style) {
+ selector = new org.eclipse.papyrus.widgets.editors.StringFileSelector(parent, style);
+ super.setEditor(selector);
+ }
+
+ public void setFilterExtensions(String[] filterExtensions) {
+ this.filterExtensions = filterExtensions;
+ checkFilters();
+ }
+
+ public void setFilterNames(String[] filterNames) {
+ this.filterNames = filterNames;
+ checkFilters();
+ }
+
+ protected void checkFilters() {
+ if(filterExtensions != null && filterNames != null) {
+
+ }
+ }
+
+ public void setAllowWorkspace(boolean allowWorkspace) {
+ this.allowWorkspace = allowWorkspace;
+ selector.setAllowWorkspace(allowWorkspace);
+ }
+
+ public boolean getAllowWorkspace() {
+ return allowWorkspace;
+ }
+
+ public void setAllowFileSystem(boolean allowFileSystem) {
+ this.allowFileSystem = allowFileSystem;
+ selector.setAllowFileSystem(allowFileSystem);
+ }
+
+ public boolean getAllowFileSystem() {
+ return allowFileSystem;
+ }
+}
diff --git a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/xwt/XWTTabDescriptor.java b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/xwt/XWTTabDescriptor.java
index 02eccbda9bb..9a29612ac3e 100644
--- a/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/xwt/XWTTabDescriptor.java
+++ b/plugins/core/org.eclipse.papyrus.properties/src/org/eclipse/papyrus/properties/xwt/XWTTabDescriptor.java
@@ -56,7 +56,7 @@ public class XWTTabDescriptor extends AbstractTabDescriptor {
public String getCategory() {
String category = tab.getCategory();
- return category == null ? "" : category;
+ return category == null ? "" : category; //$NON-NLS-1$
}
public String getId() {

Back to the top