@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;
  }
  @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;
  }
Esempio n. 3
0
  public Widget asWidget() {
    FlowLayoutContainer con = new FlowLayoutContainer();
    con.addStyleName("margin-10");

    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);
      }
    }

    StoreFilterField<BaseDto> filter =
        new StoreFilterField<BaseDto>() {

          @Override
          protected boolean doSelect(
              Store<BaseDto> store, BaseDto parent, BaseDto item, String filter) {
            if (item instanceof FolderDto) {
              return false;
            }

            String name = item.getName();
            name = name.toLowerCase();
            if (name.startsWith(filter.toLowerCase())) {
              return true;
            }
            return false;
          }
        };
    filter.bind(store);

    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.setWidth(300);
    tree.getStyle().setLeafIcon(ExampleImages.INSTANCE.music());
    ButtonBar buttonBar = new ButtonBar();

    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();
              }
            }));

    buttonBar.setLayoutData(new MarginData(4));
    con.add(filter);
    con.add(buttonBar);
    con.add(tree);
    return con;
  }