[isidorus-cvs] r819 - in branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets: base button environment view
lgiessmann at common-lisp.net
lgiessmann at common-lisp.net
Fri Sep 2 09:47:09 UTC 2011
Author: lgiessmann
Date: Fri Sep 2 02:47:08 2011
New Revision: 819
Log:
gdl-frontend: Widgets: implemented the validation of literal-values of topic-names and topic-occurrences
Modified:
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCommitButton.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/Pattern.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.java
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java Fri Sep 2 02:00:04 2011 (r818)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPanel.java Fri Sep 2 02:47:08 2011 (r819)
@@ -264,9 +264,9 @@
// this method is responsible for generating a Topic Map fo the user's
// data by using the view's getContent method.
- public ArrayList<Pair<Construct, TopicMapsTypes>> getContent() throws Exception {
+ public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(boolean validate) throws Exception {
try{
- return this.view.getContent(null, false);
+ return this.view.getContent(null, validate);
}catch(Exception e){
for (IOnErrorCallback handler : localOnErrorContainer) {
handler.onError(GdlErrorTypes.TopicMapsGenerationError, e);
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java Fri Sep 2 02:00:04 2011 (r818)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java Fri Sep 2 02:47:08 2011 (r819)
@@ -59,6 +59,7 @@
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.event.shared.EventHandler;
+import com.google.gwt.i18n.client.Messages.Select;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Window;
@@ -2214,13 +2215,17 @@
// returns the actual data that is hold by this instance
- public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean onlyValidate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException {
+ public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean validate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException {
ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
if(this.getRootConstraint() == null) return result;
Construct localCarrier = carrier;
if(carrier == null) localCarrier = TmHelper.getNearestTopicOrAssociation(this);
//TODO: finalise
+ ArrayList<Pattern> validLiteralValues = new ArrayList<Pattern>();
+ for (String literal : this.getLiterals()) validLiteralValues.add(new Pattern(literal));
+ if(validLiteralValues.size() == 0) validLiteralValues.add(new Pattern(this.getLiteralValueForConstraint()));
+
for (int idx = 0; idx != this.getSelectedValues().size(); ++idx){
if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclItemIdentifierConstraint)){
@@ -2235,6 +2240,12 @@
Name changedName = null;
if(this.getRootConstraint().equals(this.getConstraint())){
+ if(validate){
+ int i = 0;
+ for( ; i != validLiteralValues.size(); ++i) if(validLiteralValues.get(i).matches(this.getSelectedValues().get(idx))) break;
+ if(i == validLiteralValues.size()) throw new InvalidContentException("the user data " + this.getSelectedValues().get(idx) + " for the topic-name " + TmHelper.getAnyIdOfTopic(TmHelper.getConstrainedStatement(this.getConstraint())) + " does not satisfy any of the constraints: " + Utils.arrayToString(validLiteralValues));
+ }
+
if(names.length() > idx){
changedName = names.get(idx);
changedName.setValue(this.getSelectedValues().get(idx));
@@ -2250,9 +2261,15 @@
if(!(localCarrier instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " must be bound to a Topic, but is: " + localCarrier.getClass());
Topic occurrenceType = TmHelper.getConstrainedStatement(this.getConstraint());
JsArray<Occurrence> occurrences = ((Topic)localCarrier).getOccurrences(occurrenceType);
-
+
Occurrence changedOccurrence = null;
if(this.getRootConstraint().equals(this.getConstraint())){
+ if(validate){
+ int i = 0;
+ for( ; i != validLiteralValues.size(); ++i) if(validLiteralValues.get(i).matches(this.getSelectedValues().get(idx))) break;
+ if(i == validLiteralValues.size()) throw new InvalidContentException("the user data " + this.getSelectedValues().get(idx) + " for the topic-occurrence " + TmHelper.getAnyIdOfTopic(TmHelper.getConstrainedStatement(this.getConstraint())) + " does not satisfy any of the constraints: " + Utils.arrayToString(validLiteralValues));
+ }
+
if(occurrences.length() > idx){
changedOccurrence = occurrences.get(idx);
changedOccurrence.setValue(this.getSelectedValues().get(idx));
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Fri Sep 2 02:00:04 2011 (r818)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Fri Sep 2 02:47:08 2011 (r819)
@@ -31,12 +31,12 @@
mainPanel.setPixelSize(1000, 600);
ArrayList<Pair<String, TopicIdentifierTypes>> requestedTopicsToCreate = new ArrayList<Pair<String,TopicIdentifierTypes>>();
- //requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/model/types/Hash-Object", TopicIdentifierTypes.SubjectIdentifier));
- requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/model/types/Environment", TopicIdentifierTypes.SubjectIdentifier));
+ requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/model/types/Hash-Object", TopicIdentifierTypes.SubjectIdentifier));
+ //requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/model/types/Environment", TopicIdentifierTypes.SubjectIdentifier));
//requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://psi.test.org/gdl-test/Poet", TopicIdentifierTypes.SubjectIdentifier));
//requestedTopicsToCreate.add(new Pair<String, TopicIdentifierTypes>("http://psi.test.org/gdl-test/Musician", TopicIdentifierTypes.SubjectIdentifier));
- Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-env-1", TopicIdentifierTypes.SubjectIdentifier);
+ //Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-env-1", TopicIdentifierTypes.SubjectIdentifier);
//Pair<String, TopicIdentifierTypes> requestedTopicToEdit = new Pair<String, TopicIdentifierTypes>("http://textgrid.org/serviceregistry/test-hash-2", TopicIdentifierTypes.SubjectIdentifier);
GdlPanel.addClickHandler("hash_object_reset_button_id", new ClickHandler() {
@Override
@@ -46,7 +46,7 @@
}
});
- gdlPanel = new GdlPanel(requestedTopicToEdit, null);
+ gdlPanel = new GdlPanel(null, requestedTopicsToCreate);
mainPanel.add(gdlPanel);
gdlPanel.setTmEngine(new JtmsTmEngine());
gdlPanel.setLoadSchemaCallback(new LoadSchemaCallback());
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java Fri Sep 2 02:00:04 2011 (r818)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java Fri Sep 2 02:47:08 2011 (r819)
@@ -7,6 +7,20 @@
import com.google.gwt.dom.client.Element;
public class Utils {
+ // returns a string of the form [item1, item2, ... ] for all
+ // items of an ArrayList
+ public static <T> String arrayToString(ArrayList<T> data){
+ if(data == null || data.size() == 0) return "[ ]";
+
+ String result = "[";
+ for (T t : data) {
+ result += t + ", ";
+ }
+
+ return result.substring(0, result.length() - 2) + "]";
+ }
+
+
// returns true if both arrays have the same items
public static <T> boolean compareLists(ArrayList<T> lft, ArrayList<T> rgt){
if(lft == null && rgt == null) return true;
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCommitButton.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCommitButton.java Fri Sep 2 02:00:04 2011 (r818)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlCommitButton.java Fri Sep 2 02:47:08 2011 (r819)
@@ -42,7 +42,7 @@
TmEngine tmEngine = this.owner.getRoot().getTmEngine();
ICommitCallback callback = this.owner.getRoot().getCommitCallback();
- callback.commitTmConstruct(this.owner.getGdlParent().getContent(null, false), tmEngine, this.owner.getId());
+ callback.commitTmConstruct(this.owner.getGdlParent().getContent(null, true), tmEngine, this.owner.getId());
}catch(Exception e){
e.printStackTrace();
Window.alert("caught: " + e.getMessage());
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/Pattern.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/Pattern.java Fri Sep 2 02:00:04 2011 (r818)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/environment/Pattern.java Fri Sep 2 02:47:08 2011 (r819)
@@ -46,7 +46,7 @@
public final static int MULTILINE = 1;
/**
- * Declares that characters are matched reglardless of case.
+ * Declares that characters are matched regardless of case.
*/
public final static int CASE_INSENSITIVE = 2;
@@ -178,5 +178,10 @@
return parts;
}
+
+ @Override
+ public String toString(){
+ return this.pattern();
+ }
}
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java Fri Sep 2 02:00:04 2011 (r818)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java Fri Sep 2 02:47:08 2011 (r819)
@@ -185,13 +185,13 @@
@Override
- public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean onlyValidate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException{
+ public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean validate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException{
ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
for (Widget ctrl : this.subElements) {
if(ctrl instanceof ButtonableObject){
if(((ButtonableObject)ctrl).getMainObject() instanceof AssociationItem){
- for (Pair<Construct, TopicMapsTypes> pair : ((AssociationItem)((ButtonableObject)ctrl).getMainObject()).getContent(null, onlyValidate)) {
+ for (Pair<Construct, TopicMapsTypes> pair : ((AssociationItem)((ButtonableObject)ctrl).getMainObject()).getContent(null, validate)) {
result.add(pair);
}
}
@@ -264,14 +264,14 @@
@Override
- public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean onlyValidate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException {
+ public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean validate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException {
ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
Association localCarrier = this.getRepresentedAssociation();
for (Widget ctrl : this.subElements) {
if(ctrl instanceof GdlVisibleObject){
- ((GdlVisibleObject)ctrl).getContent(localCarrier, onlyValidate);
+ ((GdlVisibleObject)ctrl).getContent(localCarrier, validate);
}
}
result.add(new Pair<Construct, TopicMapsTypes>(localCarrier, TopicMapsTypes.Association));
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.java Fri Sep 2 02:00:04 2011 (r818)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlTopicView.java Fri Sep 2 02:47:08 2011 (r819)
@@ -140,7 +140,7 @@
@Override
- public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean onlyValidate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException {
+ public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean validate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException {
ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
Topic localCarrier = (Topic)this.receivedData;
@@ -152,7 +152,7 @@
if(i == result.size()) result.add(new Pair<Construct, TopicMapsTypes>(localCarrier, TopicMapsTypes.Topic));
if(ctrl instanceof GdlVisibleObject){
- for (Pair<Construct, TopicMapsTypes> pair : ((GdlVisibleObject)ctrl).getContent(localCarrier, onlyValidate)) {
+ for (Pair<Construct, TopicMapsTypes> pair : ((GdlVisibleObject)ctrl).getContent(localCarrier, validate)) {
if((this.receivedData != null || (ctrl instanceof GdlView)) && !this.indirectlyContained(pair, result))result.add(pair);
}
}
More information about the Isidorus-cvs
mailing list