Esempio n. 1
0
  @Override
  protected void configureTable() {
    super.configureTable();

    ListGrid listGrid = getListGrid();

    ListGridField resourceNameField =
        listGrid.getField(MeasurementDataTraitCriteria.SORT_FIELD_RESOURCE_NAME);
    resourceNameField.setCellFormatter(
        new CellFormatter() {
          public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
            String url =
                LinkManager.getResourceLink(
                    listGridRecord.getAttributeAsInt(AncestryUtil.RESOURCE_ID));
            return LinkManager.getHref(url, o.toString());
          }
        });
    resourceNameField.setShowHover(true);
    resourceNameField.setHoverCustomizer(
        new HoverCustomizer() {
          public String hoverHTML(
              Object value, ListGridRecord listGridRecord, int rowNum, int colNum) {
            return AncestryUtil.getResourceHoverHTML(listGridRecord, 0);
          }
        });
    resourceNameField.setCanGroupBy(true);

    AncestryUtil.setupAncestryListGridField(listGrid);
  }
  /*
   * (non-Javadoc)
   * @see
   * cz.fi.muni.xkremser.editor.client.presenter.DigitalObjectMenuPresenter.
   * MyView#setDS(com.gwtplatform.dispatch.client.DispatchAsync)
   */
  @Override
  public void setDS(DispatchAsync dispatcher, EventBus bus) {
    this.sideNavGrid.setDataSource(new RecentlyTreeGwtRPCDS(dispatcher, lang, bus));
    ListGridField nameField = new ListGridField(Constants.ATTR_NAME, lang.name());
    nameField.setRequired(true);
    nameField.setWidth("40%");
    nameField.setCellFormatter(
        new CellFormatter() {

          @Override
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            String owner = record.getAttribute(Constants.ATTR_LOCK_OWNER);
            if (owner != null) {
              return ("".equals(owner)
                      ? RecentlyTreeGwtRPCDS.FIRST_PART_OF_COLOR_LOCK_BY_USER
                      : RecentlyTreeGwtRPCDS.FIRST_PART_OF_COLOR_LOCK)
                  + record.getAttribute(Constants.ATTR_NAME)
                  + RecentlyTreeGwtRPCDS.SECOND_PART_OF_COLOR_LOCK;
            } else {
              return record.getAttribute(Constants.ATTR_NAME);
            }
          }
        });
    ListGridField uuidField = new ListGridField(Constants.ATTR_UUID, "PID");
    uuidField.setRequired(true);
    uuidField.setWidth("*");
    uuidField.setCellFormatter(
        new CellFormatter() {

          @Override
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            String owner = record.getAttribute(Constants.ATTR_LOCK_OWNER);
            if (owner != null) {
              return ("".equals(owner)
                      ? RecentlyTreeGwtRPCDS.FIRST_PART_OF_COLOR_LOCK_BY_USER
                      : RecentlyTreeGwtRPCDS.FIRST_PART_OF_COLOR_LOCK)
                  + record.getAttribute(Constants.ATTR_UUID)
                  + RecentlyTreeGwtRPCDS.SECOND_PART_OF_COLOR_LOCK;
            } else {
              return record.getAttribute(Constants.ATTR_UUID);
            }
          }
        });
    sideNavGrid.setFields(nameField, uuidField);
  }
  @Override
  protected void configureTable() {
    ListGridField idField = new ListGridField(FIELD_ID, MSG.common_title_id());

    ListGridField versionField =
        new ListGridField(BundleVersionDataSource.FIELD_VERSION, MSG.common_title_version());
    versionField.setCellFormatter(
        new CellFormatter() {
          public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
            Integer _bundleId = listGridRecord.getAttributeAsInt("bundleId");
            Integer _bvId = listGridRecord.getAttributeAsInt("id");
            return "<a href=\""
                + LinkManager.getBundleVersionLink(_bundleId, _bvId)
                + "\">"
                + o
                + "</a>";
          }
        });

    ListGridField nameField =
        new ListGridField(BundleVersionDataSource.FIELD_NAME, MSG.common_title_name());

    ListGridField descriptionField =
        new ListGridField(
            BundleVersionDataSource.FIELD_DESCRIPTION, MSG.common_title_description());

    ListGridField fileCountField =
        new ListGridField(BundleVersionDataSource.FIELD_FILECOUNT, MSG.view_bundle_bundleFiles());

    idField.setWidth(50);
    versionField.setWidth("20%");
    nameField.setWidth("25%");
    descriptionField.setWidth("*");
    fileCountField.setWidth("10%");

    setListGridFields(idField, versionField, nameField, descriptionField, fileCountField);

    setListGridDoubleClickHandler(
        new DoubleClickHandler() {
          @Override
          public void onDoubleClick(DoubleClickEvent event) {
            ListGrid listGrid = (ListGrid) event.getSource();
            ListGridRecord[] selectedRows = listGrid.getSelectedRecords();
            if (selectedRows != null && selectedRows.length == 1) {
              String selectedId =
                  selectedRows[0].getAttribute(BundleVersionDataSource.FIELD_BUNDLE_ID);
              String selectedVersionId =
                  selectedRows[0].getAttribute(BundleVersionDataSource.FIELD_ID);
              CoreGUI.goToView(
                  LinkManager.getBundleVersionLink(
                      Integer.valueOf(selectedId), Integer.valueOf(selectedVersionId)));
            }
          }
        });
  }
  private List<ListGridField> createFields() {
    List<ListGridField> fields = new ArrayList<ListGridField>();

    ListGridField nameField = new ListGridField(RolesDataSource.Field.NAME, 150);
    fields.add(nameField);

    ListGridField descriptionField = new ListGridField(RolesDataSource.Field.DESCRIPTION);
    descriptionField.setCellFormatter(new EscapedHtmlCellFormatter());
    fields.add(descriptionField);

    return fields;
  }
  {
    filter = new CityFilter();

    cityRPCService = GWT.create(CityRPCService.class);
    stateRPCService = GWT.create(StateRPCService.class);
    countryRPCService = GWT.create(CountryRPCService.class);

    textDescription = new TextItem(Attribute.DESCRIPTION, I18N.$.LABEL_DESCRIPTION());

    selectState = new SelectItem(Attribute.STATE, I18N.$.LABEL_STATE());
    selectState.setPickListHeight(100);

    selectCountry = new SelectItem(Attribute.COUNTRY, I18N.$.LABEL_COUNTRY());
    selectCountry.setPickListHeight(100);
    selectCountry.addChangeHandler(
        new ChangeHandler() {
          public void onChange(final ChangeEvent event) {
            stateRPCService.findByCountryId(
                Integer.parseInt((String) event.getValue()), stateFindCallback);
          }
        });

    fieldDescription = new ListGridField(Attribute.DESCRIPTION, I18N.$.LABEL_DESCRIPTION());
    fieldState = new ListGridField(Attribute.STATE, I18N.$.LABEL_STATE());
    fieldCountry = new ListGridField(Attribute.COUNTRY, I18N.$.LABEL_COUNTRY());
    fieldLastUpdate = new ListGridField(Attribute.LAST_UPDATE, I18N.$.LABEL_LAST_UPDATE());
    fieldLastUpdate.setCellFormatter(GWTUtils.getDateTimeCellFormatter());

    stateFindCallback =
        new AsyncCallback<List<StateDTO>>() {
          public void onFailure(final Throwable throwable) {
            GWTUtils.showError(throwable);
          }

          public void onSuccess(final List<StateDTO> dtos) {
            selectState.setValueMap(GWTUtils.getStateValueMap(dtos));
          }
        };

    countryFindCallback =
        new AsyncCallback<List<CountryDTO>>() {
          public void onFailure(final Throwable throwable) {
            GWTUtils.showError(throwable);
          }

          public void onSuccess(final List<CountryDTO> dtos) {
            selectCountry.setValueMap(GWTUtils.getCountryValueMap(dtos));
          }
        };
  }
  public ResourceLookupComboBoxItem(String name, String title) {
    super(name, title);
    setHint(MSG.widget_resourceSelector_selectResource());
    setShowHintInField(false);

    setOptionDataSource(new ResourceDatasource());

    ListGridField nameField = new ListGridField("name", MSG.common_title_name(), 250);
    nameField.setShowHover(true);
    nameField.setHoverCustomizer(
        new HoverCustomizer() {

          public String hoverHTML(
              Object value, ListGridRecord listGridRecord, int rowNum, int colNum) {
            return AncestryUtil.getResourceHoverHTML(listGridRecord, 0);
          }
        });

    ListGridField ancestryField =
        new ListGridField(AncestryUtil.RESOURCE_ANCESTRY, MSG.common_title_ancestry(), 300);
    // needs to use a different cell formatter than what AncestryUtil.setupAncestryListGridField
    // creates
    ancestryField.setCellFormatter(
        new CellFormatter() {
          public String format(Object o, ListGridRecord listGridRecord, int rowNum, int colNum) {
            return AncestryUtil.getAncestryValue(listGridRecord, false);
          }
        });
    AncestryUtil.setupAncestryListGridFieldHover(ancestryField);

    ListGridField descriptionField =
        new ListGridField("description", MSG.common_title_description());
    ListGridField categoryField = new ListGridField("category", MSG.common_title_category(), 60);
    ListGridField availabilityField =
        new ListGridField("currentAvailability", MSG.common_title_availability(), 55);
    availabilityField.setAlign(Alignment.CENTER);

    setPickListFields(nameField, ancestryField, descriptionField, categoryField, availabilityField);

    setValueField("id");
    setDisplayField("name");
    setPickListWidth(800);
    setTextMatchStyle(TextMatchStyle.SUBSTRING);
    setCompleteOnTab(true);
    setAddUnknownValues(false);
  }
  public SearchValueSetItemsListGrid() {
    super();

    i_valueSetItemSearchXmlDS = ValueSetItemSearchXmlDS.getInstance();

    setWidth100();
    setHeight100();
    setShowAllRecords(true);
    setWrapCells(false);
    setDataSource(i_valueSetItemSearchXmlDS);
    setEmptyMessage(EMPTY_MESSAGE);

    ListGridField addField = new ListGridField("add", "Add");
    addField.setType(ListGridFieldType.BOOLEAN);
    addField.setShowHover(false);
    addField.setDefaultValue(false);
    addField.setCanEdit(true);
    addField.addChangedHandler(
        new ChangedHandler() {
          @Override
          public void onChanged(ChangedEvent changedEvent) {
            if ((Boolean) changedEvent.getValue()) {
              ListGridRecord selected = getSelectedRecord();
              String uri = selected.getAttribute("uri");
              String code = selected.getAttribute("name");
              String description = selected.getAttribute("designation");
              String codeSystem = selected.getAttribute("namespace");
              String codeSystemVersion = selected.getAttribute("codeSystemVersion");
              Cts2Editor.EVENT_BUS.fireEvent(
                  new AddEntitySelectedEvent(
                      uri, code, description, codeSystem, codeSystemVersion));
            } else {
              ListGridRecord selected = getSelectedRecord();
              String href = selected.getAttribute("uri");
              Cts2Editor.EVENT_BUS.fireEvent(new AddEntityDeselectedEvent(href));
            }
          }
        });

    ListGridField nameField = new ListGridField(ID_NAME, TITLE_NAME);
    nameField.setWrap(false);
    nameField.setWidth("25%");
    nameField.setShowHover(false);
    nameField.setCanEdit(false);

    nameField.setCellFormatter(
        new CellFormatter() {

          @Override
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value != null) {
              return addCellHighlights(value.toString());
            } else {
              return null;
            }
          }
        });

    ListGridField designationField = new ListGridField(ID_DESIGNATION, TITLE_DESIGNATION);
    designationField.setWrap(false);
    designationField.setWidth("*");
    designationField.setCanEdit(false);

    designationField.setCellFormatter(
        new CellFormatter() {

          @Override
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value != null) {
              return addCellHighlights(value.toString());
            } else {
              return null;
            }
          }
        });

    setFields(addField, nameField, designationField);

    setSelectOnEdit(true);
    setSelectionAppearance(SelectionAppearance.ROW_STYLE);
    setSelectionType(SelectionStyle.SINGLE);

    // Set edit and edit event to get the download checkbox to work
    // correctly.
    setCanEdit(true);

    setAutoFetchData(false);

    setCanHover(true);
    setShowHover(true);
    setShowHoverComponents(true);

    // set the initial sort
    SortSpecifier[] sortspec = new SortSpecifier[1];
    sortspec[0] = new SortSpecifier(ID_NAME, SortDirection.ASCENDING);
    setInitialSort(sortspec);

    //		addEventHandlers();
  }
  public Canvas getViewPanel() {

    VLayout layout = new VLayout(15);
    layout.setWidth(650);
    layout.setAutoHeight();

    final ListGrid countryGrid = new ListGrid();
    countryGrid.setLeaveScrollbarGap(true);
    countryGrid.setCanFreezeFields(false);
    countryGrid.setCanGroupBy(false);
    countryGrid.setWidth100();
    countryGrid.setHeight(224);
    countryGrid.setDataSource(CountryXmlDS.getInstance());
    countryGrid.setAutoFetchData(true);

    // allow users to add formula and summary fields
    // accessible in the grid header context menu
    countryGrid.setCanAddFormulaFields(true);
    countryGrid.setCanAddSummaryFields(true);

    ListGridField countryCodeField = new ListGridField("countryCode", "Flag", 50);
    countryCodeField.setAlign(Alignment.CENTER);
    countryCodeField.setType(ListGridFieldType.IMAGE);
    countryCodeField.setImageURLPrefix("flags/16/");
    countryCodeField.setImageURLSuffix(".png");
    countryCodeField.setCanSort(false);

    ListGridField nameField = new ListGridField("countryName", "Country");
    ListGridField capitalField = new ListGridField("capital", "Capital");

    ListGridField populationField = new ListGridField("population", "Population");
    populationField.setCellFormatter(
        new CellFormatter() {
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value == null) return null;
            try {
              NumberFormat nf = NumberFormat.getFormat("0,000");
              return nf.format(((Number) value).longValue());
            } catch (Exception e) {
              return value.toString();
            }
          }
        });

    ListGridField areaField = new ListGridField("area", "Area (km&sup2;)");
    areaField.setType(ListGridFieldType.INTEGER);
    areaField.setCellFormatter(
        new CellFormatter() {
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value == null) return null;
            String val = null;
            try {
              NumberFormat nf = NumberFormat.getFormat("0,000");
              val = nf.format(((Number) value).longValue());
            } catch (Exception e) {
              return value.toString();
            }
            return val + "km&sup2";
          }
        });
    countryGrid.setFields(countryCodeField, nameField, capitalField, populationField, areaField);

    ToolStripButton formulaButton =
        new ToolStripButton("Formula Builder", "crystal/oo/sc_insertformula.png");
    formulaButton.setAutoFit(true);
    formulaButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            countryGrid.addFormulaField();
          }
        });

    ToolStripButton summaryBuilder =
        new ToolStripButton("Summary Builder", "crystal/16/apps/tooloptions.png");
    summaryBuilder.setAutoFit(true);
    summaryBuilder.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            countryGrid.addSummaryField();
          }
        });

    ToolStripButton savePreference = new ToolStripButton("Persist State", "silk/database_gear.png");
    savePreference.setAutoFit(true);
    savePreference.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            String viewState = countryGrid.getViewState();
            Offline.put("exampleState", viewState);
            SC.say("Preferences persisted.");
          }
        });

    // toolstrip to attach to the country grid
    ToolStrip countryGridToolStrip = new ToolStrip();
    countryGridToolStrip.setWidth100();
    countryGridToolStrip.addFill();
    countryGridToolStrip.addButton(formulaButton);
    countryGridToolStrip.addButton(summaryBuilder);
    countryGridToolStrip.addSeparator();
    countryGridToolStrip.addButton(savePreference);

    VLayout countryGridLayout = new VLayout(0);
    countryGridLayout.setWidth(650);
    countryGridLayout.addMember(countryGridToolStrip);
    countryGridLayout.addMember(countryGrid);
    layout.addMember(countryGridLayout);

    final String previouslySavedState = (String) Offline.get("exampleState");
    if (previouslySavedState != null) {
      countryGrid.addDrawHandler(
          new DrawHandler() {
            @Override
            public void onDraw(DrawEvent event) {
              // restore any previously saved view state for this grid
              countryGrid.setViewState(previouslySavedState);
            }
          });
    }

    return layout;
  }
Esempio n. 9
0
    @Override
    public ArrayList<ListGridField> getListGridFields() {
      ArrayList<ListGridField> fields = super.getListGridFields();

      // hide the created/modified fields, we don't need to show them by default
      // add cell formatter on the name field so we can make it a link
      for (ListGridField field : fields) {
        String fieldName = field.getName();
        if (fieldName.equals(FIELD_CTIME) || fieldName.equals(FIELD_MTIME)) {
          field.setHidden(true);
        } else if (fieldName.equals(FIELD_NAME)) {
          field.setCellFormatter(
              new CellFormatter() {
                @Override
                public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                  AlertDefinition alertDef = copyValues(record);
                  int resourceId = alertDef.getResource().getId();
                  int alertDefId = alertDef.getId();
                  String link = LinkManager.getSubsystemAlertDefinitionLink(resourceId, alertDefId);
                  return "<a href=\""
                      + link
                      + "\">"
                      + StringUtility.escapeHtml(alertDef.getName())
                      + "</a>";
                }
              });
        }
      }

      // add more columns
      ListGridField parentField = new ListGridField(FIELD_PARENT, MSG.view_alerts_field_parent());
      parentField.setWidth(100);
      parentField.setShowHover(true);
      parentField.setHoverCustomizer(
          new HoverCustomizer() {
            @Override
            public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
              if (record.getAttribute(FIELD_PARENT) != null) {
                return MSG.view_reports_alertDefinitions_parentHover();
              }
              return MSG.common_val_na();
            }
          });
      parentField.addRecordClickHandler(
          new RecordClickHandler() {
            @Override
            public void onRecordClick(RecordClickEvent event) {
              // we only do something if we really have a parent.
              // if we have a template parent, we have to get the resource's type and go to the
              // template page for that type
              // if we have a group parent, we can directly go to the group's alert def page
              Record record = event.getRecord();
              AlertDefinition alertDef = copyValues(record);
              if (alertDef.getParentId() != null && alertDef.getParentId().intValue() > 0) {
                final Integer templateId = alertDef.getParentId().intValue();
                final Integer resourceId = alertDef.getResource().getId();

                ResourceCriteria resCriteria = new ResourceCriteria();
                resCriteria.addFilterId(resourceId);
                resCriteria.fetchResourceType(true);

                GWTServiceLookup.getResourceService()
                    .findResourcesByCriteria(
                        resCriteria,
                        new AsyncCallback<PageList<Resource>>() {
                          @Override
                          public void onSuccess(PageList<Resource> result) {
                            if (result == null || result.size() != 1) {
                              CoreGUI.getErrorHandler()
                                  .handleError(
                                      MSG.view_reports_alertDefinitions_resTypeLoadError());
                            } else {
                              int typeId = result.get(0).getResourceType().getId();
                              CoreGUI.goToView(
                                  LinkManager.getAdminTemplatesLink()
                                      + "/Alert/"
                                      + typeId
                                      + "/"
                                      + templateId);
                            }
                          }

                          @Override
                          public void onFailure(Throwable caught) {
                            CoreGUI.getErrorHandler()
                                .handleError(
                                    MSG.view_reports_alertDefinitions_resTypeLoadError(), caught);
                          }
                        });
              } else if (alertDef.getGroupAlertDefinition() != null) {
                AlertDefinition groupAlertDef = alertDef.getGroupAlertDefinition();
                CoreGUI.goToView(
                    LinkManager.getEntityTabLink(
                            EntityContext.forGroup(groupAlertDef.getResourceGroup()),
                            "Alert",
                            "Definitions")
                        + "/"
                        + groupAlertDef.getId());
              }
            }
          });
      fields.add(parentField);

      ListGridField resourceField = new ListGridField(FIELD_RESOURCE, MSG.common_title_resource());
      resourceField.setCellFormatter(
          new CellFormatter() {
            public String format(Object value, ListGridRecord listGridRecord, int i, int i1) {
              String url =
                  LinkManager.getResourceLink(
                      listGridRecord.getAttributeAsInt(AncestryUtil.RESOURCE_ID));
              return SeleniumUtility.getLocatableHref(
                  url, StringUtility.escapeHtml(value.toString()), null);
            }
          });
      resourceField.setShowHover(true);
      resourceField.setHoverCustomizer(
          new HoverCustomizer() {
            public String hoverHTML(
                Object value, ListGridRecord listGridRecord, int rowNum, int colNum) {
              return AncestryUtil.getResourceHoverHTML(listGridRecord, 0);
            }
          });
      fields.add(resourceField);

      ListGridField ancestryField = AncestryUtil.setupAncestryListGridField();
      fields.add(ancestryField);

      return fields;
    }
Esempio n. 10
0
  private void initColumns(List<String> currencyGroupList) {

    if (currencyGroupList.size() > 0) {
      List<ListGridField> currencyFieldList = new LinkedList<ListGridField>();

      ListGridField dateField = new ListGridField("dt", constants.date());
      dateField.setAlign(Alignment.CENTER);
      dateField.setCellFormatter(
          new CellFormatter() {

            @Override
            public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
              if (value instanceof Date) {
                DateTimeFormat dateFormatter = DateTimeFormat.getFormat("dd.MM.yyyy");
                Date date = (Date) value;
                String format = dateFormatter.format(date);
                return format;
              } else if (value != null) return value.toString();
              else return null;
            }
          });
      currencyFieldList.add(dateField);

      CustomValidator customValidator =
          new CustomValidator() {
            protected boolean condition(Object value) {
              try {
                if (value instanceof Float) {
                  return (Float) value > 0.0;
                } else if (value instanceof Integer) {
                  return ((Integer) value).floatValue() > 0.0;
                } else {
                  Float result = Float.parseFloat((String) value);
                  return result > 0.0;
                }
              } catch (Exception ex) {
              }
              return false;
            }
          };

      FloatItem floatItem = new FloatItem();
      floatItem.setEditorValueFormatter(
          new FormItemValueFormatter() {

            @Override
            public String formatValue(
                Object value, Record record, DynamicForm form, FormItem item) {

              if (value == null) return "";
              String formattedValue = String.valueOf(value);
              formattedValue = formattedValue.replace('.', ',');
              return formattedValue;
            }
          });
      floatItem.setEditorValueParser(
          new FormItemValueParser() {

            @Override
            public Object parseValue(String value, DynamicForm form, FormItem item) {

              try {
                if (value != null) {
                  String newValue = value.replace(',', '.');
                  Float result = Float.parseFloat(newValue);
                  return result;
                }
              } catch (Exception ex) {
              }
              return null;
            }
          });

      for (int index = 0; index < currencyGroupList.size(); index++) {
        String currencyName = currencyGroupList.get(index);
        if (currencyName != null
            && !baseCurrencyPrefix.equals(currencyName)
            && !docCurrencyPrefix.equals(currencyName)) {
          ListGridField currencyField =
              new ListGridField(CurrencyRecord.IDENTITY_CURRENCY + currencyName, currencyName);
          currencyField.setCellFormatter(
              new CellFormatter() {
                public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                  if (value == null) {
                    return null;
                  } else {
                    NumberFormat nf = NumberFormat.getFormat("0.###");
                    try {
                      return nf.format((Number) value);
                    } catch (Exception e) {
                      return value.toString();
                    }
                  }
                }
              });
          currencyField.setAlign(Alignment.CENTER);
          currencyField.setRequired(true);
          currencyField.setValidators(customValidator);
          currencyField.setEditorType(floatItem);
          currencyFieldList.add(currencyField);
        }
      }

      // --------------------------------------------------------------------
      // 	Remove Row column
      // --------------------------------------------------------------------
      ListGridField removeField = new ListGridField("remove", constants.remove());
      removeField.setAlign(Alignment.CENTER);
      removeField.setType(ListGridFieldType.IMAGE);
      removeField.setCanEdit(false);
      removeField.setCanFilter(false);
      removeField.setCellFormatter(
          new CellFormatter() {

            @Override
            public String format(Object value, ListGridRecord record, int rowNum, int colNum) {

              return Canvas.imgHTML("[SKIN]/actions/remove.png");
            }
          });
      removeField.setWidth(60);
      currencyFieldList.add(removeField);
      ListGridField[] currencyFieldArray = new ListGridField[currencyFieldList.size()];
      currencyFieldList.toArray(currencyFieldArray);

      currencyGrid.setFields(currencyFieldArray);
    }
  }
Esempio n. 11
0
  public ReportReceiveLayout_2(final User currentUser) {
    setWidth(950);
    setHeight100();

    HLayout searchLayout = new HLayout();
    searchLayout.setHeight(20);

    final DynamicForm searchForm = new DynamicForm();
    searchForm.setWidth(450);
    searchForm.setHeight(30);
    searchForm.setMargin(5);
    searchForm.setNumCols(4);
    searchForm.setCellPadding(2);
    searchForm.setAutoFocus(true);
    searchForm.setSelectOnFocus(true);
    searchForm.setIsGroup(true);
    searchForm.setDataSource(TransferDS.getInstance());
    searchForm.setUseAllDataSourceFields(false);
    searchForm.setGroupTitle("ตัวกรอง");

    final SelectItem statusSelected = new SelectItem("status", "สถานะ");
    statusSelected.setWrapTitle(false);
    // statusSelected.setValueMap("รอแก้ไข", "รออนุมัติ", "อนุมัติแล้ว");
    statusSelected.setValueMap(TransferStatus.getValueMap());
    statusSelected.setAllowEmptyValue(true);
    statusSelected.setEmptyDisplayValue("ทั้งหมด");
    statusSelected.setOperator(OperatorId.EQUALS);
    final TextItem jidText = new TextItem("plan_id", "รหัสแผนการผลิต");
    jidText.setWrapTitle(false);
    jidText.setOperator(OperatorId.REGEXP);
    //		final TextItem smidText = new TextItem("smid", "รหัสช่าง");
    //		smidText.setWrapTitle(false);
    //		smidText.setOperator(OperatorId.REGEXP);

    //		final DynamicForm dateForm = new DynamicForm();
    //		dateForm.setWidth(300);
    //		dateForm.setHeight(30);
    //		dateForm.setMargin(5);
    //		dateForm.setNumCols(2);
    //		dateForm.setCellPadding(2);
    //		dateForm.setSelectOnFocus(true);
    //		dateForm.setIsGroup(true);
    //		dateForm.setGroupTitle("วันที่ขอโอนสินค้า");
    DateRange dateRange = new DateRange();
    dateRange.setRelativeStartDate(new RelativeDate("-1w"));
    dateRange.setRelativeEndDate(RelativeDate.TODAY);
    final DateItem from = new DateItem("create_from", "ตั้งแต่");
    final DateItem to = new DateItem("create_to", "ถึง");
    from.setDefaultChooserDate(dateRange.getStartDate());
    from.setDefaultValue(dateRange.getStartDate());
    from.setUseTextField(true);
    to.setDefaultChooserDate(dateRange.getEndDate());
    to.setDefaultValue(dateRange.getEndDate());
    to.setUseTextField(true);

    searchForm.setItems(jidText, statusSelected, from, to);
    // searchForm.setItems(planText, jidText);
    //        dateForm.setItems(from, to);

    final ListGrid orderListGrid = new ListGrid();

    orderListGrid.setAutoFetchData(true);
    orderListGrid.setCanMultiSort(true);
    orderListGrid.setShowRowNumbers(true);
    orderListGrid.setShowGridSummary(true);

    AdvancedCriteria criteria =
        new AdvancedCriteria(
            OperatorId.AND,
            new Criterion[] {
              // new Criterion("status", OperatorId.NOT_EQUAL, "3_to_next_process"),
              // new Criterion("created_date", OperatorId.BETWEEN_INCLUSIVE, from.getValueAsDate(),
              // to.getValueAsDate())
              new Criterion(
                  "created_date",
                  OperatorId.BETWEEN_INCLUSIVE,
                  dateRange.getStartDate(),
                  dateRange.getEndDate())
            });
    orderListGrid.setCriteria(criteria);

    orderListGrid.setDataSource(TransferDS.getInstance());
    orderListGrid.setInitialSort(
        new SortSpecifier[] {
          new SortSpecifier("status", SortDirection.DESCENDING),
          new SortSpecifier("created_date", SortDirection.DESCENDING)
        });
    orderListGrid.setUseAllDataSourceFields(false);
    orderListGrid.setSelectionType(SelectionStyle.NONE);

    ListGridField transfer_id = new ListGridField("transfer_id", 100);
    transfer_id.setSummaryFunction(
        new SummaryFunction() {
          public Object getSummaryValue(Record[] records, ListGridField field) {
            return records.length + " รายการ";
          }
        });
    transfer_id.setShowGridSummary(true);

    ListGridField status = new ListGridField("status", 120);
    ListGridField plan_id = new ListGridField("plan_id", 100);
    ListGridField transfer_by = new ListGridField("transfer_by");
    ListGridField transfer_date = new ListGridField("transfer_date", 150);

    ListGridField total_weight = new ListGridField("total_sent_weight", 120);
    total_weight.setCellFormatter(FieldFormatter.getNumberFormat());
    total_weight.setAlign(Alignment.RIGHT);
    total_weight.setSummaryFunction(SummaryFunctionType.SUM);
    total_weight.setShowGridSummary(true);

    ListGridField total_amount = new ListGridField("total_sent_amount", 120);
    total_amount.setCellFormatter(FieldFormatter.getNumberFormat());
    total_amount.setAlign(Alignment.RIGHT);
    total_amount.setSummaryFunction(SummaryFunctionType.SUM);
    total_amount.setShowGridSummary(true);

    orderListGrid.setFields(
        transfer_date, transfer_id, status, plan_id, transfer_by, total_weight, total_amount);

    // orderListGrid.hideField("status");

    HLayout buttonLayout = new HLayout();
    buttonLayout.setMargin(10);
    buttonLayout.setMembersMargin(5);
    buttonLayout.setHeight(30);
    IButton searchButton = new IButton("ค้นหาคำขอโอนสินค้า");
    searchButton.setIcon("icons/16/reports-icon.png");
    searchButton.setWidth(170);
    searchButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            Criterion search = new Criterion();
            search.addCriteria(searchForm.getValuesAsCriteria());
            AdvancedCriteria criteria =
                new AdvancedCriteria(
                    OperatorId.AND,
                    new Criterion[] {
                      new Criterion(
                          "created_date",
                          OperatorId.BETWEEN_INCLUSIVE,
                          from.getValueAsDate(),
                          to.getValueAsDate()),
                      search
                    });
            reportDate.setContents(
                "ตั้งแต่วันที่ "
                    + DateTimeFormat.getFormat("d-M-yyyy").format(from.getValueAsDate())
                    + " ถึงวันที่ "
                    + DateTimeFormat.getFormat("d-M-yyyy").format(to.getValueAsDate()));
            orderListGrid.fetchData(criteria);
            orderListGrid.deselectAllRecords();
          }
        });

    IButton listAllButton = new IButton("ล้างรายการค้นหา");
    listAllButton.setIcon("[SKIN]actions/refresh.png");
    listAllButton.setWidth(150);
    listAllButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            AdvancedCriteria criteria =
                new AdvancedCriteria(
                    OperatorId.AND,
                    new Criterion[] {
                      new Criterion(
                          "created_date",
                          OperatorId.BETWEEN_INCLUSIVE,
                          from.getValueAsDate(),
                          to.getValueAsDate())
                    });
            searchForm.reset();
            reportDate.setContents(
                "ตั้งแต่วันที่ "
                    + DateTimeFormat.getFormat("d-M-yyyy").format(from.getValueAsDate())
                    + " ถึงวันที่ "
                    + DateTimeFormat.getFormat("d-M-yyyy").format(to.getValueAsDate()));
            orderListGrid.fetchData(criteria);
            orderListGrid.deselectAllRecords();
          }
        });

    IButton printButton = new IButton("พิมพ์รายงาน");
    printButton.setIcon("icons/16/print.png");
    printButton.setWidth(120);

    buttonLayout.addMembers(searchButton, listAllButton, printButton);

    searchLayout.addMembers(searchForm);
    // reviseLayout.
    addMember(searchLayout);

    // reviseLayout.
    addMember(buttonLayout);

    final VLayout gridLayout = new VLayout();
    gridLayout.setWidth100();
    gridLayout.setHeight(500);
    Label text = new Label();
    text.setContents("รายงานการโอนสินค้าเข้าคลังสินค้า");
    text.setAlign(Alignment.CENTER);
    text.setHeight(10);
    text.setStyleName("printTitle");
    reportDate = new Label();
    reportDate.setContents(
        "ตั้งแต่วันที่ "
            + DateTimeFormat.getFormat("d-M-yyyy").format(from.getValueAsDate())
            + " ถึงวันที่ "
            + DateTimeFormat.getFormat("d-M-yyyy").format(to.getValueAsDate()));
    reportDate.setAlign(Alignment.CENTER);
    reportDate.setHeight(10);
    reportDate.setStyleName("printDetails");

    gridLayout.addMember(text);
    gridLayout.addMember(reportDate);
    gridLayout.addMember(orderListGrid);
    addMember(gridLayout);

    printButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            Canvas.showPrintPreview(gridLayout);
          }
        });
  }
Esempio n. 12
0
  public DeliveryOrderLayout(final User currentUser) {
    // Tab reviseTab = new Tab("ข้อมูลใบแจ้งหนี้", "icons/16/search-good-icon.png");
    // VLayout reviseLayout = new VLayout();
    // reviseLayout.
    setWidth(750);
    // reviseLayout.
    setHeight100();

    HLayout searchLayout = new HLayout();
    searchLayout.setHeight(20);

    final DynamicForm searchForm = new DynamicForm();
    searchForm.setWidth(450);
    searchForm.setHeight(30);
    searchForm.setMargin(5);
    searchForm.setNumCols(4);
    searchForm.setCellPadding(2);
    searchForm.setAutoFocus(true);
    searchForm.setSelectOnFocus(true);
    searchForm.setIsGroup(true);
    searchForm.setDataSource(DeliveryDS.getInstance());
    searchForm.setUseAllDataSourceFields(false);
    searchForm.setGroupTitle("ค้นหารายการนำส่งสินค้า");

    final TextItem deliveryText = new TextItem("delivery_id", "รหัสรายการนำส่งสินค้า");
    deliveryText.setWrapTitle(false);
    deliveryText.setOperator(OperatorId.REGEXP);
    final TextItem saleText = new TextItem("sale_id", "รหัสรายการขาย");
    saleText.setWrapTitle(false);
    saleText.setOperator(OperatorId.REGEXP);
    final SelectItem statusSelected = new SelectItem("issued_status", "สถานะ");
    statusSelected.setWrapTitle(false);
    // statusSelected.setValueMap("กำลังนำส่ง", "นำส่งแล้ว");
    statusSelected.setValueMap(DeliveryStatus.getIssueValueMap());
    statusSelected.setAllowEmptyValue(true);
    statusSelected.setEmptyDisplayValue("ทั้งหมด");
    statusSelected.setOperator(OperatorId.EQUALS);
    final TextItem cidText = new TextItem("cid", "รหัสลูกค้า");
    cidText.setWrapTitle(false);
    cidText.setOperator(OperatorId.REGEXP);

    final DynamicForm dateForm = new DynamicForm();
    dateForm.setWidth(300);
    dateForm.setHeight(30);
    dateForm.setMargin(5);
    dateForm.setNumCols(2);
    dateForm.setCellPadding(2);
    dateForm.setSelectOnFocus(true);
    dateForm.setIsGroup(true);
    // dateForm.setGroupTitle("วันที่นำส่งสินค้า");
    dateForm.setGroupTitle("วันที่ออกใบนำส่งสินค้า");
    DateRange dateRange = new DateRange();
    dateRange.setRelativeStartDate(new RelativeDate("-7d"));
    dateRange.setRelativeEndDate(RelativeDate.TODAY);
    // final DateItem from = new DateItem("delivery_from" , "ตั้งแต่");
    // final DateItem to = new DateItem("delivery_to" , "ถึง");
    final DateItem from = new DateItem("created_from", "ตั้งแต่");
    final DateItem to = new DateItem("created_to", "ถึง");
    from.setDefaultChooserDate(dateRange.getStartDate());
    from.setDefaultValue(dateRange.getStartDate());
    from.setUseTextField(true);
    to.setDefaultChooserDate(dateRange.getEndDate());
    to.setDefaultValue(dateRange.getEndDate());
    to.setUseTextField(true);

    FromToValidate.addValidator(from, to);
    searchForm.setItems(deliveryText, statusSelected, saleText, cidText);
    // searchForm.setItems(Text, cidText, cnameText);
    dateForm.setItems(from, to);

    // final ListGrid deliveryListGrid = new EditorListGrid(new RequestViewWindow(), currentUser);
    final ListGrid deliveryListGrid = new ListGrid();

    deliveryListGrid.setAutoFetchData(true);
    deliveryListGrid.setCanMultiSort(true);
    // deliveryListGrid.setCriteria(new Criterion("status", OperatorId.NOT_EQUAL, "ยกเลิก"));

    deliveryListGrid.setDataSource(DeliveryDS.getInstance());
    deliveryListGrid.setInitialSort(
        new SortSpecifier[] {
          new SortSpecifier("issued_status", SortDirection.ASCENDING),
          new SortSpecifier("delivery", SortDirection.DESCENDING)
        });
    deliveryListGrid.setUseAllDataSourceFields(false);
    deliveryListGrid.setGroupByField("issued_status");
    deliveryListGrid.setGroupStartOpen(GroupStartOpen.ALL);

    ListGridField delivery_id = new ListGridField("delivery_id", 120);
    ListGridField sale_id = new ListGridField("sale_id", 100);
    // ListGridField quote_id = new ListGridField("quote_id" , 90);
    ListGridField cus_name = new ListGridField("cus_name", 180);
    ListGridField status = new ListGridField("issued_status");
    //		LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();
    //		valueMap.put("3_approved", "approved");
    //		status.setValueMap(valueMap);
    ListGridField total_amount = new ListGridField("total_amount", 120);
    total_amount.setCellFormatter(FieldFormatter.getIntegerFormat());
    total_amount.setAlign(Alignment.RIGHT);
    //		ListGridField netInclusive = new ListGridField("netInclusive", 125);
    //		netInclusive.setCellFormatter(FieldFormatter.getPriceFormat());
    //		netInclusive.setAlign(Alignment.RIGHT);
    ListGridField delivery_date = new ListGridField("delivery", 120);
    //		created_date.setType(ListGridFieldType.DATE);
    //		created_date.setCellFormatter(new CellFormatter() {
    //
    //			@Override
    //			public String format(Object arg0, ListGridRecord arg1, int arg2, int arg3) {
    //			DateTimeFormat fmt = DateTimeFormat.getFormat("MM/dd/yyyy");
    //			return fmt.format(arg1.getAttributeAsDate("created_date"));
    //			}
    //		});

    //		ListGridField iconField = new ListGridField("viewDeliveryField", "เรียกดูรายการ", 80);

    deliveryListGrid.setFields(status, delivery_id, sale_id, cus_name, total_amount, delivery_date);

    searchLayout.addMembers(searchForm, dateForm);
    // reviseLayout.
    addMember(searchLayout);

    HLayout buttonLayout = new HLayout();
    buttonLayout.setMargin(10);
    buttonLayout.setMembersMargin(5);
    buttonLayout.setHeight(30);
    IButton searchButton = new IButton("ค้นหารายการนำส่งสินค้า");
    searchButton.setIcon("icons/16/icon_view.png");
    searchButton.setWidth(150);
    searchButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            Criterion search = new Criterion();
            search.addCriteria(searchForm.getValuesAsCriteria());
            AdvancedCriteria criteria =
                new AdvancedCriteria(
                    OperatorId.AND,
                    new Criterion[] {
                      // new Criterion("delivery", OperatorId.BETWEEN_INCLUSIVE,
                      // from.getValueAsDate(), to.getValueAsDate()),
                      new Criterion(
                          "created_date",
                          OperatorId.BETWEEN_INCLUSIVE,
                          from.getValueAsDate(),
                          to.getValueAsDate()),
                      search
                    });
            deliveryListGrid.fetchData(criteria);
            deliveryListGrid.deselectAllRecords();
          }
        });

    IButton listAllButton = new IButton("แสดงรายการทั้งหมด");
    listAllButton.setIcon("[SKIN]actions/refresh.png");
    listAllButton.setWidth(150);
    listAllButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            AdvancedCriteria criteria =
                new AdvancedCriteria(
                    OperatorId.AND,
                    new Criterion[] {
                      // new Criterion("delivery", OperatorId.BETWEEN_INCLUSIVE,
                      // from.getValueAsDate(), to.getValueAsDate())
                      new Criterion(
                          "created_date",
                          OperatorId.BETWEEN_INCLUSIVE,
                          from.getValueAsDate(),
                          to.getValueAsDate())
                    });
            searchForm.reset();
            deliveryListGrid.fetchData(criteria);
            deliveryListGrid.deselectAllRecords();
          }
        });

    HLayout empty = new HLayout();
    empty.setWidth("*");
    IButton viewButton = new IButton("เรียกดูรายการ");
    viewButton.setIcon("icons/16/icon_view.png");
    viewButton.setWidth(150);
    viewButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            ListGridRecord selected = deliveryListGrid.getSelectedRecord();
            if (selected == null) {
              SC.warn("กรุณาเลือกรายการเบิกสินค้า");
              return;
            }
            RequestViewWindow deliveryWindow = new RequestViewWindow();
            deliveryWindow.show(selected, false, currentUser, 1);
          }
        });

    IButton receiveOrderButton = new IButton("เบิกจ่ายสินค้า");
    receiveOrderButton.setIcon("icons/16/actions-receive-icon.png");
    receiveOrderButton.setWidth(100);
    receiveOrderButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            ListGridRecord selected = deliveryListGrid.getSelectedRecord();
            if (selected == null) {
              SC.warn("กรุณาเลือกรายการเบิกสินค้า");
              return;
            }

            if (selected
                .getAttributeAsString("issued_status")
                .equalsIgnoreCase("0_product_request")) {
              RequestViewWindow deliveryWindow = new RequestViewWindow();
              deliveryWindow.show(selected, true, currentUser, 2);
            } else {
              SC.warn("จ่ายสินค้าแล้ว");
            }
          }
        });

    buttonLayout.addMembers(searchButton, listAllButton, empty, viewButton, receiveOrderButton);
    // buttonLayout.addMembers(searchButton, listAllButton);
    // reviseLayout.
    addMember(buttonLayout);

    VLayout gridLayout = new VLayout();
    gridLayout.setWidth100();
    gridLayout.setHeight(355);

    gridLayout.addMember(deliveryListGrid);
    // reviseLayout.
    addMember(gridLayout);

    // reviseTab.setPane(reviseLayout);
    // return reviseTab;
  }
  public Canvas getViewPanel() {

    Canvas canvas = new Canvas();
    final ListGrid countryGrid = new ListGrid();
    countryGrid.setWidth(550);
    countryGrid.setHeight(224);
    countryGrid.setShowAllRecords(true);
    countryGrid.setCellHeight(22);
    countryGrid.setDataSource(CountryXmlDS.getInstance());

    ListGridField countryCodeField = new ListGridField("countryCode", "Flag", 40);
    countryCodeField.setAlign(Alignment.CENTER);
    countryCodeField.setType(ListGridFieldType.IMAGE);
    countryCodeField.setImageURLPrefix("flags/16/");
    countryCodeField.setImageURLSuffix(".png");
    countryCodeField.setCanEdit(false);

    ListGridField nameField = new ListGridField("countryName", "Country");
    ListGridField continentField = new ListGridField("continent", "Continent");
    ListGridField memberG8Field = new ListGridField("member_g8", "Member G8");
    ListGridField populationField = new ListGridField("population", "Population");
    populationField.setType(ListGridFieldType.INTEGER);
    populationField.setCellFormatter(
        new CellFormatter() {
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            if (value != null) {
              NumberFormat nf = NumberFormat.getFormat("0,000");
              try {
                return nf.format(((Number) value).longValue());
              } catch (Exception e) {
                return value.toString();
              }
            } else {
              return null;
            }
          }
        });
    ListGridField independenceField = new ListGridField("independence", "Independence");
    countryGrid.setFields(
        countryCodeField,
        nameField,
        continentField,
        memberG8Field,
        populationField,
        independenceField);

    countryGrid.setAutoFetchData(true);
    countryGrid.setCanEdit(true);
    countryGrid.setEditEvent(ListGridEditEvent.CLICK);
    countryGrid.setListEndEditAction(RowEndEditAction.NEXT);
    canvas.addChild(countryGrid);

    IButton button = new IButton("Edit New");
    button.setTop(250);
    button.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            countryGrid.startEditingNew();
          }
        });
    canvas.addChild(button);

    return canvas;
  }