Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/StandardSelector.java')
-rw-r--r--plugins/infra/ui/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/StandardSelector.java67
1 files changed, 61 insertions, 6 deletions
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;
+ }
+
}

Back to the top