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.inline;
35  
36  import info.magnolia.cms.beans.config.ServerConfiguration;
37  import info.magnolia.cms.gui.control.Bar;
38  import info.magnolia.cms.gui.control.Button;
39  import info.magnolia.cms.i18n.MessagesManager;
40  import info.magnolia.cms.security.Permission;
41  import info.magnolia.cms.core.AggregationState;
42  import info.magnolia.context.MgnlContext;
43  import info.magnolia.freemarker.FreemarkerUtil;
44  
45  import org.apache.commons.lang.StringUtils;
46  
47  import javax.servlet.http.HttpServletRequest;
48  import javax.servlet.jsp.JspWriter;
49  import java.io.IOException;
50  import java.io.Writer;
51  
52  
53  /**
54   * @author Vinzenz Wyser
55   * @version 2.0
56   */
57  public class BarEdit extends Bar {
58  
59      private ButtonEdit buttonEdit = new ButtonEdit();
60  
61      private Button buttonMove = new Button();
62  
63      private Button buttonDelete = new Button();
64  
65      private String paragraph;
66  
67      /**
68       * @deprecated since 4.0 - use the empty constructor.
69       */
70      public BarEdit(HttpServletRequest request) {
71      }
72  
73      public BarEdit() {
74  
75      }
76  
77      /**
78       * Sets the default buttons.
79       */
80      public void setDefaultButtons() {
81          this.setButtonEdit();
82          this.setButtonMove();
83          this.setButtonDelete();
84      }
85  
86      /**
87       * Places the default buttons to the very right/left position.
88       */
89      public void placeDefaultButtons() {
90          if (this.getButtonMove() != null) {
91              this.getButtonsLeft().add(0, this.getButtonMove());
92          }
93          if (this.getButtonEdit() != null) {
94              this.getButtonsLeft().add(0, this.getButtonEdit());
95          }
96          if (this.getButtonDelete() != null) {
97              this.getButtonsRight().add(this.getButtonsRight().size(), this.getButtonDelete());
98          }
99      }
100 
101     public ButtonEdit getButtonEdit() {
102         return this.buttonEdit;
103     }
104 
105     public void setButtonEdit(ButtonEdit b) {
106         this.buttonEdit = b;
107     }
108 
109     public void setButtonEdit() {
110         this.setButtonEdit(this.getPath(), this.getNodeCollectionName(StringUtils.EMPTY), this.getNodeName(StringUtils.EMPTY), this.getParagraph());
111     }
112 
113     /**
114      * Sets the default edit button.
115      *
116      * @param path , path of the current page
117      * @param nodeCollectionName , i.e. 'MainParagarphs'
118      * @param nodeName , i.e. '01'
119      * @param paragraph , paragraph type
120      */
121     public void setButtonEdit(String path, String nodeCollectionName, String nodeName, String paragraph) {
122         ButtonEdit b = new ButtonEdit(path, nodeCollectionName, nodeName, paragraph);
123         b.setDefaultOnclick();
124         this.setButtonEdit(b);
125     }
126 
127     public Button getButtonMove() {
128         return this.buttonMove;
129     }
130 
131     public void setButtonMove(Button b) {
132         this.buttonMove = b;
133     }
134 
135     public void setButtonMove() {
136         this.setButtonMove(this.getNodeCollectionName(StringUtils.EMPTY), this.getNodeName(StringUtils.EMPTY));
137     }
138 
139     /**
140      * Sets the default move button.
141      *
142      * @param nodeCollectionName , i.e. 'MainParagarphs'
143      * @param nodeName , i.e. '01'
144      */
145     public void setButtonMove(String nodeCollectionName, String nodeName) {
146         Button b = new Button();
147         b.setLabel(MessagesManager.get("buttons.move")); //$NON-NLS-1$
148         // sets the id of the bar
149         this.setId(nodeCollectionName + "__" + nodeName); //$NON-NLS-1$
150         b.setOnclick("mgnlMoveNodeStart('" + nodeCollectionName + "','" + nodeName + "','" + this.getId() + "');"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
151         this.setButtonMove(b);
152     }
153 
154     public Button getButtonDelete() {
155         return this.buttonDelete;
156     }
157 
158     public void setButtonDelete(Button b) {
159         this.buttonDelete = b;
160     }
161 
162     /**
163      * @deprecated use {@link #setButtonDelete(String)}
164      */
165     public void setButtonDelete() {
166         this.setButtonDelete(this.getPath(), this.getNodeCollectionName(), this.getNodeName());
167     }
168 
169     /**
170      * Sets the default delete button.
171      *
172      * @param path , path of the current page
173      * @param nodeCollectionName , i.e. 'MainColumnParagraphs'
174      * @param nodeName , i.e. '01'
175      *
176      * @deprecated use {@link #setButtonDelete(String)}
177      */
178     public void setButtonDelete(String path, String nodeCollectionName, String nodeName) {
179         Button b = new Button();
180         b.setLabel(MessagesManager.get("buttons.delete")); //$NON-NLS-1$
181         b.setOnclick("mgnlDeleteNode('" + path + "','" + nodeCollectionName + "','" + nodeName + "');"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
182         this.setButtonDelete(b);
183     }
184 
185     public void setButtonDelete(String pathToDelete) {
186         Button b = new Button();
187         b.setLabel(MessagesManager.get("buttons.delete"));
188         b.setOnclick("mgnlDeleteNode('" + pathToDelete + "');");
189         this.setButtonDelete(b);
190     }
191 
192     /**
193      * @deprecated use drawHtml(Writer out) instead.
194      */
195     public void drawHtml(JspWriter out) throws IOException {
196         drawHtml((Writer) out);
197     }
198 
199     /**
200      * Draws the main bar (incl. all magnolia specific js and css sources).
201      */
202     public void drawHtml(Writer out) throws IOException {
203         out.write(FreemarkerUtil.process(this));
204 //        final AggregationState aggregationState = MgnlContext.getAggregationState();
205 //        boolean isGranted = aggregationState.getMainContent().isGranted(Permission.SET);
206 //        if (!aggregationState.isPreviewMode() && isGranted && ServerConfiguration.getInstance().isAdmin()) {
207 //            this.setEvent("onmousedown", "mgnlMoveNodeEnd(this,'" + this.getPath() + "');"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
208 //            this.setEvent("onmouseover", "mgnlMoveNodeHigh(this);"); //$NON-NLS-1$ //$NON-NLS-2$
209 //            this.setEvent("onmouseout", "mgnlMoveNodeReset(this);"); //$NON-NLS-1$ //$NON-NLS-2$
210 //            println(out, getHtml());
211 //        }
212     }
213 
214     public String getParagraph() {
215         return this.paragraph;
216     }
217 
218     public void setParagraph(String paragraph) {
219         this.paragraph = paragraph;
220     }
221 }