コード例 #1
0
  /** Creates the gComponents with the list of components and add it to the panel */
  private void addGrid() {

    List<ColumnConfig> configs = new LinkedList<ColumnConfig>();

    CheckBoxSelectionModel<PaletteModelData> selectionModel =
        new CheckBoxSelectionModel<PaletteModelData>();
    configs.add(selectionModel.getColumn());

    ColumnConfig column = new ColumnConfig();
    column.setId(PaletteModelData.PROPERTY_NAME);
    column.setHeader(pmsMessages.columnHeaderName());
    column.setWidth(COLUMN_NAME_WIDTH);
    // render to show a tooltip
    column.setRenderer(
        new GridCellRenderer<PaletteModelData>() {
          public Object render(
              PaletteModelData model,
              String property,
              ColumnData config,
              int rowIndex,
              int colIndex,
              ListStore<PaletteModelData> store,
              Grid<PaletteModelData> grid) {
            String name = (String) model.get(property);
            Html html = new Html((String) model.get(property));
            html.setToolTip(name);
            html.getToolTip().setAutoWidth(true);
            return html;
          }
        });
    configs.add(column);

    column = new ColumnConfig();
    column.setId(PaletteModelData.PROPERTY_DESCRIPTION);
    column.setHeader(pmsMessages.columnHeaderDescription());
    column.setWidth(COLUMN_DESCRIPTION_WIDTH);
    configs.add(column);

    ColumnModel cm = new ColumnModel(configs);

    sGrid = new ListStore<PaletteModelData>();
    sGrid.setStoreSorter((StoreSorter) storeSorter);
    sGrid.setSortField(PaletteModelData.PROPERTY_NAME);

    gComponents = new Grid<PaletteModelData>(sGrid, cm);

    gComponents.setSelectionModel(selectionModel);
    gComponents.addPlugin(selectionModel);

    gComponents.setAutoExpandColumn(PaletteModelData.PROPERTY_DESCRIPTION);
    gComponents.setLoadMask(true);
    gComponents.getView().setForceFit(true);

    gComponents
        .getSelectionModel()
        .addSelectionChangedListener(
            new SelectionChangedListener<PaletteModelData>() {
              @Override
              public void selectionChanged(SelectionChangedEvent<PaletteModelData> se) {
                if (se.getSelection() != null && !se.getSelection().isEmpty()) {
                  ttiAddSelected.enable();
                } else {
                  ttiAddSelected.disable();
                }
              }
            });

    add(gComponents);
  }
コード例 #2
0
  private void addGrid() {

    // Grid bases:
    List<ColumnConfig> cc = new LinkedList<ColumnConfig>();

    ColumnConfig ccName =
        new ColumnConfig(
            SetFilterModelData.PROPERTY_NAME, pmsMessages.columnHeaderName(), COLUMN_NAME_WIDTH);
    cc.add(ccName);

    ColumnConfig ccDescription =
        new ColumnConfig(
            SetFilterModelData.PROPERTY_DESCRIPTION,
            pmsMessages.columnHeaderDescription(),
            COLUMN_DESCRIPTION_WIDTH);
    cc.add(ccDescription);

    ColumnConfig ccType =
        new ColumnConfig(
            SetFilterModelData.PROPERTY_TYPE, pmsMessages.columnHeaderType(), COLUMN_TYPE_WIDTH);
    ccType.setRenderer(
        new GridCellRenderer<SetFilterModelData>() {

          public Object render(
              SetFilterModelData model,
              String property,
              ColumnData config,
              int rowIndex,
              int colIndex,
              ListStore<SetFilterModelData> store,
              Grid<SetFilterModelData> grid) {
            if (model.getDTO().getType() != null) {
              return mapFilterTypes.get(model.getDTO().getType().toString());
            }
            return null;
          }
        });
    cc.add(ccType);

    ColumnModel cmOwn = new ColumnModel(cc);

    ListStore<SetFilterModelData> store = new ListStore<SetFilterModelData>();

    grid = new Grid<SetFilterModelData>(store, cmOwn);
    grid.setAutoExpandColumn(SetFilterModelData.PROPERTY_NAME);
    grid.setStyleAttribute(BORDER_TOP_KEY, BORDER_TOP_VALUE);
    GridView gView = grid.getView();
    gView.setForceFit(true);

    grid.getSelectionModel()
        .addSelectionChangedListener(
            new SelectionChangedListener<SetFilterModelData>() {
              @Override
              public void selectionChanged(SelectionChangedEvent<SetFilterModelData> se) {
                boolean enabled = false;
                if (se.getSelectedItem() != null) {
                  enabled = true;
                }
                bEdit.setEnabled(enabled);
                bDelete.setEnabled(enabled);
              }
            });
    add(grid);
  }