001: /*
002: * File : $Source: /usr/local/cvs/opencms/src/org/opencms/widgets/A_CmsGalleryWidget.java,v $
003: * Date : $Date: 2008-02-27 12:05:44 $
004: * Version: $Revision: 1.14 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.widgets;
033:
034: import org.opencms.file.CmsObject;
035: import org.opencms.workplace.CmsWorkplace;
036: import org.opencms.workplace.galleries.A_CmsGallery;
037:
038: /**
039: * Base class for all gallery widget implementations.<p>
040: *
041: * @author Alexander Kandzior
042: * @author Andreas Zahner
043: *
044: * @version $Revision: 1.14 $
045: *
046: * @since 6.0.0
047: */
048: public abstract class A_CmsGalleryWidget extends A_CmsWidget {
049:
050: /**
051: * Creates a new gallery widget.<p>
052: */
053: protected A_CmsGalleryWidget() {
054:
055: // empty constructor is required for class registration
056: this ("");
057: }
058:
059: /**
060: * Creates a new gallery widget with the given configuration.<p>
061: *
062: * @param configuration the configuration to use
063: */
064: protected A_CmsGalleryWidget(String configuration) {
065:
066: super (configuration);
067: }
068:
069: /**
070: * @see org.opencms.widgets.I_CmsWidget#getDialogIncludes(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
071: */
072: public String getDialogIncludes(CmsObject cms,
073: I_CmsWidgetDialog widgetDialog) {
074:
075: return getJSIncludeFile(CmsWorkplace.getSkinUri()
076: + "components/widgets/" + getNameLower() + "gallery.js");
077: }
078:
079: /**
080: * @see org.opencms.widgets.I_CmsWidget#getDialogInitCall(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
081: */
082: public String getDialogInitCall(CmsObject cms,
083: I_CmsWidgetDialog widgetDialog) {
084:
085: return "\tinit" + getNameUpper() + "Gallery();\n";
086: }
087:
088: /**
089: * @see org.opencms.widgets.I_CmsWidget#getDialogInitMethod(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog)
090: */
091: public String getDialogInitMethod(CmsObject cms,
092: I_CmsWidgetDialog widgetDialog) {
093:
094: StringBuffer result = new StringBuffer(16);
095: result.append("function init");
096: result.append(getNameUpper());
097: result.append("Gallery() {\n");
098: result.append("\t");
099: result.append(getNameLower());
100: result.append("GalleryPath = \"");
101: result.append(A_CmsGallery.PATH_GALLERIES);
102: result.append(A_CmsGallery.OPEN_URI_SUFFIX);
103: result.append("?");
104: result.append(A_CmsGallery.PARAM_GALLERY_TYPENAME);
105: result.append("=");
106: result.append(getNameLower());
107: result.append("gallery");
108: result.append("\";\n");
109: result.append("}\n");
110: return result.toString();
111: }
112:
113: /**
114: * @see org.opencms.widgets.I_CmsWidget#getDialogWidget(org.opencms.file.CmsObject, org.opencms.widgets.I_CmsWidgetDialog, org.opencms.widgets.I_CmsWidgetParameter)
115: */
116: public String getDialogWidget(CmsObject cms,
117: I_CmsWidgetDialog widgetDialog, I_CmsWidgetParameter param) {
118:
119: String id = param.getId();
120: StringBuffer result = new StringBuffer(128);
121: result.append("<td class=\"xmlTd\">");
122: result
123: .append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>");
124: result.append("<input class=\"xmlInputMedium");
125: if (param.hasError()) {
126: result.append(" xmlInputError");
127: }
128: result.append("\" value=\"");
129: String value = param.getStringValue(cms);
130: result.append(value);
131: result.append("\" name=\"");
132: result.append(id);
133: result.append("\" id=\"");
134: result.append(id);
135: result.append("\" onkeyup=\"checkPreview('");
136: result.append(id);
137: result.append("');\"></td>");
138: result.append(widgetDialog.dialogHorizontalSpacer(10));
139: result
140: .append("<td><table class=\"editorbuttonbackground\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
141:
142: result.append(widgetDialog.button("javascript:open"
143: + getNameUpper() + "Gallery('"
144: + A_CmsGallery.MODE_WIDGET + "', '" + id
145: + "');return false;", null, getNameLower() + "gallery",
146: Messages.getButtonName(getNameLower()), widgetDialog
147: .getButtonStyle()));
148: // create preview button
149: String previewClass = "hide";
150: if (showPreview(value)) {
151: // show button if preview is enabled
152: previewClass = "show";
153: }
154: result.append("<td class=\"");
155: result.append(previewClass);
156: result.append("\" id=\"preview");
157: result.append(id);
158: result.append("\">");
159: result
160: .append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
161: result.append(widgetDialog.button("javascript:preview"
162: + getNameUpper() + "('" + id + "');return false;",
163: null, "preview.png", Messages.GUI_BUTTON_PREVIEW_0,
164: widgetDialog.getButtonStyle()));
165: result.append("</tr></table>");
166:
167: result.append("</td></tr></table>");
168:
169: result.append("</td>");
170: result.append("</tr></table>");
171:
172: result.append("</td>");
173:
174: return result.toString();
175: }
176:
177: /**
178: * Returns the lower case name of the gallery, for example <code>"html"</code>.<p>
179: *
180: * @return the lower case name of the gallery
181: */
182: public abstract String getNameLower();
183:
184: /**
185: * Returns the upper case name of the gallery, for example <code>"Html"</code>.<p>
186: *
187: * @return the upper case name of the gallery
188: */
189: public abstract String getNameUpper();
190:
191: /**
192: * Returns <code>true</code> if the preview button should be shown.<p>
193: *
194: * @param value the current widget value
195: * @return <code>true</code> if the preview button should be shown
196: */
197: public abstract boolean showPreview(String value);
198: }
|