Changeset 817


Ignore:
Timestamp:
09/02/11 07:58:42 (14 years ago)
Author:
lgiessmann
Message:

gdl-frontend: Widgets: added a new base-structure for the validation of user data

Location:
branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlSpace.java

    r800 r817  
    22
    33import java.util.ArrayList;
    4 
    54import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
    65import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
     
    4039                // has no effect on this element
    4140        }
     41       
     42       
     43        @Override
     44        public void validate() throws ExecutionException {
     45                // this element has no editable content and is always valid
     46                return;
     47        }
    4248}
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java

    r816 r817  
    22982298                return result;
    22992299        }
     2300
     2301
     2302        // validates the entered user data, if it is invalid a ExecutionException is thrown
     2303        public void validate() throws ExecutionException{
     2304                // TODO: implement
     2305        }
    23002306}
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/button/GdlActionButton.java

    r816 r817  
    271271                // has no effect on this element
    272272        }
     273       
     274       
     275        @Override
     276        public void validate() throws ExecutionException {
     277                // this element has no editable content and is always valid
     278                return;
     279        }
    273280}
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlList.java

    r800 r817  
    211211                }
    212212        }
    213        
    214        
    215         // Wraps a ul an ol element as a widget based on a SimplePanel
    216         protected class ListWidget extends Composite implements HasMouseDownHandlers, HasMouseUpHandlers, HasFocusHandlers, HasBlurHandlers, HasMouseOutHandlers, HasMouseOverHandlers{
    217                 private AbsolutePanel basePanel = new AbsolutePanel();
    218                 private Element listElement = null;
    219                 // note: index is not the actual index of the item in the array list,
    220                 // it is the user's passed index when inserting this element
    221                 private ArrayList<Pair<ListItem, Integer>> itemsAndIndexes = new ArrayList<Pair<ListItem, Integer>>();
    222                
    223                 public ListWidget(){
    224                         initWidget(this.basePanel);
    225                         DOM.setStyleAttribute(this.basePanel.getElement(), "overflow", "visible");
    226                         this.listElement = DOM.createElement("ul");
    227                         this.basePanel.getElement().insertFirst(this.listElement);
    228                 }
    229                
    230                
    231                 public ListWidget(boolean ordered){
    232                         initWidget(this.basePanel);
    233                         DOM.setStyleAttribute(this.basePanel.getElement(), "overflow", "visible");
    234                         if(ordered) this.listElement = DOM.createElement("ol");
    235                         else this.listElement = DOM.createElement("ul");
    236                         this.basePanel.getElement().insertFirst(this.listElement);
    237                 }
    238                
    239                
    240                 // inserts the passed list item as the last child to this list element
    241                 public void appendListItem(ListItem item){
    242                         if(item == null) return;
    243                         item.appendToList(this.listElement);
    244                 }
    245                
    246                
    247                 // inserts the passed instance item to this list directly after the intance previous
    248                 public void appendListItem(ListItem item, ListItem previous){
    249                         if(item == null) return;
    250                         item.appendToList(this.listElement, previous);
    251                 }
    252                
    253                
    254                 // inserts the passed widget directly before the first item that
    255                 // has a greater position index
    256                 public void insertWidget(Widget widget, int position){
    257                         ListItem previosItem = this.getItemBeforeIndex(position);
    258                         ListItem item = new ListItem(this.listElement);
    259                         item.appendContentToListItem(widget.getElement());
    260                         this.appendListItem(item, previosItem);
    261                 }
    262                
    263                
    264                 // returns the first item that has a smaller position index
    265                 public ListItem getItemBeforeIndex(int idx){
    266                         Pair<ListItem, Integer> result = null;
    267                         for (Pair<ListItem, Integer> item : this.itemsAndIndexes) {
    268                                 if(item.getSecond() < idx && (result == null || result.getSecond() < item.getSecond()))result = item;
    269                         }
    270                
    271                         if(result != null) result.getFirst();
    272                         return null;
    273                 }
    274                
    275                
    276                 // returns the acutal DOM element
    277                 public Element getListElement(){
    278                         return this.listElement;
    279                 }
    280                
    281                 // returns all ListItems
    282                 public ArrayList<ListItem> getItems(){
    283                         ArrayList<ListItem> items = new ArrayList<GdlList.ListItem>();
    284                         for (Pair<ListItem, Integer> pair : this.itemsAndIndexes) {
    285                                 items.add(pair.getFirst());
    286                         }
    287                         return items;
    288                 }
    289                
    290                
    291                 // returns the position index of the item, that was specified when
    292                 // inserting the passed ListItem
    293                 public int indexOfItem(ListItem item){
    294                         for (Pair<ListItem, Integer> pair : this.itemsAndIndexes) {
    295                                 if(pair.getFirst().equals(item)) return pair.getSecond();
    296                         }
    297                        
    298                         return -1;
    299                 }
    300                
    301                
    302                 public void setId(String id){
    303                         DOM.setElementAttribute(this.basePanel.getElement(), "id", id);
    304                 }
    305 
    306 
    307                 @Override
    308                 public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
    309                         return this.addDomHandler(handler, MouseOverEvent.getType());
    310                 }
    311 
    312 
    313                 @Override
    314                 public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
    315                         return this.addDomHandler(handler, MouseOutEvent.getType());
    316                 }
    317 
    318 
    319                 @Override
    320                 public HandlerRegistration addBlurHandler(BlurHandler handler) {
    321                         return this.addDomHandler(handler, BlurEvent.getType());
    322                 }
    323 
    324 
    325                 @Override
    326                 public HandlerRegistration addFocusHandler(FocusHandler handler) {
    327                         return this.addDomHandler(handler, FocusEvent.getType());
    328                 }
    329 
    330 
    331                 @Override
    332                 public HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
    333                         return this.addDomHandler(handler, MouseUpEvent.getType());
    334                 }
    335 
    336 
    337                 @Override
    338                 public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
    339                         return this.addDomHandler(handler, MouseDownEvent.getType());
    340                 }
    341         }
    342        
     213
    343214       
    344215        // this class wraps a list item, i.e. a div element within a li element
     
    346217                private Element liElement = null;
    347218                private Element divElement = null;
     219                private ArrayList<GdlVisibleObject> contents = new ArrayList<GdlVisibleObject>();
     220               
    348221               
    349222                public ListItem(){
     
    391264               
    392265                // appends the content element to the inner div item
    393                 public void appendContentToListItem(Element content){
     266                public void appendContentToListItem(GdlVisibleObject content){
    394267                        if(content != null){
    395268                                Node lastChild = this.divElement.getLastChild();
    396269                                if(lastChild != null){
    397                                         this.divElement.insertAfter(content, lastChild);
     270                                        this.divElement.insertAfter(content.getElement(), lastChild);
    398271                                } else {
    399                                         this.divElement.insertFirst(content);
     272                                        this.divElement.insertFirst(content.getElement());
    400273                                }
    401                         }
     274                               
     275                                contents.add(content);
     276                        }
     277                }
     278       
     279               
     280                public void validate() throws ExecutionException {
     281                        for (GdlVisibleObject content : this.contents) content.validate();
     282                }
     283        }
     284       
     285       
     286        @Override
     287        public void validate() throws ExecutionException {
     288                for (Widget ctrl : this.subElements) {
     289                        ((ListWidget)((ButtonableObject)ctrl).getMainObject()).validate();
    402290                }
    403291        }
     
    453341                // has no effect on this element
    454342        }
     343       
     344       
     345        // Wraps a ul an ol element as a widget based on a SimplePanel
     346        protected class ListWidget extends Composite implements HasMouseDownHandlers, HasMouseUpHandlers, HasFocusHandlers, HasBlurHandlers, HasMouseOutHandlers, HasMouseOverHandlers{
     347                private AbsolutePanel basePanel = new AbsolutePanel();
     348                private Element listElement = null;
     349                // note: index is not the actual index of the item in the array list,
     350                // it is the user's passed index when inserting this element
     351                private ArrayList<Pair<ListItem, Integer>> itemsAndIndexes = new ArrayList<Pair<ListItem, Integer>>();
     352               
     353                public ListWidget(){
     354                        initWidget(this.basePanel);
     355                        DOM.setStyleAttribute(this.basePanel.getElement(), "overflow", "visible");
     356                        this.listElement = DOM.createElement("ul");
     357                        this.basePanel.getElement().insertFirst(this.listElement);
     358                }
     359               
     360               
     361                public ListWidget(boolean ordered){
     362                        initWidget(this.basePanel);
     363                        DOM.setStyleAttribute(this.basePanel.getElement(), "overflow", "visible");
     364                        if(ordered) this.listElement = DOM.createElement("ol");
     365                        else this.listElement = DOM.createElement("ul");
     366                        this.basePanel.getElement().insertFirst(this.listElement);
     367                }
     368               
     369               
     370                // inserts the passed list item as the last child to this list element
     371                public void appendListItem(ListItem item){
     372                        if(item == null) return;
     373                        item.appendToList(this.listElement);
     374                }
     375               
     376               
     377                // inserts the passed instance item to this list directly after the intance previous
     378                public void appendListItem(ListItem item, ListItem previous){
     379                        if(item == null) return;
     380                        item.appendToList(this.listElement, previous);
     381                }
     382               
     383               
     384                // inserts the passed widget directly before the first item that
     385                // has a greater position index
     386                public void insertWidget(GdlVisibleObject widget, int position){
     387                        ListItem previosItem = this.getItemBeforeIndex(position);
     388                        ListItem item = new ListItem(this.listElement);
     389                        item.appendContentToListItem(widget);
     390                        this.appendListItem(item, previosItem);
     391                }
     392               
     393               
     394                // returns the first item that has a smaller position index
     395                public ListItem getItemBeforeIndex(int idx){
     396                        Pair<ListItem, Integer> result = null;
     397                        for (Pair<ListItem, Integer> item : this.itemsAndIndexes) {
     398                                if(item.getSecond() < idx && (result == null || result.getSecond() < item.getSecond()))result = item;
     399                        }
     400               
     401                        if(result != null) result.getFirst();
     402                        return null;
     403                }
     404               
     405               
     406                // returns the acutal DOM element
     407                public Element getListElement(){
     408                        return this.listElement;
     409                }
     410               
     411                // returns all ListItems
     412                public ArrayList<ListItem> getItems(){
     413                        ArrayList<ListItem> items = new ArrayList<GdlList.ListItem>();
     414                        for (Pair<ListItem, Integer> pair : this.itemsAndIndexes) {
     415                                items.add(pair.getFirst());
     416                        }
     417                        return items;
     418                }
     419               
     420               
     421                // returns the position index of the item, that was specified when
     422                // inserting the passed ListItem
     423                public int indexOfItem(ListItem item){
     424                        for (Pair<ListItem, Integer> pair : this.itemsAndIndexes) {
     425                                if(pair.getFirst().equals(item)) return pair.getSecond();
     426                        }
     427                       
     428                        return -1;
     429                }
     430               
     431               
     432                public void validate() throws ExecutionException {
     433                        for (Pair<ListItem, Integer> item: this.itemsAndIndexes) {
     434                                item.getFirst().validate();
     435                        }
     436                }
     437               
     438               
     439                public void setId(String id){
     440                        DOM.setElementAttribute(this.basePanel.getElement(), "id", id);
     441                }
     442
     443
     444                @Override
     445                public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
     446                        return this.addDomHandler(handler, MouseOverEvent.getType());
     447                }
     448
     449
     450                @Override
     451                public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
     452                        return this.addDomHandler(handler, MouseOutEvent.getType());
     453                }
     454
     455
     456                @Override
     457                public HandlerRegistration addBlurHandler(BlurHandler handler) {
     458                        return this.addDomHandler(handler, BlurEvent.getType());
     459                }
     460
     461
     462                @Override
     463                public HandlerRegistration addFocusHandler(FocusHandler handler) {
     464                        return this.addDomHandler(handler, FocusEvent.getType());
     465                }
     466
     467
     468                @Override
     469                public HandlerRegistration addMouseUpHandler(MouseUpHandler handler) {
     470                        return this.addDomHandler(handler, MouseUpEvent.getType());
     471                }
     472
     473
     474                @Override
     475                public HandlerRegistration addMouseDownHandler(MouseDownHandler handler) {
     476                        return this.addDomHandler(handler, MouseDownEvent.getType());
     477                }
     478        }
    455479}
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/container/GdlUnit.java

    r800 r817  
    245245       
    246246       
     247        @Override
     248        public void validate() throws ExecutionException {
     249                for (Widget ctrl : this.subElements) {
     250                        ((UnitWidget)((ButtonableObject)ctrl).getMainObject()).validate();
     251                }
     252        }
     253       
     254       
    247255        protected class UnitWidget extends Composite implements HasFocusHandlers, HasBlurHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseDownHandlers, HasMouseUpHandlers{
    248256                private CaptionPanel basePanel = new CaptionPanel();
     
    371379                        }
    372380                }
     381       
     382               
     383                public void validate() throws ExecutionException{
     384                        for (Widget ctrl : this.subElements) {
     385                                if(ctrl instanceof GdlVisibleObject){
     386                                        ((GdlVisibleObject)ctrl).validate();
     387                                }
     388                        }
     389                }
    373390        }
    374391}
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlInfo.java

    r800 r817  
    109109                return new ArrayList<String>();
    110110        }
     111       
     112       
     113        @Override
     114        public void validate() throws ExecutionException {
     115                // this element has no editable content and is always valid
     116                return;
     117        }
    111118}
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlReference.java

    r800 r817  
    5959       
    6060       
     61        @Override
     62        public void validate() throws ExecutionException {
     63                // this element has no editable content and is always valid
     64                return;
     65        }
     66       
     67       
    6168        private ReferenceWidget createReference() throws InvalidGdlSchemaException, ExecutionException {
    6269                ReferenceWidget reference = new ReferenceWidget();
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlTitle.java

    r800 r817  
    450450       
    451451       
     452        @Override
     453        public void validate() throws ExecutionException {
     454                // this element has no editable content and is always valid
     455                return;
     456        }
     457       
     458       
    452459        // this class represents the acutal content of this widget, i.e.
    453460        // it wraps a h1, h2, h3 or h4 element
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java

    r816 r817  
    224224                return result;
    225225        }
     226
     227       
     228        @Override
     229        public void validate() throws ExecutionException {
     230                for (Widget ctrl : this.subElements)
     231                        if(ctrl instanceof AssociationItem) ((AssociationItem)ctrl).validate();
     232        }
    226233       
    227234
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlDefaultTopicView.java

    r801 r817  
    1616        // TODO: implement
    1717       
     18       
    1819}
  • TabularUnified branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlView.java

    r809 r817  
    126126                }
    127127        }
     128       
     129       
     130        @Override
     131        public void validate() throws ExecutionException {
     132                for (Widget ctrl : this.subElements) {
     133                        if(ctrl instanceof GdlVisibleObject){
     134                                ((GdlVisibleObject)ctrl).validate();
     135                        }
     136                }
     137        }
    128138}
Note: See TracChangeset for help on using the changeset viewer.