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