Пример #1
0
  @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;
  }
Пример #2
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;
  }
  private Grid<UserData> createGrid() {
    IdentityValueProvider<UserData> identityValueProvider =
        new IdentityValueProvider<UserData>("sm");
    CheckBoxSelectionModel<UserData> selectionModel =
        new CheckBoxSelectionModel<UserData>(identityValueProvider);
    selectionModel.setSelectionMode(Style.SelectionMode.MULTI);

    List<ColumnConfig<UserData, ?>> columnConfigList = new ArrayList<ColumnConfig<UserData, ?>>();

    columnConfigList.add(selectionModel.getColumn());
    columnConfigList.add(new ColumnConfig<UserData, Long>(userProperties.id(), 20, "ID"));
    columnConfigList.add(
        new ColumnConfig<UserData, String>(userProperties.username(), 100, "Username"));
    columnConfigList.add(
        new ColumnConfig<UserData, String>(userProperties.firstName(), 100, "First Name"));
    columnConfigList.add(
        new ColumnConfig<UserData, String>(userProperties.lastName(), 100, "Last Name"));
    columnConfigList.add(new ColumnConfig<UserData, String>(userProperties.email(), 100, "Email"));
    //    columnConfigList.add(new ColumnConfig<UserData, UserRoleTypes>(userProperties.role(), 100,
    // "Role"));

    ColumnModel<UserData> columnModel = new ColumnModel<UserData>(columnConfigList);
    ListStore<UserData> store = new ListStore<UserData>(userProperties.key());

    Grid<UserData> userDataGrid = new Grid<UserData>(store, columnModel);

    userDataGrid.setLoadMask(true);

    userDataGrid.setHideHeaders(false);
    userDataGrid.getView().setAutoFill(true);
    userDataGrid.setSelectionModel(selectionModel);

    return userDataGrid;
  }
Пример #4
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));
  }
Пример #5
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;
  }
Пример #6
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() {
    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;
  }
Пример #8
0
  /**
   * Adds jobs to grid.
   *
   * @param jobs jobs to display
   * @param selectedJobId current job
   */
  private void setJobs(List<ProcessingInProgressData> jobs, String selectedJobId) {
    MyJobsModel itemToSelect = null;
    int itemToSelectIndex = 0;

    if (jobs != null) {
      int i = 0;

      for (int ii = 0; ii < myJobsStore.size(); ii++) {
        MyJobsModel model = myJobsStore.get(ii);
        boolean found = false;
        int j = 0;

        while ((j < jobs.size()) && (!found)) {
          if (jobs.get(j).getJobId().equals(model.getJobid())) {
            found = true;
            break;
          }

          j++;
        }

        if (!found) {
          myJobsStore.remove(ii);
        }
      }

      for (ProcessingInProgressData statusData : jobs) {
        MyJobsModel myJobsModel =
            new MyJobsModel(statusData.getJobId(), statusData.getStatus(), statusData.getInput());

        if ((selectedJobId != null) && (statusData.getJobId().equals(selectedJobId))) {
          itemToSelect = myJobsModel;
          itemToSelectIndex = i;
        }

        MyJobsModel existingModel = myJobsStore.findModel(myJobsModel);

        if (existingModel != null) {
          existingModel.setStatus(statusData.getStatus());
          existingModel.setInput(statusData.getInput());
          myJobsStore.update(existingModel);
        } else {
          myJobsStore.add(myJobsModel);
        }

        i++;
      }
    }

    myJobsStore.commitChanges();

    if ((selectedJobId != null) && (myJobsStore.size() > 0)) {
      myJobsGrid.getSelectionModel().select(itemToSelect, false);

      if (isJobsListFirstTimeLoaded) {
        myJobsGrid.getView().focusRow(itemToSelectIndex);
        isJobsListFirstTimeLoaded = false;
      }
      EventBusManager.EVENT_BUS.fireEvent(new ShowJobsPanelEvent());
    } else {
      EventBusManager.EVENT_BUS.fireEvent(new HideJobsPanelEvent());
    }
  }