@Test
  public void click() {
    // Given
    final StringBuilder sb = new StringBuilder();

    // Add a selection model to handle user selection.
    final SingleSelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>();
    table.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          public void onSelectionChange(SelectionChangeEvent event) {
            Contact selected = selectionModel.getSelectedObject();
            if (selected != null) {
              sb.append(selected.name).append(" : ").append(selected.address);
            }
          }
        });

    // When 1
    Browser.click(table, CONTACTS.get(0));

    // Then 1
    assertThat(sb.toString()).isEqualTo("Gael : 666 Evil");
    assertThat(table.getSelectionModel().isSelected(CONTACTS.get(0))).isTrue();

    // When 2 : deselect
    Browser.click(table, CONTACTS.get(0));

    // Then 2
    assertThat(sb.toString()).isEqualTo("Gael : 666 Evil");
    assertThat(table.getSelectionModel().isSelected(CONTACTS.get(0))).isFalse();
  }
Beispiel #2
0
  private void setupSessionDataGrid() {
    sessionsDataGrid = new DataGrid<SessionDataDto>();
    sessionsDataGrid.setPageSize(15);
    sessionsDataGrid.setEmptyTableWidget(new Label("No Sessions"));

    // Add a selection model so we can select cells.
    final SelectionModel<SessionDataDto> selectionModel =
        new MultiSelectionModel<SessionDataDto>(
            new ProvidesKey<SessionDataDto>() {
              @Override
              public Object getKey(SessionDataDto item) {
                return item.getSessionId();
              }
            });
    sessionsDataGrid.setSelectionModel(
        selectionModel, DefaultSelectionEventManager.<SessionDataDto>createCheckboxManager());

    // Checkbox column. This table will uses a checkbox column for selection.
    // Alternatively, you can call dataGrid.setSelectionEnabled(true) to enable mouse selection.
    Column<SessionDataDto, Boolean> checkColumn =
        new Column<SessionDataDto, Boolean>(new CheckboxCell(true, false)) {
          @Override
          public Boolean getValue(SessionDataDto object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
          }
        };
    sessionsDataGrid.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    sessionsDataGrid.setColumnWidth(checkColumn, 40, Style.Unit.PX);

    sessionsDataGrid.addColumn(
        new TextColumn<SessionDataDto>() {
          @Override
          public String getValue(SessionDataDto object) {
            return object.getName();
          }
        },
        "Name");

    sessionsDataGrid.addColumn(
        new TextColumn<SessionDataDto>() {
          @Override
          public String getValue(SessionDataDto object) {
            return object.getStartDate();
          }
        },
        "Start Date");

    sessionsDataGrid.addColumn(
        new TextColumn<SessionDataDto>() {
          @Override
          public String getValue(SessionDataDto object) {
            return object.getEndDate();
          }
        },
        "End Date");

    sessionDataProvider.addDataDisplay(sessionsDataGrid);
  }
  private void initTable(
      DataGrid<KBWorkspaceObjectData> table, ListDataProvider<KBWorkspaceObjectData> dataProvider) {
    // populate the view with the current user's stuff.
    // columns: id, owner, command, mod date
    TextColumn<KBWorkspaceObjectData> idColumn =
        new TextColumn<KBWorkspaceObjectData>() {
          @Override
          public String getValue(KBWorkspaceObjectData metadata) {
            return metadata.getId();
          }
        };

    TextColumn<KBWorkspaceObjectData> workspaceColumn =
        new TextColumn<KBWorkspaceObjectData>() {
          @Override
          public String getValue(KBWorkspaceObjectData metadata) {
            return metadata.getWorkspace();
          }
        };

    TextColumn<KBWorkspaceObjectData> ownerColumn =
        new TextColumn<KBWorkspaceObjectData>() {
          @Override
          public String getValue(KBWorkspaceObjectData metadata) {
            return metadata.getOwner();
          }
        };

    TextColumn<KBWorkspaceObjectData> modDateColumn =
        new TextColumn<KBWorkspaceObjectData>() {
          @Override
          public String getValue(KBWorkspaceObjectData metadata) {
            return metadata.getModDate();
          }
        };

    // add columns to the table
    table.addColumn(idColumn, TEXT_ID_COL);
    table.addColumn(workspaceColumn, TEXT_WORKSPACE_COL);
    table.addColumn(ownerColumn, TEXT_OWNER_COL);
    table.addColumn(modDateColumn, TEXT_DATE_COL);

    // add data provider
    dataProvider.addDataDisplay(table);

    // add a selection model
    final SingleSelectionModel<KBWorkspaceObjectData> selectionModel =
        new SingleSelectionModel<KBWorkspaceObjectData>(KBWorkspaceObjectData.KEY_PROVIDER);
    table.setSelectionModel(selectionModel);
  }
  public void activate(final Session session, final SubscriptionRegistrar subscriptionRegistrar) {
    // Subscribe to session ADDED_OBJECT events (so we will see when a course is selected)
    session.subscribe(Session.Event.ADDED_OBJECT, this, subscriptionRegistrar);

    // When a problem is selected, add it to the session
    final SingleSelectionModel<ProblemAndSubmissionReceipt> selectionModel =
        new SingleSelectionModel<ProblemAndSubmissionReceipt>();
    cellTable.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            ProblemAndSubmissionReceipt selected = selectionModel.getSelectedObject();
            if (selected != null) {
              // Add the problem to the Session
              session.add(selected.getProblem());
            }
          }
        });

    // Load the exercise when the user double-clicks
    cellTable.addDomHandler(
        new DoubleClickHandler() {
          @Override
          public void onDoubleClick(DoubleClickEvent event) {
            Problem problem = session.get(Problem.class);
            if (problem != null) {
              // Switch to DevelopmentPage
              session.get(PageStack.class).push(PageId.DEVELOPMENT);
            }
          }
        },
        DoubleClickEvent.getType());

    // If there is already a Course selected, load its problems.
    // Otherwise, if there are problems already in the session, display them.
    CourseSelection courseSelection = session.get(CourseSelection.class);
    ProblemAndSubmissionReceipt[] problemList = session.get(ProblemAndSubmissionReceipt[].class);
    if (courseSelection != null) {
      loadProblemsForCourse(courseSelection);
    } else if (problemList != null) {
      displayLoadedProblems(problemList);
    }
  }
  public ExonDetailPanel() {
    dataGrid.setWidth("100%");
    initializeTable();
    dataProvider.addDataDisplay(dataGrid);
    dataGrid.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            if (selectionModel.getSelectedSet().isEmpty()) {
              exonEditContainer.setVisible(false);
            } else {
              exonEditContainer.setVisible(true);
              updateDetailData(selectionModel.getSelectedObject());
            }
          }
        });

    initWidget(ourUiBinder.createAndBindUi(this));
  }
Beispiel #6
0
  private void createDataGrid() {
    dataGrid = new DataGrid<InputItem>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<InputItem>(KEY_PROVIDER);
    dataGrid.setSelectionModel(selectionModel);

    recordStore = new ListDataProvider<InputItem>(KEY_PROVIDER);
    recordStore.addDataDisplay(dataGrid);

    sortHandler = new ColumnSortEvent.ListHandler<InputItem>(recordStore.getList());

    Column<InputItem, InputItem> colId = new IdentityColumn<InputItem>(ID_CELL);
    dataGrid.addColumn(colId, new ResizableHeader<InputItem>("#", dataGrid, colId));
    dataGrid.setColumnWidth(colId, 35, Style.Unit.PX);

    final EditTextCell cellName = new EditTextCell();
    Column<InputItem, String> colName =
        new Column<InputItem, String>(cellName) {
          @Override
          public String getValue(InputItem rec) {
            return rec.getName();
          }
        };
    colName.setFieldUpdater(
        new FieldUpdater<InputItem, String>() {
          @Override
          public void update(int index, InputItem rec, String value) {
            if (!value.equals(rec.getName())) {
              markChange(rec);
              rec.setName(value);
              cellName.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colName, new ResizableHeader<InputItem>("Name", dataGrid, colName));
    dataGrid.setColumnWidth(colName, 128, Style.Unit.PX);

    colName.setSortable(true);
    sortHandler.setComparator(
        colName,
        new Comparator<InputItem>() {
          @Override
          public int compare(InputItem o1, InputItem o2) {
            return o1.getName().compareTo(o2.getName());
          }
        });

    //        final SelectCell<String,Integer> cellActive = new SelectCell<String,Integer>(
    //                ZicoWidgets.<String,Integer>map("NO",0,"YES",1));
    //        Column<InputItem,Integer> colActive = new Column<InputItem, Integer>(cellActive) {
    //            @Override
    //            public Integer getValue(InputItem rec) {
    //                return rec.getActive();
    //            }
    //        };
    //        colActive.setFieldUpdater(new FieldUpdater<InputItem, Integer>() {
    //            @Override
    //            public void update(int index, InputItem rec, Integer value) {
    //                if (rec.getActive() != value) {
    //                    markChange(rec);
    //                    rec.setActive(value);
    //                    cellActive.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        dataGrid.addColumn(colActive, new ResizableHeader<InputItem>("Active", dataGrid,
    // colActive));
    //        dataGrid.setColumnWidth(colActive, 128, Style.Unit.PX);

    //        final DatePickerCell cellTstart = new DatePickerCell(ClientUtil.TSTAMP_FORMAT0);
    //        Column<InputItem,Date> colTstart = new Column<InputItem, Date>(cellTstart) {
    //            @Override
    //            public Date getValue(InputItem rec) {
    //                return ClientUtil.unix2date(rec.getTstart());
    //            }
    //        };
    //        colTstart.setFieldUpdater(new FieldUpdater<InputItem, Date>() {
    //            @Override
    //            public void update(int index, InputItem rec, Date value) {
    //                long t = ClientUtil.date2unix(value);
    //                if (t != rec.getTstart()) {
    //                    markChange(rec);
    //                    rec.setTstart(t);
    //                    cellTstart.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        colTstart.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    //        dataGrid.addColumn(colTstart, new ResizableHeader<InputItem>("TStart", dataGrid,
    // colTstart));
    //        dataGrid.setColumnWidth(colTstart, 100, Style.Unit.PX);

    //        final DatePickerCell cellTstop = new DatePickerCell(ClientUtil.TSTAMP_FORMAT0);
    //        Column<InputItem,Date> colTstop = new Column<InputItem, Date>(cellTstop) {
    //            @Override
    //            public Date getValue(InputItem rec) {
    //                return ClientUtil.unix2date(rec.getTstop());
    //            }
    //        };
    //        colTstop.setFieldUpdater(new FieldUpdater<InputItem, Date>() {
    //            @Override
    //            public void update(int index, InputItem rec, Date value) {
    //                long t = ClientUtil.date2unix(value);
    //                if (t != rec.getTstop()) {
    //                    markChange(rec);
    //                    rec.setTstop(t);
    //                    cellTstop.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        colTstop.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    //        dataGrid.addColumn(colTstop, new ResizableHeader<InputItem>("TStop", dataGrid,
    // colTstop));
    //        dataGrid.setColumnWidth(colTstop, 100, Style.Unit.PX);

    Column<InputItem, Integer> colInput =
        new Column<InputItem, Integer>(cellInput) {
          @Override
          public Integer getValue(InputItem iitem) {
            return iitem.getInputId();
          }
        };
    colInput.setFieldUpdater(
        new FieldUpdater<InputItem, Integer>() {
          @Override
          public void update(int index, InputItem rec, Integer value) {
            if (rec.getInputId() != value) {
              markChange(rec);
              rec.setInputId(value);
              cellInput.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colInput, new ResizableHeader<InputItem>("Input", dataGrid, colInput));
    dataGrid.setColumnWidth(colInput, 128, Style.Unit.PX);

    Column<InputItem, Integer> colTxForm =
        new Column<InputItem, Integer>(cellTxForm) {
          @Override
          public Integer getValue(InputItem rec) {
            return rec.getTxFormid();
          }
        };
    colTxForm.setFieldUpdater(
        new FieldUpdater<InputItem, Integer>() {
          @Override
          public void update(int index, InputItem iitem, Integer value) {
            if (iitem.getTxFormid() != value) {
              markChange(iitem);
              iitem.setTxFormid(value);
              cellTxForm.clearViewData(iitem.getId());
            }
          }
        });
    dataGrid.addColumn(colTxForm, new ResizableHeader<InputItem>("TxForm", dataGrid, colTxForm));
    dataGrid.setColumnWidth(colTxForm, 128, Style.Unit.PX);

    final EditTextCell cellComment = new EditTextCell();
    Column<InputItem, String> colComment =
        new Column<InputItem, String>(cellComment) {
          @Override
          public String getValue(InputItem rec) {
            return rec.getComment();
          }
        };
    colComment.setFieldUpdater(
        new FieldUpdater<InputItem, String>() {
          @Override
          public void update(int index, InputItem rec, String value) {
            if (!value.equals(rec.getComment())) {
              markChange(rec);
              rec.setComment(value);
              cellComment.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colComment, new ResizableHeader<InputItem>("Comment", dataGrid, colComment));

    colComment.setSortable(true);
    sortHandler.setComparator(
        colComment,
        new Comparator<InputItem>() {
          @Override
          public int compare(InputItem o1, InputItem o2) {
            return o1.getComment().compareTo(o2.getComment());
          }
        });

    dataGrid.addCellPreviewHandler(
        new CellPreviewEvent.Handler<InputItem>() {
          @Override
          public void onCellPreview(CellPreviewEvent<InputItem> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
              selectionModel.setSelected(event.getValue(), true);
              if (event.getValue() != null) {
                contextMenu.setPopupPosition(
                    event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                contextMenu.show();
              }
            }
          }
        });

    dataGrid.setKeyboardSelectionPolicy(
        HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    dataGrid.addDomHandler(
        new DoubleClickHandler() {
          @Override
          public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
          }
        },
        DoubleClickEvent.getType());
    dataGrid.addDomHandler(
        new ContextMenuHandler() {
          @Override
          public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
          }
        },
        ContextMenuEvent.getType());
  }
  public Widget draw() {

    // contentWidget.setSize("100%", "100%");

    DockLayoutPanel ft = new DockLayoutPanel(Style.Unit.PX);
    contentWidget.setWidget(ft);

    final DataGrid gridTable = new DataGrid();
    gridTable.setSize("100%", "100%");

    final ArrayList<Attribute> vosList = new ArrayList<Attribute>();
    final GetAttributesV2 getVos =
        new GetAttributesV2(
            new JsonCallbackEvents() {
              public void onFinished(JavaScriptObject jso) {
                vosList.addAll(
                    new TableSorter<Attribute>()
                        .sortByAttrNameTranslation(JsonUtils.<Attribute>jsoAsList(jso)));
                gridTable.setRowData(vosList);
                gridTable.redraw();
              }
            });
    getVos.getUserAttributes(3411);
    getVos.retrieveData();

    gridTable.setSelectionModel(
        new MultiSelectionModel<Attribute>(new GeneralKeyProvider<Attribute>()));
    final SelectionModel<Attribute> selectionModel = gridTable.getSelectionModel();
    gridTable.setKeyboardSelectionPolicy(
        HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);

    Column<Attribute, Boolean> checkBoxColumn =
        new Column<Attribute, Boolean>(new CheckboxCell(true, true)) {
          @Override
          public Boolean getValue(Attribute object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
          }
        };
    checkBoxColumn.setFieldUpdater(
        new FieldUpdater<Attribute, Boolean>() {
          @Override
          public void update(int i, Attribute Attribute, Boolean aBoolean) {
            selectionModel.setSelected(Attribute, aBoolean);
          }
        });

    // Checkbox column header
    CheckboxCell cb = new CheckboxCell();
    Header<Boolean> checkBoxHeader =
        new Header<Boolean>(cb) {
          public Boolean getValue() {
            return false; // return true to see a checked checkbox.
          }
        };
    checkBoxHeader.setUpdater(
        new ValueUpdater<Boolean>() {
          public void update(Boolean value) {
            // sets selected to all, if value = true, unselect otherwise
            for (Attribute obj : vosList) {
              selectionModel.setSelected(obj, value);
            }
          }
        });

    gridTable.addColumn(checkBoxColumn, checkBoxHeader, checkBoxHeader);
    gridTable.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);

    TextColumn<Attribute> idColumn =
        new TextColumn<Attribute>() {
          @Override
          public String getValue(Attribute object) {
            return String.valueOf(object.getId());
          }
        };

    if (JsonUtils.isExtendedInfoVisible()) {
      gridTable.addColumn(idColumn, "Id", "Id");
      gridTable.setColumnWidth(idColumn, "90px");
    }

    // Name column
    Column<Attribute, Attribute> nameColumn = JsonUtils.addColumn(new PerunAttributeNameCell());

    // Description column
    Column<Attribute, Attribute> descriptionColumn =
        JsonUtils.addColumn(new PerunAttributeDescriptionCell());

    // Value column
    Column<Attribute, Attribute> valueColumn =
        JsonUtils.addColumn(
            new PerunAttributeValueCell(),
            new FieldUpdater<Attribute, Attribute>() {
              public void update(int index, Attribute object, Attribute value) {
                object = value;
                selectionModel.setSelected(object, object.isAttributeValid());
              }
            });

    ColumnSortEvent.ListHandler<Attribute> columnSortHandler =
        new ColumnSortEvent.ListHandler<Attribute>(vosList);
    gridTable.addColumnSortHandler(columnSortHandler);

    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(
        nameColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_NAME));

    // Sorting description column
    descriptionColumn.setSortable(true);
    columnSortHandler.setComparator(
        descriptionColumn,
        new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_DESCRIPTION));

    // Add sorting
    gridTable.addColumnSortHandler(columnSortHandler);

    // updates the columns size
    gridTable.setColumnWidth(nameColumn, 200.0, Style.Unit.PX);
    gridTable.setColumnWidth(valueColumn, 420.0, Style.Unit.PX);

    gridTable.addColumn(nameColumn, "Name");
    gridTable.addColumn(valueColumn, "Value");
    gridTable.addColumn(descriptionColumn, "Description");

    TabMenu tabMenu = new TabMenu();

    tabMenu.addWidget(
        TabMenu.getPredefinedButton(
            ButtonType.ADD,
            "",
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent clickEvent) {
                session.getTabManager().addTabToCurrentTab(new TestDataGridTabItem(), true);
              }
            }));

    ft.addNorth(tabMenu, 50);
    ft.add(gridTable);

    return getWidget();
  }
Beispiel #8
0
  public OrganismPanel() {
    initWidget(ourUiBinder.createAndBindUi(this));
    loadingDialog = new LoadingDialog("Processing ...", null, false);

    TextColumn<OrganismInfo> organismNameColumn =
        new TextColumn<OrganismInfo>() {
          @Override
          public String getValue(OrganismInfo organism) {
            return organism.getName();
          }
        };
    Column<OrganismInfo, Number> annotationsNameColumn =
        new Column<OrganismInfo, Number>(new NumberCell()) {
          @Override
          public Integer getValue(OrganismInfo object) {
            return object.getNumFeatures();
          }
        };
    Column<OrganismInfo, Number> sequenceColumn =
        new Column<OrganismInfo, Number>(new NumberCell()) {
          @Override
          public Integer getValue(OrganismInfo object) {
            return object.getNumSequences();
          }
        };

    sequenceColumn.setSortable(true);
    organismNameColumn.setSortable(true);
    annotationsNameColumn.setSortable(true);

    Annotator.eventBus.addHandler(
        OrganismChangeEvent.TYPE,
        new OrganismChangeEventHandler() {
          @Override
          public void onOrganismChanged(OrganismChangeEvent organismChangeEvent) {
            organismInfoList.clear();
            organismInfoList.addAll(MainPanel.getInstance().getOrganismInfoList());
          }
        });

    dataGrid.setLoadingIndicator(new HTML("Calculating Annotations ... "));
    dataGrid.addColumn(organismNameColumn, "Name");
    dataGrid.addColumn(annotationsNameColumn, "Annotations");
    dataGrid.addColumn(sequenceColumn, "Ref Sequences");
    dataGrid.setEmptyTableWidget(
        new Label("No organisms available. Add new organisms using the form field."));

    singleSelectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            if (!creatingNewOrganism) {
              loadOrganismInfo();
              changeButtonSelection();
            } else {
              creatingNewOrganism = false;
            }
          }
        });
    dataGrid.setSelectionModel(singleSelectionModel);

    dataProvider.addDataDisplay(dataGrid);

    dataGrid.addDomHandler(
        new DoubleClickHandler() {
          @Override
          public void onDoubleClick(DoubleClickEvent event) {
            if (singleSelectionModel.getSelectedObject() != null) {
              String orgId = singleSelectionModel.getSelectedObject().getId();
              if (!MainPanel.getInstance().getCurrentOrganism().getId().equals(orgId)) {
                OrganismRestService.switchOrganismById(orgId);
              }
            }
          }
        },
        DoubleClickEvent.getType());

    List<OrganismInfo> trackInfoList = dataProvider.getList();

    ColumnSortEvent.ListHandler<OrganismInfo> sortHandler =
        new ColumnSortEvent.ListHandler<OrganismInfo>(trackInfoList);
    dataGrid.addColumnSortHandler(sortHandler);
    sortHandler.setComparator(
        organismNameColumn,
        new Comparator<OrganismInfo>() {
          @Override
          public int compare(OrganismInfo o1, OrganismInfo o2) {
            return o1.getName().compareTo(o2.getName());
          }
        });
    sortHandler.setComparator(
        annotationsNameColumn,
        new Comparator<OrganismInfo>() {
          @Override
          public int compare(OrganismInfo o1, OrganismInfo o2) {
            return o1.getNumFeatures() - o2.getNumFeatures();
          }
        });
    sortHandler.setComparator(
        sequenceColumn,
        new Comparator<OrganismInfo>() {
          @Override
          public int compare(OrganismInfo o1, OrganismInfo o2) {
            return o1.getNumSequences() - o2.getNumSequences();
          }
        });
  }
Beispiel #9
0
  private Widget getMainPanel() {
    SimplePanel panel = new SimplePanel();
    panel.setWidth("100%");
    panel.setHeight("100%");

    dataGrid = new DataGrid<RuleInfo>(MAX_RULES, RuleInfo.KEY_PROVIDER);
    dataGrid.setHeight(MAIN_HEIGHT);

    Column<RuleInfo, String> columnName =
        addColumn(
            new TextCell(),
            "Rule Name",
            new GetValue<String>() {
              public String getValue(RuleInfo rule) {
                return rule.getName();
              }
            },
            null);

    Column<RuleInfo, String> ruleType =
        addColumn(
            new TextCell(),
            "Type",
            new GetValue<String>() {
              public String getValue(RuleInfo rule) {
                return rule.getType().toUpperCase();
              }
            },
            null);

    Column<RuleInfo, ImageResource> ruleEnabled =
        addColumn(
            new ImageResourceCell(),
            "Enabled",
            new GetValue<ImageResource>() {
              public ImageResource getValue(RuleInfo rule) {
                if (rule.isEnabled()) {
                  return PgStudio.Images.trueBox();
                }
                return PgStudio.Images.falseBox();
              }
            },
            null);

    Column<RuleInfo, ImageResource> instead =
        addColumn(
            new ImageResourceCell(),
            "Instead",
            new GetValue<ImageResource>() {
              public ImageResource getValue(RuleInfo rule) {
                if (rule.isInstead()) {
                  return PgStudio.Images.trueBox();
                }
                return PgStudio.Images.falseBox();
              }
            },
            null);

    dataGrid.setColumnWidth(columnName, "200px");
    dataGrid.setColumnWidth(ruleType, "120px");
    dataGrid.setColumnWidth(ruleEnabled, "100px");
    dataGrid.setColumnWidth(instead, "100px");

    ruleType.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    ruleEnabled.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    instead.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);

    dataGrid.setLoadingIndicator(new Image(PgStudio.Images.spinner()));

    dataProvider.addDataDisplay(dataGrid);

    dataGrid.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(
        (new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            RuleInfo rule = selectionModel.getSelectedObject();
            ruleDef.setText(rule.getDefinition());
          }
        }));

    panel.add(dataGrid);

    return panel.asWidget();
  }
  public SupplyLayout() {
    this.res = GWT.create(SupplyResources.class);
    res.style().ensureInjected();
    initWidget(uiBinder.createAndBindUi(this));
    final ListDataProvider<Supply> dataProvider = new ListDataProvider<Supply>();
    dataGrid.setMinimumTableWidth(150, Unit.PX);
    dataGrid.setWidth("100%");
    dataGrid.setHeight("450px");
    dataGrid.setAutoHeaderRefreshDisabled(true);
    dataGrid.setEmptyTableWidget(new Label("Нет данных"));

    ListHandler<Supply> sortHandler = new ListHandler<Supply>(dataProvider.getList());
    dataGrid.addColumnSortHandler(sortHandler);

    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    SimplePager pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(dataGrid);
    pager.setPageSize(10);
    pager.setPageStart(0);
    panel.add(pager);
    final SelectionModel<Supply> selectionModel = new MultiSelectionModel<Supply>();
    dataGrid.setSelectionModel(
        selectionModel, DefaultSelectionEventManager.<Supply>createDefaultManager());

    initTableColumns(selectionModel, sortHandler);

    // Верхняя панелька для поиск
    searchFlexTable = new FlexTable();
    cellFormatter = searchFlexTable.getFlexCellFormatter();
    searchFlexTable.setWidth("80%");
    searchFlexTable.setCellSpacing(5);
    searchFlexTable.setCellPadding(1);

    Label idLabel = new Label("Номер");
    final TextBox idTBox = new TextBox();
    searchFlexTable.setWidget(0, 0, idLabel);
    searchFlexTable.setWidget(0, 1, idTBox);

    Label addressLabel = new Label("Адрес");
    final TextBox addressTBox = new TextBox();
    searchFlexTable.setWidget(1, 0, addressLabel);
    searchFlexTable.setWidget(1, 1, addressTBox);

    // Create a basic date picker
    DatePicker datePicker = new DatePicker();
    final Label text = new Label();

    // Set the value in the text box when the user selects a date
    datePicker.addValueChangeHandler(
        new ValueChangeHandler<Date>() {
          public void onValueChange(ValueChangeEvent<Date> event) {
            Date date = event.getValue();
            String dateString = DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM).format(date);
            text.setText(dateString);
          }
        });

    // Set the default value
    // datePicker.setValue(new Date(), true);

    // Create a DateBox
    DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd");
    final DateBox dateBox = new DateBox();
    dateBox.setFormat(new DateBox.DefaultFormat(dateTimeFormat));
    Label dateLabel = new Label("Дата");

    searchFlexTable.setWidget(2, 0, dateLabel);
    searchFlexTable.setWidget(2, 1, dateBox);

    Label typeLabel = new Label("Тип");
    final ListBox typeLB = new ListBox();
    typeLB.addItem("");
    typeLB.addItem("В филиал");
    typeLB.addItem("На склад");
    searchFlexTable.setWidget(3, 0, typeLabel);
    searchFlexTable.setWidget(3, 1, typeLB);

    Label statusLabel = new Label("Статус");
    final ListBox statusLB = new ListBox();
    statusLB.addItem("");
    for (String type : StatusDict.getAsStringList()) {
      statusLB.addItem(type);
    }
    searchFlexTable.setWidget(4, 0, statusLabel);
    searchFlexTable.setWidget(4, 1, statusLB);
    cellFormatter.setRowSpan(5, 0, 2);
    Button search = new Button("Найти");
    searchFlexTable.setWidget(5, 0, search);

    search.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {

            // формируем карту с where statement:
            Map<String, String> whereMap = new HashMap<String, String>();
            if (idTBox.getText() != null && !"".equals(idTBox.getText()))
              whereMap.put("supid", idTBox.getText());
            if (addressTBox.getText() != null && !"".equals(addressTBox.getText()))
              whereMap.put("address", addressTBox.getText());
            if (dateBox.getTextBox().getText() != null
                && !"".equals(dateBox.getTextBox().getText()))
              whereMap.put("date", dateBox.getTextBox().getText());
            if (typeLB.getSelectedIndex() != 0) {
              if (typeLB.getSelectedIndex() == 1) whereMap.put("DeliveryDirection", "1");
              if (typeLB.getSelectedIndex() == 2) whereMap.put("DeliveryDirection", "0");
            }
            if (statusLB.getSelectedIndex() != 0)
              whereMap.put("SupStatusID", Integer.toString(statusLB.getSelectedIndex()));
            supplyService.getByConditions(
                whereMap,
                new AsyncCallback<List<Supply>>() {

                  @Override
                  public void onSuccess(List<Supply> result) {
                    if (result != null) {
                      dataProvider.getList().clear();
                      dataProvider.getList().addAll(result);
                      dataProvider.refresh();
                    }
                  }

                  @Override
                  public void onFailure(Throwable caught) {
                    Window.alert("Ошибка");
                  }
                });
          }
        });
    additionalPanel.add(searchFlexTable);

    // /////////////////////////////////////////////////////
    supplyService.getLast(
        10,
        new AsyncCallback<List<Supply>>() {

          @Override
          public void onSuccess(List<Supply> result) {
            if (result != null) {
              dataProvider.getList().addAll(result);
              dataProvider.addDataDisplay(dataGrid);
              dataProvider.refresh();
            }
          }

          @Override
          public void onFailure(Throwable caught) {
            // TODO Auto-generated method stub

          }
        });
  }