494945: cleanup API for AbstractControlFactory

Change-Id: I1dd4efb78578631ea7de3b00d608d6a1d0ef18bc
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=494945
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 db29fe3..eaa02c2 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 279c1ec..6fb8117 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 d0e36c3..ad0be1b 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 1360490..82ff846 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 ed6f5bd..69014e8 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 594e29a..1034f4e 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 @@
 	@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 @@
 
 	}
 
+	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 @@
 	 */
 	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 @@
 		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 @@
 		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 @@
 
 		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 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 1bc5327..090938f 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.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 @@
 	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 1bf35ff..4b753b5 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.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 @@
 		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 d597290..0b1dd80 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 @@
 	}
 
 	/**
+	 * 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 @@
 		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 aea08a9..282419f 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 @@
 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 @@
 		control.assertText("")
 	}
 
-	@Test def void testStringFeatureWithProposals() {
-		factory.proposalCreator = new ProposalCreator() {
-			def proposals_ClassForControls_stringFeature(ClassForControls e) {
-				return #["First Proposal", "Second Proposal"]
-			}
+	static class CustomProposalCreator1 extends ProposalCreator {
+		def proposals_ClassForControls_stringFeature(ClassForControls e) {
+			return #["First Proposal", "Second Proposal"]
 		}
+	}
+
+	@Test def void testStringFeatureWithProposals() {
+		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 @@
 		control.assertText("Foo")
 	}
 
-	@Test def void testStringFeatureWithNullProposals() {
-		factory.proposalCreator = new ProposalCreator() {
-			def proposals_ClassForControls_stringFeature(ClassForControls e) {
-				return null
-			}
+	static class CustomProposalCreator2 extends ProposalCreator {
+		def proposals_ClassForControls_stringFeature(ClassForControls e) {
+			return null
 		}
+	}
+
+	@Test def void testStringFeatureWithNullProposals() {
+		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)
 	}
 
-	@Test def void testStringFeatureWithEmptyProposals() {
-		factory.proposalCreator = new ProposalCreator() {
-			def proposals_ClassForControls_stringFeature(ClassForControls e) {
-				return emptyList
-			}
+	static class CustomProposalCreator3 extends ProposalCreator {
+		def proposals_ClassForControls_stringFeature(ClassForControls e) {
+			return emptyList
 		}
+	}
+
+	@Test def void testStringFeatureWithEmptyProposals() {
+		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 ef7bab7..a09aab2 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 @@
 		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)