@UiFactory()
  public Grid<Stock> createGrid() {
    final NumberFormat number = NumberFormat.getFormat("0.00");

    ColumnConfig<Stock, String> nameCol =
        new ColumnConfig<Stock, String>(props.name(), 200, "Company");
    ColumnConfig<Stock, String> symbolCol =
        new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
    ColumnConfig<Stock, Double> lastCol = new ColumnConfig<Stock, Double>(props.last(), 75, "Last");

    ColumnConfig<Stock, Double> changeCol =
        new ColumnConfig<Stock, Double>(props.change(), 100, "Change");

    changeCol.setCell(
        new AbstractCell<Double>() {

          @Override
          public void render(Context context, Double value, SafeHtmlBuilder sb) {
            SafeStylesBuilder stylesBuilder = new SafeStylesBuilder();
            stylesBuilder.appendTrustedString("color:" + (value < 0 ? "red" : "green") + ";");
            String v = number.format(value);
            CellTemplates cellTemplates = GWT.create(CellTemplates.class);
            SafeHtml template = cellTemplates.template(stylesBuilder.toSafeStyles(), v, v);
            sb.append(template);
          }
        });

    ColumnConfig<Stock, Date> lastTransCol =
        new ColumnConfig<Stock, Date>(props.lastTrans(), 100, "Last Updated");
    DateCell dateCell = new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy"));
    lastTransCol.setCell(dateCell);

    List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>();
    l.add(nameCol);
    l.add(symbolCol);
    l.add(lastCol);
    l.add(changeCol);
    l.add(lastTransCol);
    ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

    ListStore<Stock> store = new ListStore<Stock>(props.key());
    store.addAll(TestData.getStocks());

    final Grid<Stock> grid = new Grid<Stock>(store, cm);
    grid.getView().setAutoExpandColumn(nameCol);
    grid.setBorders(false);
    grid.getView().setStripeRows(true);
    grid.getView().setColumnLines(true);

    // needed to enable quicktips (qtitle for the heading and qtip for the
    // content) that are setup in the change GridCellRenderer
    new QuickTip(grid);

    return grid;
  }
Exemple #2
0
  @Override
  public Widget asWidget() {
    ColumnConfig<ModelPropertyModel, String> name =
        new ColumnConfig<TableInfoTab.ModelPropertyModel, String>(props.name(), 100, "Name");
    ColumnConfig<ModelPropertyModel, String> value =
        new ColumnConfig<TableInfoTab.ModelPropertyModel, String>(props.value(), 180, "Value");
    value.setCell(
        new TitledCell() {
          @Override
          public void render(
              com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) {
            if (value == null) value = "";
            if (value.startsWith("http://") || value.startsWith("https://")) {
              sb.appendHtmlConstant(
                      "<a title=\""
                          + value
                          + "\""
                          + "href=\""
                          + value
                          + "\" target=\"_blank\""
                          + ">")
                  .appendHtmlConstant(value)
                  .appendHtmlConstant("</a>");
            } else {
              super.render(context, value, sb);
            }
          }
        });
    List<ColumnConfig<ModelPropertyModel, ?>> colList =
        new ArrayList<ColumnConfig<ModelPropertyModel, ?>>(2);
    colList.add(name);
    colList.add(value);

    ColumnModel<ModelPropertyModel> colModel =
        new ColumnModel<TableInfoTab.ModelPropertyModel>(colList);
    Grid<ModelPropertyModel> grid = new Grid<TableInfoTab.ModelPropertyModel>(getStore(), colModel);
    grid.setAllowTextSelection(true);
    grid.getView().setForceFit(true);
    grid.getView().setAutoFill(true);
    final GridEditing<ModelPropertyModel> editing = new GridInlineEditing<ModelPropertyModel>(grid);
    editing.addEditor(value, new TextField());
    editing.getEditor(value).setReadOnly(true);

    return grid;
  }
  @Override
  public Widget asWidget() {
    // reduce the padding on text element as we have widgets in the cells
    SafeStyles textStyles = SafeStylesUtils.fromTrustedString("padding: 1px 3px;");

    ColumnConfig<Plant, String> cc1 =
        new ColumnConfig<Plant, String>(properties.name(), 100, "Name");
    // IMPORTANT we want the text element (cell parent) to only be as wide as the cell and not fill
    // the cell
    cc1.setColumnTextClassName(CommonStyles.get().inlineBlock());
    cc1.setColumnTextStyle(textStyles);

    TextButtonCell button = new TextButtonCell();
    button.addSelectHandler(
        new SelectHandler() {

          @Override
          public void onSelect(SelectEvent event) {
            Context c = event.getContext();
            int row = c.getIndex();
            Plant p = store.get(row);
            Info.display("Event", "The " + p.getName() + " was clicked.");
          }
        });
    cc1.setCell(button);

    DateCell dateCell = new DateCell();
    dateCell.setPropertyEditor(
        new DateTimePropertyEditor(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT)));

    ColumnConfig<Plant, Date> cc2 =
        new ColumnConfig<Plant, Date>(properties.available(), 100, "Date");
    cc2.setColumnTextStyle(textStyles);
    cc2.setCell(dateCell);

    List<ColumnConfig<Plant, ?>> l = new ArrayList<ColumnConfig<Plant, ?>>();
    l.add(cc1);
    l.add(cc2);
    ColumnModel<Plant> cm = new ColumnModel<Plant>(l);

    store = new ListStore<Plant>(properties.key());
    store.addAll(TestData.getPlants());

    Grid<Plant> grid = new Grid<Plant>(store, cm);
    grid.getView().setForceFit(true);

    ContentPanel cp = new ContentPanel();
    cp.setHeadingText("Cell Grid");
    cp.setWidget(grid);
    cp.setPixelSize(500, 400);
    cp.addStyleName("margin-10");
    return cp;
  }
  @Override
  public Widget asWidget() {
    if (component == null) {
      final ExampleServiceAsync service = GWT.create(ExampleService.class);

      RpcProxy<PagingLoadConfig, PagingLoadResult<Post>> proxy =
          new RpcProxy<PagingLoadConfig, PagingLoadResult<Post>>() {
            @Override
            public void load(
                PagingLoadConfig loadConfig, AsyncCallback<PagingLoadResult<Post>> callback) {
              service.getPosts(loadConfig, callback);
            }
          };

      PostProperties props = GWT.create(PostProperties.class);

      store =
          new ListStore<Post>(
              new ModelKeyProvider<Post>() {
                @Override
                public String getKey(Post item) {
                  return "" + item.getId();
                }
              });

      loader = new PagingLoader<PagingLoadConfig, PagingLoadResult<Post>>(proxy);
      loader.setRemoteSort(true);
      loader.addLoadHandler(
          new LoadResultListStoreBinding<PagingLoadConfig, Post, PagingLoadResult<Post>>(store));
      loader.addBeforeLoadHandler(
          new BeforeLoadHandler<PagingLoadConfig>() {
            boolean initialLoad = true;

            @Override
            public void onBeforeLoad(BeforeLoadEvent<PagingLoadConfig> event) {
              if (!initialLoad && warnLoad.getValue()) {
                event.setCancelled(!Window.confirm("Are you sure you want to do that?"));
              }
              initialLoad = false;
            }
          });

      IdentityValueProvider<Post> identity = new IdentityValueProvider<Post>();
      sm =
          new CheckBoxSelectionModel<Post>(identity) {
            @Override
            protected void onRefresh(RefreshEvent event) {
              // this code selects all rows when paging if the header checkbox is selected
              if (isSelectAllChecked()) {
                selectAll();
              }
              super.onRefresh(event);
            }
          };
      ColumnConfig<Post, String> forumColumn =
          new ColumnConfig<Post, String>(props.forum(), 150, "Forum");
      ColumnConfig<Post, String> usernameColumn =
          new ColumnConfig<Post, String>(props.username(), 150, "Username");
      ColumnConfig<Post, String> subjectColumn =
          new ColumnConfig<Post, String>(props.subject(), 150, "Subject");
      ColumnConfig<Post, Date> dateColumn = new ColumnConfig<Post, Date>(props.date(), 150, "Date");
      dateColumn.setCell(new DateCell(DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT)));

      List<ColumnConfig<Post, ?>> l = new ArrayList<ColumnConfig<Post, ?>>();
      l.add(sm.getColumn());
      l.add(forumColumn);
      l.add(usernameColumn);
      l.add(subjectColumn);
      l.add(dateColumn);

      cm = new ColumnModel<Post>(l);

      component = uiBinder.createAndBindUi(this);

      Timer t =
          new Timer() {

            @Override
            public void run() {
              loader.load();
            }
          };
      t.schedule(100);

      toolBar.getElement().getStyle().setProperty("borderBottom", "none");
      toolBar.bind(loader);
    }

    return component;
  }
  @Override
  public Widget asWidget() {
    if (panel == null) {
      final NumberFormat number = NumberFormat.getFormat("0.00");
      final String desc =
          "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna.<br/><br/>Aliquam commodo ullamcorper erat. Nullam vel justo in neque porttitor laoreet. Aenean lacus dui, consequat eu, adipiscing eget, nonummy non, nisi. Morbi nunc est, dignissim non, ornare sed, luctus eu, massa. Vivamus eget quam. Vivamus tincidunt diam nec urna. Curabitur velit.";

      RowExpander<Stock> expander =
          new RowExpander<Stock>(
              new AbstractCell<Stock>() {
                @Override
                public void render(Context context, Stock value, SafeHtmlBuilder sb) {
                  sb.appendHtmlConstant(
                      "<p style='margin: 5px 5px 10px'><b>Company:</b>" + value.getName() + "</p>");
                  sb.appendHtmlConstant("<p style='margin: 5px 5px 10px'><b>Summary:</b> " + desc);
                }
              });

      ColumnConfig<Stock, String> nameCol =
          new ColumnConfig<Stock, String>(props.name(), 200, "Company");
      ColumnConfig<Stock, String> symbolCol =
          new ColumnConfig<Stock, String>(props.symbol(), 100, "Symbol");
      ColumnConfig<Stock, Double> lastCol =
          new ColumnConfig<Stock, Double>(props.last(), 75, "Last");

      ColumnConfig<Stock, Double> changeCol =
          new ColumnConfig<Stock, Double>(props.change(), 100, "Change");
      changeCol.setCell(
          new AbstractCell<Double>() {

            @Override
            public void render(Context context, Double value, SafeHtmlBuilder sb) {
              String style = "style='color: " + (value < 0 ? "red" : "green") + "'";
              String v = number.format(value);
              sb.appendHtmlConstant(
                  "<span " + style + " qtitle='Change' qtip='" + v + "'>" + v + "</span>");
            }
          });

      ColumnConfig<Stock, Date> lastTransCol =
          new ColumnConfig<Stock, Date>(props.lastTrans(), 100, "Last Updated");
      lastTransCol.setCell(new DateCell(DateTimeFormat.getFormat("MM/dd/yyyy")));

      List<ColumnConfig<Stock, ?>> l = new ArrayList<ColumnConfig<Stock, ?>>();
      l.add(expander);
      l.add(nameCol);
      l.add(symbolCol);
      l.add(lastCol);
      l.add(changeCol);
      l.add(lastTransCol);
      ColumnModel<Stock> cm = new ColumnModel<Stock>(l);

      ListStore<Stock> store = new ListStore<Stock>(props.key());
      store.addAll(TestData.getStocks());

      panel = new ContentPanel();
      panel.setHeadingText("RowExpander Grid");
      panel.getHeader().setIcon(ExampleImages.INSTANCE.table());
      panel.setPixelSize(600, 320);
      panel.addStyleName("margin-10");

      final Grid<Stock> grid = new Grid<Stock>(store, cm);
      grid.getView().setAutoExpandColumn(nameCol);
      grid.setBorders(false);
      grid.getView().setStripeRows(true);
      grid.getView().setColumnLines(true);

      expander.initPlugin(grid);
      panel.setWidget(grid);
    }

    return panel;
  }
  private void init(Set<SessionDataDto> chosenSessions, int width) {

    int colWidth = calculateWidth(chosenSessions.size(), width);

    treeStore.clear();
    List<ColumnConfig<TreeItem, ?>> columns = new ArrayList<ColumnConfig<TreeItem, ?>>();

    // sort sessions by number sessionId
    SortedSet<SessionDataDto> sortedSet =
        new TreeSet<SessionDataDto>(
            new Comparator<SessionDataDto>() {
              @Override
              public int compare(SessionDataDto o, SessionDataDto o2) {
                return (Long.parseLong(o.getSessionId()) - Long.parseLong(o2.getSessionId())) > 0
                    ? 1
                    : -1;
              }
            });
    sortedSet.addAll(chosenSessions);

    ColumnConfig<TreeItem, String> nameColumn =
        new ColumnConfig<TreeItem, String>(
            new MapValueProvider(NAME), (int) (colWidth * METRIC_COLUMN_WIDTH_FACTOR));
    nameColumn.setHeader(METRIC);
    nameColumn.setSortable(false);
    nameColumn.setMenuDisabled(true);
    columns.add(nameColumn);

    for (SessionDataDto session : sortedSet) {
      ColumnConfig<TreeItem, String> column =
          new ColumnConfig<TreeItem, String>(
              new MapValueProvider(SESSION_HEADER + session.getSessionId()));
      column.setHeader(SESSION_HEADER + session.getSessionId());
      column.setWidth(colWidth);
      column.setSortable(false);
      column.setCell(
          new AbstractCell<String>() {
            @Override
            public void render(Context context, String value, SafeHtmlBuilder sb) {
              if (value != null) {
                sb.appendHtmlConstant(value);
              }
            }
          });
      column.setMenuDisabled(true);

      column.setColumnTextStyle(
          new SafeStyles() {
            @Override
            public String asString() {
              return WHITE_SPACE_NORMAL;
            }
          });

      columns.add(column);
    }

    ColumnModel<TreeItem> cm = new ColumnModel<TreeItem>(columns);

    treeGrid = new NoIconsTreeGrid(treeStore, cm, nameColumn);

    treeGrid.addBeforeCollapseHandler(
        new BeforeCollapseItemEvent.BeforeCollapseItemHandler<TreeItem>() {
          @Override
          public void onBeforeCollapse(BeforeCollapseItemEvent<TreeItem> event) {
            event.setCancelled(true);
          }
        });

    treeGrid.setAutoExpand(true);
    treeGrid.getView().setStripeRows(true);
    treeGrid.setMinColumnWidth(MIN_COLUMN_WIDTH);
    treeGrid.setAllowTextSelection(true);
    treeGrid.getView().setForceFit(true);

    treeStore.addStoreAddHandler(
        new StoreAddEvent.StoreAddHandler<TreeItem>() {
          @Override
          public void onAdd(StoreAddEvent<TreeItem> event) {
            for (TreeItem item : event.getItems()) {
              treeGrid.setExpanded(item, true);
            }
          }
        });

    if (webClientProperties.isUserCommentEditAvailable()) {
      treeGrid.addCellDoubleClickHandler(
          new CellDoubleClickEvent.CellDoubleClickHandler() {
            @Override
            public void onCellClick(CellDoubleClickEvent event) {
              TreeItem item =
                  treeGrid.findNode(treeGrid.getTreeView().getRow(event.getRowIndex())).getModel();
              if (item.getKey().equals(USER_COMMENT) && event.getCellIndex() > 0) {
                SessionDataDto currentSession = defineCurrentSession(event);
                userCommentBox.popUp(
                    currentSession, item.get(SESSION_HEADER + currentSession.getSessionId()), item);
              }
            }
          });
    }

    if (webClientProperties.isTagsAvailable()) {
      treeGrid.addCellDoubleClickHandler(
          new CellDoubleClickEvent.CellDoubleClickHandler() {
            @Override
            public void onCellClick(CellDoubleClickEvent event) {
              TreeItem item =
                  treeGrid.findNode(treeGrid.getTreeView().getRow(event.getRowIndex())).getModel();
              if (item.getKey().equals(SESSION_TAGS) && event.getCellIndex() > 0) {
                SessionDataDto currentSession = defineCurrentSession(event);
                if (allTagsLoadComplete) tagBox.popUpForEdit(currentSession, item, allTags);
              }
            }
          });
    }

    add(treeGrid);
  }
  /**
   * Creates columns configurations for jobs grid.
   *
   * @return columns configurations for jobs grid
   */
  private List<ColumnConfig<MyJobsModel, ?>> createColumnConfig() {
    List<ColumnConfig<MyJobsModel, ?>> configs = new ArrayList<ColumnConfig<MyJobsModel, ?>>();

    ColumnConfig<MyJobsModel, String> inputColumn =
        new ColumnConfig<MyJobsModel, String>(
            props.input(),
            Integer.parseInt(
                ApplicationContext.getSettings().getGridProperties().get("jobs_input_width")));
    inputColumn.setHeader(
        ApplicationContext.getSettings().getGridProperties().get("jobs_input_header"));
    inputColumn.setCell(new InputCell());
    inputColumn.setResizable(true);
    inputColumn.setColumnTextClassName("eppic-my-jobs-list-input");
    inputColumn.setColumnHeaderClassName("eppic-default-font");

    ColumnConfig<MyJobsModel, String> statusColumn =
        new ColumnConfig<MyJobsModel, String>(
            props.status(),
            Integer.parseInt(
                ApplicationContext.getSettings().getGridProperties().get("jobs_status_width")));
    statusColumn.setHeader(
        ApplicationContext.getSettings().getGridProperties().get("jobs_status_header"));
    statusColumn.setCell(new JobStatusCell());
    statusColumn.setResizable(false);
    statusColumn.setColumnHeaderClassName("eppic-default-font");

    configs.add(inputColumn);
    configs.add(statusColumn);

    return configs;
  }