BrightSide Workbench Full Report + Source Code
Framework.java
Go to the documentation of this file.
1 /*
2  * Turró i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis Turró Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.zul.frame;
19 
20 import java.util.Map;
21 import org.turro.about.AboutTurro;
22 import org.turro.action.Plugins;
23 import org.turro.auth.Authentication;
24 import org.turro.command.Command;
25 import org.turro.command.CommandUtil;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.zkoss.Modal;
29 import org.turro.i18n.I_;
30 import org.turro.menu.ElephantMenuBar;
31 import org.turro.menu.ElephantStatusBar;
32 import org.turro.menu.ElephantToolbar;
33 import org.turro.zul.portal.PortalContainer;
34 import org.turro.zul.portal.PortalWindows;
35 import org.zkoss.zk.ui.Executions;
36 import org.zkoss.zk.ui.ext.AfterCompose;
37 import org.zkoss.zk.ui.sys.PageCtrl;
38 import org.zkoss.zk.ui.util.Clients;
39 import org.zkoss.zul.*;
40 
45 public class Framework extends Div implements AfterCompose {
46 
47  private static FrameClipboard clipboard;
48 
49  private final Application app = Application.getApplication();
50  private final PortalWindows portalWindows;
51 
52  private Borderlayout layout;
53  private ElephantMenuBar menuBar;
54  private ElephantToolbar toolBar;
55  private ElephantStatusBar statusBar;
56  private ContainerTab container;
57  private Popup globalPopup;
58 
59  public Framework() {
60  setSclass("bbframe");
61  setHeight("100%");
62  Executions.getCurrent().getDesktop().setAttribute("el_framework", this);
63  //Devices.setTimeoutURI("ajax", "");
64  portalWindows = new PortalWindows();
65  portalWindows.loadContainers();
66  addComponents();
67  }
68 
69  public void addContent(String label, String src) {
70  container.addContent(label, src);
71  }
72 
73  public void addContent(String label, String src, Map<String, Object> dynProps) {
74  container.addContent(label, src, dynProps);
75  }
76 
77  public void addContent(PortalContainer container) {
78  this.container.addContent(container);
79  }
80 
81  public void setSelectedAttribute(String key, Object value) {
82  Tabpanel tp = container.getSelectedPanel();
83  if(tp != null) tp.setAttribute(key, value);
84  }
85 
86  public Object getSelectedAttribute(String key) {
87  Tabpanel tp = container.getSelectedPanel();
88  return tp != null ? tp.getAttribute(key) : null;
89  }
90 
91  public Object getAttributeFrom(Tabpanel panel, String key) {
92  return panel != null ? panel.getAttribute(key) : null;
93  }
94 
95  public void invalidateSelected() {
96  container.invalidateSelected();
97  }
98 
99  public void closeSelected() {
100  container.closeSelected();
101  }
102 
103  public void setSelectedLabel(String text) {
104  container.setSelectedLabel(text);
105  }
106 
107  public void setSelectedTooltiptext(String text) {
108  container.setSelectedTooltiptext(text);
109  }
110 
111  public void showModal(String label, String src, Map arg, Command command) {
112  showModal(label, (Window) Executions.createComponents(src, null, arg), command);
113  }
114 
115  public void showModal(String label, Window window, Command command) {
116  window.setTitle(label);
117  window.setMode(Window.MODAL);
118  Modal.doModal(window, command);
119  }
120 
121  public void showPopup(String label, String src, Map arg) {
122  Window w = (Window) Executions.createComponents(src, null, arg);
123  w.setTitle(label);
124  w.setPosition("center");
125  w.doPopup();
126  }
127 
129  return portalWindows;
130  }
131 
132  public Popup getGlobalPopup() {
133  globalPopup.getChildren().clear();
134  return globalPopup;
135  }
136 
138  return statusBar;
139  }
140 
141  private void addComponents() {
142  layout = new Borderlayout();
143  appendChild(layout);
144 
145  North north = new North();
146  north.setSclass("bbframetop");
147  layout.appendChild(north);
148  Vlayout vbox = new Vlayout();
149  vbox.setSpacing("0px");
150  vbox.setVflex("1");
151  north.appendChild(vbox);
152  toolBar = new ElephantToolbar();
153  toolBar.setVflex("1");
154  menuBar = new ElephantMenuBar(toolBar);
155  vbox.appendChild(menuBar);
156  vbox.appendChild(toolBar);
157 
158  Center center = new Center();
159  center.setSclass("bbframecenter");
160  layout.appendChild(center);
161  container = new ContainerTab();
162  center.appendChild(container);
163 
164  South south = new South();
165  south.setSclass("bbframebottom");
166  layout.appendChild(south);
167  statusBar = new ElephantStatusBar();
168  south.appendChild(statusBar);
169 
170  globalPopup = new Popup();
171  appendChild(globalPopup);
172  }
173 
174  @Override
175  public void afterCompose() {
176  getPage().setAttribute("rolemap", Authentication.getIContact().getPermissions().asMap(), SESSION_SCOPE);
177  getPage().setTitle(
179  " - " +
180  I_.get("BrightSide Application Framework"));
181  if(getPage() instanceof PageCtrl) {
182  ((PageCtrl) getPage()).addBeforeHeadTags(
183  "<link rel=\"shortcut icon\" href=\"" +
185  "\" type=\"image/x-icon\">");
186  }
188  Map<String, Object> args = Plugins.execute("CurrentCompany", null);
189  statusBar.setCompany(CommandUtil.getLinkOrSpace(args.get("company")));
190  statusBar.setStatus(AboutTurro.getAbout(getPage()));
191  Clients.evalJavaScript(
192  "window.onbeforeunload = confirmExit;\n" +
193  "var exitWanted=false;\n" +
194  "function confirmExit() {\n" +
195  " if(!exitWanted) {" +
196  " return \"BrightSide Application Framework - Fundació TiC\";\n" +
197  " }" +
198  "}\n"
199  );
200  appendChild(new MessageTimer());
201  }
202 
203  public static Framework getCurrent() {
204  return (Framework) Executions.getCurrent().getDesktop().getAttribute("el_framework");
205  }
206 
207  public static Object getAttribute(Object object, String key) {
208  return Executions.getCurrent().getDesktop().getAttribute(object.getClass().getSimpleName() + "_" + key);
209  }
210 
211  public static Object getAttribute(Object object, String key, Object defaultValue) {
212  Object value = Executions.getCurrent().getDesktop().getAttribute(object.getClass().getSimpleName() + "_" + key);
213  return value == null ? defaultValue : value;
214  }
215 
216  public static void setAttribute(Object object, String key, Object value) {
217  Executions.getCurrent().getDesktop().setAttribute(object.getClass().getSimpleName() + "_" + key, value);
218  }
219 
220  public static FrameClipboard getClipboard() {
221  if(clipboard == null) {
222  clipboard = new FrameClipboard();
223  }
224  return clipboard;
225  }
226 
227 }
static Map< String, Object > execute(String name, Map params)
Definition: Plugins.java:44
static HtmlBasedComponent getLinkOrSpace(Object entity)
static int doModal(String file)
Definition: Modal.java:38
static String get(String msg)
Definition: I_.java:41
void setStatus(HtmlBasedComponent comp)
void setCompany(HtmlBasedComponent comp)
void setUser(HtmlBasedComponent comp)
void setSelectedTooltiptext(String text)
void addContent(String label, String src)
static FrameClipboard getClipboard()
Definition: Framework.java:220
void addContent(String label, String src)
Definition: Framework.java:69
void showPopup(String label, String src, Map arg)
Definition: Framework.java:121
static Object getAttribute(Object object, String key)
Definition: Framework.java:207
static Framework getCurrent()
Definition: Framework.java:203
void setSelectedLabel(String text)
Definition: Framework.java:103
static Object getAttribute(Object object, String key, Object defaultValue)
Definition: Framework.java:211
void showModal(String label, String src, Map arg, Command command)
Definition: Framework.java:111
ElephantStatusBar getStatusBar()
Definition: Framework.java:137
Object getAttributeFrom(Tabpanel panel, String key)
Definition: Framework.java:91
static void setAttribute(Object object, String key, Object value)
Definition: Framework.java:216
void addContent(String label, String src, Map< String, Object > dynProps)
Definition: Framework.java:73
void setSelectedTooltiptext(String text)
Definition: Framework.java:107
PortalWindows getPortalWindows()
Definition: Framework.java:128
Object getSelectedAttribute(String key)
Definition: Framework.java:86
void addContent(PortalContainer container)
Definition: Framework.java:77
void showModal(String label, Window window, Command command)
Definition: Framework.java:115
void setSelectedAttribute(String key, Object value)
Definition: Framework.java:81