Permalink
Browse files

Added insert attribute value methods.

  • Loading branch information...
1 parent 6499261 commit 85db8266bef05af9967c6ed675644751c71263ad @tHerrmann tHerrmann committed Feb 24, 2012
@@ -202,6 +202,74 @@ public native boolean hasType(String type) /*-{
}-*/;
/**
+ * @see com.alkacon.vie.shared.I_Entity#insertAttributeValue(java.lang.String, com.alkacon.vie.shared.I_Entity, int)
+ */
+ public void insertAttributeValue(String attributeName, I_Entity value, int index) {
+
+ I_EntityAttribute attribute = getAttribute(attributeName);
+ if (index < 0) {
+ throw new IndexOutOfBoundsException("Index should be > 0");
+ }
+ if ((attribute == null) && (index > 0)) {
+ throw new IndexOutOfBoundsException("Index of " + index + " to big.");
+ }
+ if (attribute == null) {
+ setAttributeValue(attributeName, value);
+ } else {
+ List<I_Entity> values = attribute.getComplexValues();
+ if (index > values.size()) {
+ throw new IndexOutOfBoundsException("Index of " + index + " to big.");
+ }
+ if (index == values.size()) {
+ addAttributeValue(attributeName, value);
+ } else {
+ removeAttributeSilent(attributeName);
+ for (int i = 0; i < values.size(); i++) {
+ if (i == index) {
+ addAttributeValue(attributeName, value);
+ }
+ addAttributeValue(attributeName, values.get(i));
+
+ }
+ }
+ }
+ }
+
+ /**
+ * @see com.alkacon.vie.shared.I_Entity#insertAttributeValue(java.lang.String, java.lang.String, int)
+ */
+ public void insertAttributeValue(String attributeName, String value, int index) {
+
+ I_EntityAttribute attribute = getAttribute(attributeName);
+ if (index < 0) {
+ throw new IndexOutOfBoundsException("Index should be > 0");
+ }
+ if ((attribute == null) && (index > 0)) {
+ throw new IndexOutOfBoundsException("Index of " + index + " to big.");
+ }
+ if (attribute == null) {
+ setAttributeValue(attributeName, value);
+ } else {
+ List<String> values = attribute.getSimpleValues();
+ if (index > values.size()) {
+ throw new IndexOutOfBoundsException("Index of " + index + " to big.");
+ }
+ if (index == values.size()) {
+ addAttributeValue(attributeName, value);
+ } else {
+ removeAttributeSilent(attributeName);
+ for (int i = 0; i < values.size(); i++) {
+ if (i == index) {
+ addAttributeValue(attributeName, value);
+ }
+ addAttributeValue(attributeName, values.get(i));
+
+ }
+ }
+ }
+ }
+
+ /**
* Removes the given attribute.<p>
*
* @param attributeName the attribute name
@@ -226,6 +294,36 @@ public native void removeAttributeSilent(String attributeName) /*-{
}-*/;
/**
+ * @see com.alkacon.vie.shared.I_Entity#removeAttributeValue(java.lang.String, int)
+ */
+ public void removeAttributeValue(String attributeName, int index) {
+
+ if (!hasAttribute(attributeName)) {
+ return;
+ }
+ I_EntityAttribute attribute = getAttribute(attributeName);
+ if (attribute.isSingleValue() && (index == 0)) {
+ removeAttribute(attributeName);
+ } else {
+ removeAttributeSilent(attributeName);
+ if (attribute.isSimpleValue()) {
+ for (int i = 0; i < attribute.getSimpleValues().size(); i++) {
+ if (i != index) {
+ addAttributeValue(attributeName, attribute.getSimpleValues().get(i));
+ }
+ }
+
+ } else {
+ for (int i = 0; i < attribute.getComplexValues().size(); i++) {
+ if (i != index) {
+ addAttributeValue(attributeName, attribute.getComplexValues().get(i));
+ }
+ }
+ }
+ }
+ }
+
+ /**
* @see com.alkacon.vie.shared.I_Entity#setAttributeValue(java.lang.String, com.alkacon.vie.shared.I_Entity)
*/
public void setAttributeValue(String attributeName, I_Entity value) {
@@ -474,34 +572,4 @@ private native void registerChange(Entity child) /*-{
self.change();
});
}-*/;
-
- /**
- * @see com.alkacon.vie.shared.I_Entity#removeAttributeValue(java.lang.String, int)
- */
- public void removeAttributeValue(String attributeName, int index) {
-
- if (!hasAttribute(attributeName)) {
- return;
- }
- I_EntityAttribute attribute = getAttribute(attributeName);
- if (attribute.isSingleValue() && (index == 0)) {
- removeAttribute(attributeName);
- } else {
- removeAttributeSilent(attributeName);
- if (attribute.isSimpleValue()) {
- for (int i = 0; i < attribute.getSimpleValues().size(); i++) {
- if (i != index) {
- addAttributeValue(attributeName, attribute.getSimpleValues().get(i));
- }
- }
-
- } else {
- for (int i = 0; i < attribute.getComplexValues().size(); i++) {
- if (i != index) {
- addAttributeValue(attributeName, attribute.getComplexValues().get(i));
- }
- }
- }
- }
- }
}
@@ -37,7 +37,7 @@
import java.util.List;
import java.util.Map;
-import com.google.gwt.user.client.Element;
+import com.google.gwt.dom.client.Element;
/**
* The interface for VIE implementations.<p>
@@ -37,7 +37,7 @@
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
-import com.google.gwt.user.client.Element;
+import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.ui.RootPanel;
/**
@@ -188,23 +188,23 @@ public native I_Type createType(String id) /*-{
}-*/;
/**
- * @see com.alkacon.vie.client.I_Vie#getAttributeElements(com.google.gwt.user.client.Element)
+ * @see com.alkacon.vie.client.I_Vie#getAttributeElements(com.google.gwt.dom.client.Element)
*/
public List<Element> getAttributeElements(Element context) {
return select("[property]", context);
}
/**
- * @see com.alkacon.vie.client.I_Vie#getAttributeElements(com.alkacon.vie.shared.I_Entity, java.lang.String, com.google.gwt.user.client.Element)
+ * @see com.alkacon.vie.client.I_Vie#getAttributeElements(com.alkacon.vie.shared.I_Entity, java.lang.String, com.google.gwt.dom.client.Element)
*/
public List<Element> getAttributeElements(I_Entity entity, String attributeName, Element context) {
return getAttributeElements(entity.getId(), attributeName, context);
}
/**
- * @see com.alkacon.vie.client.I_Vie#getAttributeElements(java.lang.String, java.lang.String, com.google.gwt.user.client.Element)
+ * @see com.alkacon.vie.client.I_Vie#getAttributeElements(java.lang.String, java.lang.String, com.google.gwt.dom.client.Element)
*/
public List<Element> getAttributeElements(String entityId, String attributeName, Element context) {
@@ -90,6 +90,24 @@
boolean hasAttribute(String attributeName);
/**
+ * Inserts a new attribute value at the given index.<p>
+ *
+ * @param attributeName the attribute name
+ * @param value the attribute value
+ * @param index the value index
+ */
+ void insertAttributeValue(String attributeName, I_Entity value, int index);
+
+ /**
+ * Inserts a new attribute value at the given index.<p>
+ *
+ * @param attributeName the attribute name
+ * @param value the attribute value
+ * @param index the value index
+ */
+ void insertAttributeValue(String attributeName, String value, int index);
+
+ /**
* Removes the given attribute.<p>
*
* @param attributeName the attribute name
@@ -174,7 +174,7 @@ public void testSelectors() {
Document.get().getBody().setInnerHTML(
"<div about='http://testEntity'><div property='" + ATTRIBUTE_NAME + "'>my value</div></div>");
- List<com.google.gwt.user.client.Element> elements = getVieInstance().getAttributeElements(
+ List<com.google.gwt.dom.client.Element> elements = getVieInstance().getAttributeElements(
"http://testEntity",
ATTRIBUTE_NAME,
null);

0 comments on commit 85db826

Please sign in to comment.