Beispiel #1
0
 public void updateRefreshMenu() {
   if (refreshMenuItems != null) {
     int retrievedRefreshInterval = REFRESH1_VALUE;
     if (null != UserSessionManager.getUserPreferences()) {
       retrievedRefreshInterval = UserSessionManager.getUserPreferences().getPageRefreshInterval();
     }
     String currentSelection = refreshMenuMappings.get(retrievedRefreshInterval);
     if (currentSelection != null) {
       // iterate over menu items and update icon details
       for (int i = 0; i < refreshMenuItems.length; i++) {
         MenuItem menu = refreshMenuItems[i];
         if (currentSelection.equals(menu.getTitle())) {
           menu.setIcon(ImageManager.getAvailabilityIcon(true));
         } else {
           menu.setIcon("");
         }
         refreshMenuItems[i] = menu;
       }
       // update the menu
       refreshMenuButton.getMenu().setItems(refreshMenuItems);
     }
   }
   if (this.refreshMenuButton != null) {
     this.refreshMenuButton.markForRedraw();
   }
 }
Beispiel #2
0
  private void activeSavedSearchByIdOrName(Integer savedSearchId, String savedSearchName) {
    Subject subject = UserSessionManager.getSessionSubject();
    SavedSearchCriteria criteria = new SavedSearchCriteria();
    criteria.addFilterSubjectId(subject.getId());
    criteria.addFilterId(savedSearchId); // null OK
    criteria.addFilterName(savedSearchName); // null OK

    GWTServiceLookup.getSearchService()
        .findSavedSearchesByCriteria(
            criteria,
            new AsyncCallback<List<SavedSearch>>() {
              @Override
              public void onFailure(Throwable caught) {
                CoreGUI.getErrorHandler().handleError("Failure to select saved search", caught);
              }

              @Override
              public void onSuccess(List<SavedSearch> results) {
                if (results.size() != 1) {
                  CoreGUI.getMessageCenter()
                      .notify(new Message("Error selecting saved search", Severity.Error));
                } else {
                  SavedSearch savedSearch = results.get(0);
                  activateSavedSearch(savedSearch);
                }
              }
            });
  }
Beispiel #3
0
  private void createSavedSearch(final String name, final String pattern) {
    Subject subject = UserSessionManager.getSessionSubject();
    SavedSearch newSavedSearch = new SavedSearch(searchSubsystem, name, pattern, subject);
    GWTServiceLookup.getSearchService()
        .createSavedSearch(
            newSavedSearch,
            new AsyncCallback<Integer>() {
              @Override
              public void onSuccess(Integer newSavedSearchId) {
                currentSearchId = newSavedSearchId;
              }

              @Override
              public void onFailure(Throwable caught) {}
            });
  }
  public void executeFetch(final DSRequest request, final DSResponse response) {

    long ctime = -1;
    int maxItems = -1;
    // retrieve current portlet display settings
    if ((this.portlet != null) && (this.portlet instanceof RecentlyAddedResourcesPortlet)) {
      RecentlyAddedResourcesPortlet recentAdditionsPortlet =
          (RecentlyAddedResourcesPortlet) this.portlet;
      if (recentAdditionsPortlet != null) {
        if (getMaximumRecentlyAddedToDisplay() > 0) {
          maxItems = getMaximumRecentlyAddedToDisplay();
        }

        // define the time window
        if (getMaximumRecentlyAddedWithinHours() > 0) {
          ctime =
              System.currentTimeMillis()
                  - (getMaximumRecentlyAddedWithinHours() * MeasurementUtility.HOURS);
          setOldestDate(ctime);
        }
      }
    }

    // TODO: spinder: revisit this later. ResourceCriteria mechanism does not work. Not sure if it's
    // better?
    //        ResourceCriteria c = new ResourceCriteria();
    //
    //        String p = request.getCriteria().getAttribute("parentId");
    //
    //        if (p == null) {
    //            c.addFilterResourceCategory(ResourceCategory.PLATFORM);
    //            c.fetchChildResources(true);
    //        } else {
    //            c.addFilterParentResourceId(Integer.parseInt(p));
    //        }

    // TODO GH: Enhance resourceCriteria query to support itime based filtering for
    // "Recently imported" resources

    // if logged in then proceed making server side calls
    if (UserSessionManager.isLoggedIn()) {
      GWTServiceLookup.getResourceService()
          .findRecentlyAddedResources(
              ctime,
              maxItems,
              new AsyncCallback<List<RecentlyAddedResourceComposite>>() {
                public void onFailure(Throwable throwable) {
                  CoreGUI.getErrorHandler()
                      .handleError(MSG.view_portlet_recentlyAdded_error1(), throwable);
                }

                public void onSuccess(List<RecentlyAddedResourceComposite> recentlyAddedList) {
                  List<RecentlyAddedResourceComposite> list =
                      new ArrayList<RecentlyAddedResourceComposite>();

                  for (RecentlyAddedResourceComposite recentlyAdded : recentlyAddedList) {
                    list.add(recentlyAdded);
                    list.addAll(recentlyAdded.getChildren());
                  }

                  response.setData(buildNodes(list));
                  response.setTotalRows(list.size());
                  processResponse(request.getRequestId(), response);
                }
              });
    } else { //
      Log.debug("user is not logged in. Not fetching recently added resource now.");
      // answer the datasource
      response.setTotalRows(0);
      processResponse(request.getRequestId(), response);
    }
  }
Beispiel #5
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;
  }
  protected Dashboard getDefaultDashboard() {
    Subject sessionSubject = UserSessionManager.getSessionSubject();
    Resource resource = resourceComposite.getResource();

    Dashboard dashboard = new Dashboard();

    dashboard.setName(DASHBOARD_NAME_PREFIX + sessionSubject.getId() + "_" + resource.getId());
    dashboard.setCategory(DashboardCategory.RESOURCE);
    dashboard.setResource(resource);
    dashboard.setColumns(2);

    // TODO, add real portlets
    // set leftmost column and let the rest be equally divided
    dashboard.setColumnWidths("40%");
    dashboard.getConfiguration().put(new PropertySimple(Dashboard.CFG_BACKGROUND, "#F1F2F3"));

    // figure out which portlets to display and how
    HashMap<String, String> resKeyNameMap =
        DashboardView.processPortletNameMapForResource(resourceComposite);
    int colLeft = 0;
    int colRight = 1;
    int rowLeft = 0;
    int rowRight = 0;
    // Left Column
    if (resKeyNameMap.containsKey(
        ResourceMetricsPortlet.KEY)) { // measurments top left if available
      DashboardPortlet measurements =
          new DashboardPortlet(ResourceMetricsPortlet.NAME, ResourceMetricsPortlet.KEY, 220);
      dashboard.addPortlet(measurements, colLeft, rowLeft++);
      resKeyNameMap.remove(ResourceMetricsPortlet.KEY);
    }

    // right Column(approx 60%. As larger more room to display table and N rows.)
    if (resKeyNameMap.containsKey(ResourceAlertsPortlet.KEY)) { // alerts top right if available
      DashboardPortlet alerts =
          new DashboardPortlet(ResourceAlertsPortlet.NAME, ResourceAlertsPortlet.KEY, 220);
      dashboard.addPortlet(alerts, colRight, rowRight++);
      resKeyNameMap.remove(ResourceAlertsPortlet.KEY);
    }
    if (resKeyNameMap.containsKey(ResourceOperationsPortlet.KEY)) { // operations if available
      DashboardPortlet ops =
          new DashboardPortlet(ResourceOperationsPortlet.NAME, ResourceOperationsPortlet.KEY, 220);
      dashboard.addPortlet(ops, colRight, rowRight++);
      resKeyNameMap.remove(ResourceOperationsPortlet.KEY);
    }
    if (resKeyNameMap.containsKey(
        ResourceConfigurationUpdatesPortlet.KEY)) { // configuration if available
      DashboardPortlet ops =
          new DashboardPortlet(
              ResourceConfigurationUpdatesPortlet.NAME,
              ResourceConfigurationUpdatesPortlet.KEY,
              220);
      dashboard.addPortlet(ops, colRight, rowRight++);
      resKeyNameMap.remove(ResourceConfigurationUpdatesPortlet.KEY);
    }

    // Fill out left column(typically smaller portlets) then alternate cols with remaining
    boolean displayLeft = false;
    for (String key : resKeyNameMap.keySet()) {
      DashboardPortlet portlet = new DashboardPortlet(resKeyNameMap.get(key), key, 100);
      if (rowLeft < 4) {
        dashboard.addPortlet(portlet, colLeft, rowLeft++);
      } else { // alternate
        if (!displayLeft) {
          dashboard.addPortlet(portlet, colRight, rowRight++);
        } else {
          dashboard.addPortlet(portlet, colLeft, rowLeft++);
        }
        // toggle
        displayLeft = !displayLeft;
      }
    }

    return dashboard;
  }