Exemplo n.º 1
0
  /**
   * LocatorIds need to be repeatable and non-duplicated. The natural key for a portlet is the Id
   * but the Id is not a good locatorId as it may change (it's a sequence generated id) on
   * subsequent test runs. A portlet has an internal identifier (portletKey) and a name, but the
   * key-name tuple is not guaranteed to be unique as multiple instances of the same portlet type
   * may be present on the same, or across multiple dashboards. There is one tuple that is
   * guaranteed unique and useful for a repeatable locator Id: DashBoard-Position. This means that
   * the on a single dashboard each portlet has a unique column-columnIndex pair. Although portlets
   * can move, and the positions can change at runtime, it's still valid for a locatorId because it
   * is unique and repeatable for test purposes. We also add the portletKey for an easier visual
   * cue. The portalLayout's locatorId already incorporates the dashboardName, so we need only
   * extend it with the positioning information.
   *
   * @param portalLayout
   * @param dashboardPortlet
   * @return The locatorId for the portlet. Form PortleyKey_DashboardId_Column_ColumnIndex
   */
  private String getPortletLocatorId(PortalLayout portalLayout, DashboardPortlet dashboardPortlet) {
    StringBuilder locatorId = new StringBuilder(dashboardPortlet.getPortletKey());
    locatorId.append("_");
    locatorId.append(dashboardPortlet.getColumn());
    locatorId.append("_");
    locatorId.append(dashboardPortlet.getIndex());

    return portalLayout.extendLocatorId(locatorId.toString());
  }
Exemplo n.º 2
0
  private void loadPortletWindows() {

    for (int i = 0; i < storedDashboard.getColumns(); i++) {
      for (DashboardPortlet storedPortlet : storedDashboard.getPortlets(i)) {
        String locatorId = getPortletLocatorId(portalLayout, storedPortlet);

        PortletWindow portletWindow = new PortletWindow(locatorId, this, storedPortlet, context);
        portletWindow.setTitle(storedPortlet.getName());
        portletWindow.setHeight(storedPortlet.getHeight());
        portletWindow.setVisible(true);

        portletWindows.add(portletWindow);
        portalLayout.addPortletWindow(portletWindow, i);
      }
    }
  }
Exemplo n.º 3
0
  protected void addPortlet(String portletKey, String portletName) {
    DashboardPortlet storedPortlet = new DashboardPortlet(portletName, portletKey, 250);
    storedDashboard.addPortlet(storedPortlet);

    String locatorId = getPortletLocatorId(portalLayout, storedPortlet);
    final PortletWindow newPortletWindow =
        new PortletWindow(locatorId, this, storedPortlet, context);
    newPortletWindow.setTitle(portletName);
    newPortletWindow.setHeight(350);
    newPortletWindow.setVisible(false);

    portletWindows.add(newPortletWindow);
    portalLayout.addPortletWindow(newPortletWindow, storedPortlet.getColumn());
    PortalColumn portalColumn = portalLayout.getPortalColumn(storedPortlet.getColumn());

    // also insert a blank spacer element, which will trigger the built-in
    //  animateMembers layout animation
    final LayoutSpacer placeHolder = new LayoutSpacer();
    //        placeHolder.setRect(newPortlet.getRect());
    portalColumn.addMember(placeHolder); // add to top

    // create an outline around the clicked button
    final Canvas outline = new Canvas();
    outline.setLeft(editForm.getAbsoluteLeft() + addPortlet.getLeft());
    outline.setTop(editForm.getAbsoluteTop());
    outline.setWidth(addPortlet.getWidth());
    outline.setHeight(addPortlet.getHeight());
    outline.setBorder("2px solid 8289A6");
    outline.draw();
    outline.bringToFront();

    outline.animateRect(
        newPortletWindow.getPageLeft(),
        newPortletWindow.getPageTop(),
        newPortletWindow.getVisibleWidth(),
        newPortletWindow.getViewportHeight(),
        new AnimationCallback() {
          public void execute(boolean earlyFinish) {
            // callback at end of animation - destroy placeholder and outline; show the new portlet
            placeHolder.destroy();
            outline.destroy();
            newPortletWindow.show();
          }
        },
        750);
    save();
  }
 public Integer[] extractFilterResourceIds(
     DashboardPortlet storedPortlet, Integer[] filterResourceIds) {
   PropertyList propertyList =
       storedPortlet.getConfiguration().getList("alert-range-resource-ids");
   if ((propertyList != null)
       && (propertyList.getList() != null)
       && (!propertyList.getList().isEmpty())
       && (propertyList.getList().get(0) != null)) {
     Property container = propertyList.getList().get(0);
     if (container instanceof PropertyList) {
       PropertyList anotherList = (PropertyList) container;
       if (anotherList.getList() != null) {
         filterResourceIds = new Integer[anotherList.getList().size()];
         int index = 0;
         for (Property p : anotherList.getList()) {
           filterResourceIds[index++] = ((PropertySimple) p).getIntegerValue();
         }
       }
     }
   }
   return filterResourceIds;
 }
Exemplo n.º 5
0
  /**
   * This is an enhanced equals for portlets that allows equality for unpersisted portlets. At times (like addPortlet)
   * a portlet may have been associated with its window prior to being persisted. In this case we can consider
   * it equal if it is associated with the same dashboard(1) and has the same positioning. Note that key-name pairing
   * can not be used for equality as a dashboard is allowed to have the same portlet multiple times, with a default
   * name.  But they can not hold the same position.
   * <pre>
   *   (1) Even the dashboard comparison has been made flexible. To allow for lazy persist of the dashboard (to
   *       allow for the default group or resource dashboard to not be persisted) we allow the dash comparison
   *       to be done by name if an entity id is 0.  This should be safe as dashboard names are set prior to
   *       persist, and should be unique for the session user.
   *
   * @param storedPortlet
   * @param updatedPortlet
   * @return
   */
  private boolean equalsDashboardPortlet(
      DashboardPortlet storedPortlet, DashboardPortlet updatedPortlet) {

    if (storedPortlet.equals(updatedPortlet)) {
      return true;
    }

    // make sure at least one portlet is not persisted for pseudo-equality
    if (storedPortlet.getId() > 0 && updatedPortlet.getId() > 0) {
      return false;
    }

    // must match position for pseudo-equality
    if (storedPortlet.getColumn() != updatedPortlet.getColumn()) {
      return false;
    }

    if (storedPortlet.getIndex() != updatedPortlet.getIndex()) {
      return false;
    }

    // must match dash (ids if persisted, otherwise name) for pseudo-equality
    boolean unpersistedDash =
        (storedPortlet.getDashboard().getId() == 0 || updatedPortlet.getDashboard().getId() == 0);
    boolean dashMatchId =
        (!unpersistedDash
            && (storedPortlet.getDashboard().getId() == updatedPortlet.getDashboard().getId()));
    boolean dashMatchName =
        (unpersistedDash
            && storedPortlet
                .getDashboard()
                .getName()
                .equals(updatedPortlet.getDashboard().getName()));
    if (!(dashMatchId || dashMatchName)) {
      return false;
    }

    return true;
  }