Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenzo Bettini2016-05-31 16:39:22 +0000
committerLorenzo Bettini2016-06-01 09:53:34 +0000
commit165d33883acda28b6862e9b9d6bc249a396bbf4c (patch)
treed0b7dcb577bead62c243a37c5337d3a34a0fcb5c
parent30f28cd2e29a5066c430096e57a98022d522eb6d (diff)
downloadorg.eclipse.emf-parsley-165d33883acda28b6862e9b9d6bc249a396bbf4c.tar.gz
org.eclipse.emf-parsley-165d33883acda28b6862e9b9d6bc249a396bbf4c.tar.xz
org.eclipse.emf-parsley-165d33883acda28b6862e9b9d6bc249a396bbf4c.zip
494945: cleanup API for AbstractControlFactory
Change-Id: I1dd4efb78578631ea7de3b00d608d6a1d0ef18bc Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=494945
-rw-r--r--doc/org.eclipse.emf.parsley.doc/contents/00-Main.html4
-rw-r--r--doc/org.eclipse.emf.parsley.doc/contents/00-Main_6.html4
-rw-r--r--doc/org.eclipse.emf.parsley.doc/contents/Migration-Guide.html11
-rw-r--r--doc/org.eclipse.emf.parsley.doc/contents/toc.xml2
-rw-r--r--doc/org.eclipse.emf.parsley.doc/xdoc/documentation/Migration-Guide.xdoc9
-rw-r--r--plugins/org.eclipse.emf.parsley.common/src/org/eclipse/emf/parsley/composite/AbstractControlFactory.java80
-rw-r--r--plugins/org.eclipse.emf.parsley.junit4/src/org/eclipse/emf/parsley/junit4/AbstractEmfParsleyControlBasedTest.java3
-rw-r--r--tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/AbstractControlFactoryTest.xtend6
-rw-r--r--tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/CustomDialogControlFactoryTest.xtend42
-rw-r--r--tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/DialogControlFactoryTest.xtend62
-rw-r--r--tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/DialogWidgetFactoryTest.xtend8
11 files changed, 159 insertions, 72 deletions
diff --git a/doc/org.eclipse.emf.parsley.doc/contents/00-Main.html b/doc/org.eclipse.emf.parsley.doc/contents/00-Main.html
index db29fe318..eaa02c268 100644
--- a/doc/org.eclipse.emf.parsley.doc/contents/00-Main.html
+++ b/doc/org.eclipse.emf.parsley.doc/contents/00-Main.html
@@ -135,7 +135,9 @@
</ol></li>
<li><a href="00-Main_6.html#Emf%20Parsley%20Guide_6">Appendix</a>
<ol> <li><a href="Migration-Guide.html#MigrationGuide">Migration Guide</a>
- <ol> <li><a href="Migration-Guide.html#SixSeven">From 0.6.0 to 0.7.0</a>
+ <ol> <li><a href="Migration-Guide.html#VersionOne">From 0.7.0 to 1.0.0</a>
+ </li>
+ <li><a href="Migration-Guide.html#SixSeven">From 0.6.0 to 0.7.0</a>
</li>
<li><a href="Migration-Guide.html#FiveMinors">From 0.5.0 to 0.6.0</a>
</li>
diff --git a/doc/org.eclipse.emf.parsley.doc/contents/00-Main_6.html b/doc/org.eclipse.emf.parsley.doc/contents/00-Main_6.html
index 279c1ec19..6fb8117cc 100644
--- a/doc/org.eclipse.emf.parsley.doc/contents/00-Main_6.html
+++ b/doc/org.eclipse.emf.parsley.doc/contents/00-Main_6.html
@@ -11,7 +11,9 @@
<a name="Emf%20Parsley%20Guide_6"></a>
<h1>Appendix</h1>
<ol><li><a href="Migration-Guide.html#MigrationGuide">Migration Guide</a>
-<ol> <li><a href="Migration-Guide.html#SixSeven">From 0.6.0 to 0.7.0</a>
+<ol> <li><a href="Migration-Guide.html#VersionOne">From 0.7.0 to 1.0.0</a>
+ </li>
+ <li><a href="Migration-Guide.html#SixSeven">From 0.6.0 to 0.7.0</a>
</li>
<li><a href="Migration-Guide.html#FiveMinors">From 0.5.0 to 0.6.0</a>
</li>
diff --git a/doc/org.eclipse.emf.parsley.doc/contents/Migration-Guide.html b/doc/org.eclipse.emf.parsley.doc/contents/Migration-Guide.html
index d0e36c3a3..ad0be1b9d 100644
--- a/doc/org.eclipse.emf.parsley.doc/contents/Migration-Guide.html
+++ b/doc/org.eclipse.emf.parsley.doc/contents/Migration-Guide.html
@@ -10,6 +10,17 @@
<body>
<a name="MigrationGuide"></a>
<h1>Migration Guide</h1>
+<a name="VersionOne"></a>
+<h2>From 0.7.0 to 1.0.0</h2>
+<p>
+<ul>
+ <li>
+ <em>API changes</em> If in your custom <em>ControlFactory</em> you were using the field
+ <em>edbc</em> you should now use the getter <em>getDatabindingContext()</em>. Similarly for the field
+ <em>domain</em>: use <em>getEditingDomain()</em>.
+ </li>
+</ul>
+</p>
<a name="SixSeven"></a>
<h2>From 0.6.0 to 0.7.0</h2>
<p>
diff --git a/doc/org.eclipse.emf.parsley.doc/contents/toc.xml b/doc/org.eclipse.emf.parsley.doc/contents/toc.xml
index 13604909a..82ff846cc 100644
--- a/doc/org.eclipse.emf.parsley.doc/contents/toc.xml
+++ b/doc/org.eclipse.emf.parsley.doc/contents/toc.xml
@@ -126,6 +126,8 @@
</topic>
<topic href="contents/00-Main_6.html#Emf%20Parsley%20Guide_6" label="Appendix" >
<topic href="contents/Migration-Guide.html#MigrationGuide" label="Migration Guide" >
+ <topic href="contents/Migration-Guide.html#VersionOne" label="From 0.7.0 to 1.0.0" >
+ </topic>
<topic href="contents/Migration-Guide.html#SixSeven" label="From 0.6.0 to 0.7.0" >
</topic>
<topic href="contents/Migration-Guide.html#FiveMinors" label="From 0.5.0 to 0.6.0" >
diff --git a/doc/org.eclipse.emf.parsley.doc/xdoc/documentation/Migration-Guide.xdoc b/doc/org.eclipse.emf.parsley.doc/xdoc/documentation/Migration-Guide.xdoc
index ed6f5bd46..69014e87b 100644
--- a/doc/org.eclipse.emf.parsley.doc/xdoc/documentation/Migration-Guide.xdoc
+++ b/doc/org.eclipse.emf.parsley.doc/xdoc/documentation/Migration-Guide.xdoc
@@ -1,5 +1,14 @@
chapter:MigrationGuide[Migration Guide]
+section:VersionOne[From 0.7.0 to 1.0.0]
+
+ul[
+item[e[API changes] If in your custom e[ControlFactory] you were using the field
+e[edbc] you should now use the getter e[getDatabindingContext()]. Similarly for the field
+e[domain]: use e[getEditingDomain()].
+]
+]
+
section:SixSeven[From 0.6.0 to 0.7.0]
ul[
diff --git a/plugins/org.eclipse.emf.parsley.common/src/org/eclipse/emf/parsley/composite/AbstractControlFactory.java b/plugins/org.eclipse.emf.parsley.common/src/org/eclipse/emf/parsley/composite/AbstractControlFactory.java
index 594e29a75..1034f4e40 100644
--- a/plugins/org.eclipse.emf.parsley.common/src/org/eclipse/emf/parsley/composite/AbstractControlFactory.java
+++ b/plugins/org.eclipse.emf.parsley.common/src/org/eclipse/emf/parsley/composite/AbstractControlFactory.java
@@ -95,23 +95,23 @@ public abstract class AbstractControlFactory implements IWidgetFactory {
@Inject
private ProposalCreator proposalCreator;
- protected EObject owner;
- protected Resource resource;
- protected EditingDomain domain;
- protected EMFDataBindingContext edbc;
+ private EObject owner;
+ private Resource resource;
+ private EditingDomain domain;
+ private EMFDataBindingContext edbc;
/**
* This will be created by the abstract method {@link #createWidgetFactory()}
*/
- protected IWidgetFactory widgetFactory;
+ private IWidgetFactory widgetFactory;
/**
* This will be created by the abstract method
* {@link #createFeatureLabelCaptionProvider()}
*/
- protected FeatureLabelCaptionProvider featureLabelCaptionProvider;
+ private FeatureLabelCaptionProvider featureLabelCaptionProvider;
- protected boolean readonly = false;
+ private boolean readonly = false;
public static final String EOBJECT_KEY = EcorePackage.Literals.EOBJECT
.getName();
@@ -122,6 +122,25 @@ public abstract class AbstractControlFactory implements IWidgetFactory {
}
+ protected EObject getOwner() {
+ return owner;
+ }
+
+ protected EditingDomain getEditingDomain() {
+ return domain;
+ }
+
+ protected EMFDataBindingContext getDataBindingContext() {
+ return edbc;
+ }
+
+ protected Resource getResource() {
+ if (resource == null) {
+ resource = owner.eResource();
+ }
+ return resource;
+ }
+
/**
* Concrete implementation should create a {@link IWidgetFactory} according
* to the specific widgets (e.g., for dialogs or forms).
@@ -139,30 +158,6 @@ public abstract class AbstractControlFactory implements IWidgetFactory {
*/
protected abstract FeatureLabelCaptionProvider createFeatureLabelCaptionProvider();
- public Provider<ILabelProvider> getLabelProviderProvider() {
- return labelProviderProvider;
- }
-
- public Provider<ComboViewerLabelProvider> getComboViewerLabelProviderProvider() {
- return comboViewerLabelProviderProvider;
- }
-
- protected ILabelProvider createLabelProvider() {
- return getLabelProviderProvider().get();
- }
-
- protected ILabelProvider createComboViewerLabelProvider() {
- return getComboViewerLabelProviderProvider().get();
- }
-
- public ProposalCreator getProposalCreator() {
- return proposalCreator;
- }
-
- public void setProposalCreator(ProposalCreator proposalCreator) {
- this.proposalCreator = proposalCreator;
- }
-
public boolean isReadonly() {
return readonly;
}
@@ -171,6 +166,14 @@ public abstract class AbstractControlFactory implements IWidgetFactory {
this.readonly = readonly;
}
+ private ILabelProvider createLabelProvider() {
+ return labelProviderProvider.get();
+ }
+
+ private ILabelProvider createComboViewerLabelProvider() {
+ return comboViewerLabelProviderProvider.get();
+ }
+
/**
* Initializes this factory for creating {@link Control}s with
* Data Binding.
@@ -196,13 +199,6 @@ public abstract class AbstractControlFactory implements IWidgetFactory {
this.owner = owner;
}
- protected Resource getResource() {
- if (resource == null) {
- resource = owner.eResource();
- }
- return resource;
- }
-
/**
* Creates a caption label and a {@link Control} for the passed {@link EStructuralFeature}
* of the {@link EObject} handled by this factory.
@@ -279,7 +275,7 @@ public abstract class AbstractControlFactory implements IWidgetFactory {
MultipleFeatureControl mfc = new MultipleFeatureControl(getParent(),
this, labelProviderProvider.get(), owner,
- feature, getProposalCreator(), isReadonly());
+ feature, proposalCreator, isReadonly());
IObservableValue target = new MultipleFeatureControlObservable(mfc);
return new ControlObservablePair(mfc, target);
}
@@ -348,9 +344,9 @@ public abstract class AbstractControlFactory implements IWidgetFactory {
}
}
- public List<Object> createProposals(EStructuralFeature feature) {
- getProposalCreator().setResource(getResource());
- return getProposalCreator().proposals(owner, feature);
+ protected List<Object> createProposals(EStructuralFeature feature) {
+ proposalCreator.setResource(getResource());
+ return proposalCreator.proposals(owner, feature);
}
protected ControlObservablePair createControlAndObservableWithPredefinedProposals(
diff --git a/plugins/org.eclipse.emf.parsley.junit4/src/org/eclipse/emf/parsley/junit4/AbstractEmfParsleyControlBasedTest.java b/plugins/org.eclipse.emf.parsley.junit4/src/org/eclipse/emf/parsley/junit4/AbstractEmfParsleyControlBasedTest.java
index 1bc5327e9..090938f8e 100644
--- a/plugins/org.eclipse.emf.parsley.junit4/src/org/eclipse/emf/parsley/junit4/AbstractEmfParsleyControlBasedTest.java
+++ b/plugins/org.eclipse.emf.parsley.junit4/src/org/eclipse/emf/parsley/junit4/AbstractEmfParsleyControlBasedTest.java
@@ -27,7 +27,6 @@ import org.eclipse.emf.parsley.composite.AbstractControlFactory;
import org.eclipse.emf.parsley.composite.DialogControlFactory;
import org.eclipse.emf.parsley.composite.FormControlFactory;
import org.eclipse.emf.parsley.composite.MultipleFeatureControl;
-import org.eclipse.emf.parsley.composite.ProposalCreator;
import org.eclipse.emf.parsley.junit4.ui.util.RunnableWithResult;
import org.eclipse.emf.parsley.junit4.util.TestDefaultRealm;
import org.eclipse.jface.databinding.swt.SWTObservables;
@@ -113,7 +112,7 @@ public abstract class AbstractEmfParsleyControlBasedTest extends
protected void initializeCommon(
final AbstractControlFactory controlFactory, final EObject obj) {
injectMembers(controlFactory);
- controlFactory.setProposalCreator(new ProposalCreator());
+ getOrCreateInjector().injectMembers(controlFactory);
}
protected Control createControl(final AbstractControlFactory factory,
diff --git a/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/AbstractControlFactoryTest.xtend b/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/AbstractControlFactoryTest.xtend
index 1bf35ff74..4b753b58b 100644
--- a/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/AbstractControlFactoryTest.xtend
+++ b/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/AbstractControlFactoryTest.xtend
@@ -15,9 +15,9 @@ import org.junit.Rule
import org.eclipse.emf.parsley.tests.util.EmfParsleyFixturesAndUtilitiesTestRule
abstract class AbstractControlFactoryTest extends AbstractEmfParsleyControlBasedTest {
-
+
@Rule public extension EmfParsleyFixturesAndUtilitiesTestRule fixtures = new EmfParsleyFixturesAndUtilitiesTestRule()
-
+
override protected getEditingDomain() {
return fixtures.editingDomain
}
@@ -26,4 +26,4 @@ abstract class AbstractControlFactoryTest extends AbstractEmfParsleyControlBased
return fixtures.createResourceSet
}
-} \ No newline at end of file
+}
diff --git a/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/CustomDialogControlFactoryTest.xtend b/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/CustomDialogControlFactoryTest.xtend
index d597290d6..0b1dd80d1 100644
--- a/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/CustomDialogControlFactoryTest.xtend
+++ b/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/CustomDialogControlFactoryTest.xtend
@@ -53,6 +53,30 @@ class CustomDialogControlFactoryTest extends AbstractControlFactoryTest {
}
/**
+ * Test the protected getters from the superclass
+ *
+ * <pre>
+ * Control control_ClassName_FeatureName(ClassName e)
+ * </pre>
+ */
+ @Test
+ def void testCustomControlPolymorphicGetters() {
+ val obj = createBaseClassObject
+ val factory = new DialogControlFactory {
+ def control_BaseClass_baseClassFeature(BaseClass e) {
+ obj.assertSame(owner)
+ dataBindingContext.assertNotNull
+ // in this scenario the editing domain is null
+ editingDomain.assertNull
+ createText("Foo")
+ }
+ } => [initialize(obj)]
+ val control = factory.createControl(testPackage.baseClass_BaseClassFeature)
+ control.assertTextEditable(true)
+ control.assertText("Foo")
+ }
+
+ /**
* Test the polymorphic method pattern
*
* <pre>
@@ -225,22 +249,28 @@ class CustomDialogControlFactoryTest extends AbstractControlFactoryTest {
control.assertText("Foo")
}
+ static class CustomProposalCreator extends ProposalCreator {
+ def proposals_BaseClass_baseClassFeature(BaseClass e) {
+ return #["First Proposal", "Second Proposal"]
+ }
+ }
+
@Test def void testWrongContentAssistKeyStroke() {
val factory = new DialogControlFactory => [initialize(createBaseClassObject)]
// this will replace the string for content assist shortcut with
// an unparsable KeyStroke
+
val injector = createInjector(new EmfParsleyGuiceModuleForTesting() {
override valueContentAssistShortcut() {
"Foo+Space";
}
+
+ override bindProposalCreator() {
+ org.eclipse.emf.parsley.tests.CustomDialogControlFactoryTest.CustomProposalCreator
+ }
+
})
injector.injectMembers(factory)
- // this will trigger the creation of a ContentProposalAdapter
- factory.proposalCreator = new ProposalCreator() {
- def proposals_BaseClass_baseClassFeature(BaseClass e) {
- return #["First Proposal", "Second Proposal"]
- }
- }
// during the parsing of the KeyStroke an exception will be logged
val control = factory.createControl(testPackage.baseClass_BaseClassFeature)
// but the Text will be created anyway (without ContentProposalAdapter)
diff --git a/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/DialogControlFactoryTest.xtend b/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/DialogControlFactoryTest.xtend
index aea08a94a..282419f5a 100644
--- a/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/DialogControlFactoryTest.xtend
+++ b/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/DialogControlFactoryTest.xtend
@@ -13,24 +13,27 @@ package org.eclipse.emf.parsley.tests
import org.eclipse.emf.parsley.composite.DialogControlFactory
import org.eclipse.emf.parsley.composite.MultipleFeatureControl
import org.eclipse.emf.parsley.composite.ProposalCreator
+import org.eclipse.emf.parsley.tests.DialogControlFactoryTest.CustomProposalCreator1
+import org.eclipse.emf.parsley.tests.DialogControlFactoryTest.CustomProposalCreator2
+import org.eclipse.emf.parsley.tests.DialogControlFactoryTest.CustomProposalCreator3
import org.eclipse.emf.parsley.tests.models.testmodels.ClassForControls
import org.eclipse.emf.parsley.tests.models.testmodels.EnumForControls
+import org.junit.After
import org.junit.Before
import org.junit.Test
import static extension org.junit.Assert.*
-import org.junit.After
class DialogControlFactoryTest extends AbstractControlFactoryTest {
-
+
/**
* An instance to use for testing the creation of a Control
* using an AbstractControlFactory
*/
var protected ClassForControls classForControlsInstance
-
+
var protected DialogControlFactory factory
-
+
@Before
def void setupEObject() {
classForControlsInstance = testFactory.createClassForControls
@@ -118,12 +121,21 @@ class DialogControlFactoryTest extends AbstractControlFactoryTest {
control.assertText("")
}
+ static class CustomProposalCreator1 extends ProposalCreator {
+ def proposals_ClassForControls_stringFeature(ClassForControls e) {
+ return #["First Proposal", "Second Proposal"]
+ }
+ }
+
@Test def void testStringFeatureWithProposals() {
- factory.proposalCreator = new ProposalCreator() {
- def proposals_ClassForControls_stringFeature(ClassForControls e) {
- return #["First Proposal", "Second Proposal"]
+ val injector = createInjector(new EmfParsleyGuiceModuleForTesting() {
+
+ override bindProposalCreator() {
+ CustomProposalCreator1
}
- }
+ })
+ factory = injector.getInstance(DialogControlFactory)
+ factory.init(editingDomain, classForControlsInstance, shell)
val control = factory.createControl(testPackage.classForControls_StringFeature)
control.assertTextEditable(true)
control.assertText("")
@@ -131,22 +143,40 @@ class DialogControlFactoryTest extends AbstractControlFactoryTest {
control.assertText("Foo")
}
+ static class CustomProposalCreator2 extends ProposalCreator {
+ def proposals_ClassForControls_stringFeature(ClassForControls e) {
+ return null
+ }
+ }
+
@Test def void testStringFeatureWithNullProposals() {
- factory.proposalCreator = new ProposalCreator() {
- def proposals_ClassForControls_stringFeature(ClassForControls e) {
- return null
+ val injector = createInjector(new EmfParsleyGuiceModuleForTesting() {
+
+ override bindProposalCreator() {
+ CustomProposalCreator2
}
- }
+ })
+ factory = injector.getInstance(DialogControlFactory)
+ factory.init(editingDomain, classForControlsInstance, shell)
val control = factory.createControl(testPackage.classForControls_StringFeature)
control.assertTextEditable(true)
}
+ static class CustomProposalCreator3 extends ProposalCreator {
+ def proposals_ClassForControls_stringFeature(ClassForControls e) {
+ return emptyList
+ }
+ }
+
@Test def void testStringFeatureWithEmptyProposals() {
- factory.proposalCreator = new ProposalCreator() {
- def proposals_ClassForControls_stringFeature(ClassForControls e) {
- return emptyList
+ val injector = createInjector(new EmfParsleyGuiceModuleForTesting() {
+
+ override bindProposalCreator() {
+ CustomProposalCreator3
}
- }
+ })
+ factory = injector.getInstance(DialogControlFactory)
+ factory.init(editingDomain, classForControlsInstance, shell)
val control = factory.createControl(testPackage.classForControls_StringFeature)
control.assertTextEditable(true)
}
diff --git a/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/DialogWidgetFactoryTest.xtend b/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/DialogWidgetFactoryTest.xtend
index ef7bab7a2..a09aab251 100644
--- a/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/DialogWidgetFactoryTest.xtend
+++ b/tests/org.eclipse.emf.parsley.tests/src/org/eclipse/emf/parsley/tests/DialogWidgetFactoryTest.xtend
@@ -71,12 +71,18 @@ class DialogWidgetFactoryTest extends AbstractEmfParsleyControlBasedTest {
control.assertText(TEST_TEXT)
}
- @Test def void testTextWithParentAndStyle() {
+ @Test def void testTextWithParentTextAndStyle() {
val control = factory.createText(shell, TEST_TEXT, SWT.NO_SCROLL)
control.assertText(TEST_TEXT)
control.assertStyle(SWT.NO_SCROLL)
}
+ @Test def void testTextWithParentAndStyle() {
+ val control = factory.createText(shell, SWT.NO_SCROLL)
+ control.assertText("")
+ control.assertStyle(SWT.NO_SCROLL)
+ }
+
@Test def void testTextWithStyle() {
val control = factory.createText(TEST_TEXT, SWT.NO_SCROLL)
control.assertText(TEST_TEXT)

Back to the top