View Javadoc
1   /**
2    * This file Copyright (c) 2003-2014 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.control;
35  
36  import java.util.ArrayList;
37  import java.util.Iterator;
38  import java.util.List;
39  
40  import org.apache.commons.lang.StringUtils;
41  
42  
43  /**
44   * @author Vinzenz Wyser
45   * @version 2.0
46   */
47  public class Bar extends ControlImpl {
48  
49      private List buttonsLeft = new ArrayList();
50  
51      private List buttonsRight = new ArrayList();
52  
53      private boolean small = true;
54  
55      public void setButtonsLeft(List buttons) {
56          this.buttonsLeft = buttons;
57      }
58  
59      public void setButtonsLeft(Button button) {
60          this.getButtonsLeft().add(button);
61      }
62  
63      public List getButtonsLeft() {
64          return this.buttonsLeft;
65      }
66  
67      public void setButtonsRight(List buttons) {
68          this.buttonsRight = buttons;
69      }
70  
71      public void setButtonsRight(Button button) {
72          this.getButtonsRight().add(button);
73      }
74  
75      public List getButtonsRight() {
76          return this.buttonsRight;
77      }
78  
79      public void setSmall(boolean b) {
80          this.small = b;
81      }
82  
83      public boolean getSmall() {
84          return this.small;
85      }
86  
87      @Override
88      public String getHtml() {
89          StringBuffer html = new StringBuffer();
90          if (StringUtils.isEmpty(this.getCssClass())) {
91              if (this.getSmall()) {
92                  this.setCssClass(CSSCLASS_CONTROLBARSMALL);
93              }
94              else {
95                  this.setCssClass(CSSCLASS_CONTROLBAR);
96              }
97          }
98          html.append("<table"); //$NON-NLS-1$
99          html.append(this.getHtmlEvents());
100         html.append(this.getHtmlCssClass());
101         if (this.getId() != null) {
102             html.append(" id=\"" + this.getId() + "\" cellspacing=\"0\""); //$NON-NLS-1$ //$NON-NLS-2$
103         }
104         html.append(">"); //$NON-NLS-1$
105         html.append("<tr>"); //$NON-NLS-1$
106 
107         // left
108         List btnLeft = this.getButtonsLeft();
109         if (!btnLeft.isEmpty()) {
110             html.append("<td class=\"mgnlBtnsLeft\">"); //$NON-NLS-1$
111             Iterator itLeft = btnLeft.iterator();
112             while (itLeft.hasNext()) {
113                 Button b = (Button) itLeft.next();
114                 if (this.getSmall()) {
115                     b.setSmall(true);
116                 }
117                 b.setCssStyles("background", "transparent"); //$NON-NLS-1$ //$NON-NLS-2$
118                 b.setSaveInfo(false);
119                 html.append(b.getHtml());
120             }
121             html.append("</td>"); //$NON-NLS-1$
122         }
123 
124         // title in the middle
125         final String label = getLabel();
126         if (StringUtils.isNotEmpty(label)) {
127             html.append("<td class=\"smothBarLabelContainer\">");
128             html.append("<table class=\"smothBarLabel\"><tr><td class=\"smothBarLabel\">");
129             html.append(label);
130             html.append("</td></tr></table>");
131             html.append("</td>");
132         }
133 
134         // right
135         List btnRight = this.getButtonsRight();
136         if (!btnRight.isEmpty()) {
137             html.append("<td class=\"mgnlBtnsRight\">"); //$NON-NLS-1$
138 
139             Iterator itRight = this.getButtonsRight().iterator();
140             while (itRight.hasNext()) {
141                 ControlImpl c = (ControlImpl) itRight.next();
142                 if(c instanceof Button){
143                     if (this.getSmall()) {
144                         ((Button)c).setSmall(true);
145                     }
146                     c.setCssStyles("background", "transparent"); //$NON-NLS-1$ //$NON-NLS-2$
147                 }
148                 c.setSaveInfo(false);
149                 html.append(c.getHtml());
150             }
151             html.append("</td>"); //$NON-NLS-1$
152         }
153 
154         html.append("</tr>"); //$NON-NLS-1$
155         html.append("</table>"); //$NON-NLS-1$
156         return html.toString();
157     }
158 
159 }