BrightSide Workbench Full Report + Source Code
PortalContent.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.portal;
19 
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22 import org.jdom.Element;
23 import org.turro.elephant.context.ElephantContext;
24 import org.zkoss.zk.ui.Component;
25 import org.zkoss.zk.ui.ext.AfterCompose;
26 import org.zkoss.zul.Panel;
27 import org.zkoss.zul.Panelchildren;
28 
33 public class PortalContent extends Panel implements Comparable, AfterCompose {
34 
35  private Integer order;
36  private IPortalContent content;
37 
38  public void load(Element root) {
39  order = Integer.valueOf(root.getAttributeValue("order", "0"));
40  setTitle(root.getAttributeValue("title"));
41  setBorder(root.getAttributeValue("border", "normal"));
42  setHeight(root.getAttributeValue("height", "300px"));
43  setStyle(root.getAttributeValue("style", ""));
44  setCollapsible(Boolean.valueOf(root.getAttributeValue("collapsible", "true")));
45  setMaximizable(Boolean.valueOf(root.getAttributeValue("maximizable", "true")));
46  setMovable(Boolean.valueOf(root.getAttributeValue("movable", "true")));
47  setClosable(Boolean.valueOf(root.getAttributeValue("closable", "true")));
48  createInstance(root.getChild("content"));
49  if(content instanceof Component) {
50  Panelchildren children = new Panelchildren();
51  appendChild(children);
52  children.appendChild((Component) content);
53  }
54  }
55 
56  public void save(Element root) {
57  root.setAttribute("order", getPosition(order) + "");
58  root.setAttribute("title", getTitle());
59  root.setAttribute("border", getBorder());
60  root.setAttribute("height", getHeight());
61  if(getStyle() != null) {
62  root.setAttribute("style", getStyle());
63  }
64  root.setAttribute("collapsible", Boolean.toString(isCollapsible()));
65  root.setAttribute("maximizable", Boolean.toString(isMaximizable()));
66  root.setAttribute("movable", Boolean.toString(isMovable()));
67  root.setAttribute("closable", Boolean.toString(isClosable()));
68  if(content != null) {
69  Element el = new Element("content");
70  el.setAttribute("java-class", content.getClass().getName());
71  content.setConfiguration(el);
72  root.addContent(el);
73  }
74  }
75 
76  @Override
77  public int compareTo(Object o) {
78  if(o != null && o instanceof PortalContent) {
79  return order.compareTo(((PortalContent) o).order);
80  }
81  return -1;
82  }
83 
84  private void createInstance(Element root) {
85  if(root == null) return;
86  Object impl = null;
87  try {
88  String jClass = root.getAttributeValue("java-class");
89  Class cls = Class.forName(jClass);
90  if(cls != null) {
91  java.lang.reflect.Constructor cons = cls.getConstructor(new Class[] {});
92  if(cons != null) {
93  impl = cons.newInstance(new Object[] {});
94  }
95  }
96  if(impl instanceof IPortalContent) {
97  content = (IPortalContent) impl;
98  content.getConfiguration(root);
99  }
100  } catch(Exception ex) {
101  Logger.getLogger(PortalContent.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
102  }
103  }
104 
105  private int getPosition(int order) {
106  if(getParent() == null) {
107  return order;
108  }
109  int pos = getParent().getChildren().indexOf(this);
110  if(pos > -1) {
111  return pos;
112  }
113  return order;
114  }
115 
116  @Override
117  public void afterCompose() {
118  if(content instanceof AfterCompose) {
119  ((AfterCompose) content).afterCompose();
120  }
121  }
122 
123 }
void getConfiguration(Element root)
void setConfiguration(Element root)