Author: lgiessmann Date: Fri Jul 15 03:00:51 2011 New Revision: 624
Log: gdl-frontend: Widgets: implemented GDL positioning in GdlList
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/TmHelper.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/container/GdlList.java branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java
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 Jul 15 00:55:20 2011 (r623) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java Fri Jul 15 03:00:51 2011 (r624) @@ -33,7 +33,7 @@ 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)); gdlPanel = new GdlPanel(null, requestedTopicsToCreate); - gdlPanel.setPixelSize(100, 100); + gdlPanel.setPixelSize(450, 450); DOM.setStyleAttribute(gdlPanel.getElement(), "backgroundColor", "yellow"); mainPanel.add(gdlPanel); gdlPanel.setTmEngine(new JtmsTmEngine());
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java Fri Jul 15 00:55:20 2011 (r623) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java Fri Jul 15 03:00:51 2011 (r624) @@ -1,10 +1,12 @@ package us.isidor.gdl.anaToMia.Widgets.base;
import java.util.ArrayList; +import java.util.List;
import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Association; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Locator; +import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Role; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.ScopedStub; import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic; @@ -315,14 +317,77 @@
// returns all topics that are related to the passed topic via a contains association public static ArrayList<Topic> topicContains(Topic container) { - if(container == null) return new ArrayList<Topic>(); - + if(container == null) return new ArrayList<Topic>(); TopicMap tm = container.getTopicMap(); - Topic contains = getTopicByPsi(GdlPsis.AssociationType.gdlContains, tm); + Topic containsAssocType = getTopicByPsi(GdlPsis.AssociationType.gdlContains, tm); + Topic containerRoleType = getTopicByPsi(GdlPsis.RoleType.gdlContainer, tm); + Topic visibleObject = getTopicByPsi(GdlPsis.TopicType.gdlVisibleObject, tm); + Topic containeeRoleType = getTopicByPsi(GdlPsis.RoleType.gdlContainee, tm); + + return getOtherPlayerOfBinaryAssociation(container, containerRoleType, containsAssocType, null, visibleObject, containeeRoleType); + } + + + // returns an ordered list of the list items and their index stored in a pair instance + public static ArrayList<Pair<Topic, Integer>> listContains(Topic list) throws InvalidGdlSchemaException { + if(list == null) return new ArrayList<Pair<Topic,Integer>>(); + TopicMap tm = list.getTopicMap(); + Topic containsAssocType = getTopicByPsi(GdlPsis.AssociationType.gdlContains, tm); Topic containerRoleType = getTopicByPsi(GdlPsis.RoleType.gdlContainer, tm); Topic visibleObject = getTopicByPsi(GdlPsis.TopicType.gdlVisibleObject, tm); Topic containeeRoleType = getTopicByPsi(GdlPsis.RoleType.gdlContainee, tm); - return getOtherPlayerOfBinaryAssociation(container, containerRoleType, contains, null, visibleObject, containeeRoleType); + Topic nthElement = getTopicByPsi(GdlPsis.TopicType.gdlNthElement, tm); + Topic nthElementRoleType = getTopicByPsi(GdlPsis.RoleType.gdlNthElement, tm); + + ArrayList<Pair<Topic, Topic>> rolePlayertypesAndTypes = new ArrayList<Pair<Topic,Topic>>(); + rolePlayertypesAndTypes.add(new Pair<Topic, Topic>(visibleObject, containeeRoleType)); + rolePlayertypesAndTypes.add(new Pair<Topic, Topic>(nthElement, nthElementRoleType)); + ArrayList<Association> validAssociations = getAssociationsOfTopic(list, containerRoleType, containsAssocType, null, rolePlayertypesAndTypes); + + List<Pair<Topic, Integer>> result = new ArrayList<Pair<Topic,Integer>>(); + for (Association validAssoc : validAssociations) { + Topic idx = validAssoc.getRoles(nthElementRoleType).get(0).getPlayer(); + JsArray<Occurrence> idxOccs = idx.getOccurrences(tm.getTopicBySubjectIdentifier(tm.createLocator(GdlPsis.OccurrenceType.gdlNthValue))); + ArrayList<Occurrence> validIdxOccs = new ArrayList<Occurrence>(); + for(int i = 0; i != idxOccs.length(); ++i) if(idxOccs.get(i).getScope().length() == 0) validIdxOccs.add(idxOccs.get(i)); + + if(validIdxOccs.size() != 1){ + throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(idx) + " must be bound exaclty once to an occurrence of the type " + GdlPsis.OccurrenceType.gdlNthValue + " but is bound " + validIdxOccs.size() + " times"); + }else{ + Occurrence validOcc = validIdxOccs.get(0); + if(!validOcc.getValue().toUpperCase().equals("LAST") && !Utils.isDecNumber(validOcc.getValue())){ + throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(idx) + " must be bound exaclty once to an occurrence of the type " + GdlPsis.OccurrenceType.gdlNthValue + " with a the value "last" or <positive integer>, but is " + validOcc.getValue()); + } + + int idxValue = -1; // -1 represents last + if(!validOcc.getValue().toUpperCase().equals("LAST")) idxValue = Integer.valueOf(validOcc.getValue()); + Topic item = validAssoc.getRoles(containeeRoleType).get(0).getPlayer(); + + if(result.size() == 0){ + result.add(new Pair<Topic, Integer>(item, idxValue)); + }else { + for(int i = 0; i != result.size(); ++i){ + if (result.get(i).getSecond() == idxValue){ + String idxStr = idxValue == -1 ? "last" : "" + idxValue; + throw new InvalidGdlSchemaException("the list " + getAnyIdOfTopic(list) + " contains more than one item with the idx " + idxStr); + } + + if(result.get(i).getSecond() > idxValue){ + result.add(i, new Pair<Topic, Integer>(item, idxValue)); + break; + } + + if(i == result.size() - 1){ + result.add(new Pair<Topic, Integer>(item, idxValue)); + break; + } + } + } + } + } + + ArrayList<Pair<Topic, Integer>> orderedResult = new ArrayList<Pair<Topic,Integer>>(result); + return orderedResult; }
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 Jul 15 00:55:20 2011 (r623) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java Fri Jul 15 03:00:51 2011 (r624) @@ -17,4 +17,12 @@ return true; } + + + // returns true if the string consists only of digits + public static boolean isDecNumber(String str){ + if(str == null) return false; + for(int i = 0; i != str.length(); ++i) if(!Character.isDigit(str.charAt(i))) return false; + return true; + } }
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlList.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlList.java Fri Jul 15 00:55:20 2011 (r623) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlList.java Fri Jul 15 03:00:51 2011 (r624) @@ -35,6 +35,7 @@ import us.isidor.gdl.anaToMia.Widgets.environment.ActiveStyleHandler; import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException; import us.isidor.gdl.anaToMia.Widgets.environment.FocusStyleHandler; +import us.isidor.gdl.anaToMia.Widgets.environment.GdlInstantiator; import us.isidor.gdl.anaToMia.Widgets.environment.HoverStyleHandler; import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException; import us.isidor.gdl.anaToMia.Widgets.environment.Pair; @@ -43,6 +44,9 @@
public class GdlList extends GdlVisibleObject implements IGdlContainer { + private ArrayList<Pair<Topic, Integer>> storedItems = null; + + // some constructors protected GdlList() throws InvalidGdlSchemaException, ExecutionException { super(); @@ -53,6 +57,19 @@ public GdlList(Topic tmRepresentative) throws InvalidGdlSchemaException, ExecutionException{ super(tmRepresentative); this.createList(); + + ArrayList<Topic> objectsContained = this.contains(); + + Topic currentTopic = objectsContained.size() == 0 ? null : objectsContained.get(0); + Topic lastTopic = null; + + if(objectsContained.size() != 0){ + for(int i = 1; i != objectsContained.size(); ++i){ + this.append(lastTopic, currentTopic); + lastTopic = currentTopic; + currentTopic = objectsContained.get(i); + } + } } @@ -261,7 +278,7 @@ } - // returns the position index of the item, that was psecified when + // returns the position index of the item, that was specified when // inserting the passed ListItem public int indexOfItem(ListItem item){ for (Pair<ListItem, Integer> pair : this.itemsAndIndexes) { @@ -314,7 +331,7 @@ } - // this class wrapps a list item, i.e. a div element within a li element + // this class wraps a list item, i.e. a div element within a li element protected class ListItem{ private Element liElement = null; private Element divElement = null; @@ -379,15 +396,36 @@ @Override public GdlVisibleObject append(Topic ancestor, Topic current) throws InvalidGdlSchemaException, ExecutionException { // TODO Auto-generated method stub + if(this.subElements.size() == 0) return null; + if(this.storedItems == null) this.storedItems = this.containsItems(); - return null; + // the ancestor element can be ignore, since the current idx can be looked up + // from the storedItem array list directly + int idx = -1; + for (Pair<Topic, Integer> pair : this.storedItems) if(pair.getFirst().equals(current)) idx = pair.getSecond(); + + ListWidget list = (ListWidget)this.subElements.get(0); + GdlVisibleObject newObj = GdlInstantiator.instantiate(current); + list.insertWidget(newObj, idx); + + return newObj; } - +
// returns all topics that are bound to this tm representative topic via a - // contains association + // contains association i an ordered list @Override public ArrayList<Topic> contains() throws InvalidGdlSchemaException { - return TmHelper.topicContains(this.tmRepresentative); + ArrayList<Topic> result = new ArrayList<Topic>(); + for (Pair<Topic, Integer> pair : TmHelper.listContains(super.getTmRepresentative())) + result.add(pair.getFirst()); + + return result; + } + + + // returns an ordered list of items with their index + public ArrayList<Pair<Topic, Integer>> containsItems() throws InvalidGdlSchemaException{ + return TmHelper.listContains(super.getTmRepresentative()); } }
Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java Fri Jul 15 00:55:20 2011 (r623) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java Fri Jul 15 03:00:51 2011 (r624) @@ -48,7 +48,6 @@ super(tmRepresentative); // TODO: create a text element for each TM-elem this.createNewTextArea(); // TODO: remove only for debugging - this.createNewTextArea(); // TODO: remove only for debugging }