Coverage Report - org.kuali.student.lum.common.client.lo.LOCategoryBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
LOCategoryBuilder
0%
0/88
0%
0/20
1.471
LOCategoryBuilder$1
0%
0/3
N/A
1.471
LOCategoryBuilder$2
0%
0/23
N/A
1.471
LOCategoryBuilder$2$1
0%
0/6
0%
0/2
1.471
LOCategoryBuilder$2$2
0%
0/3
N/A
1.471
LOCategoryBuilder$3
0%
0/6
N/A
1.471
LOCategoryBuilder$4
0%
0/13
0%
0/2
1.471
LOCategoryBuilder$4$1
0%
0/11
0%
0/3
1.471
LOCategoryBuilder$4$1$1
0%
0/11
0%
0/4
1.471
LOCategoryBuilder$5
0%
0/7
N/A
1.471
LOCategoryBuilder$6
0%
0/1
N/A
1.471
LOCategoryBuilder$CategoryDataParser
0%
0/12
0%
0/4
1.471
LOCategoryBuilder$CreateLoCancelGroup
0%
0/16
N/A
1.471
LOCategoryBuilder$CreateLoCancelGroup$1
0%
0/3
N/A
1.471
LOCategoryBuilder$CreateLoCancelGroup$2
0%
0/3
N/A
1.471
LOCategoryBuilder$LOCategoryListNew
0%
0/49
0%
0/10
1.471
LOCategoryBuilder$LOCategoryListNew$1
0%
0/6
N/A
1.471
LOCategoryBuilder$LOCategoryListNew$2
0%
0/7
0%
0/2
1.471
LOCategoryBuilder$LOCategoryPicker
0%
0/30
N/A
1.471
LOCategoryBuilder$LOCategoryTypeInfoList
0%
0/16
0%
0/6
1.471
LOCategoryBuilder$LoCancelEnum
0%
0/9
0%
0/3
1.471
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.lum.common.client.lo;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Arrays;
 20  
 import java.util.Date;
 21  
 import java.util.HashMap;
 22  
 import java.util.List;
 23  
 import java.util.Map;   
 24  
 
 25  
 import org.kuali.student.common.ui.client.application.Application;
 26  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 27  
 import org.kuali.student.common.ui.client.mvc.Callback;
 28  
 import org.kuali.student.common.ui.client.service.DataSaveResult;
 29  
 import org.kuali.student.common.ui.client.widgets.DataHelper;
 30  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 31  
 import org.kuali.student.common.ui.client.widgets.KSDropDown;
 32  
 import org.kuali.student.common.ui.client.widgets.KSItemLabel;
 33  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 34  
 import org.kuali.student.common.ui.client.widgets.KSLightBox;
 35  
 import org.kuali.student.common.ui.client.widgets.KSTextBox;
 36  
 import org.kuali.student.common.ui.client.widgets.KSThinTitleBar;
 37  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 38  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonGroup;
 39  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.ButtonEnum;
 40  
 import org.kuali.student.common.ui.client.widgets.buttonlayout.ButtonRow;
 41  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrButton;
 42  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.LabelPanel;
 43  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.AbbrButton.AbbrButtonType;
 44  
 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.FieldLayoutComponent;
 45  
 import org.kuali.student.common.ui.client.widgets.focus.FocusGroup;
 46  
 import org.kuali.student.common.ui.client.widgets.list.ListItems;
 47  
 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler;
 48  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotification;
 49  
 import org.kuali.student.common.ui.client.widgets.notification.KSNotifier;
 50  
 import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
 51  
 import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
 52  
 import org.kuali.student.common.ui.client.widgets.suggestbox.KSSuggestBox;
 53  
 import org.kuali.student.common.ui.client.widgets.suggestbox.SearchSuggestOracle;
 54  
 import org.kuali.student.common.ui.client.widgets.suggestbox.SuggestPicker;
 55  
 import org.kuali.student.core.assembly.data.Data;
 56  
 import org.kuali.student.core.assembly.data.Data.DataValue;
 57  
 
 58  
 import org.kuali.student.lum.common.client.lo.rpc.LoCategoryRpcServiceAsync;
 59  
 import org.kuali.student.lum.common.client.lo.rpc.LoCategoryRpcService;
 60  
 import org.kuali.student.lum.common.client.lu.LUUIConstants;
 61  
 import org.kuali.student.lum.lo.dto.LoCategoryInfo;
 62  
 import org.kuali.student.lum.lo.dto.LoCategoryTypeInfo;
 63  
 
 64  
 import com.google.gwt.core.client.GWT;
 65  
 import com.google.gwt.event.dom.client.BlurHandler;
 66  
 import com.google.gwt.event.dom.client.ClickEvent;
 67  
 import com.google.gwt.event.dom.client.ClickHandler;
 68  
 import com.google.gwt.event.dom.client.FocusHandler;
 69  
 import com.google.gwt.event.logical.shared.CloseEvent;
 70  
 import com.google.gwt.event.logical.shared.CloseHandler;
 71  
 import com.google.gwt.event.logical.shared.ValueChangeEvent;
 72  
 import com.google.gwt.event.logical.shared.ValueChangeHandler;
 73  
 import com.google.gwt.event.shared.GwtEvent;
 74  
 import com.google.gwt.event.shared.HandlerRegistration;
 75  
 import com.google.gwt.gen2.table.client.SelectionGrid.SelectionPolicy;
 76  
 import com.google.gwt.user.client.Window;
 77  
 import com.google.gwt.user.client.rpc.AsyncCallback;
 78  
 import com.google.gwt.user.client.ui.Anchor;
 79  
 import com.google.gwt.user.client.ui.Composite;
 80  
 import com.google.gwt.user.client.ui.FlexTable;
 81  
 import com.google.gwt.user.client.ui.FlowPanel;
 82  
 import com.google.gwt.user.client.ui.HTMLPanel;
 83  
 import com.google.gwt.user.client.ui.HasValue;
 84  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 85  
 import com.google.gwt.user.client.ui.VerticalPanel;
 86  
 
 87  
 /**
 88  
  * 
 89  
  * This class allows a user to select and remove LO categories within the context of 
 90  
  * LO creation. New categories can be added 'on the fly' and are persisted in the database
 91  
  * independently of LO creation 
 92  
  *  
 93  
  * @author Kuali Rice Team (kuali-rice@googlegroups.com)
 94  
  *
 95  
  */
 96  0
 public class LOCategoryBuilder extends Composite implements HasValue<List<LoCategoryInfo>> {
 97  
 
 98  
     private String type;
 99  
     private String state;
 100  
     private String repoKey;
 101  
     private String messageGroup;
 102  
 
 103  
     private LoCategoryRpcServiceAsync loCatRpcServiceAsync ;
 104  
     private LOCategoryPicker picker ;
 105  0
     private AbbrButton help = new AbbrButton(AbbrButtonType.HELP);
 106  
 
 107  
     LOCategoryListNew categoryList;
 108  
     Map<String, LoCategoryTypeInfo> categoryTypeMap ;
 109  
 
 110  0
     VerticalPanel root = new VerticalPanel();
 111  
 
 112  0
     private KSButton addButton = new KSButton("Add", ButtonStyle.SECONDARY);
 113  
 
 114  
     private KSLightBox createCategoryWindow;
 115  0
     Anchor browseCategoryLink = new Anchor("Browse for categories");
 116  0
     private final BlockingTask saving = new BlockingTask("Saving");
 117  
 
 118  
     public LOCategoryBuilder(String messageGroup, String type, String state, String loRepoKey) {
 119  0
         super();
 120  
 
 121  0
         this.type = type;
 122  0
         this.state = state;
 123  0
         this.repoKey = loRepoKey;
 124  0
         this.messageGroup = messageGroup;
 125  
 
 126  0
         loCatRpcServiceAsync = GWT.create(LoCategoryRpcService.class);
 127  0
         picker = new LOCategoryPicker();
 128  0
         categoryList = new LOCategoryListNew();
 129  
 
 130  0
         initWidget(root);
 131  
 
 132  0
         final FlowPanel selectedPanel = new FlowPanel();
 133  0
         selectedPanel.setStyleName("KS-LOSelectedCategories");
 134  0
         addButton.addClickHandler(new ClickHandler() {
 135  
             @Override
 136  
             public void onClick(ClickEvent event) {
 137  0
                 addEnteredCategory();
 138  0
             }
 139  
         });
 140  0
         browseCategoryLink.addClickHandler(new ClickHandler() {
 141  
             @Override
 142  
             public void onClick(ClickEvent event) {
 143  0
                 final CategoryManagement categoryManagement = new CategoryManagement(true,SelectionPolicy.MULTI_ROW);
 144  0
                 categoryManagement.setDeleteButtonEnabled(false);
 145  0
                 categoryManagement.setInsertButtonEnabled(false);
 146  0
                 categoryManagement.setUpdateButtonEnabled(false);
 147  
                 
 148  0
                 final KSLightBox pop = new KSLightBox();
 149  0
                 pop.setSize(600, 500);
 150  0
                 KSButton addButton = new KSButton("Add");
 151  0
                 addButton.addStyleName("KSLOLightBoxButton");
 152  0
                 KSButton cancelButton = new KSButton("Cancel");
 153  0
                 cancelButton.addStyleName("KSLOLightBoxButtonSecondary");
 154  0
                 HorizontalPanel buttonPanel = new HorizontalPanel();
 155  0
                 buttonPanel.addStyleName("KSLOLightBoxButtonPanel");
 156  0
                 buttonPanel.add(addButton);
 157  0
                 buttonPanel.add(cancelButton);
 158  
                 
 159  
                 
 160  0
                 VerticalPanel mainPanel = new VerticalPanel();
 161  
                 //mainPanel.addStyleName("KSLOLightBoxMainPanel");
 162  0
                 mainPanel.add(categoryManagement);
 163  0
                 mainPanel.add(buttonPanel);
 164  
                 
 165  0
                 addButton.addClickHandler(new ClickHandler(){
 166  
                     @Override
 167  
                     public void onClick(ClickEvent event) {
 168  0
                         List<LoCategoryInfo> list = categoryManagement.getSelectedCategoryList();        
 169  0
                         for(LoCategoryInfo info: list){
 170  0
                             addCategory(info);
 171  
                         }
 172  0
                         pop.hide();
 173  0
                     }
 174  
                 });
 175  
                 
 176  0
                 cancelButton.addClickHandler(new ClickHandler(){
 177  
                     @Override
 178  
                     public void onClick(ClickEvent event) {
 179  0
                         pop.hide();
 180  0
                     }
 181  
                 });
 182  
                 
 183  
                 
 184  0
                 pop.setWidget(mainPanel);
 185  0
                 pop.show();
 186  
                 
 187  
                 
 188  
                 
 189  0
             }
 190  
         }); 
 191  
 
 192  0
         VerticalPanel main = new VerticalPanel();
 193  0
         HorizontalPanel suggestPanel = new HorizontalPanel();
 194  0
         suggestPanel.add(picker);
 195  0
         suggestPanel.add(addButton);
 196  
         
 197  0
         VerticalPanel suggestAndBrowsePanel = new VerticalPanel();
 198  0
         suggestAndBrowsePanel.add(suggestPanel);
 199  0
         suggestAndBrowsePanel.add(browseCategoryLink);
 200  
 
 201  
         
 202  0
         selectedPanel.add(categoryList);
 203  
         
 204  0
         String fieldHTMLId = HTMLPanel.createUniqueId();
 205  0
         String title = getLabelText(LUUIConstants.LO_CATEGORY_KEY);
 206  0
         String helpText = getLabelText(LUUIConstants.LO_CATEGORY_KEY + FieldLayoutComponent.HELP_MESSAGE_KEY);
 207  0
         LabelPanel fieldTitle = new LabelPanel(title, fieldHTMLId);
 208  
         
 209  0
         if(helpText != null){
 210  0
             setHelp(helpText);
 211  
         } else {
 212  0
             help.setVisible(false);
 213  
         }
 214  
 
 215  0
         fieldTitle.add(help);
 216  0
         main.add(fieldTitle);
 217  0
         main.add(suggestAndBrowsePanel);
 218  0
         main.add(selectedPanel);
 219  0
         root.add(main);
 220  
 
 221  0
         main.addStyleName("KS-LOCategoryPicker");
 222  0
         addButton.addStyleName("KS-LOCategoryPicker-Button");
 223  
 
 224  0
     }
 225  
 
 226  
     public void setHelp(final String html){
 227  0
         if(html != null && !html.trim().equals("")){
 228  0
             help.setVisible(true);
 229  0
             help.setHoverHTML(html);
 230  
             /*help.addClickHandler(new ClickHandler(){
 231  
 
 232  
                 @Override
 233  
                 public void onClick(ClickEvent event) {
 234  
                     //TODO show actual help window
 235  
                     Window.alert(html);
 236  
 
 237  
                 }
 238  
             });*/
 239  
         }
 240  
         else{
 241  0
             help.setVisible(false);
 242  
         }
 243  0
     }
 244  
     
 245  
     private void addEnteredCategory() {
 246  
 
 247  0
         if (categoryList == null)
 248  0
             categoryList = new LOCategoryListNew();
 249  
 
 250  0
         if (picker.getSelectedId().trim().equals("")) {
 251  0
             showNewCategoryWindow();
 252  
         }
 253  
         else {
 254  0
             loCatRpcServiceAsync.getData(picker.getSelectedId(),new KSAsyncCallback<Data>() {
 255  
 
 256  
                 @Override
 257  
                 public void handleFailure(Throwable caught) {
 258  0
                     Window.alert("getLoCategory failed " + caught.getMessage());
 259  0
                 }
 260  
 
 261  
                 @Override
 262  
                 public void onSuccess(Data result) {
 263  0
                     final LoCategoryInfo newCategory = CategoryDataUtil.toLoCategoryInfo(result);
 264  0
                     addCategory(newCategory);
 265  
 
 266  0
                 }
 267  
             });
 268  
         }
 269  0
     }
 270  
 
 271  
     private void showNewCategoryWindow() {
 272  
 
 273  0
         final VerticalPanel main = new VerticalPanel();
 274  0
         final KSDropDown typesDropDown = new KSDropDown();
 275  0
         createCategoryWindow = new KSLightBox();
 276  
 
 277  0
         FlexTable layoutTable = new FlexTable();
 278  0
         final KSTextBox nameTextBox = new KSTextBox();
 279  0
         nameTextBox.setText(picker.getText());//+ enteredWord);
 280  
         
 281  0
         layoutTable.setWidget(0, 0, new KSLabel("Category"));
 282  0
         layoutTable.setWidget(0, 1, new KSLabel("Type"));
 283  0
         layoutTable.setWidget(1, 0, nameTextBox);
 284  0
         layoutTable.setWidget(1, 1, typesDropDown);
 285  
 
 286  0
         KSThinTitleBar titleBar = new KSThinTitleBar("Create New Category");
 287  0
         main.add(titleBar);
 288  0
         main.add(layoutTable);
 289  
         
 290  0
         loCatRpcServiceAsync.getLoCategoryTypes(new KSAsyncCallback<List<LoCategoryTypeInfo>>() {
 291  
 
 292  
             @Override
 293  
             public void handleFailure(Throwable caught) {
 294  0
                 Window.alert("getLoCategoryTypes failed " + caught.getMessage());
 295  0
             }
 296  
 
 297  
             @Override
 298  
             public void onSuccess(List<LoCategoryTypeInfo> result) {
 299  0
                 final LOCategoryTypeInfoList list = new LOCategoryTypeInfoList(result);
 300  0
                 typesDropDown.setListItems(list);
 301  0
                 if (categoryTypeMap == null) {
 302  0
                     loadCategoryTypes(result);                    
 303  
                 }
 304  
 
 305  0
                 CreateLoCancelGroup buttonPanel = new CreateLoCancelGroup(new Callback<LoCancelEnum>(){
 306  
 
 307  
                     @Override
 308  
                     public void exec(LoCancelEnum result) {
 309  0
                         switch(result){
 310  
                             case CREATE:
 311  
 
 312  0
                                 LoCategoryInfoHelper catHelper = new LoCategoryInfoHelper(new Data());
 313  0
                                 catHelper.setName(nameTextBox.getText());
 314  0
                                 catHelper.setState("active");
 315  0
                                 catHelper.setLoRepository(repoKey);
 316  0
                                 catHelper.setType(typesDropDown.getSelectedItem());
 317  
 
 318  0
                                 loCatRpcServiceAsync.saveData(catHelper.getData(), new KSAsyncCallback<DataSaveResult>(){
 319  
                                     @Override
 320  
                                     public void handleFailure(Throwable caught) {
 321  0
                                         Window.alert("Create LO Category failed: " + caught.getMessage());
 322  0
                                     }
 323  
                                     @Override
 324  
                                     public void onSuccess(DataSaveResult result) {
 325  0
                                         KSBlockingProgressIndicator.removeTask(saving);
 326  
 
 327  0
                                         if(result.getValidationResults()!=null && !result.getValidationResults().isEmpty()){
 328  0
                                             Window.alert("Create LO Category failed: " + result.getValidationResults().get(0).getMessage());
 329  
                                        }else{
 330  
 
 331  0
                                             final LoCategoryInfo newCategory = CategoryDataUtil.toLoCategoryInfo(result.getValue());
 332  0
                                             addCategory(newCategory);
 333  0
                                             createCategoryWindow.hide();
 334  0
                                             KSNotifier.add(new KSNotification("Create LO Category Successful", false, 3000));
 335  
                                         }
 336  0
                                     }
 337  
                                 });
 338  0
                                 break;
 339  
                             case CANCEL:
 340  0
                                 createCategoryWindow.hide();
 341  
                                 break;
 342  
                         }
 343  0
                     }
 344  
                 });
 345  
 
 346  0
                 main.add(buttonPanel);
 347  0
                 main.setPixelSize(300, 300);
 348  0
                 createCategoryWindow.setWidget(main);
 349  0
                 createCategoryWindow.show();
 350  0
             }
 351  
 
 352  
 
 353  
 
 354  
         });
 355  0
     }
 356  
 
 357  
     private void loadCategoryTypes(List<LoCategoryTypeInfo> categoryTypes) {
 358  0
         if (categoryTypeMap == null) {
 359  0
             categoryTypeMap = new HashMap<String, LoCategoryTypeInfo>();
 360  
         }
 361  0
         if (categoryTypes != null){
 362  0
                 for (LoCategoryTypeInfo i: categoryTypes) {
 363  0
                     categoryTypeMap.put(i.getId(), i);
 364  
                 }
 365  
         }
 366  0
     }
 367  
 
 368  
     private void addCategory(final LoCategoryInfo category) {
 369  0
         if (categoryTypeMap == null) {
 370  0
             categoryTypeMap = new HashMap<String, LoCategoryTypeInfo>();
 371  
         }
 372  
 
 373  0
         if (categoryTypeMap.containsKey(category.getType())) {
 374  0
             categoryList.addItem(category);
 375  0
             picker.reset();
 376  
         }
 377  
         else {
 378  0
             loCatRpcServiceAsync.getLoCategoryType(category.getType(), new KSAsyncCallback<LoCategoryTypeInfo> () {
 379  
 
 380  
                 @Override
 381  
                 public void handleFailure(Throwable caught) {
 382  0
                     Window.alert("getLoCategoryType failed " + caught.getMessage());
 383  0
                 }
 384  
 
 385  
                 @Override
 386  
                 public void onSuccess(LoCategoryTypeInfo result) {
 387  0
                     categoryTypeMap.put(result.getId(), result);
 388  0
                     categoryList.addItem(category);
 389  0
                     picker.reset();
 390  
 
 391  0
                 }
 392  
 
 393  
             });        
 394  
         }
 395  
 
 396  0
     }
 397  
     
 398  
     private String getLabelText(String labelKey) {
 399  0
         return Application.getApplicationContext().getUILabel(messageGroup, type, state, labelKey);
 400  
     }
 401  
 
 402  
     @Override
 403  
     public void setValue(List<LoCategoryInfo> categories) {
 404  0
         categoryList.setValue(categories);
 405  
 
 406  0
     }
 407  
 
 408  
     @Override
 409  
     public void setValue(List<LoCategoryInfo> value, boolean fireEvents) {
 410  0
         setValue(value);
 411  0
     }
 412  
 
 413  
     /**
 414  
      * @see com.google.gwt.user.client.ui.HasValue#getValue()
 415  
      */
 416  
     @Override
 417  
     public List<LoCategoryInfo> getValue() {
 418  0
         return categoryList.getValue();
 419  
     }
 420  
 
 421  
     /**
 422  
      * @see com.google.gwt.event.logical.shared.HasValueChangeHandlers#addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)
 423  
      */
 424  
     @Override
 425  
     public HandlerRegistration addValueChangeHandler(ValueChangeHandler<List<LoCategoryInfo>> handler) {
 426  0
         return categoryList.addValueChangeHandler(handler);
 427  
     }
 428  
 
 429  
     /**
 430  
      * 
 431  
      * This class provides a suggest box for existing LO categories backed by a search on category name
 432  
      *  
 433  
      * @author Kuali Rice Team (kuali-rice@googlegroups.com)
 434  
      *
 435  
      */
 436  0
     private class LOCategoryPicker extends Composite implements SuggestPicker {
 437  
 
 438  
         //FIXME:   [KSCOR-225] Class needs to be rewritten to use KSPicker instead of SuggestPicker and use lookup config through metadata
 439  
         
 440  0
          final SearchSuggestOracle loSearchOracle = new SearchSuggestOracle(
 441  
                  "lo.search.loCategories",
 442  
                  "lo.queryParam.loOptionalCategoryName",
 443  
                  "lo.queryParam.loCategoryId",
 444  
                  "lo.resultColumn.categoryId", 
 445  
          "lo.resultColumn.categoryNameAndType");
 446  
 
 447  0
          final KSSuggestBox suggestBox = new KSSuggestBox(loSearchOracle);
 448  
 
 449  0
          private final FocusGroup focus = new FocusGroup(this);
 450  
 
 451  0
          private VerticalPanel main = new VerticalPanel();
 452  
 
 453  0
          protected LOCategoryPicker() {
 454  0
              super();
 455  0
              init();
 456  0
          }
 457  
 
 458  
          public String getSelectedId() {
 459  0
              return suggestBox.getSelectedId();
 460  
          }
 461  
 
 462  
          private void init () {
 463  0
              focus.addWidget(suggestBox);
 464  0
              loSearchOracle.setTextWidget(suggestBox.getTextBox());
 465  0
              main.add(suggestBox);
 466  0
              initWidget(main);
 467  0
          }
 468  
 
 469  
          @Override
 470  
          public String getValue() {
 471  0
              return suggestBox.getSelectedId();
 472  
          }
 473  
 
 474  
          @Override
 475  
          public void setValue(String value) {
 476  0
              setValue(value, true);
 477  0
          }
 478  
 
 479  
          @Override
 480  
          public void setValue(String value, boolean fireEvents) {
 481  0
              suggestBox.reset();
 482  0
              suggestBox.setValue(value, fireEvents);
 483  0
          }
 484  
 
 485  
 
 486  
          @Override
 487  
          public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler) {
 488  0
              return suggestBox.addValueChangeHandler(handler);
 489  
          }
 490  
 
 491  
          @Override
 492  
          public void fireEvent(GwtEvent<?> event) {
 493  0
              super.fireEvent(event);
 494  0
          }
 495  
 
 496  
          public void reset(){
 497  0
              suggestBox.reset();
 498  0
          }
 499  
 
 500  
          @Override
 501  
          public HandlerRegistration addFocusHandler(FocusHandler handler) {
 502  0
              return focus.addFocusHandler(handler);
 503  
          }
 504  
 
 505  
          @Override
 506  
          public HandlerRegistration addBlurHandler(BlurHandler handler) {
 507  0
              return focus.addBlurHandler(handler);
 508  
          }
 509  
 
 510  
          public String getText() {
 511  0
              return suggestBox.getText();
 512  
          }
 513  
 
 514  
         @Override
 515  
         public HandlerRegistration addSelectionChangeHandler(SelectionChangeHandler handler) {
 516  0
             return suggestBox.addSelectionChangeHandler(handler);
 517  
         }
 518  
      }
 519  
 
 520  
      private class LOCategoryTypeInfoList implements ListItems{
 521  0
          Map<String, LoCategoryTypeInfo> loTypeMap = new HashMap<String, LoCategoryTypeInfo>();
 522  
 
 523  0
          public LOCategoryTypeInfoList(List<LoCategoryTypeInfo> loTypes){
 524  0
              for (LoCategoryTypeInfo type: loTypes){
 525  0
                  loTypeMap.put(type.getId(), type);
 526  
              }
 527  0
          }
 528  
 
 529  
          public List<String> getAttrKeys() {
 530  0
              return Arrays.asList("Name");
 531  
          }
 532  
 
 533  
          public String getItemAttribute(String id, String attrkey) {
 534  0
              LoCategoryTypeInfo lo = loTypeMap.get(id);
 535  
 
 536  0
              if (attrkey.equals("Name")){
 537  0
                  return lo.getName(); 
 538  
              }
 539  
 
 540  0
              return null;
 541  
          }
 542  
 
 543  
          public int getItemCount() {
 544  0
              return loTypeMap.size();
 545  
          }
 546  
 
 547  
          public List<String> getItemIds() {
 548  0
              List<String> keys = new ArrayList<String>();
 549  
 
 550  0
              for (String s:loTypeMap.keySet()){
 551  0
                  keys.add(s);
 552  
              }
 553  
 
 554  0
              return keys;
 555  
          }
 556  
 
 557  
          public String getItemText(String id) {
 558  0
              return ((LoCategoryTypeInfo)loTypeMap.get(id)).getName();
 559  
          }
 560  
      }
 561  
      
 562  0
      public class LOCategoryListNew extends Composite implements HasValue<List<LoCategoryInfo>>{
 563  
          private static final String CATEGORY_TYPE_SEPARATOR = " - ";
 564  
          private VerticalPanel listPanel;
 565  0
          private VerticalPanel main = new VerticalPanel();
 566  0
          protected List<LoCategoryInfo> categories = new ArrayList<LoCategoryInfo>();
 567  
          
 568  0
          final CloseHandler<KSItemLabel> deleteHandler = new CloseHandler<KSItemLabel>() {
 569  
              @Override
 570  
             public void onClose(CloseEvent<KSItemLabel> event) {
 571  0
                  KSItemLabel itemLabel = event.getTarget();
 572  0
                  String itemText = itemLabel.getDeletedKey();
 573  0
                  categoryList.removeItem(itemText);
 574  0
                  categoryList.redraw();
 575  0
             }
 576  
          };
 577  
 
 578  0
          public LOCategoryListNew() {
 579  0
              listPanel = new VerticalPanel();
 580  0
              main.add(listPanel);
 581  0
              super.initWidget(main);
 582  0
          }
 583  
          
 584  
          public HandlerRegistration addValueChangeHandler(ValueChangeHandler<List<LoCategoryInfo>> handler) {
 585  0
              return addHandler(handler, ValueChangeEvent.getType());
 586  
          }
 587  
 
 588  
          private void fireChangeEvent(){
 589  0
                  ValueChangeEvent.fire(this, categories);
 590  0
          }
 591  
          
 592  
          public void redraw() {
 593  
 
 594  0
              if (null == categoryTypeMap || categoryTypeMap.isEmpty()) {
 595  
                               
 596  0
                  loCatRpcServiceAsync.getLoCategoryTypes(new KSAsyncCallback<List<LoCategoryTypeInfo>>() {
 597  
                  
 598  
                      @Override
 599  
                      public void handleFailure(Throwable caught) {
 600  0
                      Window.alert("getLoCategoryTypes failed " + caught.getMessage());
 601  0
                      }
 602  
                      
 603  
                      @Override
 604  
                      public void onSuccess(List<LoCategoryTypeInfo> result) {
 605  0
                          if (categoryTypeMap == null) {
 606  0
                              loadCategoryTypes(result);                    
 607  
                          }
 608  0
                          redrawCategoryTable();
 609  0
                      }
 610  
      
 611  
                  });
 612  
              } else {
 613  0
                  redrawCategoryTable();
 614  
              }
 615  0
          }
 616  
 
 617  
          private void redrawCategoryTable() {
 618  0
              listPanel.clear();
 619  
      
 620  0
              for (int i = 0; i < categories.size(); i++) {
 621  0
                  String name = categories.get(i).getName();
 622  0
                  String typeKey = categories.get(i).getType();
 623  
                  // TODO - need to somehow ensure that categoryTypeMap is initialized before redraw() 
 624  0
                  KSItemLabel newItemLabel = new KSItemLabel(true, new CategoryDataParser());
 625  0
                  Data categoryData = CategoryDataUtil.toData(categories.get(i));
 626  0
                  newItemLabel.setValue(new DataValue(categoryData));
 627  0
                  newItemLabel.addCloseHandler(deleteHandler);
 628  
                  
 629  0
                  listPanel.add(newItemLabel);
 630  
 //               String name = categories.get(i).getName();
 631  
 //               String typeKey = categories.get(i).getType();
 632  
 //               // TODO - need to somehow ensure that categoryTypeMap is initialized before redraw() 
 633  
 //               String typeName = "ERROR: uninitialized categoryTypeMap";
 634  
 //               if (null != categoryTypeMap) {
 635  
 //                   typeName = categoryTypeMap.get(typeKey).getName();
 636  
 //               } 
 637  
 //               categoryTable.setWidget(row, col++, new KSLabel(name + CATEGORY_TYPE_SEPARATOR + typeName));
 638  
 //               KSLabel deleteLabel = new KSLabel("[x]");
 639  
 //               deleteLabel.addStyleName("KS-LOBuilder-Search-Link");
 640  
 //               deleteLabel.addClickHandler(deleteHandler);
 641  
 //               categoryTable.setWidget(row, col++, deleteLabel);
 642  
 //               row++;
 643  
 //               col = 0;                                
 644  
              }
 645  0
          }
 646  
 
 647  
          public List<LoCategoryInfo> getValue() {
 648  0
              return categories;
 649  
          }
 650  
 
 651  
          public void setValue(List<LoCategoryInfo> categories) {
 652  0
              this.categories = categories;
 653  0
              redraw();            
 654  0
          }
 655  
          
 656  
                  @Override
 657  
                 public void setValue(List<LoCategoryInfo> value, boolean fireEvents) {
 658  0
                          setValue(value);                        
 659  0
                 }
 660  
          
 661  
 
 662  
          public void removeItem(String text) {
 663  
 
 664  0
              int a  = text.indexOf(CATEGORY_TYPE_SEPARATOR);
 665  0
              text = text.substring(0,a);
 666  
 
 667  0
              int i = 0;
 668  0
              for (LoCategoryInfo catInfo : categories) {
 669  0
                  String name = catInfo.getName();
 670  
 
 671  0
                  if (name.equals(text)) {
 672  0
                      categories.remove(i);
 673  0
                      fireChangeEvent();
 674  0
                      break;
 675  
                  }
 676  0
                  i++;                              
 677  0
              }
 678  0
              redraw();
 679  0
          }
 680  
 
 681  
          public void addItem(LoCategoryInfo category) {
 682  0
              categories.add(category);
 683  0
              fireChangeEvent();
 684  0
              redraw();
 685  0
          }
 686  
      }    
 687  
      
 688  
      public class CategoryDataParser implements DataHelper {
 689  
          
 690  0
          public CategoryDataParser() {};
 691  
 
 692  
          @Override
 693  
          public String getKey(Data data) {
 694  0
              return parse(data);
 695  
          }
 696  
 
 697  
          @Override
 698  
          public String parse(Data data) {
 699  0
              String result = null;
 700  0
              if (data != null) {
 701  0
                  LoCategoryInfo loCategoryInfo = CategoryDataUtil.toLoCategoryInfo(data);
 702  0
                  String typeName = "ERROR: uninitialized categoryTypeMap";
 703  0
                  if (null != categoryTypeMap) {
 704  0
                      typeName = categoryTypeMap.get(loCategoryInfo.getType()).getName();
 705  
                  }
 706  0
                  result = loCategoryInfo.getName() + 
 707  
                  LOCategoryBuilder.LOCategoryListNew.CATEGORY_TYPE_SEPARATOR + typeName;
 708  0
              } else {
 709  0
                  result = "";
 710  
              }
 711  0
              return result;
 712  
          }
 713  
           
 714  
       }
 715  
      
 716  0
      public class CreateLoCancelGroup extends ButtonGroup<LoCancelEnum> {
 717  0
          public CreateLoCancelGroup(Callback<LoCancelEnum> callback) {
 718  0
              layout = new ButtonRow();
 719  0
              this.addCallback(callback);
 720  
 
 721  0
              addButton(LoCancelEnum.CANCEL);
 722  0
              addButtonToSecondaryGroup(LoCancelEnum.CREATE);
 723  
 
 724  0
              this.initWidget(layout);
 725  0
          }
 726  
 
 727  
          private void addButton(final LoCancelEnum type){
 728  0
              KSButton button = new KSButton(type.getText(), new ClickHandler(){
 729  
                  
 730  
                  @Override
 731  
                  public void onClick(ClickEvent event) {
 732  0
                      sendCallbacks(type);
 733  0
                  }
 734  
              });
 735  0
              layout.addButton(button);
 736  0
              buttonMap.put(type, button);
 737  0
          }
 738  
          
 739  
          private void addButtonToSecondaryGroup(final LoCancelEnum type){
 740  0
              KSButton button = new KSButton(type.getText(), new ClickHandler(){
 741  
                  
 742  
                  @Override
 743  
                  public void onClick(ClickEvent event) {
 744  0
                      sendCallbacks(type);
 745  0
                  }
 746  
              });
 747  0
              ((ButtonRow)layout).addButtonToSecondaryGroup(button);
 748  0
              buttonMap.put(type, button);
 749  0
          }
 750  
      }
 751  
      
 752  0
      public static enum LoCancelEnum implements ButtonEnum {
 753  0
         CREATE, CANCEL;
 754  
         @Override
 755  
         public ButtonEnum getActionType() {
 756  0
             return CREATE;  
 757  
         }
 758  
 
 759  
         @Override
 760  
         public ButtonEnum getCancelType() {
 761  0
             return CANCEL;
 762  
         }
 763  
 
 764  
         @Override
 765  
         public ButtonStyle getStyle() {
 766  0
             return ButtonStyle.PRIMARY;
 767  
         }
 768  
 
 769  
         @Override
 770  
         public String getText() {
 771  0
             switch(this){
 772  
                 case CREATE:
 773  0
                     return "Create";
 774  
                 case CANCEL:
 775  0
                     return "Cancel";
 776  
             }
 777  0
             return null;
 778  
         }
 779  
      }
 780  
 }