Skip to content

Instantly share code, notes, and snippets.

@oanhthai
Created January 22, 2016 06:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save oanhthai/ba7614a110b865b073ff to your computer and use it in GitHub Desktop.
Index: ../../git/magnolia-5.4-repo/ui/magnolia-ui-form/src/test/java/info/magnolia/ui/form/field/transformer/composite/SwitchableTransformerTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- ../../git/magnolia-5.4-repo/ui/magnolia-ui-form/src/test/java/info/magnolia/ui/form/field/transformer/composite/SwitchableTransformerTest.java (revision 82aabf82b28efe35f423dd18563294faa18a31cf)
+++ ../../git/magnolia-5.4-repo/ui/magnolia-ui-form/src/test/java/info/magnolia/ui/form/field/transformer/composite/SwitchableTransformerTest.java (revision )
@@ -1,5 +1,5 @@
/**
- * This file Copyright (c) 2014-2015 Magnolia International
+ * This file Copyright (c) 2014-2016 Magnolia International
* Ltd. (http://www.magnolia-cms.com). All rights reserved.
*
*
@@ -153,8 +153,6 @@
assertEquals("hidden", jcrNode.getProperty("switch").getString());
assertTrue(jcrNode.hasProperty("switchhidden"));
assertTrue(jcrNode.getProperty("switchhidden").getBoolean());
- assertTrue(jcrNode.hasProperty("switchtext"));
- assertEquals("hop!", jcrNode.getProperty("switchtext").getString());
}
@Test
Index: ../../git/magnolia-5.4-repo/ui/magnolia-ui-form/src/test/java/info/magnolia/ui/form/field/factory/SwitchableFieldFactoryTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- ../../git/magnolia-5.4-repo/ui/magnolia-ui-form/src/test/java/info/magnolia/ui/form/field/factory/SwitchableFieldFactoryTest.java (revision 82aabf82b28efe35f423dd18563294faa18a31cf)
+++ ../../git/magnolia-5.4-repo/ui/magnolia-ui-form/src/test/java/info/magnolia/ui/form/field/factory/SwitchableFieldFactoryTest.java (revision )
@@ -1,5 +1,5 @@
/**
- * This file Copyright (c) 2013-2015 Magnolia International
+ * This file Copyright (c) 2013-2016 Magnolia International
* Ltd. (http://www.magnolia-cms.com). All rights reserved.
*
*
@@ -190,7 +190,6 @@
assertEquals("text", baseItem.getItemProperty(propertyName).getValue());
assertEquals("text", baseNode.getProperty(propertyName).getString());
assertFalse(baseNode.hasProperty(propertyName + "text"));
- assertTrue(baseNode.hasProperty(propertyName + "code"));
}
@Test
@@ -209,7 +208,6 @@
assertEquals("text", baseNode.getProperty(propertyName).getString());
assertTrue(baseNode.hasProperty(propertyName + "text"));
assertEquals("hop!", baseNode.getProperty(propertyName + "text").getString());
- assertTrue(baseNode.hasProperty(propertyName + "code"));
}
@Test
Index: ../../git/magnolia-5.4-repo/ui/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/transformer/composite/SwitchableTransformer.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- ../../git/magnolia-5.4-repo/ui/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/transformer/composite/SwitchableTransformer.java (revision 82aabf82b28efe35f423dd18563294faa18a31cf)
+++ ../../git/magnolia-5.4-repo/ui/magnolia-ui-form/src/main/java/info/magnolia/ui/form/field/transformer/composite/SwitchableTransformer.java (revision )
@@ -1,5 +1,5 @@
/**
- * This file Copyright (c) 2013-2015 Magnolia International
+ * This file Copyright (c) 2013-2016 Magnolia International
* Ltd. (http://www.magnolia-cms.com). All rights reserved.
*
*
@@ -35,7 +35,9 @@
import info.magnolia.ui.api.i18n.I18NAuthoringSupport;
import info.magnolia.ui.form.field.definition.ConfiguredFieldDefinition;
+import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter;
+import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
@@ -67,7 +69,25 @@
@Override
public void writeToItem(PropertysetItem newValues) {
- super.writeToItem(newValues);
+ // Alter newsValues to clear all data that not belong to selections
+ String currentSelection = (String) newValues.getItemProperty(propertyPrefix).getValue();
+
+ // Get iterator.
+ Iterator<?> propertyNames = newValues.getItemPropertyIds().iterator();
+
+ while (propertyNames.hasNext()) {
+ String propertyName = (String) propertyNames.next();
+ String compositePropertyName = getCompositePropertyName(propertyName);
+ if (!propertyName.equalsIgnoreCase(currentSelection) && !propertyName.equalsIgnoreCase(propertyPrefix)){
+ relatedFormItem.removeItemProperty(compositePropertyName);
+ } else{
+ if (newValues.getItemProperty(propertyName) != null) {
+ relatedFormItem.addItemProperty(compositePropertyName, newValues.getItemProperty(propertyName));
+ // Need to remove it from the removedProperties map
+ ((JcrNodeAdapter)relatedFormItem).unRemoveItemProperty(compositePropertyName);
+ }
+ }
+ }
}
@Override
Index: ../../git/magnolia-5.4-repo/ui/magnolia-ui-vaadin-integration/src/main/java/info/magnolia/ui/vaadin/integration/jcr/JcrNodeAdapter.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- ../../git/magnolia-5.4-repo/ui/magnolia-ui-vaadin-integration/src/main/java/info/magnolia/ui/vaadin/integration/jcr/JcrNodeAdapter.java (revision 82aabf82b28efe35f423dd18563294faa18a31cf)
+++ ../../git/magnolia-5.4-repo/ui/magnolia-ui-vaadin-integration/src/main/java/info/magnolia/ui/vaadin/integration/jcr/JcrNodeAdapter.java (revision )
@@ -1,5 +1,5 @@
/**
- * This file Copyright (c) 2012-2015 Magnolia International
+ * This file Copyright (c) 2012-2016 Magnolia International
* Ltd. (http://www.magnolia-cms.com). All rights reserved.
*
*
@@ -133,6 +133,19 @@
res = true;
} else if (jcrItemHasProperty((String) id)) {
getRemovedProperties().put((String) id, super.getItemProperty(id));
+ res = true;
+ }
+ return res;
+ }
+
+ /**
+ * Remove a property from a removedProperties map.
+ * If the property was already remove, remove it for the removedProperties Map.
+ */
+ public boolean unRemoveItemProperty(Object id) {
+ boolean res = false;
+ if (getRemovedProperties().containsKey(id)) {
+ getRemovedProperties().remove(id);
res = true;
}
return res;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment