@SuppressWarnings("unchecked")
  @Override
  protected void createColumns(
      DefaultCellTable<ArtifactReference> table, ListDataProvider<ArtifactReference> dataProvider) {
    final TextColumn<ArtifactReference> nameColumn =
        new TextColumn<ArtifactReference>() {
          @Override
          public String getValue(ArtifactReference reference) {
            return reference.getName();
          }
        };
    nameColumn.setSortable(true);

    final TextColumn<ArtifactReference> urlColumn =
        new TextColumn<ArtifactReference>() {
          @Override
          public String getValue(ArtifactReference reference) {
            return reference.getUrl();
          }
        };
    urlColumn.setSortable(true);

    ColumnSortEvent.ListHandler<ArtifactReference> sortHandler =
        new ColumnSortEvent.ListHandler<ArtifactReference>(dataProvider.getList());
    sortHandler.setComparator(nameColumn, createColumnCommparator(nameColumn));
    sortHandler.setComparator(urlColumn, createColumnCommparator(urlColumn));

    table.addColumn(nameColumn, "Name");
    table.addColumn(urlColumn, "URL");
    table.addColumnSortHandler(sortHandler);

    table.addColumnSortHandler(sortHandler);
    table.getColumnSortList().push(urlColumn);
    table.getColumnSortList().push(nameColumn);
  }
  @Override
  protected void createColumns(
      DefaultCellTable<Transformer> table, ListDataProvider<Transformer> dataProvider) {
    TextColumn<Transformer> fromColumn =
        new TextColumn<Transformer>() {
          @Override
          public String getValue(Transformer transform) {
            return transform.getFrom();
          }
        };
    fromColumn.setSortable(true);

    TextColumn<Transformer> toColumn =
        new TextColumn<Transformer>() {
          @Override
          public String getValue(Transformer transform) {
            return transform.getTo();
          }
        };
    toColumn.setSortable(true);

    TextColumn<Transformer> typeColumn =
        new TextColumn<Transformer>() {
          @Override
          public String getValue(Transformer transform) {
            return transform.getType();
          }
        };
    typeColumn.setSortable(true);

    ColumnSortEvent.ListHandler<Transformer> sortHandler =
        new ColumnSortEvent.ListHandler<Transformer>(dataProvider.getList());
    sortHandler.setComparator(fromColumn, createColumnCommparator(fromColumn));
    sortHandler.setComparator(toColumn, createColumnCommparator(toColumn));
    sortHandler.setComparator(typeColumn, createColumnCommparator(typeColumn));

    table.addColumn(fromColumn, "From");
    table.addColumn(toColumn, "To");
    table.addColumn(typeColumn, "Type");

    table.addColumnSortHandler(sortHandler);
    table.getColumnSortList().push(typeColumn);
    table.getColumnSortList().push(toColumn);
    table.getColumnSortList().push(fromColumn);

    table.setWidth("100%", false);
    table.setColumnWidth(fromColumn, 45, Style.Unit.PCT);
    table.setColumnWidth(toColumn, 45, Style.Unit.PCT);
    table.setColumnWidth(typeColumn, 10, Style.Unit.PCT);
  }
Exemplo n.º 3
0
  private void createDataGrid() {
    dataGrid = new DataGrid<InputItem>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<InputItem>(KEY_PROVIDER);
    dataGrid.setSelectionModel(selectionModel);

    recordStore = new ListDataProvider<InputItem>(KEY_PROVIDER);
    recordStore.addDataDisplay(dataGrid);

    sortHandler = new ColumnSortEvent.ListHandler<InputItem>(recordStore.getList());

    Column<InputItem, InputItem> colId = new IdentityColumn<InputItem>(ID_CELL);
    dataGrid.addColumn(colId, new ResizableHeader<InputItem>("#", dataGrid, colId));
    dataGrid.setColumnWidth(colId, 35, Style.Unit.PX);

    final EditTextCell cellName = new EditTextCell();
    Column<InputItem, String> colName =
        new Column<InputItem, String>(cellName) {
          @Override
          public String getValue(InputItem rec) {
            return rec.getName();
          }
        };
    colName.setFieldUpdater(
        new FieldUpdater<InputItem, String>() {
          @Override
          public void update(int index, InputItem rec, String value) {
            if (!value.equals(rec.getName())) {
              markChange(rec);
              rec.setName(value);
              cellName.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colName, new ResizableHeader<InputItem>("Name", dataGrid, colName));
    dataGrid.setColumnWidth(colName, 128, Style.Unit.PX);

    colName.setSortable(true);
    sortHandler.setComparator(
        colName,
        new Comparator<InputItem>() {
          @Override
          public int compare(InputItem o1, InputItem o2) {
            return o1.getName().compareTo(o2.getName());
          }
        });

    //        final SelectCell<String,Integer> cellActive = new SelectCell<String,Integer>(
    //                ZicoWidgets.<String,Integer>map("NO",0,"YES",1));
    //        Column<InputItem,Integer> colActive = new Column<InputItem, Integer>(cellActive) {
    //            @Override
    //            public Integer getValue(InputItem rec) {
    //                return rec.getActive();
    //            }
    //        };
    //        colActive.setFieldUpdater(new FieldUpdater<InputItem, Integer>() {
    //            @Override
    //            public void update(int index, InputItem rec, Integer value) {
    //                if (rec.getActive() != value) {
    //                    markChange(rec);
    //                    rec.setActive(value);
    //                    cellActive.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        dataGrid.addColumn(colActive, new ResizableHeader<InputItem>("Active", dataGrid,
    // colActive));
    //        dataGrid.setColumnWidth(colActive, 128, Style.Unit.PX);

    //        final DatePickerCell cellTstart = new DatePickerCell(ClientUtil.TSTAMP_FORMAT0);
    //        Column<InputItem,Date> colTstart = new Column<InputItem, Date>(cellTstart) {
    //            @Override
    //            public Date getValue(InputItem rec) {
    //                return ClientUtil.unix2date(rec.getTstart());
    //            }
    //        };
    //        colTstart.setFieldUpdater(new FieldUpdater<InputItem, Date>() {
    //            @Override
    //            public void update(int index, InputItem rec, Date value) {
    //                long t = ClientUtil.date2unix(value);
    //                if (t != rec.getTstart()) {
    //                    markChange(rec);
    //                    rec.setTstart(t);
    //                    cellTstart.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        colTstart.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    //        dataGrid.addColumn(colTstart, new ResizableHeader<InputItem>("TStart", dataGrid,
    // colTstart));
    //        dataGrid.setColumnWidth(colTstart, 100, Style.Unit.PX);

    //        final DatePickerCell cellTstop = new DatePickerCell(ClientUtil.TSTAMP_FORMAT0);
    //        Column<InputItem,Date> colTstop = new Column<InputItem, Date>(cellTstop) {
    //            @Override
    //            public Date getValue(InputItem rec) {
    //                return ClientUtil.unix2date(rec.getTstop());
    //            }
    //        };
    //        colTstop.setFieldUpdater(new FieldUpdater<InputItem, Date>() {
    //            @Override
    //            public void update(int index, InputItem rec, Date value) {
    //                long t = ClientUtil.date2unix(value);
    //                if (t != rec.getTstop()) {
    //                    markChange(rec);
    //                    rec.setTstop(t);
    //                    cellTstop.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        colTstop.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    //        dataGrid.addColumn(colTstop, new ResizableHeader<InputItem>("TStop", dataGrid,
    // colTstop));
    //        dataGrid.setColumnWidth(colTstop, 100, Style.Unit.PX);

    Column<InputItem, Integer> colInput =
        new Column<InputItem, Integer>(cellInput) {
          @Override
          public Integer getValue(InputItem iitem) {
            return iitem.getInputId();
          }
        };
    colInput.setFieldUpdater(
        new FieldUpdater<InputItem, Integer>() {
          @Override
          public void update(int index, InputItem rec, Integer value) {
            if (rec.getInputId() != value) {
              markChange(rec);
              rec.setInputId(value);
              cellInput.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colInput, new ResizableHeader<InputItem>("Input", dataGrid, colInput));
    dataGrid.setColumnWidth(colInput, 128, Style.Unit.PX);

    Column<InputItem, Integer> colTxForm =
        new Column<InputItem, Integer>(cellTxForm) {
          @Override
          public Integer getValue(InputItem rec) {
            return rec.getTxFormid();
          }
        };
    colTxForm.setFieldUpdater(
        new FieldUpdater<InputItem, Integer>() {
          @Override
          public void update(int index, InputItem iitem, Integer value) {
            if (iitem.getTxFormid() != value) {
              markChange(iitem);
              iitem.setTxFormid(value);
              cellTxForm.clearViewData(iitem.getId());
            }
          }
        });
    dataGrid.addColumn(colTxForm, new ResizableHeader<InputItem>("TxForm", dataGrid, colTxForm));
    dataGrid.setColumnWidth(colTxForm, 128, Style.Unit.PX);

    final EditTextCell cellComment = new EditTextCell();
    Column<InputItem, String> colComment =
        new Column<InputItem, String>(cellComment) {
          @Override
          public String getValue(InputItem rec) {
            return rec.getComment();
          }
        };
    colComment.setFieldUpdater(
        new FieldUpdater<InputItem, String>() {
          @Override
          public void update(int index, InputItem rec, String value) {
            if (!value.equals(rec.getComment())) {
              markChange(rec);
              rec.setComment(value);
              cellComment.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colComment, new ResizableHeader<InputItem>("Comment", dataGrid, colComment));

    colComment.setSortable(true);
    sortHandler.setComparator(
        colComment,
        new Comparator<InputItem>() {
          @Override
          public int compare(InputItem o1, InputItem o2) {
            return o1.getComment().compareTo(o2.getComment());
          }
        });

    dataGrid.addCellPreviewHandler(
        new CellPreviewEvent.Handler<InputItem>() {
          @Override
          public void onCellPreview(CellPreviewEvent<InputItem> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
              selectionModel.setSelected(event.getValue(), true);
              if (event.getValue() != null) {
                contextMenu.setPopupPosition(
                    event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                contextMenu.show();
              }
            }
          }
        });

    dataGrid.setKeyboardSelectionPolicy(
        HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    dataGrid.addDomHandler(
        new DoubleClickHandler() {
          @Override
          public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
          }
        },
        DoubleClickEvent.getType());
    dataGrid.addDomHandler(
        new ContextMenuHandler() {
          @Override
          public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
          }
        },
        ContextMenuEvent.getType());
  }
Exemplo n.º 4
0
  public DataObjectBrowser() {
    initWidget(uiBinder.createAndBindUi(this));

    objectButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            selectCurrentObject(true);
          }
        });

    dataObjectPropertiesProvider.setList(new ArrayList<ObjectProperty>());

    // Init data objects table

    dataObjectPropertiesTable.setEmptyTableWidget(
        new Label(Constants.INSTANCE.objectBrowser_emptyTable()));

    // Init property name column

    final TextColumn<ObjectProperty> propertyNameColumn =
        new TextColumn<ObjectProperty>() {

          @Override
          public void render(Cell.Context context, ObjectProperty object, SafeHtmlBuilder sb) {
            SafeHtml startDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "<div style=\"cursor: pointer;\">";
                  }
                };
            SafeHtml endDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "</div>";
                  }
                };

            sb.append(startDiv);
            super.render(context, object, sb);
            sb.append(endDiv);
          }

          @Override
          public String getValue(final ObjectProperty objectProperty) {
            return objectProperty.getName();
          }
        };

    propertyNameColumn.setSortable(true);
    dataObjectPropertiesTable.addColumn(
        propertyNameColumn, Constants.INSTANCE.objectBrowser_columnName());
    // dataObjectPropertiesTable.setColumnWidth(propertyNameColumn, 100, Style.Unit.PX);
    dataObjectPropertiesTable.setColumnWidth(propertyNameColumn, 30, Style.Unit.PCT);

    ColumnSortEvent.ListHandler<ObjectProperty> propertyNameColHandler =
        new ColumnSortEvent.ListHandler<ObjectProperty>(dataObjectPropertiesProvider.getList());
    propertyNameColHandler.setComparator(propertyNameColumn, new ObjectPropertyComparator("name"));
    dataObjectPropertiesTable.addColumnSortHandler(propertyNameColHandler);

    // Init property Label column

    final TextColumn<ObjectProperty> propertyLabelColumn =
        new TextColumn<ObjectProperty>() {

          @Override
          public void render(Cell.Context context, ObjectProperty object, SafeHtmlBuilder sb) {
            SafeHtml startDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "<div style=\"cursor: pointer;\">";
                  }
                };
            SafeHtml endDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "</div>";
                  }
                };

            sb.append(startDiv);
            super.render(context, object, sb);
            sb.append(endDiv);
          }

          @Override
          public String getValue(final ObjectProperty objectProperty) {
            return AnnotationValueHandler.getStringValue(
                objectProperty,
                MainDomainAnnotations.LABEL_ANNOTATION,
                MainDomainAnnotations.VALUE_PARAM);
          }
        };

    propertyLabelColumn.setSortable(true);
    dataObjectPropertiesTable.addColumn(
        propertyLabelColumn, Constants.INSTANCE.objectBrowser_columnLabel());
    dataObjectPropertiesTable.setColumnWidth(propertyLabelColumn, 30, Style.Unit.PCT);

    ColumnSortEvent.ListHandler<ObjectProperty> propertyLabelColHandler =
        new ColumnSortEvent.ListHandler<ObjectProperty>(dataObjectPropertiesProvider.getList());
    propertyNameColHandler.setComparator(
        propertyLabelColumn, new ObjectPropertyComparator("label"));
    dataObjectPropertiesTable.addColumnSortHandler(propertyLabelColHandler);

    // Init property type browsing column
    ClickableImageResourceCell typeImageCell = new ClickableImageResourceCell(true, 25);
    //        final TooltipCellDecorator<ImageResource> typeImageDecorator = new
    // TooltipCellDecorator<ImageResource>( typeImageCell );
    //        typeImageDecorator.setText(
    // Constants.INSTANCE.objectBrowser_action_goToDataObjectDefinition() );

    final Column<ObjectProperty, ImageResource> typeImageColumn =
        new Column<ObjectProperty, ImageResource>(typeImageCell) {
          @Override
          public ImageResource getValue(final ObjectProperty property) {

            if (!property.isBaseType()
                && !getDataObject().getClassName().equals(property.getClassName())
                && !getDataModel().isExternal(property.getClassName())) {
              return ImagesResources.INSTANCE.BrowseObject();
            } else {
              return null;
            }
          }
        };

    typeImageColumn.setFieldUpdater(
        new FieldUpdater<ObjectProperty, ImageResource>() {
          public void update(
              final int index, final ObjectProperty property, final ImageResource value) {

            onTypeCellSelection(property);
          }
        });

    dataObjectPropertiesTable.addColumn(typeImageColumn);

    // Init property type column
    final TextColumn<ObjectProperty> propertyTypeColumn =
        new TextColumn<ObjectProperty>() {

          @Override
          public void render(Cell.Context context, ObjectProperty object, SafeHtmlBuilder sb) {
            SafeHtml startDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "<div style=\"cursor: pointer;\">";
                  }
                };
            SafeHtml endDiv =
                new SafeHtml() {
                  @Override
                  public String asString() {
                    return "</div>";
                  }
                };

            sb.append(startDiv);
            super.render(context, object, sb);
            sb.append(endDiv);
          }

          @Override
          public String getValue(final ObjectProperty objectProperty) {
            return propertyTypeDisplay(objectProperty);
          }
        };
    propertyTypeColumn.setSortable(true);
    dataObjectPropertiesTable.addColumn(
        propertyTypeColumn, Constants.INSTANCE.objectBrowser_columnType());
    dataObjectPropertiesTable.setColumnWidth(propertyTypeColumn, 40, Style.Unit.PCT);

    // Init delete column
    final Column<ObjectProperty, String> deletePropertyColumnImg =
        new Column<ObjectProperty, String>(deleteCell) {
          @Override
          public String getValue(final ObjectProperty global) {
            return "Remove";
          }
        };

    deletePropertyColumnImg.setFieldUpdater(
        new FieldUpdater<ObjectProperty, String>() {
          public void update(final int index, final ObjectProperty property, final String value) {
            if (!isReadonly()) {
              checkAndDeleteDataObjectProperty(property, index);
            }
          }
        });

    dataObjectPropertiesTable.addColumn(deletePropertyColumnImg);

    ColumnSortEvent.ListHandler<ObjectProperty> propertyTypeColHandler =
        new ColumnSortEvent.ListHandler<ObjectProperty>(dataObjectPropertiesProvider.getList());
    propertyTypeColHandler.setComparator(
        propertyTypeColumn, new ObjectPropertyComparator("className"));
    dataObjectPropertiesTable.addColumnSortHandler(propertyTypeColHandler);

    dataObjectPropertiesTable.getColumnSortList().push(propertyNameColumn);

    // Init the selection model
    SingleSelectionModel<ObjectProperty> selectionModel =
        new SingleSelectionModel<ObjectProperty>();
    dataObjectPropertiesTable.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {

          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            ObjectProperty selectedProperty =
                ((SingleSelectionModel<ObjectProperty>)
                        dataObjectPropertiesTable.getSelectionModel())
                    .getSelectedObject();
            notifyFieldSelected(selectedProperty);
          }
        });

    dataObjectPropertiesTable.setKeyboardSelectionPolicy(
        HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.BOUND_TO_SELECTION);

    dataObjectPropertiesTable.addCellPreviewHandler(
        new CellPreviewEvent.Handler<ObjectProperty>() {

          @Override
          public void onCellPreview(CellPreviewEvent<ObjectProperty> event) {
            if (showingObject && "click".equals(event.getNativeEvent().getType())) {
              int selectedRow = dataObjectPropertiesTable.getKeyboardSelectedRow();
              if (lastSelectedRow >= 0 && lastSelectedRow == selectedRow) {
                ObjectProperty selectedProperty =
                    dataObjectPropertiesProvider.getList().get(selectedRow);
                ((SingleSelectionModel<ObjectProperty>)
                        dataObjectPropertiesTable.getSelectionModel())
                    .setSelected(selectedProperty, true);
              }
              showingObject = false;
            }
          }
        });

    dataObjectPropertiesProvider.addDataDisplay(dataObjectPropertiesTable);
    dataObjectPropertiesProvider.refresh();

    newPropertyButton.setIcon(IconType.PLUS);

    setReadonly(true);
  }
  public Widget draw() {

    // contentWidget.setSize("100%", "100%");

    DockLayoutPanel ft = new DockLayoutPanel(Style.Unit.PX);
    contentWidget.setWidget(ft);

    final DataGrid gridTable = new DataGrid();
    gridTable.setSize("100%", "100%");

    final ArrayList<Attribute> vosList = new ArrayList<Attribute>();
    final GetAttributesV2 getVos =
        new GetAttributesV2(
            new JsonCallbackEvents() {
              public void onFinished(JavaScriptObject jso) {
                vosList.addAll(
                    new TableSorter<Attribute>()
                        .sortByAttrNameTranslation(JsonUtils.<Attribute>jsoAsList(jso)));
                gridTable.setRowData(vosList);
                gridTable.redraw();
              }
            });
    getVos.getUserAttributes(3411);
    getVos.retrieveData();

    gridTable.setSelectionModel(
        new MultiSelectionModel<Attribute>(new GeneralKeyProvider<Attribute>()));
    final SelectionModel<Attribute> selectionModel = gridTable.getSelectionModel();
    gridTable.setKeyboardSelectionPolicy(
        HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);

    Column<Attribute, Boolean> checkBoxColumn =
        new Column<Attribute, Boolean>(new CheckboxCell(true, true)) {
          @Override
          public Boolean getValue(Attribute object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
          }
        };
    checkBoxColumn.setFieldUpdater(
        new FieldUpdater<Attribute, Boolean>() {
          @Override
          public void update(int i, Attribute Attribute, Boolean aBoolean) {
            selectionModel.setSelected(Attribute, aBoolean);
          }
        });

    // Checkbox column header
    CheckboxCell cb = new CheckboxCell();
    Header<Boolean> checkBoxHeader =
        new Header<Boolean>(cb) {
          public Boolean getValue() {
            return false; // return true to see a checked checkbox.
          }
        };
    checkBoxHeader.setUpdater(
        new ValueUpdater<Boolean>() {
          public void update(Boolean value) {
            // sets selected to all, if value = true, unselect otherwise
            for (Attribute obj : vosList) {
              selectionModel.setSelected(obj, value);
            }
          }
        });

    gridTable.addColumn(checkBoxColumn, checkBoxHeader, checkBoxHeader);
    gridTable.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);

    TextColumn<Attribute> idColumn =
        new TextColumn<Attribute>() {
          @Override
          public String getValue(Attribute object) {
            return String.valueOf(object.getId());
          }
        };

    if (JsonUtils.isExtendedInfoVisible()) {
      gridTable.addColumn(idColumn, "Id", "Id");
      gridTable.setColumnWidth(idColumn, "90px");
    }

    // Name column
    Column<Attribute, Attribute> nameColumn = JsonUtils.addColumn(new PerunAttributeNameCell());

    // Description column
    Column<Attribute, Attribute> descriptionColumn =
        JsonUtils.addColumn(new PerunAttributeDescriptionCell());

    // Value column
    Column<Attribute, Attribute> valueColumn =
        JsonUtils.addColumn(
            new PerunAttributeValueCell(),
            new FieldUpdater<Attribute, Attribute>() {
              public void update(int index, Attribute object, Attribute value) {
                object = value;
                selectionModel.setSelected(object, object.isAttributeValid());
              }
            });

    ColumnSortEvent.ListHandler<Attribute> columnSortHandler =
        new ColumnSortEvent.ListHandler<Attribute>(vosList);
    gridTable.addColumnSortHandler(columnSortHandler);

    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(
        nameColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_NAME));

    // Sorting description column
    descriptionColumn.setSortable(true);
    columnSortHandler.setComparator(
        descriptionColumn,
        new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_DESCRIPTION));

    // Add sorting
    gridTable.addColumnSortHandler(columnSortHandler);

    // updates the columns size
    gridTable.setColumnWidth(nameColumn, 200.0, Style.Unit.PX);
    gridTable.setColumnWidth(valueColumn, 420.0, Style.Unit.PX);

    gridTable.addColumn(nameColumn, "Name");
    gridTable.addColumn(valueColumn, "Value");
    gridTable.addColumn(descriptionColumn, "Description");

    TabMenu tabMenu = new TabMenu();

    tabMenu.addWidget(
        TabMenu.getPredefinedButton(
            ButtonType.ADD,
            "",
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent clickEvent) {
                session.getTabManager().addTabToCurrentTab(new TestDataGridTabItem(), true);
              }
            }));

    ft.addNorth(tabMenu, 50);
    ft.add(gridTable);

    return getWidget();
  }
Exemplo n.º 6
0
  public OrganismPanel() {
    initWidget(ourUiBinder.createAndBindUi(this));
    loadingDialog = new LoadingDialog("Processing ...", null, false);

    TextColumn<OrganismInfo> organismNameColumn =
        new TextColumn<OrganismInfo>() {
          @Override
          public String getValue(OrganismInfo organism) {
            return organism.getName();
          }
        };
    Column<OrganismInfo, Number> annotationsNameColumn =
        new Column<OrganismInfo, Number>(new NumberCell()) {
          @Override
          public Integer getValue(OrganismInfo object) {
            return object.getNumFeatures();
          }
        };
    Column<OrganismInfo, Number> sequenceColumn =
        new Column<OrganismInfo, Number>(new NumberCell()) {
          @Override
          public Integer getValue(OrganismInfo object) {
            return object.getNumSequences();
          }
        };

    sequenceColumn.setSortable(true);
    organismNameColumn.setSortable(true);
    annotationsNameColumn.setSortable(true);

    Annotator.eventBus.addHandler(
        OrganismChangeEvent.TYPE,
        new OrganismChangeEventHandler() {
          @Override
          public void onOrganismChanged(OrganismChangeEvent organismChangeEvent) {
            organismInfoList.clear();
            organismInfoList.addAll(MainPanel.getInstance().getOrganismInfoList());
          }
        });

    dataGrid.setLoadingIndicator(new HTML("Calculating Annotations ... "));
    dataGrid.addColumn(organismNameColumn, "Name");
    dataGrid.addColumn(annotationsNameColumn, "Annotations");
    dataGrid.addColumn(sequenceColumn, "Ref Sequences");
    dataGrid.setEmptyTableWidget(
        new Label("No organisms available. Add new organisms using the form field."));

    singleSelectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            if (!creatingNewOrganism) {
              loadOrganismInfo();
              changeButtonSelection();
            } else {
              creatingNewOrganism = false;
            }
          }
        });
    dataGrid.setSelectionModel(singleSelectionModel);

    dataProvider.addDataDisplay(dataGrid);

    dataGrid.addDomHandler(
        new DoubleClickHandler() {
          @Override
          public void onDoubleClick(DoubleClickEvent event) {
            if (singleSelectionModel.getSelectedObject() != null) {
              String orgId = singleSelectionModel.getSelectedObject().getId();
              if (!MainPanel.getInstance().getCurrentOrganism().getId().equals(orgId)) {
                OrganismRestService.switchOrganismById(orgId);
              }
            }
          }
        },
        DoubleClickEvent.getType());

    List<OrganismInfo> trackInfoList = dataProvider.getList();

    ColumnSortEvent.ListHandler<OrganismInfo> sortHandler =
        new ColumnSortEvent.ListHandler<OrganismInfo>(trackInfoList);
    dataGrid.addColumnSortHandler(sortHandler);
    sortHandler.setComparator(
        organismNameColumn,
        new Comparator<OrganismInfo>() {
          @Override
          public int compare(OrganismInfo o1, OrganismInfo o2) {
            return o1.getName().compareTo(o2.getName());
          }
        });
    sortHandler.setComparator(
        annotationsNameColumn,
        new Comparator<OrganismInfo>() {
          @Override
          public int compare(OrganismInfo o1, OrganismInfo o2) {
            return o1.getNumFeatures() - o2.getNumFeatures();
          }
        });
    sortHandler.setComparator(
        sequenceColumn,
        new Comparator<OrganismInfo>() {
          @Override
          public int compare(OrganismInfo o1, OrganismInfo o2) {
            return o1.getNumSequences() - o2.getNumSequences();
          }
        });
  }
Exemplo n.º 7
0
  private void initializeTable() {
    typeColumn =
        new TextColumn<AnnotationInfo>() {
          @Override
          public String getValue(AnnotationInfo annotationInfo) {
            String annotationTypeString = annotationInfo.getType();
            if (annotationTypeString.equals("non_canonical_five_prime_splice_site")) {
              annotationTypeString = "NC 5' splice";
            } else if (annotationTypeString.equals("non_canonical_three_prime_splice_site")) {
              annotationTypeString = "NC 3' splice";
            }
            return annotationTypeString;
          }
        };
    typeColumn.setSortable(true);

    startColumn =
        new Column<AnnotationInfo, Number>(new NumberCell()) {
          @Override
          public Integer getValue(AnnotationInfo annotationInfo) {
            return getDisplayMin(annotationInfo.getMin());
          }
        };
    startColumn.setSortable(true);

    stopColumn =
        new Column<AnnotationInfo, Number>(new NumberCell()) {
          @Override
          public Integer getValue(AnnotationInfo annotationInfo) {
            return annotationInfo.getMax();
          }
        };
    stopColumn.setSortable(true);

    lengthColumn =
        new Column<AnnotationInfo, Number>(new NumberCell()) {
          @Override
          public Integer getValue(AnnotationInfo annotationInfo) {
            return annotationInfo.getLength();
          }
        };
    lengthColumn.setSortable(true);

    dataGrid.addColumn(typeColumn, "Type");
    dataGrid.addColumn(startColumn, "Start");
    //        dataGrid.addColumn(stopColumn, "Stop");
    dataGrid.addColumn(lengthColumn, "Length");

    ColumnSortEvent.ListHandler<AnnotationInfo> sortHandler =
        new ColumnSortEvent.ListHandler<AnnotationInfo>(annotationInfoList);
    dataGrid.addColumnSortHandler(sortHandler);

    sortHandler.setComparator(
        typeColumn,
        new Comparator<AnnotationInfo>() {
          @Override
          public int compare(AnnotationInfo o1, AnnotationInfo o2) {
            return o1.getType().compareTo(o2.getType());
          }
        });

    sortHandler.setComparator(
        startColumn,
        new Comparator<AnnotationInfo>() {
          @Override
          public int compare(AnnotationInfo o1, AnnotationInfo o2) {
            return o1.getMin() - o2.getMin();
          }
        });

    sortHandler.setComparator(
        stopColumn,
        new Comparator<AnnotationInfo>() {
          @Override
          public int compare(AnnotationInfo o1, AnnotationInfo o2) {
            return o1.getMax() - o2.getMax();
          }
        });

    sortHandler.setComparator(
        lengthColumn,
        new Comparator<AnnotationInfo>() {
          @Override
          public int compare(AnnotationInfo o1, AnnotationInfo o2) {
            return o1.getLength() - o2.getLength();
          }
        });
  }