예제 #1
0
  @Override
  public void initStore(BaseListLoader<? extends ListLoadResult<ModelData>> gridLoader) {
    GroupingStore<ModelData> groupstore = new GroupingStore<ModelData>(gridLoader);
    groupstore.setSortDir(SortDir.ASC);
    groupstore.setSortField(AdminUserBeanDesc.login.getName());
    groupstore.groupBy(AdminUserBeanDesc.role.getName(), true);

    // groupstore.groupBy(getSortedGroupLabel(AdminUserBeanDesc.role.getName()), true);
    groupstore.setStoreSorter(
        new StoreSorter<ModelData>() { // for compare RoleBean,only compare its label

          @Override
          public int compare(Store<ModelData> store, ModelData m1, ModelData m2, String property) {

            if (property != null) {
              Object v1 = m1.get(property);
              Object v2 = m2.get(property);
              if ((v1 instanceof RoleBean) && (v2 instanceof RoleBean)) {
                return comparator.compare(
                    getSortedGroupLabel(((RoleBean) v1).getLabel()),
                    getSortedGroupLabel(((RoleBean) v2).getLabel()));
              } else {
                return comparator.compare(v1, v2);
              }
            }
            return comparator.compare(m1, m2);
          }
        });
    setStore(groupstore);
  }
예제 #2
0
 protected void onShowGroupsClick(MenuEvent be, boolean checked) {
   if (checked) {
     onGroupByClick(be, activeHdIndex);
   } else {
     groupingStore.clearGrouping();
   }
 }
  public LatestVirtualReportItemsPanel() {
    setHeading("Virtual Level Monitoring");
    setLayout(new FitLayout());

    ToolBar toolBar = new ToolBar();
    Button reflesh = new Button("Refresh");
    reflesh.setIcon(IconHelper.createStyle("icon-email-add"));
    id = new TextField<String>();
    id.setFieldLabel("Virtual ID");
    id.setAllowBlank(false);
    toolBar.add(new LabelToolItem("Virtual ID: "));
    toolBar.add(id);
    toolBar.add(reflesh);
    setTopComponent(toolBar);
    reflesh.addSelectionListener(
        new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            String virtualId = id.getValue();
            service = (MonitoringManagerWebServiceAsync) Registry.get("guiservice");
            service.getMonitoringResources(
                "virtual",
                virtualId,
                new AsyncCallback<List<MonitoringResource>>() {
                  public void onFailure(Throwable caught) {
                    Dispatcher.forwardEvent(MainEvents.Error, caught);
                  }

                  public void onSuccess(List<MonitoringResource> result) {
                    getVirtualStore().removeAll();
                    if (result.size() > 0) virtualStore.add(result);
                  }
                });
          }
        });

    virtualStore = new GroupingStore<MonitoringResource>();
    virtualStore.groupBy("resource_type");
    cm = new ColumnModel(OptimisResource.getColumnConfig());
    GroupingView view = new GroupingView();
    view.setShowGroupedColumn(true);
    view.setForceFit(true);
    view.setGroupRenderer(
        new GridGroupRenderer() {
          public String render(GroupColumnData data) {
            String f = cm.getColumnById(data.field).getHeader();
            String l = data.models.size() == 1 ? "Item" : "Items";
            return f + ": " + data.group + " (" + data.models.size() + " " + l + ")";
          }
        });

    virtualGrid = new Grid<MonitoringResource>(virtualStore, cm);
    virtualGrid.setTitle(" Service Resources ");
    virtualGrid.setView(view);
    virtualGrid.setBorders(true);
    virtualGrid.getView().setForceFit(true);
    add(virtualGrid);
  }
  public void draw(DoneDrawingCallback callback) {
    removeAll();

    final List<ColumnConfig> cols = getColumns();

    final Map<String, RowData> group = getGroupsForRows();
    final Map<String, String> groupIDToName = new HashMap<String, String>();
    final GroupingStore<BaseModelData> store = new GroupingStore<BaseModelData>();
    for (RowData row : getRows()) {
      final BaseModelData model = new BaseModelData();
      model.set("id", row.getField("id"));
      model.set("lockid", row.getField("lockid"));
      for (ColumnConfig col : cols) model.set(col.getId(), row.getField(col.getId()));
      RowData gID = group.get(row.getField("id"));
      if (gID == null) {
        model.set("groupid", "none");
        model.set("groupidentifier", null);
        groupIDToName.put("none", "No Group Defined");
      } else {
        model.set("groupid", gID.get("groupid"));
        model.set("groupidentifier", gID.get("id"));
        groupIDToName.put(gID.get("groupid"), "Working Set: " + gID.get("groupname"));
      }

      store.add(model);
    }
    store.groupBy("groupid");

    final GroupingView view = new GroupingView();
    view.setShowGroupedColumn(false);
    view.setGroupRenderer(
        new GridGroupRenderer() {
          public String render(GroupColumnData data) {
            return groupIDToName.get(data.group);
          }
        });

    final GridSelectionModel<BaseModelData> sel = new GridSelectionModel<BaseModelData>();
    sel.setSelectionMode(SelectionMode.SINGLE);

    grid = new Grid<BaseModelData>(store, new ColumnModel(cols));
    grid.setSelectionModel(sel);
    grid.setView(view);
    grid.addListener(
        Events.RowClick,
        new Listener<GridEvent>() {
          public void handleEvent(GridEvent be) {
            if (groupButton != null && be != null && be.getModel() != null)
              groupButton.setEnabled(be.getModel().get("groupidentifier") != null);
          }
        });
    // grid.setWidth(680);

    int size = 25;

    final LayoutContainer wrapper = new LayoutContainer();
    wrapper.setLayout(new FillLayout());
    // wrapper.setScrollMode(Scroll.ALWAYS);
    wrapper.add(grid);

    final LayoutContainer container = new LayoutContainer(new BorderLayout());
    container.setBorders(false);
    container.add(getToolBar(), new BorderLayoutData(LayoutRegion.SOUTH, size, size, size));
    container.add(wrapper, new BorderLayoutData(LayoutRegion.CENTER));

    add(container);

    callback.isDrawn();
  }
예제 #5
0
 private void onGroupByClick(MenuEvent me, int colIndex) {
   groupingStore.groupBy(cm.getDataIndex(colIndex));
 }
예제 #6
0
 protected String getGroupField() {
   return groupingStore.getGroupState();
 }
예제 #7
0
  private Window createGridWindow() {
    Window w = new Window();
    w.setIcon(IconHelper.createStyle("icon-grid"));
    w.setMinimizable(true);
    w.setMaximizable(true);
    w.setHeading("Messages Window");
    w.setSize(500, 400);
    w.setLayout(new FitLayout());

    GroupingStore<Employee> employeeList = new GroupingStore<Employee>();
    employeeList.add(TestData.getEmployees());
    employeeList.groupBy("department");

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

    ColumnConfig column = new ColumnConfig();
    column.setId("name");
    column.setHeader("Sender Name");
    column.setWidth(200);
    configs.add(column);

    column = new ColumnConfig("department", "User group", 150);
    column.setAlignment(HorizontalAlignment.LEFT);
    configs.add(column);

    column = new ColumnConfig("designation", "Taggs", 150);
    column.setAlignment(HorizontalAlignment.LEFT);
    configs.add(column);

    column = new ColumnConfig("salary", "Length", 100);
    column.setAlignment(HorizontalAlignment.RIGHT);
    final NumberFormat number = NumberFormat.getFormat("0.00");
    GridCellRenderer<Employee> checkSalary =
        new GridCellRenderer<Employee>() {
          public String render(
              Employee model,
              String property,
              ColumnData config,
              int rowIndex,
              int colIndex,
              ListStore<Employee> employeeList,
              Grid<Employee> grid) {
            double val = (Double) model.get(property);
            String style = val < 70000 ? "red" : "green";
            return "<span style='color:" + style + "'>" + number.format(val) + "</span>";
          }
        };
    column.setRenderer(checkSalary);
    configs.add(column);

    column = new ColumnConfig("joiningdate", "Date", 100);
    column.setAlignment(HorizontalAlignment.RIGHT);
    column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());
    configs.add(column);

    final ColumnModel cm = new ColumnModel(configs);

    GroupingView view = new GroupingView();
    view.setForceFit(true);
    view.setGroupRenderer(
        new GridGroupRenderer() {
          public String render(GroupColumnData data) {
            String f = cm.getColumnById(data.field).getHeader();
            String l = data.models.size() == 1 ? "Item" : "Items";
            return f + ": " + data.group + " (" + data.models.size() + " " + l + ")";
          }
        });

    Grid<Employee> grid = new Grid<Employee>(employeeList, cm);
    grid.setView(view);
    grid.setBorders(true);

    ContentPanel cp = new ContentPanel();
    cp.setBodyBorder(false);
    cp.setHeading("Friends List");
    cp.setButtonAlign(HorizontalAlignment.CENTER);
    cp.setLayout(new FitLayout());
    cp.setSize(700, 420);
    cp.add(grid);
    w.add(cp);

    return w;
  }