public void service(HttpServletRequest request, HttpServletResponse response)
     throws FormatterException {
   renderFragment("outputStart");
   renderFragment("workspacesSelect");
   if (getNavigationManager().isAdminBarVisible())
     try {
       Workspace currentWorkspace = getNavigationManager().getCurrentWorkspace();
       BackOfficePermission createPerm =
           BackOfficePermission.newInstance(null, BackOfficePermission.ACTION_CREATE_WORKSPACE);
       WorkspacePermission editPerm =
           WorkspacePermission.newInstance(currentWorkspace, WorkspacePermission.ACTION_EDIT);
       WorkspacePermission deletePerm =
           WorkspacePermission.newInstance(currentWorkspace, WorkspacePermission.ACTION_DELETE);
       boolean canAddWorkspace = getUserStatus().hasPermission(createPerm);
       if (canAddWorkspace) {
         renderFragment("createNewButton");
       }
       if (getUserStatus().hasPermission(editPerm)) {
         renderFragment("editButton");
       }
       if (UIServices.lookup().getWorkspacesManager().getAvailableWorkspacesIds().size() > 1
           && getUserStatus().hasPermission(deletePerm)) {
         renderFragment("deleteButton");
       }
       if (canAddWorkspace) {
         renderFragment("duplicateButton");
       }
     } catch (Exception e) {
       throw new FormatterException(e);
     }
   renderFragment("outputEnd");
 }
  public void actionSaveProperties(CommandRequest request) throws Exception {
    Workspace workspace = getWorkspace();
    WorkspacePermission workspacePerm =
        WorkspacePermission.newInstance(workspace, WorkspacePermission.ACTION_ADMIN);
    UserStatus.lookup().checkPermission(workspacePerm);

    resetFormStatus();

    PanelInstance instance = getPanelInstance();

    if (instance != null) {
      ((MessagesComponentHandler) Factory.lookup(messagesComponentHandler)).clearAll();
      boolean propertiesOk =
          setSystemParameters(request, instance) && setCustomParameters(request, instance);
      if (propertiesOk) {
        resetFormStatus();
        if (!closeDialog(request)) {
          ((MessagesComponentHandler) Factory.lookup(messagesComponentHandler))
              .addMessage(PROPERTIES_STORED);
        } else {
          reset();
        }
      } else {
        ((MessagesComponentHandler) Factory.lookup(messagesComponentHandler))
            .addError(PROPERTIES_NOT_STORED);
      }
    }
  }
  @Override
  public void service(HttpServletRequest request, HttpServletResponse response)
      throws FormatterException {
    currentSection = NavigationManager.lookup().getCurrentSection();
    cellspacingPanels = currentSection.getPanelsCellSpacing().intValue();
    String regionID = (String) request.getAttribute(Parameters.RENDER_IDREGION);
    currentRegion = currentSection.getLayout().getRegion(regionID);
    currentSectionRegion = currentSection.getSectionRegion(currentRegion.getId());

    regionPanels = getRegionPanels();

    panelRecommendedWidth =
        regionPanels.isEmpty()
            ? 100
            : (currentRegion.isRowRegion() ? (100 / regionPanels.size()) : 100);

    WorkspaceImpl workspace = NavigationManager.lookup().getCurrentWorkspace();

    if (workspace != null) {
      WorkspacePermission permToCheck =
          WorkspacePermission.newInstance(workspace, WorkspacePermission.ACTION_ADMIN);
      userAdmin = getUserStatus().hasPermission(permToCheck);
    }
  }
  /**
   * 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");
  }