コード例 #1
0
 /**
  * Determine the text being shown for given panel.
  *
  * @param panel
  * @return The text shown, i18n.
  */
 public Map getHtmlCode(Panel panel) {
   PanelSession pSession = SessionManager.getPanelSession(panel);
   Map m = (Map) pSession.getAttribute(ATTR_TEXT);
   if (m != null) return m;
   HTMLText text = load(panel.getInstance());
   if (text != null) return text.getText();
   try {
     HTMLText textToCreate = new HTMLText();
     textToCreate.setPanelInstance(panel.getInstance());
     Locale[] locales = LocaleManager.lookup().getPlatformAvailableLocales();
     for (int i = 0; i < locales.length; i++) {
       Locale locale = locales[i];
       ResourceBundle i18n =
           localeManager.getBundle("org.jboss.dashboard.ui.panel.advancedHTML.messages", locale);
       textToCreate.setText(locale.getLanguage(), i18n.getString("defaultContent"));
     }
     textToCreate.save();
   } catch (Exception e) {
     log.error("Error creating empty text for panel: ", e);
   }
   text = load(panel.getInstance());
   if (text != null) return text.getText();
   log.error("Current HTML code is null for panel " + panel);
   return null;
 }
コード例 #2
0
  private List<Panel> getRegionPanels() {
    Panel[] allPanels = currentSectionRegion.getPanels();
    List<Panel> panels = new ArrayList<Panel>();

    boolean onlyOnePanel = false;
    // When a panel is maximized in region, only show it.
    for (int i = 0; i < allPanels.length; i++) {
      Panel panel = allPanels[i];
      PanelSession status = panel.getPanelSession();
      if (status.isMaximizedInRegion()) {
        PanelPermission viewPerm = PanelPermission.newInstance(panel, PanelPermission.ACTION_VIEW);
        boolean canViewPanel = getUserStatus().hasPermission(viewPerm);
        if (canViewPanel) {
          panels.add(panel);
          onlyOnePanel = true;
          break;
        }
      }
    }
    if (!onlyOnePanel)
      for (int i = 0; i < allPanels.length; i++) {
        Panel panel = allPanels[i];
        PanelPermission viewPerm = PanelPermission.newInstance(panel, PanelPermission.ACTION_VIEW);
        boolean canViewPanel = getUserStatus().hasPermission(viewPerm);
        if (canViewPanel) {
          panels.add(panel);
        }
      }

    return panels;
  }
コード例 #3
0
 public void initPanelSession(PanelSession status, HttpSession session) {
   status.setCurrentPageId(PAGE_SHOW);
 }
コード例 #4
0
  /**
   * Perform the required logic for this Formatter. Inside, the methods setAttribute and
   * renderFragment are intended to be used to generate the output and set parameters for this
   * output. Method getParameter is intended to retrieve input parameters by name.
   *
   * <p>Exceptions are to be catched inside the method, and not to be thrown, normally, formatters
   * could use a error fragment to be displayed when an error happens in displaying. But if the
   * error is unexpected, it can be wrapped inside a FormatterException.
   *
   * @param request user request
   * @param response response to the user
   * @throws org.jboss.dashboard.ui.taglib.formatter.FormatterException in case of an unexpected
   *     exception.
   */
  public void service(HttpServletRequest request, HttpServletResponse response)
      throws FormatterException {
    Panel panel = (Panel) getParameter("panel");
    PanelSession status = panel.getPanelSession();
    SectionRegion sectionRegion = panel.getSection().getSectionRegion(panel.getRegion().getId());
    boolean columnRegion = panel.getRegion().isColumnRegion();
    WorkspaceImpl workspace = NavigationManager.lookup().getCurrentWorkspace();
    boolean userIsAdmin = false;
    if (workspace != null) {
      WorkspacePermission permToCheck =
          WorkspacePermission.newInstance(workspace, WorkspacePermission.ACTION_ADMIN);
      userIsAdmin = UserStatus.lookup().hasPermission(permToCheck);
    }

    if (!userIsAdmin) return;

    PanelPermission editPanelPerm = PanelPermission.newInstance(panel, PanelPermission.ACTION_EDIT);
    boolean userCanEditPanel = UserStatus.lookup().hasPermission(editPanelPerm);

    renderFragment("movePanel");

    setAttribute("cursorStyle", "move");
    setAttribute(
        "title",
        StringEscapeUtils.escapeHtml((String) LocaleManager.lookup().localize(panel.getTitle())));
    renderFragment("menuLink");
    renderFragment("menuStart");

    setAttribute("title", LocalizeTag.getLocalizedValue(panel.getTitle(), getLang(), true));
    renderFragment("menuTitle");

    // Invalidate cache button.
    if (panel.getCacheTime() > 0)
      renderMenuOption(
          "ui.panel.refresh",
          getPanelActionLink(request, response, panel, "_invalidate-cache"),
          refreshIco,
          "R",
          panel.getCacheTime() > 0);

    if (status.isShowMode()) {
      boolean isEditModeEnabled =
          !status.isEditMode() && panel.supportsEditMode() && userCanEditPanel;
      // Edit button.
      if (isEditModeEnabled)
        renderMenuOption(
            "ui.panel.editMode",
            getPanelActionLink(request, response, panel, "_edit-mode"),
            editModeIco,
            "L",
            isEditModeEnabled);
    } else {
      // Show mode.
      renderMenuOption(
          "ui.panel.showMode",
          getPanelActionLink(request, response, panel, "_show-mode"),
          showModeIco,
          "S",
          !status.isShowMode());
    }
    // Properties mode
    renderMenuOption(
        "ui.panel.editProperties",
        getPanelActionLink(request, response, panel, "_start-config"),
        propertiesModeIco,
        "P",
        true);

    // Close button
    renderFragment("menuSeparator");
    renderMenuOption(
        "ui.panel.close",
        getPanelActionLink(request, response, panel, "_close"),
        eraseIco,
        "D",
        true,
        false);

    // Help mode
    renderMenuOption(
        "ui.panel.helpMode",
        getPanelActionLink(request, response, panel, "_help-mode"),
        helpModeIco,
        "?",
        !status.isHelpMode() && panel.supportsHelpMode());

    setAttribute("imageKey", closeIco);
    renderFragment("menuEnd");
  }