Пример #1
0
  private void buildFavoriteGroupsMenu(Favorites favorites, Menu menu, Set<Integer> groupIds) {

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

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

    for (final Integer groupId : groupIds) {
      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.setItems(items.toArray(new MenuItem[items.size()]));
  }
Пример #2
0
  public Menu addMenu(String menuName, int width) {
    // initialise the new menu
    Menu menu = new Menu();
    menu.setTitle(menuName);
    menu.setShowShadow(true);
    menu.setShadowDepth(DEFAULT_SHADOW_DEPTH);
    menu.setWidth(width);

    Menu[] menus = new Menu[1];
    menus[0] = menu;
    menuBar.addMenus(menus, menuPosition);
    menuPosition++;

    return menu;
  }
  private void setupContextMenu() {
    userListMenu = new Menu();
    userListMenu.setCellHeight(22);

    MenuItem detailsMenuItem = new MenuItem("Show Details", "silk/application_form.png");
    detailsMenuItem.addClickHandler(
        new com.smartgwt.client.widgets.menu.events.ClickHandler() {
          public void onClick(MenuItemClickEvent event) {
            userDetailTabPane.selectTab(0);
            userDetailTabPane.updateDetails();
          }
        });

    final MenuItem editMenuItem = new MenuItem("Edit User", "demoApp/icon_edit.png");
    editMenuItem.addClickHandler(
        new com.smartgwt.client.widgets.menu.events.ClickHandler() {
          public void onClick(MenuItemClickEvent event) {
            userDetailTabPane.selectTab(1);
            userDetailTabPane.updateDetails();
          }
        });

    final MenuItem deleteMenuItem = new MenuItem("Delete User", "silk/delete.png");
    deleteMenuItem.addClickHandler(
        new com.smartgwt.client.widgets.menu.events.ClickHandler() {
          public void onClick(MenuItemClickEvent event) {

            SC.ask(
                "Delete",
                "Are you sure?",
                new BooleanCallback() {
                  public void execute(Boolean value) {
                    if (value == Boolean.TRUE) {
                      // userList.removeSelectedData();
                      userDetailTabPane.deleteDetail(
                          userList.getSelectedRecord().getAttribute("userId"));
                      userDetailTabPane.clearDetails();

                      userList.invalidateCache();
                    }
                  }
                });
          }
        });

    userListMenu.setData(detailsMenuItem, editMenuItem, deleteMenuItem);
  }
Пример #4
0
  public Menu addMenu(String menuName, int width, String menuItemNames, ClickHandler clickHandler) {
    // initialise the new menu
    Menu menu = new Menu();
    menu.setTitle(menuName);
    menu.setShowShadow(true);
    menu.setShadowDepth(DEFAULT_SHADOW_DEPTH);
    menu.setWidth(width);

    // create an array of menu item names
    String[] menuItems = process(menuItemNames);

    for (int i = 0; i < menuItems.length; i++) {
      // remove any whitespace
      String menuItemName = menuItems[i].replaceAll("\\W", "");

      if (menuItemName.contentEquals(SEPARATOR)) {
        MenuItemSeparator separator = new MenuItemSeparator();
        menu.addItem(separator);
        continue;
      }

      MenuItem menuItem = new MenuItem(menuItems[i], getIcon(menuItems[i]));
      menuItem.addClickHandler(clickHandler);
      menu.addItem(menuItem);
    }

    Menu[] menus = new Menu[1];
    menus[0] = menu;
    menuBar.addMenus(menus, menuPosition);
    menuPosition++;

    return menus[0];
  }
  private Canvas buildLocaleSelection() {
    String[] languages = {"English", "Spanish"};
    String[] languageCodes = {"en", "sp"};
    Menu localeMenu = new Menu();
    MenuItem[] menuItems = new MenuItem[languages.length];
    for (int i = 0; i < languages.length; i++) {
      MenuItem tempMenuItem = new MenuItem(languages[i]);
      menuItems[i] = tempMenuItem;
    }
    localeMenu.setData(menuItems);
    localeMenu.setShowIcons(false);

    String currentLanguage = languages[0];

    IMenuButton moduleSelectionButton = new IMenuButton(currentLanguage, localeMenu);
    moduleSelectionButton.setOverflow(Overflow.VISIBLE);
    return moduleSelectionButton;
  }
Пример #6
0
  private void createContextMenu() {

    Menu contextMenu = new Menu();

    MenuItem createItem = UIFactory.createMenuItem(ActionRegistry.NEW_FOLDER);
    createItem.setEnableIfCondition(
        new MenuItemIfFunction() {

          public boolean execute(Canvas target, Menu menu, MenuItem item) {

            IGWTFolder folder = GWTUtil.getGwtFolder((TreeNode) tree.getSelectedRecord());
            return folder.isCreateSubfolderSupported();
          }
        });

    MenuItem deleteItem = UIFactory.createMenuItem(ActionRegistry.DELETE_FOLDER);
    deleteItem.setEnableIfCondition(
        new MenuItemIfFunction() {

          public boolean execute(Canvas target, Menu menu, MenuItem item) {

            IGWTFolder folder = GWTUtil.getGwtFolder((TreeNode) tree.getSelectedRecord());
            return folder.isDeleteSupported();
          }
        });

    MenuItem emptyItem = UIFactory.createMenuItem(ActionRegistry.EMPTY_FOLDER);
    emptyItem.setEnableIfCondition(
        new MenuItemIfFunction() {

          public boolean execute(Canvas target, Menu menu, MenuItem item) {

            IGWTFolder folder = GWTUtil.getGwtFolder((TreeNode) tree.getSelectedRecord());
            return folder.isEmptySupported();
          }
        });

    contextMenu.setItems(createItem, deleteItem, emptyItem);

    this.tree.setContextMenu(contextMenu);
  }
Пример #7
0
  public Menu addSubMenu(Menu parentMenu, String subMenuName, String menuItemNames) {
    // initialise the new sub menu
    Menu menu = new Menu();
    menu.setShowShadow(true);
    menu.setShadowDepth(DEFAULT_SHADOW_DEPTH);

    MenuItem menuItem = new MenuItem(subMenuName);

    // create an array of menu item names
    String[] menuItems = process(menuItemNames);

    for (int i = 0; i < menuItems.length; i++) {
      // remove any whitespace
      String menuItemName = menuItems[i].replaceAll("\\W", "");

      if (menuItemName.contentEquals(SEPARATOR)) {
        MenuItemSeparator separator = new MenuItemSeparator();
        menu.addItem(separator);
        continue;
      }

      menuItem = new MenuItem(menuItems[i], getIcon(menuItems[i]));
      // menuItem.addClickHandler(clickHandler);
      menu.addItem(menuItem);
    }

    // add the sub menu to the menu item
    menuItem = new MenuItem(subMenuName);
    parentMenu.addItem(menuItem);
    menuItem.setSubmenu(menu);

    return menu;
  }
Пример #8
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()]));
  }
  private Canvas buildUserInfo() {
    HLayout userFields = new HLayout();
    userFields.setAlign(Alignment.RIGHT);
    userFields.addMember(buildUserImage());
    LayoutSpacer sp1 = new LayoutSpacer();
    sp1.setWidth(8);
    userFields.addMember(sp1);

    // Label userLabel = new Label(SecurityManager.USER.getUserName());
    //  userLabel.setBaseStyle("userText");
    //  userLabel.setWidth(1);
    //   userLabel.setOverflow(Overflow.VISIBLE);
    //   userFields.addMember(userLabel);

    //  userFields.addMember(buildLogoutImage());

    Menu menu = new Menu();
    menu.setShowShadow(true);
    menu.setShadowDepth(10);
    menu.setShowIcons(false);

    MenuItem logout = new MenuItem("Logout");
    MenuItem edit = new MenuItem("Edit ...");
    MenuItem changePassword = new MenuItem("Change Password ...");

    menu.setItems(edit, changePassword, logout);

    changePassword.addClickHandler(
        new com.smartgwt.client.widgets.menu.events.ClickHandler() {
          @Override
          public void onClick(MenuItemClickEvent event) {
            redirect(GWT.getHostPageBaseURL() + "blcadmin/changePassword");
          }
        });
    //        changePassword.addClickHandler(new
    // com.smartgwt.client.widgets.menu.events.ClickHandler() {
    //                    @Override
    //                    public void onClick(MenuItemClickEvent event) {
    //                        final DynamicEntityDataSource userDS = new
    // DynamicEntityDataSource(CeilingEntities.ADMIN_USER);
    //                        userDS.buildFields(null, false, new AsyncCallbackAdapter() {
    //                            public void onSetupSuccess(DataSource ds) {
    //                                //strip out password validation
    //                                userDS.getField("password").setValidators();
    //
    //                                AdminUser currentUser = SecurityManager.USER;
    //                                Record userRecord = new Record();
    //                                userRecord.setAttribute("id", currentUser.getId());
    //                                userRecord.setAttribute("login", currentUser.getUserName());
    //                                userRecord.setAttribute("_type", new
    // String[]{EntityImplementations.ADMIN_USER});
    //
    //                                EntityEditDialog ed = new EntityEditDialog();
    //
    //                                ed.editRecord("Change Password", userDS, userRecord, new
    // ItemEditedHandler() {
    //                                    public void onItemEdited(ItemEdited event) {
    //                                        String currentPage =
    // BLCLaunch.getSelectedPage(History.getToken());
    //                                        if ("User Management".equals(currentPage)) {
    //                                            buildHistoryNewItem(currentPage,
    // BLCLaunch.getSelectedModule(History.getToken()), event.getRecord().getAttribute("id"));
    //                                        }
    //                                    }
    //                                }, new String[]{"password"}, new String[]{}, false);
    //                            }
    //                        });
    //
    //                    }
    //                });

    edit.addClickHandler(
        new com.smartgwt.client.widgets.menu.events.ClickHandler() {
          @Override
          public void onClick(MenuItemClickEvent event) {
            final DynamicEntityDataSource userDS =
                new DynamicEntityDataSource(CeilingEntities.ADMIN_USER);
            userDS.buildFields(
                null,
                false,
                new AsyncCallbackAdapter() {
                  public void onSetupSuccess(DataSource ds) {
                    AdminUser currentUser = SecurityManager.USER;
                    Record userRecord = new Record();
                    userRecord.setAttribute("id", currentUser.getId());
                    userRecord.setAttribute("name", currentUser.getName());
                    userRecord.setAttribute("email", currentUser.getEmail());
                    userRecord.setAttribute("phoneNumber", currentUser.getPhoneNumber());
                    userRecord.setAttribute("login", currentUser.getUserName());
                    userRecord.setAttribute(
                        "_type", new String[] {EntityImplementations.ADMIN_USER});

                    EntityEditDialog ed = new EntityEditDialog();

                    ed.editRecord(
                        "Edit User Information",
                        userDS,
                        userRecord,
                        new ItemEditedHandler() {
                          public void onItemEdited(ItemEdited event) {
                            SecurityManager.USER.setPhoneNumber(
                                event.getRecord().getAttribute("phoneNumber"));
                            SecurityManager.USER.setName(event.getRecord().getAttribute("name"));
                            SecurityManager.USER.setEmail(event.getRecord().getAttribute("email"));
                            String currentPage = BLCLaunch.getSelectedPage(History.getToken());
                            // If we are on the user module, reload the page with the specifically
                            // edited item.
                            if ("User Management".equals(currentPage)) {
                              buildHistoryNewItem(
                                  currentPage,
                                  BLCLaunch.getSelectedModule(History.getToken()),
                                  event.getRecord().getAttribute("id"));
                            }
                          }
                        },
                        null,
                        new String[] {"login", "activeStatusFlag", "password"},
                        false);
                  }
                });
          }
        });

    logout.addClickHandler(
        new com.smartgwt.client.widgets.menu.events.ClickHandler() {
          @Override
          public void onClick(MenuItemClickEvent event) {
            UrlBuilder builder = Window.Location.createUrlBuilder();
            builder.setPath(BLCMain.webAppContext + "/adminLogout.htm");
            builder.setHash(null);
            builder.setParameter("time", String.valueOf(System.currentTimeMillis()));
            Window.open(builder.buildString(), "_self", null);
          }
        });

    IMenuButton menuButton = new IMenuButton(SecurityManager.USER.getUserName(), menu);
    menuButton.setPadding(5);
    menuButton.setChildrenSnapResizeToGrid(true);
    menuButton.setOverflow(Overflow.VISIBLE);
    userFields.addMember(menuButton);

    LayoutSpacer sp2 = new LayoutSpacer();
    sp2.setWidth(200);
    userFields.addMember(sp2);

    return userFields;
  }
Пример #10
0
  SampleSelectionWizardPageImpl(
      final LocationFactory locationFactory,
      final TreeComponentFactory treeComponentFactory,
      final boolean showMudpit,
      final List<IdentificationType> validAnalysisTypes) {
    this.locationFactory = locationFactory;
    this.treeComponentFactory = treeComponentFactory;
    this.showMudpit = showMudpit;
    this.validAnalysisTypes = validAnalysisTypes;

    setCanFinishEarly(true);
    setTitle(CONSTANTS.scaffoldWizardSampleTitle());
    setDescription(CONSTANTS.scaffoldWizardSampleDescription());

    // Setup Data Source

    final DataSourceField nameField = SmartUtils.getFieldBuilder("Name").editable().get();
    final DataSourceField categoryField = SmartUtils.getFieldBuilder("Category").editable().get();
    DataSourceItemBuilder mudpitFieldBuilder =
        SmartUtils.getFieldBuilder("Mudpit").editable().withWidth("100");
    if (showMudpit) {
      mudpitFieldBuilder.checkbox();
    } else {
      mudpitFieldBuilder.hidden();
    }
    final DataSourceField mudpitField = mudpitFieldBuilder.get();
    final DataSourceField idField = SmartUtils.getHiddenIdField();
    dataSource = SmartUtils.newDataSourceWithFields(nameField, mudpitField, categoryField, idField);
    listGrid = new ClientListGrid(dataSource);

    // Setup list grid
    listGrid.setCanEdit(true);
    listGrid.setEditByCell(true);
    listGrid.setEditEvent(ListGridEditEvent.DOUBLECLICK);
    listGrid.setEmptyMessage("No samples to show.");

    final Menu contextMenu = new Menu();
    final MenuItem editItem =
        SmartUtils.getMenuItem(
            "Edit",
            Resources.EDIT,
            new Command() {
              public void execute() {
                editRecord(contextRecord);
              }
            });
    final MenuItem removeItem =
        SmartUtils.getMenuItem(
            "Remove",
            Resources.CROSS,
            new Command() {
              public void execute() {
                removeRecord(contextRecord);
              }
            });
    contextMenu.setItems(editItem, removeItem);
    listGrid.setContextMenu(contextMenu);
    listGrid.addCellContextClickHandler(
        new CellContextClickHandler() {
          public void onCellContextClick(final CellContextClickEvent event) {
            contextRecord = event.getRecord();
          }
        });
    listGrid.addSelectionChangedHandler(
        new SelectionChangedHandler() {
          public void onSelectionChanged(final SelectionEvent event) {
            onSelectionUpdated();
          }
        });

    final Button addButton =
        SmartUtils.getButton(
            "Add...",
            Resources.ADD,
            new Command() {
              public void execute() {
                new SampleComponentImpl();
              }
            });

    editButton =
        SmartUtils.getButton(
            "Edit...",
            Resources.EDIT,
            new Command() {
              public void execute() {
                try {
                  editRecord(listGrid.getSelectedRecord());
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }
            });

    removeButton =
        SmartUtils.getButton(
            "Remove",
            Resources.CROSS,
            new Command() {
              public void execute() {
                removeRecord(listGrid.getSelectedRecord());
              }
            });

    final ToolStrip toolStrip = new ToolStrip();
    toolStrip.setMembers(addButton, editButton, removeButton);
    toolStrip.setMargin(3);
    toolStrip.setWidth100();

    onSelectionUpdated();

    setCanvas(new VLayout());
    getCanvas().setMembers(toolStrip, listGrid);
  }
Пример #11
0
  public FavoritesButton() {
    super(CoreGUI.getMessages().favorites());

    // this is the main menu - the "favorites" button shown in the UI the user initially clicks
    favoritesMenu = new Menu();
    favoritesMenu.setSubmenuDirection("left");
    setMenu(favoritesMenu);
    setAutoFit(true);

    // these are the child menus directly under the main favorites button
    favoriteResourcesMenu = new Menu();
    favoriteGroupsMenu = new Menu();
    recentlyViewedMenu = new Menu();
    favoriteResourcesMenu.setSubmenuDirection("left");
    favoriteResourcesMenu.setAutoWidth();
    favoriteGroupsMenu.setSubmenuDirection("left");
    favoriteGroupsMenu.setAutoWidth();
    recentlyViewedMenu.setSubmenuDirection("left");
    recentlyViewedMenu.setAutoWidth();
    MenuItem favoriteResourcesMenuItem =
        new MenuItem(MSG.favorites_resources(), "Favorite_Resource_16.png");
    favoriteResourcesMenuItem.setSubmenu(favoriteResourcesMenu);
    favoriteResourcesMenu.setEmptyMessage(MSG.common_val_none());

    MenuItem favoriteGroupsMenuItem = new MenuItem(MSG.favorites_groups(), "Favorite_Group_16.png");
    favoriteGroupsMenuItem.setSubmenu(favoriteGroupsMenu);
    favoriteGroupsMenu.setEmptyMessage(MSG.common_val_none());

    MenuItem recentlyViewedMenuItem =
        new MenuItem(MSG.favorites_recentlyViewed(), "global/Recent_16.png");
    recentlyViewedMenuItem.setSubmenu(recentlyViewedMenu);
    recentlyViewedMenu.setEmptyMessage(MSG.common_val_none());

    favoritesMenu.setItems(
        favoriteResourcesMenuItem, favoriteGroupsMenuItem, recentlyViewedMenuItem);
    addClickHandler(
        new ClickHandler() {

          public void onClick(ClickEvent clickEvent) {
            // Cancel the click event. We'll call show() on the menu ourselves only if we're able to
            // load the
            // favorite Resources successfully.
            clickEvent.cancel();
            showMenu();
          }
        });
  }
Пример #12
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()]));
  }
Пример #13
0
  public void showMenu() {
    setLeft(DOM.getElementById(MenuBarView.BTN_FAV_ID).getAbsoluteLeft());
    final Set<Integer> favoriteResourceIds =
        UserSessionManager.getUserPreferences().getFavoriteResources();
    final Set<Integer> favoriteGroupIds =
        UserSessionManager.getUserPreferences().getFavoriteResourceGroups();
    final List<Integer> recentResourceIds =
        UserSessionManager.getUserPreferences().getRecentResources();
    final List<Integer> recentGroupIds =
        UserSessionManager.getUserPreferences().getRecentResourceGroups();

    // if we have no menu items at all, then show the empty menu now
    if (favoriteGroupIds.isEmpty()
        && favoriteResourceIds.isEmpty()
        && recentResourceIds.isEmpty()
        && recentGroupIds.isEmpty()) {
      favoritesMenu.showNextTo(FavoritesButton.this, "bottom");
      return;
    }

    // keep a list of all the ids we need to pull from the db. combine favs and recents to minimize
    // db round trips.
    Set<Integer> resourceIds = new HashSet<Integer>();
    Set<Integer> groupIds = new HashSet<Integer>();

    resourceIds.addAll(favoriteResourceIds);
    resourceIds.addAll(recentResourceIds);
    groupIds.addAll(favoriteGroupIds);
    groupIds.addAll(recentGroupIds);

    fetchFavorites(
        resourceIds,
        groupIds,
        new AsyncCallback<Favorites>() {

          public void onFailure(Throwable caught) {
            CoreGUI.getErrorHandler().handleError(MSG.view_dashboard_favorites_error1(), caught);
          }

          public void onSuccess(final Favorites favorites) {
            // For Ancestry we need all the resource types and ancestry resource types loaded
            HashSet<Integer> typesSet = new HashSet<Integer>();
            HashSet<String> ancestries = new HashSet<String>();
            for (Resource resource : favorites.resources) {
              typesSet.add(resource.getResourceType().getId());
              ancestries.add(resource.getAncestry());
            }

            // In addition to the types of the result resources, get the types of their ancestry
            typesSet.addAll(AncestryUtil.getAncestryTypeIds(ancestries));

            ResourceTypeRepository typeRepo = ResourceTypeRepository.Cache.getInstance();
            typeRepo.getResourceTypes(
                typesSet.toArray(new Integer[typesSet.size()]),
                new TypesLoadedCallback() {
                  @Override
                  public void onTypesLoaded(Map<Integer, ResourceType> types) {
                    // Smartgwt has issues storing a Map as a ListGridRecord attribute. Wrap it in a
                    // pojo.
                    AncestryUtil.MapWrapper typesWrapper = new AncestryUtil.MapWrapper(types);

                    // generate the menus
                    buildFavoriteResourcesMenu(
                        favorites, favoriteResourcesMenu, favoriteResourceIds, typesWrapper);
                    buildFavoriteGroupsMenu(favorites, favoriteGroupsMenu, favoriteGroupIds);
                    buildRecentlyViewedMenu(
                        favorites,
                        recentlyViewedMenu,
                        recentResourceIds,
                        recentGroupIds,
                        typesWrapper);

                    favoritesMenu.showNextTo(FavoritesButton.this, "bottom");
                  }
                });
          }
        });
  }
Пример #14
0
  private DynamicForm buildEditForm() {
    editForm = new LocatableDynamicForm(extendLocatorId("Editor"));
    editForm.setMargin(5);
    editForm.setAutoWidth();
    editForm.setNumCols(canEditName() ? 12 : 10);

    TextItem nameItem = null;
    if (dashboardContainer.supportsDashboardNameEdit()) {
      nameItem = new TextItem("name", MSG.common_title_dashboard_name());
      nameItem.setValue(storedDashboard.getName());
      nameItem.setLength(200);
      nameItem.setWrapTitle(false);
      nameItem.addBlurHandler(
          new BlurHandler() {
            public void onBlur(BlurEvent blurEvent) {
              FormItem nameItem = blurEvent.getItem();
              String name = (String) nameItem.getValue();
              String trimmedName = (name == null) ? "" : name.trim();
              if (dashboardContainer.isValidDashboardName(trimmedName)) {
                storedDashboard.setName(trimmedName);
                save();
                dashboardContainer.updateDashboardNames();
              } else {
                // TODO: i18n
                Message message =
                    new Message(
                        "There is already a dashboard named '"
                            + trimmedName
                            + "'. Please specify a name that is not already in use.",
                        Message.Severity.Error,
                        EnumSet.of(Message.Option.Transient));
                CoreGUI.getMessageCenter().notify(message);
                nameItem.setValue(storedDashboard.getName());
              }
            }
          });
    }

    final StaticTextItem numColItem = new StaticTextItem();
    numColItem.setTitle(MSG.common_title_columns());
    numColItem.setValue(storedDashboard.getColumns());

    ButtonItem addColumn = new ButtonItem("addColumn", MSG.common_title_add_column());
    addColumn.setAutoFit(true);
    addColumn.setStartRow(false);
    addColumn.setEndRow(false);

    final ButtonItem removeColumn =
        new ButtonItem("removeColumn", MSG.common_title_remove_column());
    removeColumn.setAutoFit(true);
    removeColumn.setStartRow(false);
    removeColumn.setEndRow(false);
    removeColumn.setDisabled(storedDashboard.getColumns() == 1);

    addColumn.addClickHandler(
        new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
          public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
            portalLayout.addMember(new PortalColumn());
            numColItem.setValue(storedDashboard.getColumns() + 1);
            storedDashboard.setColumns(storedDashboard.getColumns() + 1);
            removeColumn.setDisabled(storedDashboard.getColumns() == 1);
            save();
          }
        });

    removeColumn.addClickHandler(
        new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
          public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {

            Canvas[] columns = portalLayout.getMembers();
            int numColumns = columns.length;
            if (numColumns > 0) {
              PortalColumn lastColumn = (PortalColumn) columns[numColumns - 1];
              for (Canvas portletWindow : lastColumn.getMembers()) {
                storedDashboard.removePortlet(((PortletWindow) portletWindow).getStoredPortlet());
              }
              portalLayout.removeMember(lastColumn);
              numColItem.setValue(numColumns - 1);
              storedDashboard.setColumns(storedDashboard.getColumns() - 1);
              removeColumn.setDisabled(storedDashboard.getColumns() == 1);
              save();
            }
          }
        });

    // build the menu of valid portlets for this context, sorted by portlet name
    final Menu addPortletMenu = new LocatableMenu(editForm.extendLocatorId("PortletMenu"));
    LinkedHashMap<String, String> valueMap;

    switch (context.getType()) {
      case SubsystemView:
        valueMap = PortletFactory.getGlobalPortletMenuMap();
        break;

      case ResourceGroup:
        valueMap = processPortletNameMapForGroup(this.groupComposite);
        // In addition to the group-specific portlets, make the global portlets available
        valueMap.putAll(PortletFactory.getGlobalPortletMenuMap());
        break;

      case Resource:
        valueMap = processPortletNameMapForResource(this.resourceComposite);
        // In addition to the resource-specific portlets, make the global portlets available
        valueMap.putAll(PortletFactory.getGlobalPortletMenuMap());
        break;

      default:
        throw new IllegalStateException("Unsupported context [" + context + "]");
    }
    for (Iterator<String> i = valueMap.keySet().iterator(); i.hasNext(); ) {
      String portletKey = i.next();
      String portletName = valueMap.get(portletKey);
      MenuItem menuItem = new MenuItem(portletName);
      menuItem.setAttribute("portletKey", portletKey);
      addPortletMenu.addItem(menuItem);
    }

    addPortlet =
        new LocatableIMenuButton(
            editForm.extendLocatorId("AddPortlet"), MSG.common_title_add_portlet(), addPortletMenu);
    addPortlet.setIcon("[skin]/images/actions/add.png");
    addPortlet.setAutoFit(true);

    addPortletMenu.addItemClickHandler(
        new ItemClickHandler() {
          public void onItemClick(ItemClickEvent itemClickEvent) {
            String key = itemClickEvent.getItem().getAttribute("portletKey");
            String name = itemClickEvent.getItem().getTitle();
            addPortlet(key, name);
          }
        });

    CanvasItem addCanvas = new CanvasItem();
    addCanvas.setShowTitle(false);
    addCanvas.setCanvas(addPortlet);
    addCanvas.setStartRow(false);
    addCanvas.setEndRow(false);

    ColorButtonItem picker = new ColorButtonItem("colorButton", MSG.common_title_background());
    picker.setStartRow(false);
    picker.setEndRow(false);
    picker.setCurrentColor(
        storedDashboard.getConfiguration().getSimpleValue(Dashboard.CFG_BACKGROUND, "white"));
    picker.setColorSelectedHandler(
        new ColorSelectedHandler() {
          @Override
          public void onColorSelected(ColorSelectedEvent event) {
            String selectedColor = event.getColor();
            if (selectedColor != null) {
              setBackgroundColor(selectedColor);
              storedDashboard
                  .getConfiguration()
                  .put(new PropertySimple(Dashboard.CFG_BACKGROUND, selectedColor));
              save();
            }
          }
        });

    // refresh interval
    LocatableMenu refreshMenu = new LocatableMenu("AutoRefreshMenu");
    refreshMenu.setShowShadow(true);
    refreshMenu.setShadowDepth(10);
    refreshMenu.setAutoWidth();
    refreshMenu.setHeight(15);
    ClickHandler menuClick =
        new ClickHandler() {
          @Override
          public void onClick(MenuItemClickEvent event) {
            String selection = event.getItem().getTitle();
            refreshInterval = 0;
            if (selection != null) {
              if (selection.equals(STOP)) {
                refreshInterval = STOP_VALUE;
              } else if (selection.equals(REFRESH1)) {
                refreshInterval = REFRESH1_VALUE;
              } else if (selection.equals(REFRESH5)) {
                refreshInterval = REFRESH5_VALUE;
              } else if (selection.equals(REFRESH10)) {
                refreshInterval = REFRESH10_VALUE;
              } else { // unable to locate value disable refresh
                refreshInterval = STOP_VALUE; //
              }
              UserSessionManager.getUserPreferences()
                  .setPageRefreshInterval(refreshInterval, new UpdatePortletRefreshCallback());
            }
          }
        };

    String[] refreshIntervals = {STOP, REFRESH1, REFRESH5, REFRESH10};
    Integer[] refreshValues = {STOP_VALUE, REFRESH1_VALUE, REFRESH5_VALUE, REFRESH10_VALUE};
    refreshMenuMappings = new HashMap<Integer, String>();
    refreshMenuItems = new MenuItem[refreshIntervals.length];
    int retrievedRefreshInterval = REFRESH1_VALUE;
    if (null != UserSessionManager.getUserPreferences()) {
      retrievedRefreshInterval = UserSessionManager.getUserPreferences().getPageRefreshInterval();
    }
    for (int i = 0; i < refreshIntervals.length; i++) {
      MenuItem item = new MenuItem(refreshIntervals[i], "");
      item.addClickHandler(menuClick);
      refreshMenuMappings.put(refreshValues[i], refreshIntervals[i]);
      if (retrievedRefreshInterval == refreshValues[i]) {
        item.setIcon(ImageManager.getAvailabilityIcon(true));
      }
      refreshMenuItems[i] = item;
    }

    refreshMenu.setItems(refreshMenuItems);
    refreshMenuButton =
        new LocatableIMenuButton(
            "AutoRefreshButton", MSG.common_title_change_refresh_time(), refreshMenu);
    refreshMenu.setAutoHeight();
    refreshMenuButton.getMenu().setItems(refreshMenuItems);
    refreshMenuButton.setWidth(140);
    refreshMenuButton.setShowTitle(true);
    refreshMenuButton.setTop(0);
    refreshMenuButton.setIconOrientation("left");

    CanvasItem refreshCanvas = new CanvasItem();
    refreshCanvas.setShowTitle(false);
    refreshCanvas.setCanvas(refreshMenuButton);
    refreshCanvas.setStartRow(false);
    refreshCanvas.setEndRow(false);

    if (null != nameItem) {
      editForm.setItems(
          nameItem, addCanvas, numColItem, addColumn, removeColumn, picker, refreshCanvas);
    } else {
      editForm.setItems(addCanvas, numColItem, addColumn, removeColumn, picker, refreshCanvas);
    }

    updateRefreshMenu();
    this.refreshMenuButton.markForRedraw();

    markForRedraw();

    // attempt to initialize
    editForm.markForRedraw();
    markForRedraw();

    return editForm;
  }
Пример #15
0
  /**
   * Instantiates a new side nav input tree.
   *
   * @param dispatcher the dispatcher
   * @param lang
   */
  private InputQueueTree(
      final DispatchAsync dispatcher, final LangConstants lang, final EventBus eventBus) {
    this.lang = lang;
    setWidth100();
    setHeight100();
    setCustomIconProperty("icon");
    setAnimateFolderTime(100);
    setAnimateFolders(true);
    setAnimateFolderSpeed(1000);
    setNodeIcon("silk/application_view_list.png");
    setFolderIcon("silk/folder.png");
    setShowOpenIcons(true);
    setShowDropIcons(false);
    setShowSortArrow(SortArrow.CORNER);
    setShowConnectors(true);
    setShowAllRecords(true);
    setLoadDataOnDemand(true);
    setCanSort(true);
    setAutoFetchData(true);
    setShowRoot(false);
    setSelectionType(SelectionStyle.SINGLE);
    setShowRollOverCanvas(true);

    MenuItem showItem = new MenuItem(lang.show(), "icons/16/structure.png");
    final Menu showMenu = new Menu();
    showMenu.setShowShadow(true);
    showMenu.setShadowDepth(10);
    showMenu.setItems(showItem);

    createItem = new MenuItem(lang.create(), "icons/16/structure_into.png");

    final Menu editMenu = new Menu();
    editMenu.setShowShadow(true);
    editMenu.setShadowDepth(10);
    setContextMenu(editMenu);

    dispatcher.execute(
        new HasUserRightsAction(new EDITOR_RIGHTS[] {EDITOR_RIGHTS.LONG_RUNNING_PROCESS}),
        new DispatchCallback<HasUserRightsResult>() {

          @Override
          public void callback(HasUserRightsResult result) {
            canLongProcess = result.getOk()[0];
          }
        });

    addCellContextClickHandler(
        new CellContextClickHandler() {

          @Override
          public void onCellContextClick(CellContextClickEvent event) {

            ListGridRecord record = event.getRecord();
            final String path = record.getAttribute(Constants.ATTR_ID);
            if (path != null && path.length() > 1 && path.substring(1).contains("/")) {
              // String model = path.substring(1, path.substring(1).indexOf("/") + 1);
              String id = path.substring(path.substring(1).indexOf("/") + 2);
              if (id.contains("/")) {
                id = id.substring(0, id.indexOf("/"));
              }

              MenuItem quartz = new MenuItem(lang.addToScheduler(), "icons/16/clock.png");
              quartz.addClickHandler(
                  new ClickHandler() {

                    @Override
                    public void onClick(MenuItemClickEvent event) {

                      String msg = event.getMenu().getEmptyMessage(); // duplicate code
                      String model = msg.substring(0, msg.indexOf("/"));
                      String path = msg.substring(msg.indexOf("/") + 1);

                      QuartzConvertImagesAction action = new QuartzConvertImagesAction(model, path);

                      DispatchCallback<QuartzConvertImagesResult> quartzConvertCallback =
                          new DispatchCallback<QuartzConvertImagesResult>() {

                            @Override
                            public void callback(QuartzConvertImagesResult result) {
                              if (result.getNumberOfImages() != null) {
                                SC.say(
                                    result.getNumberOfImages().toString()
                                        + " images will be converted");
                              } else {
                                SC.say("No images found");
                              }
                            }
                          };

                      dispatcher.execute(action, quartzConvertCallback);
                    }
                  });

              if (record.getAttributeAsBoolean(Constants.ATTR_INGEST_INFO)) {
                MenuItem ingestInfo = new MenuItem(lang.ingestInfo(), "icons/16/export1.png");
                ingestInfo.addClickHandler(
                    new ClickHandler() {

                      @Override
                      public void onClick(MenuItemClickEvent event) {
                        getIngestInfo(path, dispatcher, eventBus);
                      }
                    });
                if (canLongProcess) {
                  editMenu.setItems(createItem, ingestInfo, quartz);
                } else {
                  editMenu.setItems(createItem, ingestInfo);
                }
              } else {
                if (canLongProcess) {
                  editMenu.setItems(createItem, quartz);
                } else {
                  editMenu.setItems(createItem);
                }
              }

              editMenu.setEmptyMessage(path.substring(1, path.length()));
              editMenu.showContextMenu();
            } else {
              showMenu.showContextMenu();
            }
          }
        });
    addShowContextMenuHandler(
        new ShowContextMenuHandler() {

          @Override
          public void onShowContextMenu(ShowContextMenuEvent event) {
            event.cancel();
          }
        });

    eventBus.addHandler(
        RefreshTreeEvent.getType(),
        new RefreshTreeEvent.RefreshTreeHandler() {

          @Override
          public void onRefreshTree(RefreshTreeEvent event) {
            if (event.getTree() == NAME_OF_TREE.INPUT_QUEUE) refreshTree();
          }
        });

    TreeGridField field1 = new TreeGridField();
    field1.setCanFilter(true);
    field1.setName(Constants.ATTR_BARCODE);
    field1.setTitle("ID");
    field1.setCellFormatter(
        new CellFormatter() {

          @Override
          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
            boolean ingestInfo = record.getAttributeAsBoolean(Constants.ATTR_INGEST_INFO);
            if (ingestInfo) {
              return record.getAttribute(Constants.ATTR_BARCODE) + HTML_TICK_CODE;

            } else {
              return record.getAttribute(Constants.ATTR_BARCODE);
            }
          }
        });
    ListGridField nameField = new ListGridField();
    nameField.setCanFilter(true);
    nameField.setName(Constants.ATTR_NAME);
    nameField.setTitle(lang.name());

    setFields(field1, nameField);
    setDataSource(new InputTreeGwtRPCDS(dispatcher, lang));
  }