Skip to content

Commit

Permalink
494910: createDefaultControl in the AbstractControlFactory
Browse files Browse the repository at this point in the history
Change-Id: Ia5c647d292cc01b6f3dee2a13fed75548a7a0c7a
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=494910
Signed-off-by: Lorenzo Bettini <lorenzo.bettini@gmail.com>
  • Loading branch information
LorenzoBettini committed Jun 8, 2016
1 parent 8369e35 commit 4857548
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 29 deletions.
Expand Up @@ -212,20 +212,36 @@ public void createEditingField(EStructuralFeature feature) {

/**
* Creates a {@link Control} for the passed {@link EStructuralFeature}
* of the {@link EObject} handled by this factory.
* of the {@link EObject} handled by this factory, using polymorphic dispatch.
*
* @param feature the {@link EStructuralFeature} for the creation of control
* @return a {@link Control}
*/
public Control create(EStructuralFeature feature) {
return create(feature, true);
}

/**
* Creates a {@link Control} for the passed {@link EStructuralFeature}
* of the {@link EObject} handled by this factory, using polymorphic dispatch, if
* specified in the argument withPolymorphicDispatch.
*
* @param feature
* @param withPolymorphicDispatch
* @return
*/
public Control create(EStructuralFeature feature, boolean withPolymorphicDispatch) {
Control control = null;

control = polymorphicCreateControl(feature);
if (withPolymorphicDispatch) {
control = polymorphicCreateControl(feature);
}

if (control == null) {
if (feature.isMany()) {
control = createAndBindList(feature);
control = createAndBindList(feature, withPolymorphicDispatch);
} else {
control = createAndBindValue(feature);
control = createAndBindValue(feature, withPolymorphicDispatch);
}
setupControl(feature, control);
}
Expand All @@ -235,17 +251,29 @@ public Control create(EStructuralFeature feature) {
return control;
}

/**
* Creates a {@link Control} for the passed {@link EStructuralFeature}
* of the {@link EObject} handled by this factory, using the default
* implementation, that is, without using polymorphic dispatch.
*
* @param feature the {@link EStructuralFeature} for the creation of control
* @return a {@link Control}
*/
public Control createDefaultControl(EStructuralFeature feature) {
return create(feature, false);
}

protected KeyListener registerUndoRedo(Control control) {
if (control instanceof Text) {
return new TextUndoRedo((Text) control);
}
return null;
}

protected Control createAndBindList(final EStructuralFeature feature) {
IObservableValue source = createFeatureObserveable(feature);
protected Control createAndBindList(final EStructuralFeature feature, boolean withPolymorphicDispatch) {
IObservableValue source = createFeatureObserveable(feature, withPolymorphicDispatch);

ControlObservablePair retValAndTargetPair = createControlForList(feature);
ControlObservablePair retValAndTargetPair = createControlForList(feature, withPolymorphicDispatch);
Control retVal = retValAndTargetPair.getControl();
IObservableValue target = retValAndTargetPair.getObservableValue();

Expand All @@ -254,23 +282,27 @@ protected Control createAndBindList(final EStructuralFeature feature) {
return retVal;
}

protected IObservableValue createFeatureObserveable(final EStructuralFeature feature) {
IObservableValue source = polymorphicCreateObserveable(domain, feature);
if (source == null) {
if (domain != null) {
source = EMFEditProperties.value(domain, feature).observe(owner);
} else {
source = EMFProperties.value(feature).observe(owner);
protected IObservableValue createFeatureObserveable(final EStructuralFeature feature, boolean withPolymorphicDispatch) {
if (withPolymorphicDispatch) {
IObservableValue source = polymorphicCreateObserveable(domain, feature);
if (source != null) {
return source;
}
}
return source;
if (domain != null) {
return EMFEditProperties.value(domain, feature).observe(owner);
} else {
return EMFProperties.value(feature).observe(owner);
}
}

protected ControlObservablePair createControlForList(
final EStructuralFeature feature) {
ControlObservablePair result = polymorphicGetObservableControl(feature);
if (result != null) {
return result;
final EStructuralFeature feature, boolean withPolymorphicDispatch) {
if (withPolymorphicDispatch) {
ControlObservablePair result = polymorphicGetObservableControl(feature);
if (result != null) {
return result;
}
}

MultipleFeatureControl mfc = new MultipleFeatureControl(getParent(),
Expand All @@ -280,15 +312,17 @@ protected ControlObservablePair createControlForList(
return new ControlObservablePair(mfc, target);
}

Control createAndBindValue(EStructuralFeature feature) {
IObservableValue featureObservable = createFeatureObserveable(feature);
protected Control createAndBindValue(EStructuralFeature feature, boolean withPolymorphicDispatch) {
IObservableValue featureObservable = createFeatureObserveable(feature, withPolymorphicDispatch);

Control control = polymorphicCreateControl(feature, featureObservable);
if (control != null) {
return control;
if (withPolymorphicDispatch) {
Control control = polymorphicCreateControl(feature, featureObservable);
if (control != null) {
return control;
}
}

ControlObservablePair retValAndTargetPair = createControlAndObservableValue(feature);
ControlObservablePair retValAndTargetPair = createControlAndObservableValue(feature, withPolymorphicDispatch);
Control retVal = retValAndTargetPair.getControl();
IObservableValue controlObservable = retValAndTargetPair
.getObservableValue();
Expand All @@ -301,10 +335,12 @@ Control createAndBindValue(EStructuralFeature feature) {
}

protected ControlObservablePair createControlAndObservableValue(
EStructuralFeature feature) {
ControlObservablePair result = polymorphicGetObservableControl(feature);
if (result != null) {
return result;
EStructuralFeature feature, boolean withPolymorphicDispatch) {
if (withPolymorphicDispatch) {
ControlObservablePair result = polymorphicGetObservableControl(feature);
if (result != null) {
return result;
}
}

if (featureHelper.isBooleanFeature(feature)) {
Expand Down
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2016 RCP Vision (http://www.rcp-vision.com) 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:
* Lorenzo Bettini - Initial contribution and API
*******************************************************************************/
package org.eclipse.emf.parsley.tests

import org.eclipse.emf.ecore.EStructuralFeature
import org.eclipse.emf.parsley.composite.DialogControlFactory
import org.eclipse.swt.widgets.Text
import org.eclipse.emf.parsley.tests.models.testmodels.BaseClass
import org.junit.Test

/**
* Tests control creation without using polymorphic dispatch by default.
*
* @author Lorenzo Bettini
*/
class DefaultControlFactoryTest extends DialogControlFactoryTest {

def override protected createAndInitializeFactory() {
new DialogControlFactory() {
override create(EStructuralFeature feature) {
super.createDefaultControl(feature)
}
} => [
initialize(classForControlsInstance)
]
}

@Test
def void testCustomControlPolymorphicUsingDefaultCreate() {
val factory = new DialogControlFactory {
def control_BaseClass_baseClassFeature(BaseClass e) {
createDefaultControl(testPackage.baseClass_BaseClassFeature) => [
(it as Text).text = "Foo"
]
}
} => [initialize(testFactory.createBaseClass)]
val control = factory.createControl(testPackage.baseClass_BaseClassFeature)
control.assertTextEditable(true)
control.assertText("Foo")
}
}

0 comments on commit 4857548

Please sign in to comment.