Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas FAUVERGUE2018-06-28 10:48:42 -0400
committerPatrick Tessier2018-11-23 13:22:24 -0500
commited4985eca2c022c61b9b0a51eaaf698b13456262 (patch)
tree40d06b0c029ec2150e1d788f70117280b3966a70
parent07059884d867f9b3ae5219b2234220a355ccb0ff (diff)
downloadorg.eclipse.papyrus-ed4985eca2c022c61b9b0a51eaaf698b13456262.tar.gz
org.eclipse.papyrus-ed4985eca2c022c61b9b0a51eaaf698b13456262.tar.xz
org.eclipse.papyrus-ed4985eca2c022c61b9b0a51eaaf698b13456262.zip
Bug 475369: List of string has always null string item
Use java8 to remove reflection. Change-Id: I35eaa7c6615494b786a4740ae731ebcc28ae6645 Signed-off-by: Nicolas FAUVERGUE <nicolas.fauvergue@cea.fr> Also-by: Camille Letavernier <cletavernier@eclipsesource.com>
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleStringEditor.java2
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/StandardSelector.java67
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/util/EditorFactory.java27
3 files changed, 89 insertions, 7 deletions
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleStringEditor.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleStringEditor.java
index 104b39f842a..30be8311588 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleStringEditor.java
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleStringEditor.java
@@ -256,7 +256,7 @@ public class MultipleStringEditor<T extends StringSelector> extends MultipleValu
}
public void setContentProvider(final IStaticContentProvider provider) {
- StandardSelector selector = new StandardSelector(StringCombo.class) {
+ StandardSelector selector = new StandardSelector(StringCombo::new) {
@Override
public void createControls(Composite parent) {
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/StandardSelector.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/StandardSelector.java
index 57b85572a49..88643403c13 100644
--- a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/StandardSelector.java
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/StandardSelector.java
@@ -25,6 +25,7 @@ import org.eclipse.papyrus.infra.widgets.editors.AbstractValueEditor;
import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
import org.eclipse.papyrus.infra.widgets.editors.IElementSelectionListener;
import org.eclipse.papyrus.infra.widgets.editors.IElementSelector;
+import org.eclipse.papyrus.infra.widgets.util.EditorFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
@@ -38,26 +39,71 @@ import org.eclipse.swt.widgets.Composite;
public class StandardSelector implements IElementSelector {
/**
- * The AbstractValueEditor class used for instantiating this selector
+ * The AbstractValueEditor class used for instantiating this selector.
+ *
+ * @deprecated since 3.3
*/
+ @Deprecated
protected Class<? extends AbstractValueEditor> editorClass;
/**
+ * The editor factory to create the correct editor.
+ *
+ * @since 3.3
+ */
+ private EditorFactory editorFactory;
+
+ /**
* The AbstractValueEditor used by this selector
*/
protected AbstractValueEditor editor;
- protected Set<IElementSelectionListener> elementSelectionListeners = new HashSet<IElementSelectionListener>();
+ protected Set<IElementSelectionListener> elementSelectionListeners = new HashSet<>();
/**
* Instantiates this selector, using the specified editor class
*
* @param editorClass
* The AbstractValueEditor Class used to instantiate this selector
+ *
+ * @deprecated since 3.3, use {@link #StandardSelector(EditorFactory)} instead.
*/
+ @Deprecated
public StandardSelector(Class<? extends AbstractValueEditor> editorClass) {
- Assert.isNotNull(editorClass, "The StandardSelector editor class should not be null"); //$NON-NLS-1$
- this.editorClass = editorClass;
+ this(reflexiveEditorFactory(editorClass));
+ }
+
+ /**
+ * Create an {@link EditorFactory} from an {@link AbstractValueEditor} class.
+ * This is only here to support legacy behavior; {@link EditorFactory} is the preferred
+ * way to create new editor instances.
+ *
+ * @deprecated
+ */
+ @Deprecated
+ private static EditorFactory reflexiveEditorFactory(Class<? extends AbstractValueEditor> editorClass) {
+ return (parent, style, label, commitOnFocusLost) -> {
+ try {
+ Constructor<? extends AbstractValueEditor> construct = editorClass.getDeclaredConstructor(Composite.class, Integer.TYPE, String.class, Boolean.TYPE);
+ return construct.newInstance(parent, SWT.BORDER, null, false);
+ } catch (Exception ex) {
+ Activator.log.error(ex);
+ return null;
+ }
+ };
+ }
+
+ /**
+ * Instantiates this selector, using the specified editor class
+ *
+ * @param editorFactory
+ * The editor factory to create the correct editor.
+ *
+ * @since 3.3
+ */
+ public StandardSelector(final EditorFactory editorFactory) {
+ Assert.isNotNull(editorFactory, "The StandardSelector editor class should not be null"); //$NON-NLS-1$
+ this.editorFactory = editorFactory;
}
/**
@@ -98,8 +144,7 @@ public class StandardSelector implements IElementSelector {
@Override
public void createControls(Composite parent) {
try {
- Constructor<? extends AbstractValueEditor> construct = editorClass.getDeclaredConstructor(Composite.class, Integer.TYPE, String.class, Boolean.TYPE);
- editor = construct.newInstance(parent, SWT.BORDER, null, false);
+ editor = editorFactory.create(parent, SWT.BORDER, null, false);
editor.addCommitListener(new ICommitListener() {
@Override
@@ -138,4 +183,14 @@ public class StandardSelector implements IElementSelector {
elementSelectionListeners.remove(listener);
}
+ /**
+ * Return the editor factory.
+ *
+ * @return the editorFactory The editor factory.
+ * @since 3.3
+ */
+ public EditorFactory getEditorFactory() {
+ return editorFactory;
+ }
+
}
diff --git a/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/util/EditorFactory.java b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/util/EditorFactory.java
new file mode 100644
index 00000000000..967c32f863f
--- /dev/null
+++ b/plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/util/EditorFactory.java
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * Copyright (c) 2018 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:
+ * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.widgets.util;
+
+import org.eclipse.papyrus.infra.widgets.editors.AbstractValueEditor;
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * The editor factory to create value editor.
+ *
+ * @since 3.3
+ */
+@FunctionalInterface
+public interface EditorFactory {
+ AbstractValueEditor create(final Composite parent, final int style, final String label, final boolean commitOnFocusLost);
+}

Back to the top