All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.workplace.CmsTabDialog Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 18.0
Show newest version
/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH & Co. KG, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.workplace;

import org.opencms.i18n.CmsEncoder;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsLog;
import org.opencms.util.CmsStringUtil;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;

import org.apache.commons.logging.Log;

/**
 * Provides methods for tab styled dialogs.

* * Extend this class in order to create a tab styled dialog and provide the methods * getTabs() and getTabParameterOrder() in the new dialog class which should return lists * which represent the tabs of the dialog.

* * This class is used for the following dialogs: *

    *
  • User preferences (CmsPreferences.java) *
*

* * @since 6.0.0 */ public abstract class CmsTabDialog extends CmsDialog { /** Value for the action: switch the tab. */ public static final int ACTION_SWITCHTAB = 100; /** Request parameter value for the action: switch the tab. */ public static final String DIALOG_SWITCHTAB = "switchtab"; /** Name of the request parameter for the set button pressed flag. */ public static final String PARAM_SETPRESSED = "setpressed"; /** Name of the request parameter for the current tab. */ public static final String PARAM_TAB = "tab"; /** The log object for this class. */ private static final Log LOG = CmsLog.getLog(CmsTabDialog.class); /** Stores the currently active tab. */ private int m_activeTab = -1; /** Determines if the "set" button was pressed. */ private String m_paramSetPressed; /** Stores the current tab. */ private String m_paramTab; /** * Public constructor.

* * @param jsp an initialized JSP action element */ public CmsTabDialog(CmsJspActionElement jsp) { super(jsp); } /** * Public constructor with JSP variables.

* * @param context the JSP page context * @param req the JSP request * @param res the JSP response */ public CmsTabDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { this(new CmsJspActionElement(context, req, res)); } /** * Builds the tab content area of the dialog window.

* * @param segment the HTML segment (START / END) * @param title the title String for the dialog window * @param attributes additional attributes for the content <div> area of the tab dialog * @return a tab content area start / end segment */ public String dialogTabContent(int segment, String title, String attributes) { if (segment == HTML_START) { StringBuffer result = new StringBuffer(512); // null title is ok, we always want the title headline result.append(dialogHead(title)); result.append("

\n"); result.append("\n"); result.append(dialogTabRow()); result.append("
\n"); result.append("\n"); return result.toString(); } else { return "\n
\n
"; } } /** * Returns the end html for the tab content area of the dialog window.

* * @return the end html for the tab content area of the dialog window */ public String dialogTabContentEnd() { return dialogTabContent(HTML_END, null, null); } /** * Returns the start html for the tab content area of the dialog window.

* * @param title the title for the dialog * @return the start html for the tab content area of the dialog window */ public String dialogTabContentStart(String title) { return dialogTabContent(HTML_START, title, null); } /** * Returns the start html for the tab content area of the dialog window.

* * @param title the title for the dialog * @param attributes additional attributes for the content <div> area of the tab dialog * @return the start html for the tab content area of the dialog window */ public String dialogTabContentStart(String title, String attributes) { return dialogTabContent(HTML_START, title, attributes); } /** * Builds the html for the tab row of the tab dialog.

* * @return the html for the tab row */ public String dialogTabRow() { StringBuffer result = new StringBuffer(512); StringBuffer lineRow = new StringBuffer(256); List tabNames = getTabs(); if (tabNames.size() < 2) { // less than 2 tabs present, do not show them and create a border line result.append( "

\n"); result.append("\n"); result.append("\t\n"); result.append("\n"); result.append("
\n"); return result.toString(); } Iterator i = tabNames.iterator(); int counter = 1; int activeTab = getActiveTab(); result.append( "\n"); result.append("\n"); while (i.hasNext()) { // build a tab entry String curTab = i.next(); String curTabLink = "javascript:openTab('" + counter + "');"; if (counter == activeTab) { // create the currently active tab int addDelta = 0; result.append("\t\n"); lineRow.append("\t\n"); } else { // create an inactive tab result.append("\t\n"); lineRow.append("\t\n"); } counter++; } result.append("\t\n"); result.append("\n"); result.append("\n"); result.append(lineRow); result.append("\t\n"); result.append("\n"); result.append("
"); result.append(""); result.append(curTab); result.append(""); result.append(""); result.append(curTab); result.append("
\n"); return result.toString(); } /** * Returns the number of the currently active tab depending on the request parameter.

* * This method has to be called once in initWorkplaceRequestValues after filling the request parameters.

* * @return the number of the currently active tab */ public int getActiveTab() { if (m_activeTab < 0) { String paramTab = getParamTab(); int tab = 1; if (CmsStringUtil.isNotEmpty(paramTab)) { try { tab = Integer.parseInt(paramTab); } catch (NumberFormatException e) { // do nothing, the first tab is returned if (LOG.isInfoEnabled()) { LOG.info(e.getLocalizedMessage()); } } } setParamTab("" + tab); m_activeTab = tab; return tab; } else { return m_activeTab; } } /** * Returns the localized name of the currently active tab.

* * @return the localized name of the currently active tab or null if no tab name was found */ public String getActiveTabName() { if (m_activeTab < 0) { getActiveTab(); } List tabNames = getTabs(); try { return tabNames.get(m_activeTab - 1); } catch (IndexOutOfBoundsException e) { // should usually never happen if (LOG.isInfoEnabled()) { LOG.info(e.getLocalizedMessage()); } return null; } } /** * Returns the value of the setpressed parameter.

* * @return the value of the setpressed parameter */ public String getParamSetPressed() { return m_paramSetPressed; } /** * Returns the value of the tab parameter.

* * @return the value of the tab parameter */ public String getParamTab() { return m_paramTab; } /** * Returns the order of the parameter prefixes for each tab.

* * For example, all parameters stored in tab 1 have the prefix "Tab1", i.e. * the getter and setter methods must be getParamTab1MyParameterName().

* * To change the tab order, simply change the order in the String array * and in the generated tab list.

* * @return the ordered parameter prefix List * @see org.opencms.workplace.CmsTabDialog#getTabs() */ public abstract List getTabParameterOrder(); /** * Returns a list with localized Strings representing the names of the tabs.

* * @return list with localized String for the tabs */ public abstract List getTabs(); /** * Builds the start html of the page, including setting of DOCTYPE and * inserting a header with the content-type.

* * This overloads the default method of the parent class.

* * @return the start html of the page */ @Override public String htmlStart() { return htmlStart(null); } /** * Builds the start html of the page, including setting of DOCTYPE and * inserting a header with the content-type.

* * This overloads the default method of the parent class.

* * @param helpUrl the key for the online help to include on the page * @return the start html of the page */ @Override public String htmlStart(String helpUrl) { String stylesheet = null; if (isPopup()) { stylesheet = "popup.css"; } StringBuffer result = new StringBuffer(super.pageHtmlStyle(HTML_START, null, stylesheet)); if (getSettings().isViewExplorer()) { result.append("\n"); } result.append("\n"); return result.toString(); } /** * Returns all initialized parameters of the current workplace class * as hidden field tags that can be inserted in a form.

* * This overwrites the method in CmsWorkplace because for each tab, * only the hidden parameters of the non displayed tabs are added.

* * @return all initialized parameters of the current workplace class * as hidden field tags that can be inserted in a html form */ @Override public String paramsAsHidden() { StringBuffer result = new StringBuffer(512); String activeTab = getTabParameterOrder().get(getActiveTab() - 1); Map params = paramValues(); Iterator> i = params.entrySet().iterator(); while (i.hasNext()) { Entry entry = i.next(); String param = entry.getKey(); if (!param.startsWith(activeTab)) { // add only parameters which are not displayed in currently active tab result.append("\n"); } } return result.toString(); } /** * Sets the value of the setpressed parameter.

* * @param value the value to set */ public void setParamSetPressed(String value) { m_paramSetPressed = value; } /** * Sets the value of the tab parameter.

* * @param value the value to set */ public void setParamTab(String value) { m_paramTab = value; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy