Commits

MikhailKotelnikov  committed 4d558d0

DataObject internal implementation was slightly changed.

  • Participants
  • Parent commits 4b4c8b6

Comments (0)

Files changed (7)

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/client/WebAnnotatorDialogBox.java

 import org.mandriva.annotator.gwtapp.client.model.Annotation;
 import org.mandriva.annotator.gwtapp.client.model.AnnotationLoadRequest;
 import org.mandriva.annotator.gwtapp.client.model.DataObject;
+import org.mandriva.annotator.gwtapp.client.model.Entity;
 import org.mandriva.annotator.gwtapp.client.model.LoadTypesRequest;
 import org.mandriva.annotator.gwtapp.client.model.LoadTypesResult;
 import org.mandriva.annotator.gwtapp.client.model.SuggestionsRequest;
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.core.client.JsArray;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.Style.Float;
 import com.google.gwt.event.dom.client.ClickEvent;
 
     private Annotation fAnnotation = Annotation.createObject().cast();
 
+    private Button fCloseButton;
+
     private DialogBoxWithButtons fDialogBox = new DialogBoxWithButtons();
 
     private XdmSocket fFetcher;
                     revert();
                 }
             });
-        fDialogBox.addButton(fResources.btnClose(), new ClickHandler() {
-            public void onClick(ClickEvent event) {
-                fDialogBox.hide();
-            }
-        });
+        fCloseButton = fDialogBox.addButton(
+            fResources.btnClose(),
+            new ClickHandler() {
+                public void onClick(ClickEvent event) {
+                    fDialogBox.hide();
+                }
+            });
         // fPanel
         // .addValueChangeHandler(new ValueChangeHandler<WebAnnotatorPanel>() {
         // public void onValueChange(
             str = getPageUrl();
             annotation.setUri(str);
         }
+
+        Entity type = annotation.getType();
+        if (type == null) {
+            type = fPanel.getSelectedType();
+            annotation.setType(type);
+        }
+
+        JsArray<Entity> relatedEntities = annotation.getRelatedEntities();
+        if (relatedEntities == null) {
+            relatedEntities = JavaScriptObject.createArray().cast();
+            annotation.setRelatedEntities(relatedEntities);
+        }
         fAnnotation = annotation;
         fPanel.setAnnotation(fAnnotation);
 
         boolean changed = fPanel.isChanged();
         fSaveButton.setEnabled(changed);
         fRevertButton.setEnabled(changed);
+        fCloseButton.setEnabled(!changed);
     }
 
 }

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/client/WebAnnotatorPanel.java

             relatedEntities);
     }
 
-    private Entity getSelectedType() {
+    protected Entity getSelectedType() {
         Entity type = null;
         int idx = fType.getSelectedIndex();
         if (idx >= 0 && idx < fType.getItemCount()) {

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/client/model/Annotation.java

 package org.mandriva.annotator.gwtapp.client.model;
 
+import com.google.gwt.core.client.JavaScriptObject;
 import com.google.gwt.core.client.JsArray;
 
 /**
     protected Annotation() {
     }
 
-    public final native String getDescription() /*-{
-        return this.description;
-    }-*/;
+    public final String getDescription() {
+        return getString("description");
+    }
 
-    public final native JsArray<Entity> getRelatedEntities() /*-{
-        return this.relatedEntities;
-    }-*/;
+    public final JsArray<Entity> getRelatedEntities() {
+        JsArray<Entity> result = get("relatedEntities");
+        if (result == null) {
+            result = JavaScriptObject.createArray().cast();
+        }
+        return result;
+    }
 
-    public final native Entity getType() /*-{
-        return this.type;
-    }-*/;
+    public final Entity getType() {
+        return get("type");
+    }
+
+    public final void setRelatedEntities(JsArray<Entity> relatedEntities) {
+        set("relatedEntities", relatedEntities);
+    }
+
+    public final void setType(Entity type) {
+        set("relatedEntities", type);
+    }
 }

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/client/model/DataObject.java

         return toString(this);
     }
 
+    protected final native <T> T get(String key) /*-{
+        return this[key];
+    }-*/;
+
+    protected final String getString(String key) {
+        return getString(key, "");
+    }
+
+    protected final native String getString(String key, String defaultValue) /*-{
+        var val = this[key];
+        if (!val) {
+        val = defaultValue;
+        }
+        return val;
+    }-*/;
+
+    protected final native void set(String key, Object value) /*-{
+        this[key] = value;
+    }-*/;
+
+    protected final native void setString(String key, String value) /*-{
+        this[key] = value;
+    }-*/;
+
 }

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/client/model/Entity.java

     protected Entity() {
     }
 
-    public final native String getLabel() /*-{
-        return this.label;
-    }-*/;
+    public final String getLabel() {
+        return getString("label");
+    }
 
-    public final native String getUri() /*-{
-        return this.uri;
-    }-*/;
+    public final String getUri() {
+        return getString("uri");
+    }
 
-    public final native void setLabel(String str) /*-{
-        this.label = str;
-    }-*/;
+    public final void setLabel(String str) {
+        setString("label", str);
+    }
 
-    public final native void setUri(String str)/*-{
-        this.uri = str;
-    }-*/;
+    public final void setUri(String str) {
+        setString("uri", str);
+    }
 
 }

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/java/org/mandriva/annotator/gwtapp/server/SimpleServlet.java

 
             String action = getActionName(req);
             String str = readString(req.getInputStream());
-            JSONObject request = new JSONObject(str);
+            str = str.trim();
+            JSONObject request = !"".equals(str)
+                ? new JSONObject(str)
+                : new JSONObject();
             JSONObject response = handleAction(action, request);
             if (response == null) {
                 response = new JSONObject();

File org.mandriva.annotator/org.mandriva.annotator.gwtapp/src/main/resources/WebAnnotatorMessages.json

     "labelRelations" : "Relations:",
     "labelSuggestedRelations" : "Suggested relations:",
     "labelTitle" : "Title:",
-    "labelType" : "Type:", "labelUrl" : "Page URL:",
+    "labelType" : "Type:",
+    "labelUrl" : "URL:",
     "msgAnnotationLoading" : "Annotation loading...",
     "msgAnnotationSaved" : "The annotation was successfully saved.",
     "msgAnnotationSaving" : "Save annotation...",