View Javadoc

1   /**
2    * This file Copyright (c) 2003-2010 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.cms.gui.dialog;
35  
36  import info.magnolia.cms.gui.dialog.DialogControlImpl;
37  import info.magnolia.cms.gui.dialog.DialogLine;
38  import info.magnolia.cms.gui.misc.CssConstants;
39  
40  import java.io.IOException;
41  import java.io.Writer;
42  
43  import org.apache.commons.lang.StringUtils;
44  
45  
46  /**
47   * @author Vinzenz Wyser
48   * @version 2.0
49   */
50  public class DialogBox extends DialogControlImpl {
51  
52      public static final int BOXTYPE_2COLS = 0;
53  
54      public static final int BOXTYPE_1COL = 1;
55  
56      private int boxType = BOXTYPE_2COLS;
57  
58      public void setBoxType(int i) {
59          this.boxType = i;
60      }
61  
62      public int getBoxType() {
63          String configBoxType = this.getConfigValue("boxType"); //$NON-NLS-1$
64          if (configBoxType.equals("1Col")) { //$NON-NLS-1$
65              return BOXTYPE_1COL;
66          }
67          return this.boxType;
68  
69      }
70  
71      public void drawHtmlPre(Writer out) throws IOException {
72          if (this.getConfigValue("lineSemi", "false").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
73              out.write(new DialogLine().getHtml(1, 1));
74          }
75          else if (this.getConfigValue("line", "true").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
76              out.write(new DialogLine().getHtml());
77          }
78          out.write("<tr>"); //$NON-NLS-1$
79          if (this.getBoxType() == BOXTYPE_2COLS) {
80              out.write("<td style=\"width:1%\" class=\"" + CssConstants.CSSCLASS_BOXLABEL + "\"><label for= \""+ this.getName()+ "\">"); //$NON-NLS-1$ //$NON-NLS-2$
81              // write the label
82              out.write(this.getMessage(this.getLabel()));
83              if (this.isRequired()) {
84                  out.write(" (*)");
85              }
86              if (StringUtils.isNotEmpty(this.getConfigValue("labelDescription"))) { //$NON-NLS-1$
87                  String desc = this.getConfigValue("labelDescription"); //$NON-NLS-1$
88                  desc = this.getMessage(desc);
89                  out.write("<div class=\"" + CssConstants.CSSCLASS_DESCRIPTION + "\">" + desc + "</div>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
90              }
91              out.write("</label></td>"); //$NON-NLS-1$
92              String cssClass = CssConstants.CSSCLASS_BOXINPUT;
93              if (this.getClass().getName().indexOf("DialogStatic") != -1 //$NON-NLS-1$
94                  || this.getClass().getName().indexOf("DialogButton") != -1) { //$NON-NLS-1$
95                  cssClass = CssConstants.CSSCLASS_BOXLABEL;
96              }
97              out.write("<td style=\"width:100%\" class=\"" + cssClass + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
98          }
99          else {
100         	
101             out.write("<td style=\"width:100%\" colspan=\"2\" class=\"" + CssConstants.CSSCLASS_BOXLABEL + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
102             if (StringUtils.isNotEmpty(this.getLabel())) {
103                 out.write("<div class=\"" //$NON-NLS-1$
104                     + CssConstants.CSSCLASS_BOXLABEL
105                     + "\"><label for= \""+ this.getName()+ "\">" //$NON-NLS-1$
106                     + this.getMessage(this.getLabel())
107                     + (this.isRequired() ? "(*)" : "")
108                     + "</label></div>"); //$NON-NLS-1$
109             }
110             if (StringUtils.isNotEmpty(this.getConfigValue("labelDescription"))) { //$NON-NLS-1$
111                 String desc = this.getConfigValue("labelDescription"); //$NON-NLS-1$
112                 out.write("<div class=\"" //$NON-NLS-1$
113                     + CssConstants.CSSCLASS_DESCRIPTION
114                     + "\"><label for= \""+ this.getName()+ "\">" //$NON-NLS-1$
115                     + this.getMessage(desc)
116                     + "</label></div>"); //$NON-NLS-1$
117             }
118         }
119     }
120 
121     public void drawHtmlPost(Writer out) throws IOException {
122         out.write(this.getHtmlDescription());
123 
124         if (this.getConfigValue("saveHandler") != null) {
125             out.write("<input type=\"hidden\" name=\"");
126             out.write(this.getName());
127             out.write("_saveHandler\" value=\"");
128             out.write(this.getConfigValue("saveHandler"));
129             out.write("\" />");
130 
131             out.write("<input type=\"hidden\" name=\"");
132             out.write(this.getName());
133             out.write("_configNode\" value=\"");
134             out.write(this.getConfigValue("handle"));
135             out.write("\" />");
136         }
137 
138         out.write("</td></tr>\n"); //$NON-NLS-1$
139     }
140 
141     public String getHtmlDescription() {
142 
143         // use div to force a new line
144         if (StringUtils.isNotEmpty(this.getDescription())) {
145             String desc = this.getDescription();
146             desc = this.getMessage(desc);
147             return "<div class=\"" + CssConstants.CSSCLASS_DESCRIPTION + "\">" + desc + "</div>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
148         }
149 
150         return StringUtils.EMPTY;
151     }
152 
153 }