示例#1
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;
  }
示例#2
0
  @Override
  public Widget asWidget() {
    if (cp == null) {
      ExampleResources bundle = GWT.create(ExampleResources.class);

      this.style = bundle.style();
      this.style.ensureInjected();

      cp = new ContentPanel(GWT.<ContentPanelAppearance>create(FramedPanelAppearance.class));
      cp.addStyleName("margin-10");
      cp.setPixelSize(500, 400);
      cp.getBody().getStyle().setBackgroundColor("white");
      cp.getBody().addClassName(ThemeStyles.getStyle().border());

      con = new CardLayoutContainer();
      cp.add(con);

      ToggleGroup group = new ToggleGroup();

      for (Category cat : Category.values()) {
        final ToggleButton btn = new ToggleButton(cat.desc);
        btn.setData("cat", cat);
        btn.addValueChangeHandler(
            new ValueChangeHandler<Boolean>() {

              @Override
              public void onValueChange(ValueChangeEvent<Boolean> event) {
                if (event.getValue() == true) {
                  onClick((Category) btn.getData("cat"));
                }
              }
            });

        group.add(btn);
        cp.addButton(btn);
      }

      ToggleButton normal = (ToggleButton) cp.getButtonBar().getWidget(0);
      normal.setValue(true, true);
    }
    return cp;
  }
  @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;
  }
  @Override
  public Widget asWidget() {
    if (panel == null) {
      panel = new ContentPanel();
      panel.setHeadingText("Cell Action Tree");
      panel.setPixelSize(315, 400);
      panel.addStyleName("margin-10");

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

      TreeStore<BaseDto> store = new TreeStore<BaseDto>(new KeyProvider());

      FolderDto root = TestData.getMusicRootFolder();
      for (BaseDto base : root.getChildren()) {
        store.add(base);
        if (base instanceof FolderDto) {
          processFolder(store, (FolderDto) base);
        }
      }

      SimpleSafeHtmlCell<String> cell =
          new SimpleSafeHtmlCell<String>(SimpleSafeHtmlRenderer.getInstance(), "click") {
            @Override
            public void onBrowserEvent(
                Context context,
                Element parent,
                String value,
                NativeEvent event,
                ValueUpdater<String> valueUpdater) {
              super.onBrowserEvent(context, parent, value, event, valueUpdater);
              if ("click".equals(event.getType())) {
                Info.display("Click", "You clicked \"" + value + "\"!");
              }
            }
          };

      final Tree<BaseDto, String> tree =
          new Tree<BaseDto, String>(
              store,
              new ValueProvider<BaseDto, String>() {

                @Override
                public String getValue(BaseDto object) {
                  return object.getName();
                }

                @Override
                public void setValue(BaseDto object, String value) {}

                @Override
                public String getPath() {
                  return "name";
                }
              });
      tree.setCell(cell);
      tree.setWidth(300);
      tree.getStyle().setLeafIcon(ExampleImages.INSTANCE.music());

      ToolBar buttonBar = new ToolBar();

      buttonBar.add(
          new TextButton(
              "Expand All",
              new SelectHandler() {

                @Override
                public void onSelect(SelectEvent event) {
                  tree.expandAll();
                }
              }));
      buttonBar.add(
          new TextButton(
              "Collapse All",
              new SelectHandler() {
                @Override
                public void onSelect(SelectEvent event) {
                  tree.collapseAll();
                }
              }));

      con.add(buttonBar, new VerticalLayoutData(1, -1));
      con.add(tree, new VerticalLayoutData(1, 1));
    }

    return panel;
  }