aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFanch BONNABESSE2017-09-27 09:50:49 -0400
committervincent lorenzo2017-10-06 10:28:57 -0400
commit73d973ff0f3d05ea87c9fae8de058c5dec3f91c2 (patch)
tree2e98deb98f5ed01e9bf534bb32a49c7174726463
parent26a242ff21befc3235965a322c11b9995d6dd930 (diff)
downloadorg.eclipse.papyrus-73d973ff0f3d05ea87c9fae8de058c5dec3f91c2.zip
org.eclipse.papyrus-73d973ff0f3d05ea87c9fae8de058c5dec3f91c2.tar.gz
org.eclipse.papyrus-73d973ff0f3d05ea87c9fae8de058c5dec3f91c2.tar.xz
Bug 521908: [Property View][DataType] No editor for list of Real or list
of UnlimitedNatural https://bugs.eclipse.org/bugs/show_bug.cgi?id=521908 Added management of Real and Unlimitednatural. Change-Id: Ie951079e463e17a7d8405450f36d6c9323429843 Signed-off-by: Fanch BONNABESSE <fanch.bonnabesse@all4tec.net>
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java47
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/MultipleCellEditor.java40
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java38
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/Constants.java36
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/UnlimitedNaturalSelector.java70
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/util/Constants.java31
6 files changed, 252 insertions, 10 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java
index bbd2f90..1eb292b 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/EObjectObservableValueEditingSupport.java
@@ -9,7 +9,8 @@
* Contributors:
* Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
* Thanh Liem PHAN (ALL4TEC) thanhliem.phan@all4tec.net - Bug 515491
- * Sebastien Gabel (Esterel Technologies SAS) - Bug 519143 (Fix NPE)
+ * Sebastien Gabel (Esterel Technologies SAS) - Bug 519143 (Fix NPE)
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 521908
*****************************************************************************/
package org.eclipse.papyrus.infra.ui.emf.databinding;
@@ -32,13 +33,16 @@ import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.infra.ui.emf.utils.Constants;
import org.eclipse.papyrus.infra.widgets.Activator;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider;
import org.eclipse.papyrus.infra.widgets.selectors.BooleanSelector;
import org.eclipse.papyrus.infra.widgets.selectors.IntegerSelector;
+import org.eclipse.papyrus.infra.widgets.selectors.RealSelector;
import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector;
import org.eclipse.papyrus.infra.widgets.selectors.StringSelector;
+import org.eclipse.papyrus.infra.widgets.selectors.UnlimitedNaturalSelector;
import org.eclipse.swt.SWT;
/**
@@ -139,6 +143,12 @@ public class EObjectObservableValueEditingSupport extends EditingSupport {
case "String": //$NON-NLS-1$
multiEditor.setSelector(new StringSelector());
break;
+ case "Real": //$NON-NLS-1$
+ multiEditor.setSelector(new RealSelector());
+ break;
+ case "UnlimitedNatural": //$NON-NLS-1$
+ multiEditor.setSelector(new UnlimitedNaturalSelector());
+ break;
default:
break;
}
@@ -151,7 +161,6 @@ public class EObjectObservableValueEditingSupport extends EditingSupport {
*/
@Override
protected Object getValue(final Object element) {
-
if (element instanceof EObjectObservableValue) {
EObjectObservableValue observableValue = (EObjectObservableValue) element;
EStructuralFeature feature = (EStructuralFeature) observableValue.getValueType();
@@ -162,6 +171,11 @@ public class EObjectObservableValueEditingSupport extends EditingSupport {
Object object = observableValue.getValue();
if (feature.isMany()) {
+ String eTypeName = eType.getName();
+ if (eTypeName.equals("UnlimitedNatural")) { //$NON-NLS-1$
+ return getMultiUnlimitedNaturalValue(object);
+ }
+
return object;
} else {
if (eType instanceof EEnum) {
@@ -171,7 +185,6 @@ public class EObjectObservableValueEditingSupport extends EditingSupport {
if (eTypeName.equals("Boolean")) { //$NON-NLS-1$
return getBooleanValue(object);
}
-
return object;
}
}
@@ -198,6 +211,34 @@ public class EObjectObservableValueEditingSupport extends EditingSupport {
}
/**
+ * Return Multi value when the feature is UnlimitedNatural. Replace '-1' by '*'.
+ *
+ * @param object
+ * The old value.
+ * @return The value to return.
+ * @since 2.0
+ */
+ protected Object getMultiUnlimitedNaturalValue(final Object objects) {
+ if (objects instanceof List<?>) {
+ List<Object> objectToReturn = new ArrayList<Object>();
+ if (objects instanceof List<?>) {
+ for (int i = 0; i < ((List<?>) objects).size(); i++) {
+ Object object = ((List<?>) objects).get(i);
+ String string = object.toString();
+ if (string.equals(Constants.INFINITE_MINUS_ONE)) {
+ objectToReturn.add(new String(Constants.INFINITY_STAR));
+ } else {
+ objectToReturn.add(object);
+ }
+ }
+ }
+ return objectToReturn;
+ }
+
+ return objects;
+ }
+
+ /**
* Returns the value from the feature.
*
* @return the boolean value.
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/MultipleCellEditor.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/MultipleCellEditor.java
index 949c8d2..4709055 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/MultipleCellEditor.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/databinding/MultipleCellEditor.java
@@ -21,14 +21,19 @@ import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.viewers.DialogCellEditor;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.ui.emf.utils.Constants;
import org.eclipse.papyrus.infra.widgets.editors.IElementSelector;
import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectionDialog;
+import org.eclipse.papyrus.infra.widgets.selectors.UnlimitedNaturalSelector;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
/**
* A CellEditor uses to set multiple values of an object.
+ *
* @since 2.0
*/
public class MultipleCellEditor extends DialogCellEditor {
@@ -92,6 +97,11 @@ public class MultipleCellEditor extends DialogCellEditor {
}
}
+ // Add a LabelProvider for the UnlimitedNatural values.
+ if (selector instanceof UnlimitedNaturalSelector) {
+ multipleValueSelectionDialog.setLabelProvider(new UnlimitedNaturalLabelProvider());
+ }
+
if (Window.OK == multipleValueSelectionDialog.open()) {
result = Arrays.asList(multipleValueSelectionDialog.getResult());
}
@@ -99,4 +109,34 @@ public class MultipleCellEditor extends DialogCellEditor {
return result;
}
+ /**
+ *
+ * LabelProvider used to change the display of an UnlimitedNatural.
+ *
+ * @since 2.0
+ */
+ private class UnlimitedNaturalLabelProvider extends LabelProvider {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getText(Object element) {
+ String text = element.toString();
+ if (Constants.INFINITE_MINUS_ONE.equals(text)) {
+ text = Constants.INFINITY_STAR;
+ }
+
+ return text;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Image getImage(Object element) {
+ return null;
+ }
+ }
+
}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java
index b2949f4..9a9c6f1 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/providers/EObjectObservableValueLabelProvider.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2016 CEA LIST and others.
+ * Copyright (c) 2016, 2017 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -7,7 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation, Bug 521908
*
*****************************************************************************/
@@ -15,12 +15,15 @@ package org.eclipse.papyrus.infra.ui.emf.providers;
import org.eclipse.emf.databinding.EObjectObservableValue;
import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.edit.ui.provider.DelegatingStyledCellLabelProvider;
+import org.eclipse.papyrus.infra.ui.emf.utils.Constants;
/**
* LabelProvider used to show feature name and EObject of an EObjectObservaleValue.
+ *
* @since 2.0
*
*/
@@ -48,13 +51,11 @@ public class EObjectObservableValueLabelProvider extends DelegatingStyledCellLab
/**
* {@inheritDoc}
- *
- * @see org.eclipse.emf.edit.ui.provider.DelegatingStyledCellLabelProvider#getColumnText(java.lang.Object, int)
*/
@Override
public String getColumnText(final Object element, final int columnIndex) {
if (element instanceof EObjectObservableValue) {
- String columnText = ""; //$NON-NLS-1$
+ String columnText = Constants.EMPTY_STRING;
EObjectObservableValue elementObservableValue = (EObjectObservableValue) element;
Object valueType = elementObservableValue.getValueType();
if (valueType instanceof EAttribute) {
@@ -65,8 +66,12 @@ public class EObjectObservableValueLabelProvider extends DelegatingStyledCellLab
}
break;
case EOBJECT:
- if (null != elementObservableValue.getValue()) {
- columnText = elementObservableValue.getValue().toString();
+ Object value = elementObservableValue.getValue();
+ if (null != value) {
+ columnText = value.toString();
+ if (isUnlimitedNatural((EAttribute) valueType)) {
+ columnText = columnText.replace(Constants.INFINITE_MINUS_ONE, Constants.INFINITY_STAR);
+ }
}
break;
default:
@@ -85,4 +90,23 @@ public class EObjectObservableValueLabelProvider extends DelegatingStyledCellLab
}
return super.getColumnText(element, columnIndex);
}
+
+ /**
+ * Check if the EAttribute is a UnlimitedNatural.
+ *
+ * @param valueType
+ * The EAttribute.
+ * @return The boolean result.
+ */
+ private boolean isUnlimitedNatural(final EAttribute valueType) {
+ boolean isUnlimitedNatural = false;
+ EClassifier eType = ((EAttribute) valueType).getEType();
+ if (null != eType) {
+ String name = eType.getName();
+ if (Constants.UNLIMITED_NATURAL.equals(name)) {
+ isUnlimitedNatural = true;
+ }
+ }
+ return isUnlimitedNatural;
+ }
}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/Constants.java b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/Constants.java
new file mode 100644
index 0000000..8b66745
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.ui.emf/src/org/eclipse/papyrus/infra/ui/emf/utils/Constants.java
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.ui.emf.utils;
+
+/**
+ *
+ * The constants for the org.eclipse.papyrus.plugin infra.ui.emf.
+ *
+ * @since 2.0
+ *
+ */
+public class Constants {
+
+ private Constants() {
+ // to prevent instanciation
+ }
+
+ public static final String INFINITY_STAR = "*"; //$NON-NLS-1$
+
+ public static final String INFINITE_MINUS_ONE = "-1"; //$NON-NLS-1$
+
+ public static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+ public static final String UNLIMITED_NATURAL = "UnlimitedNatural"; //$NON-NLS-1$
+}
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/UnlimitedNaturalSelector.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/UnlimitedNaturalSelector.java
new file mode 100644
index 0000000..45a8fc5
--- /dev/null
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/UnlimitedNaturalSelector.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation, Bug 521908
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.widgets.selectors;
+
+import org.eclipse.papyrus.infra.widgets.util.Constants;
+
+/**
+ * Selector for the UnlimitedNaturalEditor. It accepts "-1", "*" and all integer >=0.
+ *
+ * @since 3.1
+ */
+public class UnlimitedNaturalSelector extends StringSelector {
+
+ /**
+ * Constructs a Selector for Integer values
+ */
+ public UnlimitedNaturalSelector() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Integer[] getSelectedElements() {
+ Integer[] result = new Integer[0];
+ String newText = text.getText();
+ if (isInteger(newText)) {
+ int value = Integer.parseInt(newText);
+ if (value >= -1) {
+ result = new Integer[] { value };
+ text.setText(Constants.EMPTY_STRING);
+ }
+ } else {
+ if (Constants.INFINITY_STAR.equals(newText)) {
+ result = new Integer[] { new Integer(-1) };
+ text.setText(Constants.EMPTY_STRING);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ *
+ * @param textToCheck
+ * @return
+ */
+ private boolean isInteger(final String textToCheck) {
+ boolean isInteger = true;
+ try {
+ Integer.parseInt(textToCheck);
+ } catch (NumberFormatException e) {
+ isInteger = false;
+ }
+ return isInteger;
+ }
+
+}
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/util/Constants.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/util/Constants.java
new file mode 100644
index 0000000..999d88c
--- /dev/null
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/util/Constants.java
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST and others.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.widgets.util;
+
+/**
+ * The constants for the org.eclipse.papyrus.plugin infra.widgets.
+ *
+ * @since 3.1
+ *
+ */
+public class Constants {
+ private Constants() {
+ // to prevent instanciation
+ }
+
+ public static final String INFINITY_STAR = "*"; //$NON-NLS-1$
+
+ public static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+}