View Javadoc

1   /**
2    * This file Copyright (c) 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.templating.editor.client;
35  
36  
37  import static info.magnolia.templating.editor.client.PageEditor.getDictionary;
38  import info.magnolia.templating.editor.client.dom.CMSComment;
39  import info.magnolia.templating.editor.client.jsni.LegacyJavascript;
40  
41  import com.google.gwt.dom.client.Style.Float;
42  import com.google.gwt.dom.client.Style.Unit;
43  import com.google.gwt.event.dom.client.ClickEvent;
44  import com.google.gwt.event.dom.client.ClickHandler;
45  import com.google.gwt.user.client.ui.Button;
46  
47  /**
48   * Page bar.
49   */
50  public class PageBarWidget extends AbstractBarWidget {
51  
52      private PageEditor pageEditor;
53  
54      private String workspace;
55      private String path;
56      private String dialog;
57      private boolean previewMode = false;
58  
59      public PageBarWidget(final PageEditor pageEditor, final CMSComment comment) {
60          super(null);
61          this.pageEditor = pageEditor;
62  
63          String content = comment.getAttribute("content");
64          int i = content.indexOf(':');
65          this.workspace = content.substring(0, i);
66          this.path = content.substring(i + 1);
67          this.dialog = comment.getAttribute("dialog");
68  
69          if(LegacyJavascript.isPreviewMode()){
70              createPreviewModeBar();
71          } else {
72              createAuthoringModeBar();
73          }
74      }
75  
76      private void createAuthoringModeBar() {
77  
78          Button properties = new Button(getDictionary().get("buttons.properties.js"));
79          properties.addClickHandler(new ClickHandler() {
80              @Override
81              public void onClick(ClickEvent event) {
82                  pageEditor.openDialog(dialog, workspace, path, null, null);
83              }
84          });
85          addButton(properties, Float.RIGHT);
86  
87          Button preview = new Button(getDictionary().get("buttons.preview.js"));
88          preview.addClickHandler(new ClickHandler() {
89              @Override
90              public void onClick(ClickEvent event) {
91                  pageEditor.preview(true);
92              }
93          });
94          addButton(preview, Float.LEFT);
95  
96          Button adminCentral = new Button(getDictionary().get("buttons.admincentral.js"));
97          adminCentral.addClickHandler(new ClickHandler() {
98              @Override
99              public void onClick(ClickEvent event) {
100                 pageEditor.showTree(workspace, path);
101             }
102         });
103         addButton(adminCentral, Float.LEFT);
104 
105         setClassName("mgnlMainbar mgnlControlBar");
106 
107         previewMode = false;
108     }
109 
110     private void createPreviewModeBar() {
111         Button preview = new Button(getDictionary().get("buttons.preview.hidden.js"));
112         preview.addClickHandler(new ClickHandler() {
113             @Override
114             public void onClick(ClickEvent event) {
115                 pageEditor.preview(false);
116             }
117         });
118         preview.getElement().getStyle().setTop(4.0, Unit.PX);
119         preview.getElement().getStyle().setLeft(4.0, Unit.PX);
120         preview.getElement().getStyle().setBackgroundColor("#9DB517");
121         addButton(preview, Float.LEFT);
122         //bar has to show up on the left hand side
123         getStyle().setTop(0.0, Unit.PX);
124         getStyle().setLeft(0.0, Unit.PX);
125         setClassName("mgnlMainbarPreview");
126 
127         previewMode = true;
128     }
129 
130     public final boolean isPreviewMode() {
131         return previewMode;
132     }
133 }