@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. 2
0
  @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;
  }
Esempio n. 3
0
  private void updateStatusInfo() {
    if (vectorLayers != null) {
      List<VectorLayerInfo> vectors = new ArrayList<VectorLayerInfo>();

      for (Layer layer : vectorLayers) {
        vectors.add(new VectorLayerInfo((Vector) layer));
      }

      layerStore.clear();
      layerStore.addAll(vectors);
      layerCombo.redraw();
    }

    if (selectedLayer != null) {
      layerCombo.setValue(new VectorLayerInfo(selectedLayer));
    }
  }
Esempio n. 4
0
  /** @param supportedValidatorTypes use these to construct content of the combo box */
  AddValidatorDialog(
      Set<ArgumentValidatorType> supportedValidatorTypes, ArgumentValidatorMessages avMessages) {
    this.avMessages = avMessages;

    setHeadingText(avMessages.validatorDialogHeading());
    setAutoHide(false);
    setSize("400", "250");
    // Initialize the ComboBox list store with the given Set<..>
    ListStore<ArgumentValidatorType> validatorTypes = new ListStore<>(new AVTLabelKeyProvider());
    validatorTypes.addAll(supportedValidatorTypes);

    // Initialize the ComboBox
    validatorTypeCB = new ComboBox<>(validatorTypes, new AVTLabelKeyProvider());
    validatorTypeCB.setForceSelection(true);
    validatorTypeCB.setAllowBlank(false);
    validatorTypeCB.setTriggerAction(TriggerAction.ALL);

    // Construct all "provided" fields.
    constructDoubleSpinnerFields();
    constructIntegerSpinnerFields();
    charLimitField = new NumberField<>(new NumberPropertyEditor.IntegerPropertyEditor());
    charLimitField.setAllowBlank(false);
    charLimitField.addValidHandler(this);
    charLimitField.addInvalidHandler(this);

    add(BINDER.createAndBindUi(this));

    // Initialize validatorTypeToCardMap
    validatorTypeToCardMap = Maps.newHashMap();
    validatorTypeToCardMap.put(ArgumentValidatorType.DoubleAbove, dblAboveValidatorCon);
    validatorTypeToCardMap.put(ArgumentValidatorType.DoubleBelow, dblBelowValidatorCon);
    validatorTypeToCardMap.put(ArgumentValidatorType.DoubleRange, dblRangeValidatorCon);

    validatorTypeToCardMap.put(ArgumentValidatorType.IntAbove, intAboveValidatorCon);
    validatorTypeToCardMap.put(ArgumentValidatorType.IntBelow, intBelowValidatorCon);
    validatorTypeToCardMap.put(ArgumentValidatorType.IntRange, intRangeValidatorCon);

    validatorTypeToCardMap.put(ArgumentValidatorType.Regex, regexValidatorCon);
    validatorTypeToCardMap.put(ArgumentValidatorType.CharacterLimit, characterLimitValidatorCon);

    // Set default values.
    ArgumentValidatorType next = supportedValidatorTypes.iterator().next();
    validatorTypeCB.setValue(next, true);
    cardLC.setActiveWidget(validatorTypeToCardMap.get(next));
  }
Esempio n. 5
0
  @Override
  public Widget asWidget() {
    final ListStore<Data> store = new ListStore<Data>(dataAccess.nameKey());
    store.addAll(TestData.getData(12, 20, 100));

    final Chart<Data> chart = new Chart<Data>();
    chart.setStore(store);
    chart.setShadowChart(true);

    NumericAxis<Data> axis = new NumericAxis<Data>();
    axis.setPosition(Position.BOTTOM);
    axis.addField(dataAccess.data1());
    axis.addField(dataAccess.data2());
    axis.addField(dataAccess.data3());
    TextSprite title = new TextSprite("Number of Hits");
    title.setFontSize(18);
    axis.setTitleConfig(title);
    axis.setDisplayGrid(true);
    axis.setMinimum(0);
    axis.setMaximum(100);
    chart.addAxis(axis);

    CategoryAxis<Data, String> catAxis = new CategoryAxis<Data, String>();
    catAxis.setPosition(Position.LEFT);
    catAxis.setField(dataAccess.name());
    title = new TextSprite("Month of the Year");
    title.setFontSize(18);
    catAxis.setTitleConfig(title);
    chart.addAxis(catAxis);

    final BarSeries<Data> bar = new BarSeries<Data>();
    bar.setYAxisPosition(Position.BOTTOM);
    bar.addYField(dataAccess.data1());
    bar.addYField(dataAccess.data2());
    bar.addYField(dataAccess.data3());
    bar.addColor(new RGB(148, 174, 10));
    bar.addColor(new RGB(17, 95, 166));
    bar.addColor(new RGB(166, 17, 32));
    chart.addSeries(bar);

    final Legend<Data> legend = new Legend<Data>();
    legend.setPosition(Position.RIGHT);
    legend.setItemHighlighting(true);
    legend.setItemHiding(true);
    chart.setLegend(legend);

    TextButton regenerate = new TextButton("Reload Data");
    regenerate.addSelectHandler(
        new SelectHandler() {
          @Override
          public void onSelect(SelectEvent event) {
            store.clear();
            store.addAll(TestData.getData(12, 0, 100));
            chart.redrawChart();
          }
        });

    ToggleButton animation = new ToggleButton("Animate");
    animation.addValueChangeHandler(
        new ValueChangeHandler<Boolean>() {
          @Override
          public void onValueChange(ValueChangeEvent<Boolean> event) {
            chart.setAnimated(event.getValue());
          }
        });
    animation.setValue(true, true);
    ToggleButton shadow = new ToggleButton("Shadow");
    shadow.addValueChangeHandler(
        new ValueChangeHandler<Boolean>() {
          @Override
          public void onValueChange(ValueChangeEvent<Boolean> event) {
            chart.setShadowChart(event.getValue());
            chart.redrawChart();
          }
        });
    shadow.setValue(true);

    ToolBar toolBar = new ToolBar();
    toolBar.add(regenerate);
    toolBar.add(animation);
    toolBar.add(shadow);

    ContentPanel panel = new FramedPanel();
    panel.getElement().getStyle().setMargin(10, Unit.PX);
    panel.setCollapsible(true);
    panel.setHeadingText("Grouped Bar Chart");
    panel.setPixelSize(620, 500);
    panel.setBodyBorder(true);

    final Resizable resize = new Resizable(panel, Dir.E, Dir.SE, Dir.S);
    resize.setMinHeight(400);
    resize.setMinWidth(400);

    panel.addExpandHandler(
        new ExpandHandler() {
          @Override
          public void onExpand(ExpandEvent event) {
            resize.setEnabled(true);
          }
        });
    panel.addCollapseHandler(
        new CollapseHandler() {
          @Override
          public void onCollapse(CollapseEvent event) {
            resize.setEnabled(false);
          }
        });

    new Draggable(panel, panel.getHeader()).setUseProxy(false);

    VerticalLayoutContainer layout = new VerticalLayoutContainer();
    panel.add(layout);

    toolBar.setLayoutData(new VerticalLayoutData(1, -1));
    layout.add(toolBar);

    chart.setLayoutData(new VerticalLayoutData(1, 1));
    layout.add(chart);

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