예제 #1
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();
          }
        });
  }
예제 #2
0
  private Widget getMainPanel() {
    SimplePanel panel = new SimplePanel();
    panel.setWidth("100%");
    panel.setHeight("100%");

    dataGrid = new DataGrid<RuleInfo>(MAX_RULES, RuleInfo.KEY_PROVIDER);
    dataGrid.setHeight(MAIN_HEIGHT);

    Column<RuleInfo, String> columnName =
        addColumn(
            new TextCell(),
            "Rule Name",
            new GetValue<String>() {
              public String getValue(RuleInfo rule) {
                return rule.getName();
              }
            },
            null);

    Column<RuleInfo, String> ruleType =
        addColumn(
            new TextCell(),
            "Type",
            new GetValue<String>() {
              public String getValue(RuleInfo rule) {
                return rule.getType().toUpperCase();
              }
            },
            null);

    Column<RuleInfo, ImageResource> ruleEnabled =
        addColumn(
            new ImageResourceCell(),
            "Enabled",
            new GetValue<ImageResource>() {
              public ImageResource getValue(RuleInfo rule) {
                if (rule.isEnabled()) {
                  return PgStudio.Images.trueBox();
                }
                return PgStudio.Images.falseBox();
              }
            },
            null);

    Column<RuleInfo, ImageResource> instead =
        addColumn(
            new ImageResourceCell(),
            "Instead",
            new GetValue<ImageResource>() {
              public ImageResource getValue(RuleInfo rule) {
                if (rule.isInstead()) {
                  return PgStudio.Images.trueBox();
                }
                return PgStudio.Images.falseBox();
              }
            },
            null);

    dataGrid.setColumnWidth(columnName, "200px");
    dataGrid.setColumnWidth(ruleType, "120px");
    dataGrid.setColumnWidth(ruleEnabled, "100px");
    dataGrid.setColumnWidth(instead, "100px");

    ruleType.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    ruleEnabled.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
    instead.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);

    dataGrid.setLoadingIndicator(new Image(PgStudio.Images.spinner()));

    dataProvider.addDataDisplay(dataGrid);

    dataGrid.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(
        (new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {
            RuleInfo rule = selectionModel.getSelectedObject();
            ruleDef.setText(rule.getDefinition());
          }
        }));

    panel.add(dataGrid);

    return panel.asWidget();
  }