View Javadoc

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