@Override
  protected void onInit() {

    // To properly filter Create Child and Import menus we need existing singleton child resources.
    // If the
    // user has create permission and the parent type has singleton child types and creatable or
    // importable child
    // types, perform an async call to fetch the singleton children. If we make the async call don't
    // declare this
    // instance initialized until after it completes as we must have the children before the menu
    // buttons can be drawn.

    final Resource parentResource = parentResourceComposite.getResource();
    ResourceType parentType = parentResource.getResourceType();
    creatableChildTypes = getCreatableChildTypes(parentType);
    importableChildTypes = getImportableChildTypes(parentType);
    hasCreatableTypes = !creatableChildTypes.isEmpty();
    hasImportableTypes = !importableChildTypes.isEmpty();
    refreshSingletons(
        parentResource,
        new AsyncCallback<PageList<Resource>>() {

          public void onFailure(Throwable caught) {
            ResourceCompositeSearchView.super.onInit();
            initialized = true;
          }

          public void onSuccess(PageList<Resource> result) {
            ResourceCompositeSearchView.super.onInit();
            initialized = true;
          }
        });
  }
  private void setDashboard(Dashboard dashboard) {
    Canvas[] members = getMembers();
    removeMembers(members);
    // pass in the resource information
    dashboardView =
        new DashboardView(
            extendLocatorId(dashboard.getName()),
            this,
            dashboard,
            EntityContext.forResource(resourceComposite.getResource().getId()),
            resourceComposite);
    addMember(dashboardView);

    footer = new LocatableToolStrip(extendLocatorId("Footer"));
    footer.setPadding(5);
    footer.setWidth100();
    footer.setMembersMargin(15);

    editButton =
        new LocatableIButton(
            footer.extendLocatorId("Mode"),
            editMode ? MSG.common_title_view_mode() : MSG.common_title_edit_mode());
    editButton.setAutoFit(true);
    editButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent clickEvent) {
            editMode = !editMode;
            editButton.setTitle(
                editMode ? MSG.common_title_view_mode() : MSG.common_title_edit_mode());
            dashboardView.setEditMode(editMode);
          }
        });

    resetButton = new LocatableIButton(footer.extendLocatorId("Reset"), MSG.common_button_reset());
    resetButton.setAutoFit(true);
    resetButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent clickEvent) {
            String message = MSG.view_summaryDashboard_resetConfirm();

            SC.ask(
                message,
                new BooleanCallback() {
                  public void execute(Boolean confirmed) {
                    if (confirmed) {
                      dashboardView.delete();
                      setDashboard(getDefaultDashboard());
                      markForRedraw();
                    }
                  }
                });
          }
        });

    footer.addMember(editButton);
    footer.addMember(resetButton);

    addMember(footer);
  }
 public static ResourceCompositeSearchView getChildrenOf(
     ResourceComposite parentResourceComposite) {
   return new ResourceCompositeSearchView(
       parentResourceComposite,
       new Criteria("parentId", String.valueOf(parentResourceComposite.getResource().getId())),
       MSG.view_tabs_common_child_resources(),
       null);
 }
예제 #4
0
  /** Return the relevant sorted value map for the resource */
  public static LinkedHashMap<String, String> processPortletNameMapForResource(
      ResourceComposite composite) {

    LinkedHashMap<String, String> resourceMenuMap = PortletFactory.getResourcePortletMenuMap();

    if ((composite != null) && (composite.getResource() != null)) {
      resourceMenuMap = new LinkedHashMap<String, String>(resourceMenuMap);

      // filter out portlets not relevent for facets
      Set<ResourceTypeFacet> facets = composite.getResourceFacets().getFacets();
      if (!facets.isEmpty()) {
        // Operation related portlets
        if (!facets.contains(ResourceTypeFacet.OPERATION)) {
          resourceMenuMap.remove(ResourceOperationsPortlet.KEY);
        }
        // MEASUREMENT related portlets(METRICS)
        if (!facets.contains(ResourceTypeFacet.MEASUREMENT)) {
          resourceMenuMap.remove(ResourceMetricsPortlet.KEY);
          resourceMenuMap.remove(ResourceMetricsPortlet.KEY);
        }
        // Content related portlets
        if (!facets.contains(ResourceTypeFacet.CONTENT)) {
          resourceMenuMap.remove(ResourcePkgHistoryPortlet.KEY);
        }
        // Event related portlets
        if (!facets.contains(ResourceTypeFacet.EVENT)) {
          resourceMenuMap.remove(ResourceEventsPortlet.KEY);
        }
        // Configuration related portlets
        if (!facets.contains(ResourceTypeFacet.CONFIGURATION)) {
          resourceMenuMap.remove(ResourceConfigurationUpdatesPortlet.KEY);
        }
        // Bundle related portlets
        if (!facets.contains(ResourceTypeFacet.BUNDLE)) {
          resourceMenuMap.remove(ResourceBundleDeploymentsPortlet.KEY);
        }
      }
    }

    return resourceMenuMap;
  }
  @Override
  public void refresh() {
    refreshSingletons(
        parentResourceComposite.getResource(),
        new AsyncCallback<PageList<Resource>>() {

          @Override
          public void onSuccess(PageList<Resource> result) {
            addImportAndCreateButtons(true);
            ResourceCompositeSearchView.super.refresh();
          }

          @Override
          public void onFailure(Throwable caught) {
            ResourceCompositeSearchView.super.refresh();
          }
        });
  }
  @SuppressWarnings("unchecked")
  private void addImportAndCreateButtons(boolean override) {

    final Resource parentResource = parentResourceComposite.getResource();

    // Create Child Menu and Manual Import Menu
    if (canCreate && (hasCreatableTypes || hasImportableTypes)) {
      if (hasCreatableTypes) {
        Map<String, ResourceType> displayNameMap = getDisplayNames(creatableChildTypes);
        LinkedHashMap<String, ResourceType> createTypeValueMap =
            new LinkedHashMap<String, ResourceType>(displayNameMap);
        removeExistingSingletons(singletonChildren, createTypeValueMap);
        AbstractTableAction createAction =
            new AbstractTableAction(TableActionEnablement.ALWAYS) {
              public void executeAction(ListGridRecord[] selection, Object actionValue) {
                ResourceFactoryCreateWizard.showCreateWizard(
                    parentResource, (ResourceType) actionValue);
                // we can refresh the table buttons immediately since the wizard is a dialog, the
                // user can't access enabled buttons anyway.
                ResourceCompositeSearchView.this.refreshTableInfo();
              }
            };
        if (override) {
          updateTableAction(MSG.common_button_create_child(), createTypeValueMap, createAction);
        } else {
          addTableAction(MSG.common_button_create_child(), null, createTypeValueMap, createAction);
        }
      }

      if (hasImportableTypes) {
        Map<String, ResourceType> displayNameMap = getDisplayNames(importableChildTypes);
        LinkedHashMap<String, ResourceType> importTypeValueMap =
            new LinkedHashMap<String, ResourceType>(displayNameMap);
        removeExistingSingletons(singletonChildren, importTypeValueMap);
        AbstractTableAction importAction =
            new AbstractTableAction(TableActionEnablement.ALWAYS) {
              public void executeAction(ListGridRecord[] selection, Object actionValue) {
                ResourceFactoryImportWizard.showImportWizard(
                    parentResource, (ResourceType) actionValue);
                // we can refresh the table buttons immediately since the wizard is a dialog, the
                // user can't access enabled buttons anyway.
                ResourceCompositeSearchView.this.refreshTableInfo();
              }
            };
        if (override) {
          updateTableAction(MSG.common_button_import(), importTypeValueMap, importAction);
        } else {
          addTableAction(MSG.common_button_import(), null, importTypeValueMap, importAction);
        }
      }

    } else if (!override) {
      if (!canCreate && hasCreatableTypes) {
        addTableAction(
            MSG.common_button_create_child(),
            new AbstractTableAction(TableActionEnablement.NEVER) {
              public void executeAction(ListGridRecord[] selection, Object actionValue) {
                // never called
              }
            });
      }
      if (!canCreate && hasImportableTypes) {
        addTableAction(
            MSG.common_button_import(),
            new AbstractTableAction(TableActionEnablement.NEVER) {
              public void executeAction(ListGridRecord[] selection, Object actionValue) {
                // never called
              }
            });
      }
    }
  }
  public ResourceOperationHistoryListView(String locatorId, ResourceComposite resourceComposite) {
    super(locatorId, null, EntityContext.forResource(resourceComposite.getResource().getId()));

    this.resourceComposite = resourceComposite;
  }
  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;
  }