Exemplo n.º 1
0
  /**
   * Instantiates a new side nav input tree.
   *
   * @param dispatcher the dispatcher
   * @param lang
   */
  private InputQueueTree(
      final DispatchAsync dispatcher, final LangConstants lang, final EventBus eventBus) {
    this.lang = lang;
    setWidth100();
    setHeight100();
    setCustomIconProperty("icon");
    setAnimateFolderTime(100);
    setAnimateFolders(true);
    setAnimateFolderSpeed(1000);
    setNodeIcon("silk/application_view_list.png");
    setFolderIcon("silk/folder.png");
    setShowOpenIcons(true);
    setShowDropIcons(false);
    setShowSortArrow(SortArrow.CORNER);
    setShowConnectors(true);
    setShowAllRecords(true);
    setLoadDataOnDemand(true);
    setCanSort(true);
    setAutoFetchData(true);
    setShowRoot(false);
    setSelectionType(SelectionStyle.SINGLE);
    setShowRollOverCanvas(true);

    MenuItem showItem = new MenuItem(lang.show(), "icons/16/structure.png");
    final Menu showMenu = new Menu();
    showMenu.setShowShadow(true);
    showMenu.setShadowDepth(10);
    showMenu.setItems(showItem);

    createItem = new MenuItem(lang.create(), "icons/16/structure_into.png");

    final Menu editMenu = new Menu();
    editMenu.setShowShadow(true);
    editMenu.setShadowDepth(10);
    setContextMenu(editMenu);

    dispatcher.execute(
        new HasUserRightsAction(new EDITOR_RIGHTS[] {EDITOR_RIGHTS.LONG_RUNNING_PROCESS}),
        new DispatchCallback<HasUserRightsResult>() {

          @Override
          public void callback(HasUserRightsResult result) {
            canLongProcess = result.getOk()[0];
          }
        });

    addCellContextClickHandler(
        new CellContextClickHandler() {

          @Override
          public void onCellContextClick(CellContextClickEvent event) {

            ListGridRecord record = event.getRecord();
            final String path = record.getAttribute(Constants.ATTR_ID);
            if (path != null && path.length() > 1 && path.substring(1).contains("/")) {
              // String model = path.substring(1, path.substring(1).indexOf("/") + 1);
              String id = path.substring(path.substring(1).indexOf("/") + 2);
              if (id.contains("/")) {
                id = id.substring(0, id.indexOf("/"));
              }

              MenuItem quartz = new MenuItem(lang.addToScheduler(), "icons/16/clock.png");
              quartz.addClickHandler(
                  new ClickHandler() {

                    @Override
                    public void onClick(MenuItemClickEvent event) {

                      String msg = event.getMenu().getEmptyMessage(); // duplicate code
                      String model = msg.substring(0, msg.indexOf("/"));
                      String path = msg.substring(msg.indexOf("/") + 1);

                      QuartzConvertImagesAction action = new QuartzConvertImagesAction(model, path);

                      DispatchCallback<QuartzConvertImagesResult> quartzConvertCallback =
                          new DispatchCallback<QuartzConvertImagesResult>() {

                            @Override
                            public void callback(QuartzConvertImagesResult result) {
                              if (result.getNumberOfImages() != null) {
                                SC.say(
                                    result.getNumberOfImages().toString()
                                        + " images will be converted");
                              } else {
                                SC.say("No images found");
                              }
                            }
                          };

                      dispatcher.execute(action, quartzConvertCallback);
                    }
                  });

              if (record.getAttributeAsBoolean(Constants.ATTR_INGEST_INFO)) {
                MenuItem ingestInfo = new MenuItem(lang.ingestInfo(), "icons/16/export1.png");
                ingestInfo.addClickHandler(
                    new ClickHandler() {

                      @Override
                      public void onClick(MenuItemClickEvent event) {
                        getIngestInfo(path, dispatcher, eventBus);
                      }
                    });
                if (canLongProcess) {
                  editMenu.setItems(createItem, ingestInfo, quartz);
                } else {
                  editMenu.setItems(createItem, ingestInfo);
                }
              } else {
                if (canLongProcess) {
                  editMenu.setItems(createItem, quartz);
                } else {
                  editMenu.setItems(createItem);
                }
              }

              editMenu.setEmptyMessage(path.substring(1, path.length()));
              editMenu.showContextMenu();
            } else {
              showMenu.showContextMenu();
            }
          }
        });
    addShowContextMenuHandler(
        new ShowContextMenuHandler() {

          @Override
          public void onShowContextMenu(ShowContextMenuEvent event) {
            event.cancel();
          }
        });

    eventBus.addHandler(
        RefreshTreeEvent.getType(),
        new RefreshTreeEvent.RefreshTreeHandler() {

          @Override
          public void onRefreshTree(RefreshTreeEvent event) {
            if (event.getTree() == NAME_OF_TREE.INPUT_QUEUE) refreshTree();
          }
        });

    TreeGridField field1 = new TreeGridField();
    field1.setCanFilter(true);
    field1.setName(Constants.ATTR_BARCODE);
    field1.setTitle("ID");
    field1.setCellFormatter(
        new CellFormatter() {

          @Override
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            boolean ingestInfo = record.getAttributeAsBoolean(Constants.ATTR_INGEST_INFO);
            if (ingestInfo) {
              return record.getAttribute(Constants.ATTR_BARCODE) + HTML_TICK_CODE;

            } else {
              return record.getAttribute(Constants.ATTR_BARCODE);
            }
          }
        });
    ListGridField nameField = new ListGridField();
    nameField.setCanFilter(true);
    nameField.setName(Constants.ATTR_NAME);
    nameField.setTitle(lang.name());

    setFields(field1, nameField);
    setDataSource(new InputTreeGwtRPCDS(dispatcher, lang));
  }
Exemplo n.º 2
0
  private void initWidgets() {
    addGoodsCategory = new AddGoodsCategory();

    mainLayout = new VLayout();
    gridLayout = new HLayout();
    gridLayout.setBackgroundColor("BurlyWood");
    gridLayout.setHeight100();
    gridLayout.setOverflow(Overflow.SCROLL);
    controlLayout = new HLayout();
    controlLayout.setMargin(10);
    controlLayout.setHeight(buttonSizeHeight);
    goodsCategoryList = new ListGrid();
    goodsCategoryList.setDataSource(DataSource.get("goodsCategory"));
    goodsCategoryList.setCanEdit(false);
    goodsCategoryList.setAutoSaveEdits(true);
    goodsCategoryList.setAutoFetchData(true);
    ListGridField goodsCategoryId = new ListGridField();
    goodsCategoryId.setTitle(Constants.GOODSCATEGORY_GOODSCATEGORYID_TITLE);
    goodsCategoryId.setName(Constants.GOODSCATEGORY_GOODSCATEGORYID);
    goodsCategoryId.setWidth("10%");
    ListGridField goodsCategoryShortNameTH = new ListGridField();
    goodsCategoryShortNameTH.setTitle(Constants.GOODSCATEGORY_GOODSCATEGORYSHORTNAME_TH_TITLE);
    goodsCategoryShortNameTH.setName(Constants.GOODSCATEGORY_GOODSCATEGORYSHORTNAME_TH);
    goodsCategoryShortNameTH.setWidth("10%");
    ListGridField goodsCategoryDetailsTH = new ListGridField();
    goodsCategoryDetailsTH.setTitle(Constants.GOODSCATEGORY_GOODSCATEGORYDETAILS_TH_TITLE);
    goodsCategoryDetailsTH.setName(Constants.GOODSCATEGORY_GOODSCATEGORYDETAILS_TH);
    goodsCategoryDetailsTH.setWidth("60%");

    goodsCategoryList.setFields(goodsCategoryId, goodsCategoryShortNameTH, goodsCategoryDetailsTH);
    goodsCategoryList.addRecordDoubleClickHandler(
        new RecordDoubleClickHandler() {
          @Override
          public void onRecordDoubleClick(RecordDoubleClickEvent event) {
            Record record = new Record();
            record.setAttribute("goodsCategory", event.getRecord());
            AddGoods.setGoodsCategoryAsRecord(record);
          }
        });

    submit = new IButton(Constants.BUTTON_TITLE_SUBMIT);
    submit.setMargin(1);
    cancel = new IButton(Constants.BUTTON_TITLE_CANCEL);
    cancel.setMargin(1);
    search = new IButton(Constants.BUTTON_TITLE_SEARCH);
    search.setMargin(1);

    add = new IButton(Constants.BUTTON_TITLE_ADD);
    add.setMargin(1);
    edit = new IButton(Constants.BUTTON_TITLE_EDIT);
    edit.setMargin(1);

    submit.setSize(buttonSizeHeight, buttonSizeHeight);
    cancel.setSize(buttonSizeHeight, buttonSizeHeight);
    search.setSize(buttonSizeHeight, buttonSizeHeight);

    add.setSize(buttonSizeWidth, buttonSizeHeight);
    edit.setSize(buttonSizeWidth, buttonSizeHeight);

    add.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            addGoodsCategory.showAddGoodsCategory();
          }
        });

    edit.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            addGoodsCategory.showAddGoodsCategory(
                Constants.RECORD_ACTION_EDIT, goodsCategoryList.getSelectedRecord());
          }
        });

    cancel.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            hide();
          }
        });

    submit.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            Record record = new Record();
            record.setAttribute("goodsCategory", goodsCategoryList.getSelectedRecord());
            // SC.say("GoodsCategoryList:"+"goodCategory");
            AddGoods.setGoodsCategoryAsRecord(record);
            hide();
          }
        });

    addKeyPressHandler(
        new KeyPressHandler() {
          @Override
          public void onKeyPress(KeyPressEvent event) {
            if (event.getKeyName().equals(KeyNames.ENTER)) {
              Record record = new Record();
              record.setAttribute("goodsCategory", goodsCategoryList.getSelectedRecord());
              AddGoods.setGoodsCategoryAsRecord(record);
              hide();
            }
            if (event.isAltKeyDown() && event.getKeyName().equals("A")) {
              addGoodsCategory.showAddGoodsCategory();
            }
            if (event.isAltKeyDown() && event.getKeyName().equals("E")) {
              addGoodsCategory.showAddGoodsCategory(
                  Constants.RECORD_ACTION_EDIT, goodsCategoryList.getSelectedRecord());
            }
          }
        });

    Canvas emptyButtonWSize = new Canvas();
    emptyButtonWSize.setSize(buttonSizeWidth, buttonSizeHeight);
    gridLayout.addMember(goodsCategoryList);
    controlLayout.addMembers(submit, cancel, search, emptyButtonWSize, add, edit);
    mainLayout.addMembers(gridLayout, controlLayout);

    setDataSectionBackgroundColor("Grey");
    addDataSection(mainLayout);
  }