Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2008-08-22 14:13:35 +0000
committerkmoore2008-08-22 14:13:35 +0000
commit25f75314ee46090080fb394015c5324bdeaf7edc (patch)
tree931b73e14caf594294c51c12979da5ecc1122e71 /jpa
parent04af6873eed774bbdf25573e5078c82567b72e92 (diff)
downloadwebtools.dali-25f75314ee46090080fb394015c5324bdeaf7edc.tar.gz
webtools.dali-25f75314ee46090080fb394015c5324bdeaf7edc.tar.xz
webtools.dali-25f75314ee46090080fb394015c5324bdeaf7edc.zip
created CachingTransformationPropertyValueModel to cache the transformed value so that we do not have to transfrom the oldValue when fire change events
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java188
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java328
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CachingTransformationPropertyValueModel.java96
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CachingTransformationWritablePropertyValueModel.java84
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TransformationPropertyValueModel.java21
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java218
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java249
-rw-r--r--jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java2
8 files changed, 935 insertions, 251 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java
index f29571e634..478d7e8722 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/EmbeddedAttributeOverridesComposite.java
@@ -27,12 +27,12 @@ import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane;
import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane;
import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter;
import org.eclipse.jpt.utility.internal.StringTools;
+import org.eclipse.jpt.utility.internal.model.value.CachingTransformationWritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel;
import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel;
-import org.eclipse.jpt.utility.internal.model.value.TransformationWritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel;
import org.eclipse.jpt.utility.model.value.ListValueModel;
import org.eclipse.jpt.utility.model.value.PropertyValueModel;
@@ -70,6 +70,8 @@ public class EmbeddedAttributeOverridesComposite extends AbstractFormPane<BaseEm
{
private WritablePropertyValueModel<AttributeOverride> selectedAttributeOverrideHolder;
+ private WritablePropertyValueModel<Boolean> overrideVirtualAttributeOverrideHolder;
+
/**
* Creates a new <code>EmbeddedAttributeOverridesComposite</code>.
*
@@ -96,6 +98,87 @@ public class EmbeddedAttributeOverridesComposite extends AbstractFormPane<BaseEm
super(subjectHolder, parent, widgetFactory);
}
+ @Override
+ protected void initialize() {
+ super.initialize();
+ this.selectedAttributeOverrideHolder = buildAttributeOverrideHolder();
+ }
+
+ private AddRemoveListPane<BaseEmbeddedMapping> initializeAttributeOverridesList(Composite container) {
+
+ return new AddRemoveListPane<BaseEmbeddedMapping>(
+ this,
+ buildSubPane(container, 8),
+ buildAttributeOverridesAdapter(),
+ buildAttributeOverridesListModel(),
+ this.selectedAttributeOverrideHolder,
+ buildAttributeOverrideLabelProvider(),
+ JpaHelpContextIds.MAPPING_EMBEDDED_ATTRIBUTE_OVERRIDES
+ )
+ {
+ @Override
+ protected void initializeButtonPane(Composite container, String helpId) {
+ }
+
+ @Override
+ protected void updateButtons() {
+ }
+ };
+ }
+
+ @Override
+ protected void initializeLayout(Composite container) {
+
+ // Attribute Overrides group box
+ container = buildTitledPane(
+ container,
+ JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides
+ );
+
+ // Attribute Overrides list
+ initializeAttributeOverridesList(container);
+
+ // Property pane
+ initializePropertyPane(buildSubPane(container, 5, 0));
+ }
+
+ private void initializePropertyPane(Composite container) {
+
+ // Override Default check box
+ Button overrideDefaultButton = buildCheckBox(
+ buildSubPane(container, 0, groupBoxMargin()),
+ JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault,
+ getOverrideVirtualAttributeOverrideHolder()
+ );
+
+ removeFromEnablementControl(overrideDefaultButton);
+ installOverrideDefaultButtonEnabler(overrideDefaultButton);
+
+ // Column widgets
+ ColumnComposite columnComposite = new ColumnComposite(
+ this,
+ buildColumnHolder(this.selectedAttributeOverrideHolder),
+ container
+ );
+
+ installColumnCompositeEnabler(columnComposite);
+ removeFromEnablementControl(columnComposite.getControl());
+ }
+
+ private void installColumnCompositeEnabler(ColumnComposite columnComposite) {
+ new PaneEnabler(
+ getOverrideVirtualAttributeOverrideHolder(),
+ columnComposite
+ );
+ }
+
+ private void installOverrideDefaultButtonEnabler(Button overrideDefaultButton) {
+ new ControlEnabler(
+ buildOverrideVirtualAttributeOverrideEnablerHolder(),
+ overrideDefaultButton
+ );
+ }
+
private WritablePropertyValueModel<AttributeOverride> buildAttributeOverrideHolder() {
return new SimplePropertyValueModel<AttributeOverride>();
}
@@ -123,7 +206,7 @@ public class EmbeddedAttributeOverridesComposite extends AbstractFormPane<BaseEm
private ListValueModel<AttributeOverride> buildAttributeOverridesListHolder() {
List<ListValueModel<AttributeOverride>> list = new ArrayList<ListValueModel<AttributeOverride>>();
list.add(buildSpecifiedAttributeOverridesListHolder());
- list.add(buildDefaultAttributeOverridesListHolder());
+ list.add(buildVirtualAttributeOverridesListHolder());
return new CompositeListValueModel<ListValueModel<AttributeOverride>, AttributeOverride>(list);
}
@@ -143,7 +226,7 @@ public class EmbeddedAttributeOverridesComposite extends AbstractFormPane<BaseEm
};
}
- private ListValueModel<AttributeOverride> buildDefaultAttributeOverridesListHolder() {
+ private ListValueModel<AttributeOverride> buildVirtualAttributeOverridesListHolder() {
return new ListAspectAdapter<BaseEmbeddedMapping, AttributeOverride>(
this.getSubjectHolder(),
BaseEmbeddedMapping.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST)
@@ -160,7 +243,7 @@ public class EmbeddedAttributeOverridesComposite extends AbstractFormPane<BaseEm
};
}
- private PropertyValueModel<Boolean> buildOverrideDefaultAttributeOverrideEnablerHolder() {
+ private PropertyValueModel<Boolean> buildOverrideVirtualAttributeOverrideEnablerHolder() {
return new TransformationPropertyValueModel<AttributeOverride, Boolean>(this.selectedAttributeOverrideHolder) {
@Override
protected Boolean transform(AttributeOverride value) {
@@ -169,8 +252,15 @@ public class EmbeddedAttributeOverridesComposite extends AbstractFormPane<BaseEm
};
}
- private WritablePropertyValueModel<Boolean> buildOverrideDefaultAttributeOverrideHolder() {
- return new TransformationWritablePropertyValueModel<AttributeOverride, Boolean>(this.selectedAttributeOverrideHolder) {
+ protected WritablePropertyValueModel<Boolean> getOverrideVirtualAttributeOverrideHolder() {
+ if (this.overrideVirtualAttributeOverrideHolder == null) {
+ this.overrideVirtualAttributeOverrideHolder = buildOverrideVirtualAttributeOverrideHolder();
+ }
+ return this.overrideVirtualAttributeOverrideHolder;
+ }
+
+ private WritablePropertyValueModel<Boolean> buildOverrideVirtualAttributeOverrideHolder() {
+ return new CachingTransformationWritablePropertyValueModel<AttributeOverride, Boolean>(this.selectedAttributeOverrideHolder) {
@Override
public void setValue(Boolean value) {
updateAttributeOverride(value);
@@ -214,92 +304,6 @@ public class EmbeddedAttributeOverridesComposite extends AbstractFormPane<BaseEm
};
}
- /*
- * (non-Javadoc)
- */
- @Override
- protected void initialize() {
- super.initialize();
- this.selectedAttributeOverrideHolder = buildAttributeOverrideHolder();
- }
-
- private AddRemoveListPane<BaseEmbeddedMapping> initializeAttributeOverridesList(Composite container) {
-
- return new AddRemoveListPane<BaseEmbeddedMapping>(
- this,
- buildSubPane(container, 8),
- buildAttributeOverridesAdapter(),
- buildAttributeOverridesListModel(),
- this.selectedAttributeOverrideHolder,
- buildAttributeOverrideLabelProvider(),
- JpaHelpContextIds.MAPPING_EMBEDDED_ATTRIBUTE_OVERRIDES
- )
- {
- @Override
- protected void initializeButtonPane(Composite container, String helpId) {
- }
-
- @Override
- protected void updateButtons() {
- }
- };
- }
-
- /*
- * (non-Javadoc)
- */
- @Override
- protected void initializeLayout(Composite container) {
-
- // Attribute Overrides group box
- container = buildTitledPane(
- container,
- JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides
- );
-
- // Attribute Overrides list
- initializeAttributeOverridesList(container);
-
- // Property pane
- initializePropertyPane(buildSubPane(container, 5, 0));
- }
-
- private void initializePropertyPane(Composite container) {
-
- // Override Default check box
- Button overrideDefaultButton = buildCheckBox(
- buildSubPane(container, 0, groupBoxMargin()),
- JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault,
- buildOverrideDefaultAttributeOverrideHolder()
- );
-
- removeFromEnablementControl(overrideDefaultButton);
- installOverrideDefaultButtonEnabler(overrideDefaultButton);
-
- // Column widgets
- ColumnComposite columnComposite = new ColumnComposite(
- this,
- buildColumnHolder(this.selectedAttributeOverrideHolder),
- container
- );
-
- installColumnCompositeEnabler(columnComposite);
- removeFromEnablementControl(columnComposite.getControl());
- }
-
- private void installColumnCompositeEnabler(ColumnComposite columnComposite) {
- new PaneEnabler(
- buildOverrideDefaultAttributeOverrideHolder(),
- columnComposite
- );
- }
-
- private void installOverrideDefaultButtonEnabler(Button overrideDefaultButton) {
- new ControlEnabler(
- buildOverrideDefaultAttributeOverrideEnablerHolder(),
- overrideDefaultButton
- );
- }
private void updateAttributeOverride(boolean selected) {
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java
index 43bc625147..9c3a55f5b8 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java
@@ -32,6 +32,7 @@ import org.eclipse.jpt.ui.internal.widgets.PostExecution;
import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter;
import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.Transformer;
+import org.eclipse.jpt.utility.internal.model.value.CachingTransformationWritablePropertyValueModel;
import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel;
import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter;
import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter;
@@ -82,7 +83,9 @@ public class OverridesComposite extends AbstractFormPane<Entity>
{
private Composite columnPane;
private Composite joinColumnsPane;
- private WritablePropertyValueModel<BaseOverride> overrideHolder;
+ private WritablePropertyValueModel<BaseOverride> selectedOverrideHolder;
+ private WritablePropertyValueModel<Boolean> overrideVirtualAttributeOverrideHolder;
+ private WritablePropertyValueModel<Boolean> overrideVirtualAssociationOverrideHolder;
/**
* Creates a new <code>OverridesComposite</code>.
@@ -110,21 +113,142 @@ public class OverridesComposite extends AbstractFormPane<Entity>
super(subjectHolder, parent, widgetFactory);
}
- private void addJoinColumn(AssociationOverride subject) {
+ @Override
+ protected void initialize() {
+ super.initialize();
+ this.selectedOverrideHolder = buildSelectedOverrideHolder();
+ }
- JoinColumnInAssociationOverrideDialog dialog =
- new JoinColumnInAssociationOverrideDialog(shell(), subject, null);
+ private WritablePropertyValueModel<BaseOverride> buildSelectedOverrideHolder() {
+ return new SimplePropertyValueModel<BaseOverride>();
+ }
- dialog.openDialog(buildAddJoinColumnPostExecution());
+
+ @Override
+ protected void initializeLayout(Composite container) {
+
+ // Overrides group pane
+ container = buildTitledPane(
+ container,
+ JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides
+ );
+
+ // Overrides list pane
+ initializeOverridesList(container);
+
+ // Property pane
+ PageBook pageBook = buildPageBook(container);
+ initializeJoinColumnsPane(pageBook);
+ initializeColumnPane(pageBook);
+ installOverrideControlSwitcher(this.selectedOverrideHolder, pageBook);
}
- private void addJoinColumn(JoinColumnInAssociationOverrideStateObject stateObject) {
+ private AddRemoveListPane<Entity> initializeOverridesList(Composite container) {
- AssociationOverride associationOverride = stateObject.getOwner();
- int index = associationOverride.specifiedJoinColumnsSize();
+ return new AddRemoveListPane<Entity>(
+ this,
+ buildSubPane(container, 8),
+ buildOverridesAdapter(),
+ buildOverridesListModel(),
+ this.selectedOverrideHolder,
+ buildOverrideLabelProvider(),
+ JpaHelpContextIds.ENTITY_ATTRIBUTE_OVERRIDES
+ )
+ {
+ @Override
+ protected void initializeButtonPane(Composite container, String helpId) {
+ }
- JoinColumn joinColumn = associationOverride.addSpecifiedJoinColumn(index);
- stateObject.updateJoinColumn(joinColumn);
+ @Override
+ protected void updateButtons() {
+ }
+ };
+ }
+
+ private void initializeColumnPane(PageBook pageBook) {
+
+ int groupBoxMargin = groupBoxMargin();
+ this.columnPane = buildSubPane(pageBook, 5);
+
+ // Override Default check box
+ buildCheckBox(
+ buildSubPane(this.columnPane, 0, groupBoxMargin, 0, groupBoxMargin),
+ JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault,
+ getOverrideVirtualAttributeOverrideHolder()
+ );
+
+ // Column widgets (for IOverrideAttribute)
+ ColumnComposite columnComposite = new ColumnComposite(
+ this,
+ buildColumnHolder(buildAttributeOverrideHolder()),
+ this.columnPane,
+ false
+ );
+
+ this.columnPane.setVisible(false);
+ installColumnsPaneEnabler(columnComposite);
+ }
+
+ private void installColumnsPaneEnabler(ColumnComposite pane) {
+ new PaneEnabler(
+ getOverrideVirtualAttributeOverrideHolder(),
+ pane
+ );
+ }
+
+ private void initializeJoinColumnsPane(PageBook pageBook) {
+
+ this.joinColumnsPane = buildSubPane(pageBook);
+
+ // Override Default check box
+ buildCheckBox(
+ buildSubPane(this.joinColumnsPane, 5, groupBoxMargin()),
+ JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault,
+ getOverrideVirtualAssociationOverrideHolder()
+ );
+
+ Group joinColumnsGroupPane = buildTitledPane(
+ this.joinColumnsPane,
+ JptUiMappingsMessages.OverridesComposite_joinColumn
+ );
+
+ // Join Columns list pane (for IOverrideAssociation)
+ JoinColumnsComposite<AssociationOverride> joinColumnsComposite =
+ new JoinColumnsComposite<AssociationOverride>(
+ this,
+ buildAssociationOverrideHolder(),
+ joinColumnsGroupPane,
+ buildJoinColumnsEditor(),
+ false
+ );
+
+ this.joinColumnsPane.setVisible(false);
+ installJoinColumnsPaneEnabler(joinColumnsComposite);
+ }
+
+ private void installJoinColumnsPaneEnabler(JoinColumnsComposite<AssociationOverride> pane) {
+ new PaneEnabler(
+ getOverrideVirtualAssociationOverrideHolder(),
+ pane
+ );
+ }
+
+ private void installOverrideControlSwitcher(PropertyValueModel<BaseOverride> overrideHolder,
+ PageBook pageBook) {
+
+ new ControlSwitcher(
+ overrideHolder,
+ buildPaneTransformer(),
+ pageBook
+ );
+ }
+
+ private void addJoinColumn(AssociationOverride subject) {
+
+ JoinColumnInAssociationOverrideDialog dialog =
+ new JoinColumnInAssociationOverrideDialog(shell(), subject, null);
+
+ dialog.openDialog(buildAddJoinColumnPostExecution());
}
private PostExecution<JoinColumnInAssociationOverrideDialog> buildAddJoinColumnPostExecution() {
@@ -137,8 +261,17 @@ public class OverridesComposite extends AbstractFormPane<Entity>
};
}
+ private void addJoinColumn(JoinColumnInAssociationOverrideStateObject stateObject) {
+
+ AssociationOverride associationOverride = stateObject.getOwner();
+ int index = associationOverride.specifiedJoinColumnsSize();
+
+ JoinColumn joinColumn = associationOverride.addSpecifiedJoinColumn(index);
+ stateObject.updateJoinColumn(joinColumn);
+ }
+
private WritablePropertyValueModel<AssociationOverride> buildAssociationOverrideHolder() {
- return new TransformationWritablePropertyValueModel<BaseOverride, AssociationOverride>(overrideHolder) {
+ return new TransformationWritablePropertyValueModel<BaseOverride, AssociationOverride>(this.selectedOverrideHolder) {
@Override
protected AssociationOverride transform_(BaseOverride value) {
return (value instanceof AssociationOverride) ? (AssociationOverride) value : null;
@@ -147,7 +280,7 @@ public class OverridesComposite extends AbstractFormPane<Entity>
}
private WritablePropertyValueModel<AttributeOverride> buildAttributeOverrideHolder() {
- return new TransformationWritablePropertyValueModel<BaseOverride, AttributeOverride>(overrideHolder) {
+ return new TransformationWritablePropertyValueModel<BaseOverride, AttributeOverride>(this.selectedOverrideHolder) {
@Override
protected AttributeOverride transform_(BaseOverride value) {
return (value instanceof AttributeOverride) ? (AttributeOverride) value : null;
@@ -168,12 +301,12 @@ public class OverridesComposite extends AbstractFormPane<Entity>
return new ListAspectAdapter<Entity, AssociationOverride>(getSubjectHolder(), Entity.VIRTUAL_ASSOCIATION_OVERRIDES_LIST) {
@Override
protected ListIterator<AssociationOverride> listIterator_() {
- return subject.virtualAssociationOverrides();
+ return this.subject.virtualAssociationOverrides();
}
@Override
protected int size_() {
- return subject.virtualAssociationOverridesSize();
+ return this.subject.virtualAssociationOverridesSize();
}
};
}
@@ -182,12 +315,12 @@ public class OverridesComposite extends AbstractFormPane<Entity>
return new ListAspectAdapter<Entity, AttributeOverride>(getSubjectHolder(), Entity.VIRTUAL_ATTRIBUTE_OVERRIDES_LIST) {
@Override
protected ListIterator<AttributeOverride> listIterator_() {
- return subject.virtualAttributeOverrides();
+ return this.subject.virtualAttributeOverrides();
}
@Override
protected int size_() {
- return subject.virtualAttributeOverridesSize();
+ return this.subject.virtualAttributeOverridesSize();
}
};
}
@@ -206,8 +339,15 @@ public class OverridesComposite extends AbstractFormPane<Entity>
return new JoinColumnsProvider();
}
- private WritablePropertyValueModel<Boolean> buildOverrideDefaultAssociationOverrideHolder() {
- return new TransformationWritablePropertyValueModel<AssociationOverride, Boolean>(buildAssociationOverrideHolder()) {
+ protected WritablePropertyValueModel<Boolean> getOverrideVirtualAssociationOverrideHolder() {
+ if (this.overrideVirtualAssociationOverrideHolder == null) {
+ this.overrideVirtualAssociationOverrideHolder = buildOverrideVirtualAssociationOverrideHolder();
+ }
+ return this.overrideVirtualAssociationOverrideHolder;
+ }
+
+ private WritablePropertyValueModel<Boolean> buildOverrideVirtualAssociationOverrideHolder() {
+ return new CachingTransformationWritablePropertyValueModel<AssociationOverride, Boolean>(buildAssociationOverrideHolder()) {
@Override
public void setValue(Boolean value) {
updateOverride(value);
@@ -220,8 +360,16 @@ public class OverridesComposite extends AbstractFormPane<Entity>
};
}
- private WritablePropertyValueModel<Boolean> buildOverrideDefaultAttributeOverrideHolder() {
- return new TransformationWritablePropertyValueModel<AttributeOverride, Boolean>(buildAttributeOverrideHolder()) {
+ protected WritablePropertyValueModel<Boolean> getOverrideVirtualAttributeOverrideHolder() {
+ if (this.overrideVirtualAttributeOverrideHolder == null) {
+ this.overrideVirtualAttributeOverrideHolder = buildOverrideVirtualAttributeOverrideHolder();
+ }
+ return this.overrideVirtualAttributeOverrideHolder;
+ }
+
+
+ private WritablePropertyValueModel<Boolean> buildOverrideVirtualAttributeOverrideHolder() {
+ return new CachingTransformationWritablePropertyValueModel<AttributeOverride, Boolean>(buildAttributeOverrideHolder()) {
@Override
public void setValue(Boolean value) {
updateOverride(value);
@@ -261,10 +409,6 @@ public class OverridesComposite extends AbstractFormPane<Entity>
return sb.toString();
}
- private WritablePropertyValueModel<BaseOverride> buildOverrideHolder() {
- return new SimplePropertyValueModel<BaseOverride>();
- }
-
private ILabelProvider buildOverrideLabelProvider() {
return new LabelProvider() {
@Override
@@ -351,7 +495,7 @@ public class OverridesComposite extends AbstractFormPane<Entity>
JoinColumnInAssociationOverrideDialog dialog =
new JoinColumnInAssociationOverrideDialog(
shell(),
- (AssociationOverride) overrideHolder.getValue(),
+ (AssociationOverride) this.selectedOverrideHolder.getValue(),
joinColumn
);
@@ -362,136 +506,6 @@ public class OverridesComposite extends AbstractFormPane<Entity>
stateObject.updateJoinColumn(stateObject.getJoinColumn());
}
- /*
- * (non-Javadoc)
- */
- @Override
- protected void initialize() {
- super.initialize();
- overrideHolder = buildOverrideHolder();
- }
-
- private void initializeColumnPane(PageBook pageBook) {
-
- int groupBoxMargin = groupBoxMargin();
- columnPane = buildSubPane(pageBook, 5);
-
- // Override Default check box
- buildCheckBox(
- buildSubPane(columnPane, 0, groupBoxMargin, 0, groupBoxMargin),
- JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault,
- buildOverrideDefaultAttributeOverrideHolder()
- );
-
- // Column widgets (for IOverrideAttribute)
- ColumnComposite columnComposite = new ColumnComposite(
- this,
- buildColumnHolder(buildAttributeOverrideHolder()),
- columnPane,
- false
- );
-
- columnPane.setVisible(false);
- installColumnsPaneEnabler(columnComposite);
- }
-
- private void initializeJoinColumnsPane(PageBook pageBook) {
-
- joinColumnsPane = buildSubPane(pageBook);
-
- // Override Default check box
- buildCheckBox(
- buildSubPane(joinColumnsPane, 5, groupBoxMargin()),
- JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault,
- buildOverrideDefaultAssociationOverrideHolder()
- );
-
- Group joinColumnsGroupPane = buildTitledPane(
- joinColumnsPane,
- JptUiMappingsMessages.OverridesComposite_joinColumn
- );
-
- // Join Columns list pane (for IOverrideAssociation)
- JoinColumnsComposite<AssociationOverride> joinColumnsComposite =
- new JoinColumnsComposite<AssociationOverride>(
- this,
- buildAssociationOverrideHolder(),
- joinColumnsGroupPane,
- buildJoinColumnsEditor(),
- false
- );
-
- joinColumnsPane.setVisible(false);
- installJoinColumnsPaneEnabler(joinColumnsComposite);
- }
-
- /*
- * (non-Javadoc)
- */
- @Override
- protected void initializeLayout(Composite container) {
-
- // Overrides group pane
- container = buildTitledPane(
- container,
- JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides
- );
-
- // Overrides list pane
- initializeOverridesList(container);
-
- // Property pane
- PageBook pageBook = buildPageBook(container);
- initializeJoinColumnsPane(pageBook);
- initializeColumnPane(pageBook);
- installOverrideControlSwitcher(overrideHolder, pageBook);
- }
-
- private AddRemoveListPane<Entity> initializeOverridesList(Composite container) {
-
- return new AddRemoveListPane<Entity>(
- this,
- buildSubPane(container, 8),
- buildOverridesAdapter(),
- buildOverridesListModel(),
- overrideHolder,
- buildOverrideLabelProvider(),
- JpaHelpContextIds.ENTITY_ATTRIBUTE_OVERRIDES
- )
- {
- @Override
- protected void initializeButtonPane(Composite container, String helpId) {
- }
-
- @Override
- protected void updateButtons() {
- }
- };
- }
-
- private void installColumnsPaneEnabler(ColumnComposite pane) {
- new PaneEnabler(
- buildOverrideDefaultAttributeOverrideHolder(),
- pane
- );
- }
-
- private void installJoinColumnsPaneEnabler(JoinColumnsComposite<AssociationOverride> pane) {
- new PaneEnabler(
- buildOverrideDefaultAssociationOverrideHolder(),
- pane
- );
- }
-
- private void installOverrideControlSwitcher(PropertyValueModel<BaseOverride> overrideHolder,
- PageBook pageBook) {
-
- new ControlSwitcher(
- overrideHolder,
- buildPaneTransformer(),
- pageBook
- );
- }
private void updateOverride(boolean selected) {
@@ -502,10 +516,10 @@ public class OverridesComposite extends AbstractFormPane<Entity>
setPopulating(true);
try {
- BaseOverride override = overrideHolder.getValue();
+ BaseOverride override = this.selectedOverrideHolder.getValue();
BaseOverride newOverride = override.setVirtual(!selected);
- overrideHolder.setValue(newOverride);
+ this.selectedOverrideHolder.setValue(newOverride);
}
finally {
setPopulating(false);
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CachingTransformationPropertyValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CachingTransformationPropertyValueModel.java
new file mode 100644
index 0000000000..3f584aa496
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CachingTransformationPropertyValueModel.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.internal.model.value;
+
+import org.eclipse.jpt.utility.internal.Transformer;
+import org.eclipse.jpt.utility.model.value.PropertyValueModel;
+
+/**
+ * A <code>CachingTransformationPropertyValueModel</code> wraps another
+ * <code>PropertyValueModel</code> and uses a <code>Transformer</code>
+ * to transform the wrapped value before it is returned by <code>value()</code>.
+ * It also caches the value so that a transform is not done on the oldValue when
+ * firing a property change event.
+ * <p>
+ * As an alternative to building a <code>Transformer</code>,
+ * a subclass of <code>CachingTransformationPropertyValueModel</code> can
+ * either override the <code>transform_(Object)</code> method or,
+ * if something other than null should be returned when the wrapped value
+ * is null, override the <code>transform(Object)</code> method.
+ */
+public class CachingTransformationPropertyValueModel<T1, T2>
+ extends TransformationPropertyValueModel<T1, T2>
+ implements PropertyValueModel<T2>
+{
+
+ /**
+ * Cache the transformed value so that during property change event notification
+ * we do not have to transform the value. The oldValue could no longer be valid in
+ * the model, thus transforming it would not be valid.
+ */
+ protected T2 cachedValue;
+
+ // ********** constructors/initialization **********
+
+ /**
+ * Construct a property value model with the specified nested
+ * property value model and the default transformer.
+ * Use this constructor if you want to override the
+ * <code>transform_(Object)</code> or <code>transform(Object)</code>
+ * method instead of building a <code>Transformer</code>.
+ */
+ public CachingTransformationPropertyValueModel(PropertyValueModel<? extends T1> valueHolder) {
+ super(valueHolder);
+ }
+
+ /**
+ * Construct an property value model with the specified nested
+ * property value model and transformer.
+ */
+ public CachingTransformationPropertyValueModel(PropertyValueModel<? extends T1> valueHolder, Transformer<T1, T2> transformer) {
+ super(valueHolder, transformer);
+ }
+
+ // ********** behavior **********
+
+ @Override
+ protected void engageValueHolder() {
+ super.engageValueHolder();
+ this.cachedValue = this.transform(this.valueHolder.getValue());
+ }
+
+ @Override
+ protected void disengageValueHolder() {
+ super.disengageValueHolder();
+ this.cachedValue = null;
+ }
+
+ @Override
+ public T2 getValue() {
+ return this.cachedValue;
+ }
+
+ /**
+ * Transform the new value, caching it before returning it
+ */
+ @Override
+ protected T2 transformNew(T1 value) {
+ this.cachedValue = super.transformNew(value);
+ return this.cachedValue;
+ };
+
+ /**
+ * no transformation, just return the cachedValue which is already transformed
+ */
+ @Override
+ protected T2 transformOld(T1 value) {
+ return this.cachedValue;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CachingTransformationWritablePropertyValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CachingTransformationWritablePropertyValueModel.java
new file mode 100644
index 0000000000..1d97e46fca
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/CachingTransformationWritablePropertyValueModel.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.internal.model.value;
+
+import org.eclipse.jpt.utility.internal.BidiTransformer;
+import org.eclipse.jpt.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
+
+/**
+ * A <code>TransformationPropertyValueModel</code> wraps another
+ * <code>PropertyValueModel</code> and uses a <code>Transformer</code>
+ * to transform the wrapped value before it is returned by <code>value()</code>.
+ * <p>
+ * As an alternative to building a <code>Transformer</code>,
+ * a subclass of <code>TransformationPropertyValueModel</code> can
+ * either override the <code>transform_(Object)</code> method or,
+ * if something other than null should be returned when the wrapped value
+ * is null, override the <code>transform(Object)</code> method.
+ */
+public class CachingTransformationWritablePropertyValueModel<T1, T2>
+ extends TransformationWritablePropertyValueModel<T1, T2>
+ implements PropertyValueModel<T2>
+{
+
+ protected T2 cachedValue;
+
+ // ********** constructors/initialization **********
+
+ /**
+ * Construct a property value model with the specified nested
+ * property value model and the default transformer.
+ * Use this constructor if you want to override the
+ * <code>transform_(Object)</code> or <code>transform(Object)</code>
+ * method instead of building a <code>Transformer</code>.
+ */
+ public CachingTransformationWritablePropertyValueModel(WritablePropertyValueModel<T1> valueHolder) {
+ super(valueHolder);
+ }
+
+ /**
+ * Construct an property value model with the specified nested
+ * property value model and transformer.
+ */
+ public CachingTransformationWritablePropertyValueModel(WritablePropertyValueModel<T1> valueHolder, BidiTransformer<T1, T2> transformer) {
+ super(valueHolder, transformer);
+ }
+
+ // ********** behavior **********
+
+ @Override
+ protected void engageValueHolder() {
+ super.engageValueHolder();
+ this.cachedValue = this.transform(this.valueHolder.getValue());
+ }
+
+ @Override
+ protected void disengageValueHolder() {
+ super.disengageValueHolder();
+ this.cachedValue = null;
+ }
+
+ @Override
+ public T2 getValue() {
+ return this.cachedValue;
+ }
+
+ @Override
+ protected T2 transformNew(T1 value) {
+ this.cachedValue = super.transformNew(value);
+ return this.cachedValue;
+ };
+
+ @Override
+ protected T2 transformOld(T1 value) {
+ return this.cachedValue;
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TransformationPropertyValueModel.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TransformationPropertyValueModel.java
index 5d3b93e821..cc115cc1c8 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TransformationPropertyValueModel.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/model/value/TransformationPropertyValueModel.java
@@ -73,9 +73,9 @@ public class TransformationPropertyValueModel<T1, T2>
protected void valueChanged(PropertyChangeEvent event) {
// transform the values before propagating the change event
@SuppressWarnings("unchecked")
- Object oldValue = this.transform((T1) event.getOldValue());
+ Object oldValue = this.transformOld((T1) event.getOldValue());
@SuppressWarnings("unchecked")
- Object newValue = this.transform((T1) event.getNewValue());
+ Object newValue = this.transformNew((T1) event.getNewValue());
this.firePropertyChanged(VALUE, oldValue, newValue);
}
@@ -97,6 +97,23 @@ public class TransformationPropertyValueModel<T1, T2>
throw new UnsupportedOperationException();
}
+ /**
+ * Transform the specified old value and return the result.
+ * In this case just call {@link #transform(Object)}, override to change.
+ * This is called by #valueChanged(PropertyChangeEvent).
+ */
+ protected T2 transformOld(T1 value) {
+ return this.transform(value);
+ }
+
+ /**
+ * Transform the specified new value and return the result.
+ * In this case just call {@link #transform(Object)}, override to change.
+ * This is called by #valueChanged(PropertyChangeEvent).
+ */
+ protected T2 transformNew(T1 value) {
+ return this.transform(value);
+ }
// ********** default transformer **********
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java
new file mode 100644
index 0000000000..fd6ff2ae34
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java
@@ -0,0 +1,218 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import junit.framework.TestCase;
+import org.eclipse.jpt.utility.internal.BidiTransformer;
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.utility.internal.model.value.CachingTransformationPropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.jpt.utility.tests.internal.TestTools;
+
+public class CachingTransformationPropertyValueModelTests extends TestCase {
+ private WritablePropertyValueModel<Person> objectHolder;
+ PropertyChangeEvent event;
+
+ private PropertyValueModel<Person> transformationObjectHolder;
+ PropertyChangeEvent transformationEvent;
+
+ public CachingTransformationPropertyValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null));
+ this.transformationObjectHolder = new CachingTransformationPropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer());
+ }
+
+ private BidiTransformer<Person, Person> buildTransformer() {
+ return new BidiTransformer<Person, Person>() {
+ public Person transform(Person p) {
+ return (p == null) ? null : p.getParent();
+ }
+ public Person reverseTransform(Person p) {
+ return (p == null) ? null : p.getChild();
+ }
+ };
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testValue() {
+ PropertyChangeListener listener = this.buildTransformationListener();
+ this.transformationObjectHolder.addPropertyChangeListener(listener);
+
+
+ Person person = this.objectHolder.getValue();
+ assertEquals("Karen", person.getName());
+ Person parent = this.transformationObjectHolder.getValue();
+ assertEquals(person.getParent().getName(), parent.getName());
+ assertNotSame(person.getParent(), this.transformationObjectHolder.getValue());
+ assertEquals(parent, this.transformationObjectHolder.getValue());
+
+ Person person1 = new Person("Matt", "Mitch", null);
+ this.objectHolder.setValue(person1);
+ Person parent2 = this.transformationObjectHolder.getValue();
+ assertEquals(person1.getParent().getName(), parent2.getName());
+ assertNotSame(person1.getParent(), this.transformationObjectHolder.getValue());
+ assertEquals(parent2, this.transformationObjectHolder.getValue());
+
+
+ this.objectHolder.setValue(null);
+ assertNull(this.objectHolder.getValue());
+ assertNull(this.transformationObjectHolder.getValue());
+
+ Person person3 = new Person("Karen", "Peggy", null);
+ this.objectHolder.setValue(person3);
+ assertEquals("Karen", person3.getName());
+ Person parent3 = this.transformationObjectHolder.getValue();
+ assertEquals(person3.getParent().getName(), parent3.getName());
+ assertNotSame(person3.getParent(), this.transformationObjectHolder.getValue());
+ assertEquals(parent3, this.transformationObjectHolder.getValue());
+ }
+
+ public void testLazyListening() {
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ PropertyChangeListener listener = this.buildTransformationListener();
+ this.transformationObjectHolder.addPropertyChangeListener(listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.transformationObjectHolder.removePropertyChangeListener(listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.transformationObjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testPropertyChange1() {
+ this.objectHolder.addPropertyChangeListener(this.buildListener());
+ this.transformationObjectHolder.addPropertyChangeListener(this.buildTransformationListener());
+ this.verifyPropertyChanges();
+ }
+
+ public void testPropertyChange2() {
+ this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener());
+ this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener());
+ this.verifyPropertyChanges();
+ }
+
+ private void verifyPropertyChanges() {
+ this.event = null;
+ this.transformationEvent = null;
+ Person karen = this.objectHolder.getValue();
+ Person peggyParent = this.transformationObjectHolder.getValue();
+ Person peggy = new Person("Peggy", "Marian", null);
+ this.objectHolder.setValue(peggy);
+ Person marianParent = this.transformationObjectHolder.getValue();
+ this.verifyEvent(this.event, this.objectHolder, karen, peggy);
+ this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, peggyParent, marianParent);
+
+ this.event = null;
+ this.transformationEvent = null;
+ Person matt = new Person("Matt", "Mitch", null);
+ this.objectHolder.setValue(matt);
+ Person mitchParent = this.transformationObjectHolder.getValue();
+ this.verifyEvent(this.event, this.objectHolder, peggy, matt);
+ this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, marianParent, mitchParent);
+
+ this.event = null;
+ this.transformationEvent = null;
+ this.objectHolder.setValue(null);
+ this.verifyEvent(this.event, this.objectHolder, matt, null);
+ this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, mitchParent, null);
+
+ this.event = null;
+ this.transformationEvent = null;
+ this.objectHolder.setValue(matt);
+ mitchParent = this.transformationObjectHolder.getValue();
+ this.verifyEvent(this.event, this.objectHolder, null, matt);
+ this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, null, mitchParent);
+ }
+
+ private PropertyChangeListener buildListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ CachingTransformationPropertyValueModelTests.this.event = e;
+ }
+ };
+ }
+
+ private PropertyChangeListener buildTransformationListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ CachingTransformationPropertyValueModelTests.this.transformationEvent = e;
+ }
+ };
+ }
+
+ private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) {
+ assertEquals(source, e.getSource());
+ assertEquals(PropertyValueModel.VALUE, e.getPropertyName());
+ assertEquals(oldValue, e.getOldValue());
+ assertEquals(newValue, e.getNewValue());
+ }
+
+
+ private class Person extends AbstractModel {
+
+ private String name;
+ public static final String NAME_PROPERTY = "nameProperty";
+
+ private String parentName;
+ public static final String PARENT_NAME_PROPERTY = "parentNameProperty";
+
+ private Person child;
+
+ public Person(String name, String parentName, Person child) {
+ this.name = name;
+ this.parentName = parentName;
+ this.child = child;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String newName) {
+ String oldName = this.name;
+ this.name = newName;
+ firePropertyChanged(NAME_PROPERTY, oldName, newName);
+ }
+
+ public Person getParent() {
+ return new Person(this.parentName, null, this);
+ }
+
+ public String getParentName() {
+ return this.parentName;
+ }
+
+ public void setParentName(String newParentName) {
+ String oldParentName = this.parentName;
+ this.parentName = newParentName;
+ firePropertyChanged(PARENT_NAME_PROPERTY, oldParentName, newParentName);
+ }
+
+ public Person getChild() {
+ return this.child;
+ }
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java
new file mode 100644
index 0000000000..023c3134dd
--- /dev/null
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java
@@ -0,0 +1,249 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 Oracle. 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:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.utility.tests.internal.model.value;
+
+import org.eclipse.jpt.utility.internal.BidiTransformer;
+import org.eclipse.jpt.utility.internal.model.AbstractModel;
+import org.eclipse.jpt.utility.internal.model.value.CachingTransformationWritablePropertyValueModel;
+import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.utility.model.event.PropertyChangeEvent;
+import org.eclipse.jpt.utility.model.listener.PropertyChangeListener;
+import org.eclipse.jpt.utility.model.value.PropertyValueModel;
+import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel;
+import org.eclipse.jpt.utility.tests.internal.TestTools;
+
+import junit.framework.TestCase;
+
+public class CachingTransformationWritablePropertyValueModelTests extends TestCase {
+ private WritablePropertyValueModel<Person> objectHolder;
+ PropertyChangeEvent event;
+
+ private WritablePropertyValueModel<Person> transformationObjectHolder;
+ PropertyChangeEvent transformationEvent;
+
+ public CachingTransformationWritablePropertyValueModelTests(String name) {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null));
+ this.transformationObjectHolder = new CachingTransformationWritablePropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer());
+ }
+
+ private BidiTransformer<Person, Person> buildTransformer() {
+ return new BidiTransformer<Person, Person>() {
+ public Person transform(Person p) {
+ return (p == null) ? null : p.getParent();
+ }
+ public Person reverseTransform(Person p) {
+ return (p == null) ? null : p.getChild();
+ }
+ };
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ TestTools.clear(this);
+ super.tearDown();
+ }
+
+ public void testValue() {
+ PropertyChangeListener listener = this.buildTransformationListener();
+ this.transformationObjectHolder.addPropertyChangeListener(listener);
+
+
+ Person person = this.objectHolder.getValue();
+ assertEquals("Karen", person.getName());
+ Person parent = this.transformationObjectHolder.getValue();
+ assertEquals(person.getParent().getName(), parent.getName());
+ assertNotSame(person.getParent(), this.transformationObjectHolder.getValue());
+ assertEquals(parent, this.transformationObjectHolder.getValue());
+
+ Person person1 = new Person("Matt", "Mitch", null);
+ this.objectHolder.setValue(person1);
+ Person parent2 = this.transformationObjectHolder.getValue();
+ assertEquals(person1.getParent().getName(), parent2.getName());
+ assertNotSame(person1.getParent(), this.transformationObjectHolder.getValue());
+ assertEquals(parent2, this.transformationObjectHolder.getValue());
+
+
+ this.objectHolder.setValue(null);
+ assertNull(this.objectHolder.getValue());
+ assertNull(this.transformationObjectHolder.getValue());
+
+ Person person3 = new Person("Karen", "Peggy", null);
+ this.objectHolder.setValue(person3);
+ assertEquals("Karen", person3.getName());
+ Person parent3 = this.transformationObjectHolder.getValue();
+ assertEquals(person3.getParent().getName(), parent3.getName());
+ assertNotSame(person3.getParent(), this.transformationObjectHolder.getValue());
+ assertEquals(parent3, this.transformationObjectHolder.getValue());
+ }
+
+ public void testSetValue() {
+ PropertyChangeListener listener = this.buildTransformationListener();
+ this.transformationObjectHolder.addPropertyChangeListener(listener);
+
+ Person person = new Person("Chris", "Noel", null);
+ this.transformationObjectHolder.setValue(person.getParent());
+ assertEquals(person, this.objectHolder.getValue());
+ assertEquals(person.getParent().getName(), this.transformationObjectHolder.getValue().getName());
+ assertNotSame(person.getParent(), this.transformationObjectHolder.getValue());
+
+ Person person2 = new Person("Jon", "Elizabeth", null);
+ this.transformationObjectHolder.setValue(person2.getParent());
+ assertEquals(person2, this.objectHolder.getValue());
+ assertEquals(person2.getParent().getName(), this.transformationObjectHolder.getValue().getName());
+ assertNotSame(person2.getParent(), this.transformationObjectHolder.getValue());
+
+ this.transformationObjectHolder.setValue(null);
+ assertNull(this.objectHolder.getValue());
+ assertNull(this.transformationObjectHolder.getValue());
+
+ this.transformationObjectHolder.setValue(person.getParent());
+ assertEquals(person, this.objectHolder.getValue());
+ assertEquals(person.getParent().getName(), this.transformationObjectHolder.getValue().getName());
+ assertNotSame(person.getParent(), this.transformationObjectHolder.getValue());
+ }
+
+ public void testLazyListening() {
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ PropertyChangeListener listener = this.buildTransformationListener();
+ this.transformationObjectHolder.addPropertyChangeListener(listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.transformationObjectHolder.removePropertyChangeListener(listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+
+ this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE));
+ this.transformationObjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, listener);
+ assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE));
+ }
+
+ public void testPropertyChange1() {
+ this.objectHolder.addPropertyChangeListener(this.buildListener());
+ this.transformationObjectHolder.addPropertyChangeListener(this.buildTransformationListener());
+ this.verifyPropertyChanges();
+ }
+
+ public void testPropertyChange2() {
+ this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener());
+ this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener());
+ this.verifyPropertyChanges();
+ }
+
+ private void verifyPropertyChanges() {
+ this.event = null;
+ this.transformationEvent = null;
+ Person oldPerson = this.objectHolder.getValue();
+ Person oldParent = this.transformationObjectHolder.getValue();
+ Person newPerson = new Person("Karen" , "Peggy", null);
+ this.objectHolder.setValue(newPerson);
+ Person newParent = this.transformationObjectHolder.getValue();
+ this.verifyEvent(this.event, this.objectHolder, oldPerson, newPerson);
+ this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, oldParent, newParent);
+
+//
+// this.event = null;
+// this.transformationEvent = null;
+// this.objectHolder.setValue("Foo");
+// this.verifyEvent(this.event, this.objectHolder, "baz", "Foo");
+// this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "BAZ", "FOO");
+//
+// this.event = null;
+// this.transformationEvent = null;
+// this.objectHolder.setValue("FOO");
+// this.verifyEvent(this.event, this.objectHolder, "Foo", "FOO");
+// assertNull(this.transformationEvent);
+//
+// this.event = null;
+// this.transformationEvent = null;
+// this.objectHolder.setValue(null);
+// this.verifyEvent(this.event, this.objectHolder, "FOO", null);
+// this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "FOO", null);
+//
+// this.event = null;
+// this.transformationEvent = null;
+// this.objectHolder.setValue("bar");
+// this.verifyEvent(this.event, this.objectHolder, null, "bar");
+// this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, null, "BAR");
+ }
+
+ private PropertyChangeListener buildListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ CachingTransformationWritablePropertyValueModelTests.this.event = e;
+ }
+ };
+ }
+
+ private PropertyChangeListener buildTransformationListener() {
+ return new PropertyChangeListener() {
+ public void propertyChanged(PropertyChangeEvent e) {
+ CachingTransformationWritablePropertyValueModelTests.this.transformationEvent = e;
+ }
+ };
+ }
+
+ private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) {
+ assertEquals(source, e.getSource());
+ assertEquals(PropertyValueModel.VALUE, e.getPropertyName());
+ assertEquals(oldValue, e.getOldValue());
+ assertEquals(newValue, e.getNewValue());
+ }
+
+
+ private class Person extends AbstractModel {
+
+ private String name;
+ public static final String NAME_PROPERTY = "nameProperty";
+
+ private String parentName;
+ public static final String PARENT_NAME_PROPERTY = "parentNameProperty";
+
+ private Person child;
+
+ public Person(String name, String parentName, Person child) {
+ this.name = name;
+ this.parentName = parentName;
+ this.child = child;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String newName) {
+ String oldName = this.name;
+ this.name = newName;
+ firePropertyChanged(NAME_PROPERTY, oldName, newName);
+ }
+
+ public Person getParent() {
+ return new Person(this.parentName, null, this);
+ }
+
+ public String getParentName() {
+ return this.parentName;
+ }
+
+ public void setParentName(String newParentName) {
+ String oldParentName = this.parentName;
+ this.parentName = newParentName;
+ firePropertyChanged(PARENT_NAME_PROPERTY, oldParentName, newParentName);
+ }
+
+ public Person getChild() {
+ return this.child;
+ }
+ }
+}
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java
index e53070c828..1939e03021 100644
--- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java
+++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java
@@ -24,6 +24,8 @@ public class JptUtilityModelValueTests {
suite.addTest(JptUtilityModelValueSwingTests.suite());
suite.addTestSuite(BufferedWritablePropertyValueModelTests.class);
+ suite.addTestSuite(CachingTransformationPropertyValueModelTests.class);
+ suite.addTestSuite(CachingTransformationWritablePropertyValueModelTests.class);
suite.addTestSuite(CollectionAspectAdapterTests.class);
suite.addTestSuite(CollectionListValueModelAdapterTests.class);
suite.addTestSuite(CollectionPropertyValueModelAdapterTests.class);

Back to the top