Esempio n. 1
0
  private void initializeStatusGrid() {
    // Creacion del Grid Base
    StatusItemProperties props = GWT.create(StatusItemProperties.class);
    statusStore = new ListStore<StatusItem>(props.key());
    statusStore.setAutoCommit(true);

    ColumnConfig<StatusItem, String> nameCol =
        new ColumnConfig<StatusItem, String>(
            props.name(), 75, UIMessages.INSTANCE.fedColumnNameText());

    ColumnConfig<StatusItem, String> valueCol =
        new ColumnConfig<StatusItem, String>(
            props.value(), 150, UIMessages.INSTANCE.fedNewAttributeDefaultNameText());

    List<ColumnConfig<StatusItem, ?>> columns = new ArrayList<ColumnConfig<StatusItem, ?>>();
    columns.add(nameCol);
    columns.add(valueCol);

    statusGrid = new Grid<StatusItem>(statusStore, new ColumnModel<StatusItem>(columns));
    statusGrid.setSelectionModel(new CellSelectionModel<StatusItem>());
    statusGrid.getColumnModel().getColumn(1).setHideable(false);
    statusGrid.setHideHeaders(true);
    statusGrid.setAllowTextSelection(true);
    statusGrid.getView().setStripeRows(true);
    statusGrid.getView().setColumnLines(true);
    statusGrid.setBorders(false);

    statusStore.add(new StatusItem(LON_LABEL, null));
    statusStore.add(new StatusItem(LAT_LABEL, null));
    statusStore.add(new StatusItem(SCALE_LABEL, null));
    statusStore.add(new StatusItem(CLICK_COORD_X, null));
    statusStore.add(new StatusItem(CLICK_COORD_Y, null));
  }
  @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;
  }
Esempio n. 3
0
  /**
   * Creates jobs grid.
   *
   * @param myJobsColumnModel column model used for jobs grid
   * @return grid with jobs
   */
  private Grid<MyJobsModel> createJobsGrid(ColumnModel<MyJobsModel> myJobsColumnModel) {
    final Grid<MyJobsModel> myJobsGrid = new Grid<MyJobsModel>(myJobsStore, myJobsColumnModel);
    myJobsGrid.setBorders(false);
    myJobsGrid.setHideHeaders(true);
    myJobsGrid.getView().setStripeRows(true);
    myJobsGrid.getView().setColumnLines(false);
    myJobsGrid.getView().setForceFit(true);
    myJobsGrid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

    myJobsGrid.addStyleName("eppic-default-font");

    myJobsGrid.setContextMenu(new JobsPanelContextMenu(myJobsGrid));

    myJobsGrid.addCellClickHandler(
        new CellClickHandler() {

          @Override
          public void onCellClick(CellClickEvent event) {
            History.newItem("id/" + myJobsStore.get(event.getRowIndex()).getJobid());
          }
        });

    myJobsGrid
        .getSelectionModel()
        .addSelectionHandler(
            new SelectionHandler<MyJobsModel>() {

              @Override
              public void onSelection(SelectionEvent<MyJobsModel> event) {
                if (event.getSelectedItem() != null) {
                  History.newItem("id/" + event.getSelectedItem().getJobid());
                }
              }
            });

    new KeyNav(myJobsGrid) {
      @Override
      public void onDelete(NativeEvent event) {
        MyJobsModel selectedItem = myJobsGrid.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
          CrkWebServiceProvider.getServiceController().deleteJob(selectedItem.getJobid());
        }
      }
    };

    QuickTip gridQT = new QuickTip(myJobsGrid);
    // Bug-Fix in GXt 3.0.1
    // To fix the issue of blank Tooltips we set the delay
    gridQT.setQuickShowInterval(0);
    gridQT.getToolTipConfig().setShowDelay(0);

    return myJobsGrid;
  }
  @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;
  }