@Override
  protected void configureTable() {
    super.configureTable();

    ListGrid listGrid = getListGrid();

    ListGridField resourceNameField =
        listGrid.getField(MeasurementDataTraitCriteria.SORT_FIELD_RESOURCE_NAME);
    resourceNameField.setCellFormatter(
        new CellFormatter() {
          public String format(Object o, ListGridRecord listGridRecord, int i, int i1) {
            String url =
                LinkManager.getResourceLink(
                    listGridRecord.getAttributeAsInt(AncestryUtil.RESOURCE_ID));
            return LinkManager.getHref(url, o.toString());
          }
        });
    resourceNameField.setShowHover(true);
    resourceNameField.setHoverCustomizer(
        new HoverCustomizer() {
          public String hoverHTML(
              Object value, ListGridRecord listGridRecord, int rowNum, int colNum) {
            return AncestryUtil.getResourceHoverHTML(listGridRecord, 0);
          }
        });
    resourceNameField.setCanGroupBy(true);

    AncestryUtil.setupAncestryListGridField(listGrid);
  }
Example #2
0
  private void buildFavoriteResourcesMenu(
      Favorites favorites,
      Menu menu,
      Set<Integer> resourceIds,
      AncestryUtil.MapWrapper typesWrapper) {

    if (resourceIds.isEmpty()) {
      menu.setItems();
      return;
    }

    List<MenuItem> items = new ArrayList<MenuItem>(resourceIds.size());

    for (final Integer resourceId : resourceIds) {
      Resource resource = favorites.getResource(resourceId);
      if (null == resource) {
        // if the resource is gone just skip it
        continue;
      }

      MenuItem item = new MenuItem(resource.getName());
      item.setIcon(ImageManager.getResourceIcon(resource));

      // build a subMenu to display a disambiguated resource
      item.setAttribute(AncestryUtil.RESOURCE_ID, resourceId);
      item.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry());
      item.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper);
      Menu ancestryMenu = new Menu();
      MenuItem ancestryItem = new MenuItem(AncestryUtil.getAncestryHoverHTML(item, -1));
      ancestryItem.setEnabled(false);
      ancestryMenu.setItems(ancestryItem);
      ancestryMenu.setSubmenuDirection("left");
      ancestryMenu.setAutoWidth();
      item.setSubmenu(ancestryMenu);

      item.addClickHandler(
          new com.smartgwt.client.widgets.menu.events.ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
              CoreGUI.goToView(LinkManager.getResourceLink(resourceId));
            }
          });

      items.add(item);
    }

    menu.setCanSelectParentItems(Boolean.TRUE);
    menu.setItems(items.toArray(new MenuItem[items.size()]));
  }
  public ResourceLookupComboBoxItem(String name, String title) {
    super(name, title);
    setHint(MSG.widget_resourceSelector_selectResource());
    setShowHintInField(false);

    setOptionDataSource(new ResourceDatasource());

    ListGridField nameField = new ListGridField("name", MSG.common_title_name(), 250);
    nameField.setShowHover(true);
    nameField.setHoverCustomizer(
        new HoverCustomizer() {

          public String hoverHTML(
              Object value, ListGridRecord listGridRecord, int rowNum, int colNum) {
            return AncestryUtil.getResourceHoverHTML(listGridRecord, 0);
          }
        });

    ListGridField ancestryField =
        new ListGridField(AncestryUtil.RESOURCE_ANCESTRY, MSG.common_title_ancestry(), 300);
    // needs to use a different cell formatter than what AncestryUtil.setupAncestryListGridField
    // creates
    ancestryField.setCellFormatter(
        new CellFormatter() {
          public String format(Object o, ListGridRecord listGridRecord, int rowNum, int colNum) {
            return AncestryUtil.getAncestryValue(listGridRecord, false);
          }
        });
    AncestryUtil.setupAncestryListGridFieldHover(ancestryField);

    ListGridField descriptionField =
        new ListGridField("description", MSG.common_title_description());
    ListGridField categoryField = new ListGridField("category", MSG.common_title_category(), 60);
    ListGridField availabilityField =
        new ListGridField("currentAvailability", MSG.common_title_availability(), 55);
    availabilityField.setAlign(Alignment.CENTER);

    setPickListFields(nameField, ancestryField, descriptionField, categoryField, availabilityField);

    setValueField("id");
    setDisplayField("name");
    setPickListWidth(800);
    setTextMatchStyle(TextMatchStyle.SUBSTRING);
    setCompleteOnTab(true);
    setAddUnknownValues(false);
  }
Example #4
0
  private void buildRecentlyViewedMenu(
      Favorites favorites,
      Menu menu,
      List<Integer> recentResourceIds,
      List<Integer> recentGroupIds,
      AncestryUtil.MapWrapper typesWrapper) {

    if (recentResourceIds.isEmpty() && recentGroupIds.isEmpty()) {
      return;
    }
    List<MenuItem> items =
        new ArrayList<MenuItem>(recentResourceIds.size() + recentGroupIds.size() + 1);

    for (final Integer resourceId : recentResourceIds) {
      Resource resource = favorites.getResource(resourceId);
      if (null == resource) {
        // if the resource is gone just skip it
        continue;
      }

      MenuItem item = new MenuItem(resource.getName());
      item.setIcon(ImageManager.getResourceIcon(resource));

      // build a subMenu to display a disambiguated resource
      item.setAttribute(AncestryUtil.RESOURCE_ID, resourceId);
      item.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry());
      item.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId());
      item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper);

      Menu ancestryMenu = new Menu();
      MenuItem ancestryItem = new MenuItem(AncestryUtil.getAncestryHoverHTML(item, -1));
      ancestryItem.setEnabled(false);
      ancestryMenu.setItems(ancestryItem);
      ancestryMenu.setSubmenuDirection("left");
      ancestryMenu.setAutoWidth();
      item.setSubmenu(ancestryMenu);

      item.addClickHandler(
          new com.smartgwt.client.widgets.menu.events.ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
              CoreGUI.goToView(LinkManager.getResourceLink(resourceId));
            }
          });

      items.add(item);
    }

    if (!recentResourceIds.isEmpty() && !recentGroupIds.isEmpty()) {
      items.add(new MenuItemSeparator());
    }

    for (final Integer groupId : recentGroupIds) {
      ResourceGroupComposite groupComposite = favorites.getGroupComposite(groupId);
      if (null == groupComposite) {
        // if the resource group is gone just skip it
        continue;
      }
      final ResourceGroup group = groupComposite.getResourceGroup();

      MenuItem item = new MenuItem(String.valueOf(groupId));
      item.setTitle(group.getName());
      item.setIcon(
          ImageManager.getGroupIcon(
              group.getGroupCategory(), groupComposite.getExplicitAvailabilityType()));

      item.addClickHandler(
          new com.smartgwt.client.widgets.menu.events.ClickHandler() {
            public void onClick(MenuItemClickEvent event) {
              CoreGUI.goToView(LinkManager.getResourceGroupLink(group));
            }
          });
      items.add(item);
    }

    menu.setCanSelectParentItems(Boolean.TRUE);
    menu.setItems(items.toArray(new MenuItem[items.size()]));
  }