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.misc.CssConstants;
37  
38  import java.io.IOException;
39  import java.io.Writer;
40  
41  import org.apache.commons.lang.StringUtils;
42  
43  
44  /**
45   * @author Vinzenz Wyser
46   * @version 2.0
47   */
48  public class DialogBox extends DialogControlImpl {
49  
50      public static final int BOXTYPE_2COLS = 0;
51  
52      public static final int BOXTYPE_1COL = 1;
53  
54      private int boxType = BOXTYPE_2COLS;
55  
56      public void setBoxType(int i) {
57          this.boxType = i;
58      }
59  
60      public int getBoxType() {
61          String configBoxType = this.getConfigValue("boxType"); //$NON-NLS-1$
62          if (configBoxType.equals("1Col")) { //$NON-NLS-1$
63              return BOXTYPE_1COL;
64          }
65          return this.boxType;
66  
67      }
68  
69      public void drawHtmlPre(Writer out) throws IOException {
70          if (this.getConfigValue("lineSemi", "false").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
71              out.write(new DialogLine().getHtml(1, 1));
72          }
73          else if (this.getConfigValue("line", "true").equals("true")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
74              out.write(new DialogLine().getHtml());
75          }
76          out.write("<tr>"); //$NON-NLS-1$
77          if (this.getBoxType() == BOXTYPE_2COLS) {
78              out.write("<td style=\"width:1%\" class=\"" + CssConstants.CSSCLASS_BOXLABEL + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
79              // write the label
80              out.write(this.getMessage(this.getLabel()));
81              if (this.isRequired()) {
82                  out.write(" (*)");
83              }
84              if (StringUtils.isNotEmpty(this.getConfigValue("labelDescription"))) { //$NON-NLS-1$
85                  String desc = this.getConfigValue("labelDescription"); //$NON-NLS-1$
86                  desc = this.getMessage(desc);
87                  out.write("<div class=\"" + CssConstants.CSSCLASS_DESCRIPTION + "\">" + desc + "</div>"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
88              }
89              out.write("</td>"); //$NON-NLS-1$
90              String cssClass = CssConstants.CSSCLASS_BOXINPUT;
91              if (this.getClass().getName().indexOf("DialogStatic") != -1 //$NON-NLS-1$
92                  || this.getClass().getName().indexOf("DialogButton") != -1) { //$NON-NLS-1$
93                  cssClass = CssConstants.CSSCLASS_BOXLABEL;
94              }
95              out.write("<td style=\"width:100%\" class=\"" + cssClass + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
96          }
97          else {
98              out.write("<td style=\"width:100%\" colspan=\"2\" class=\"" + CssConstants.CSSCLASS_BOXLABEL + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
99              if (StringUtils.isNotEmpty(this.getLabel())) {
100                 out.write("<div class=\"" //$NON-NLS-1$
101                     + CssConstants.CSSCLASS_BOXLABEL
102                     + "\">" //$NON-NLS-1$
103                     + this.getMessage(this.getLabel())
104                     + (this.isRequired() ? "(*)" : "")
105                     + "</div>"); //$NON-NLS-1$
106             }
107             if (StringUtils.isNotEmpty(this.getConfigValue("labelDescription"))) { //$NON-NLS-1$
108                 String desc = this.getConfigValue("labelDescription"); //$NON-NLS-1$
109                 out.write("<div class=\"" //$NON-NLS-1$
110                     + CssConstants.CSSCLASS_DESCRIPTION
111                     + "\">" //$NON-NLS-1$
112                     + this.getMessage(desc)
113                     + "</div>"); //$NON-NLS-1$
114             }
115         }
116     }
117 
118     public void drawHtmlPost(Writer out) throws IOException {
119         out.write(this.getHtmlDescription());
120 
121         if (this.getConfigValue("saveHandler") != null) {
122             out.write("<input type=\"hidden\" name=\"");
123             out.write(this.getName());
124             out.write("_saveHandler\" value=\"");
125             out.write(this.getConfigValue("saveHandler"));
126             out.write("\" />");
127 
128             out.write("<input type=\"hidden\" name=\"");
129             out.write(this.getName());
130             out.write("_configNode\" value=\"");
131             out.write(this.getConfigValue("handle"));
132             out.write("\" />");
133         }
134 
135         out.write("</td></tr>\n"); //$NON-NLS-1$
136     }
137 
138     public String getHtmlDescription() {
139 
140         // use div to force a new line
141         if (StringUtils.isNotEmpty(this.getDescription())) {
142             String desc = this.getDescription();
143             desc = this.getMessage(desc);
144             return "<div class=\"" + CssConstants.CSSCLASS_DESCRIPTION + "\">" + desc + "</div>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
145         }
146 
147         return StringUtils.EMPTY;
148     }
149 
150 }