BrightSide Workbench Full Report + Source Code
ContainerTab.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 java.util.Stack;
22 import org.turro.zul.portal.PortalContainer;
23 import org.zkoss.zk.ui.event.Event;
24 import org.zkoss.zk.ui.event.EventListener;
25 import org.zkoss.zk.ui.event.Events;
26 import org.zkoss.zul.*;
27 
32 public class ContainerTab extends Tabbox {
33 
34  private Tabs tabs;
35  private Tabpanels panels;
36  private Stack<Tabpanel> selections = new Stack<>();
37 
38  public ContainerTab() {
39  setSclass("bbcontbox");
40  setVflex("1");
41  createContainers();
42  }
43 
44  public void addContent(String label, String src) {
45  addContent(label, src, null);
46  }
47 
48  public void addContent(String label, String src, Map<String, Object> dynProps) {
49  Tab tab = new Tab(label);
50  tab.setClosable(true);
51  tabs.appendChild(tab);
52  Tabpanel panel = new Tabpanel();
53  panel.setSclass("bbcontpanel");
54  panels.appendChild(panel);
55  Include inc = new Include(src);
56  inc.setWidth("100%");
57  inc.setHeight("100%");
58  inc.setMode("defer");
59  if(dynProps != null) {
60  for(Map.Entry<String, Object> entry : dynProps.entrySet()) {
61  if(entry.getValue() != null) {
62  inc.setDynamicProperty(entry.getKey(), entry.getValue());
63  }
64  }
65  }
66  panel.appendChild(inc);
67  setSelectedPanel(panel);
68  selections.push(panel);
69  tab.addEventListener(Events.ON_CLOSE, new EventListener() {
70  @Override
71  public void onEvent(Event event) throws Exception {
72  Tabpanel panel = ((Tab) event.getTarget()).getLinkedPanel();
73  selections.remove(panel);
74  selectDefaultPanel();
75  }
76  });
77  }
78 
79  public void addContent(PortalContainer container) {
80  Tab tab = new Tab(container.getLabel());
81  tab.setClosable(true);
82  tabs.appendChild(tab);
83  Tabpanel panel = new Tabpanel();
84  panel.setSclass("bbcontpanel");
85  panels.appendChild(panel);
86  //container.setWidth("100%");
87  //container.setHeight("100%");
88  panel.appendChild(new Toolbar());
89  panel.appendChild(container);
90  setSelectedPanel(panel);
91  selections.push(panel);
92  container.afterCompose();
93  tab.addEventListener(Events.ON_CLOSE, new EventListener() {
94  @Override
95  public void onEvent(Event event) throws Exception {
96  Tabpanel panel = ((Tab) event.getTarget()).getLinkedPanel();
97  selections.remove(panel);
98  selectDefaultPanel();
99  }
100  });
101  }
102 
103  public void invalidateSelected() {
104  Tabpanel panel = getSelectedPanel();
105  if(panel != null) {
106  panel.getFirstChild().invalidate();
107  }
108  }
109 
110  public void closeSelected() {
111  Tabpanel panel = getSelectedPanel();
112  if(panel != null) {
113  Tab tab = panel.getLinkedTab();
114  tabs.removeChild(tab);
115  panels.removeChild(panel);
116  selections.remove(panel);
117  }
118  selectDefaultPanel();
119  }
120 
121  public void setSelectedLabel(String text) {
122  Tabpanel panel = getSelectedPanel();
123  if(panel != null) {
124  Tab tab = panel.getLinkedTab();
125  tab.setLabel(text);
126  }
127  }
128 
129  public void setSelectedTooltiptext(String text) {
130  Tabpanel panel = getSelectedPanel();
131  if(panel != null) {
132  Tab tab = panel.getLinkedTab();
133  tab.setTooltiptext(text);
134  }
135  }
136 
137  private void createContainers() {
138  tabs = new Tabs();
139  tabs.setSclass("bbconttabs");
140  appendChild(tabs);
141  panels = new Tabpanels();
142  panels.setSclass("bbcontpanels");
143  appendChild(panels);
144  addEventListener(Events.ON_SELECT, new EventListener() {
145  @Override
146  public void onEvent(Event event) throws Exception {
147  Tabpanel panel = ((Tab) event.getTarget()).getLinkedPanel();
148  selections.remove(panel);
149  selections.push(panel);
150  }
151  });
152  }
153 
154  private void selectDefaultPanel() {
155  if(!selections.empty()) {
156  Tabpanel tp = selections.pop();
157  if(tp != null) setSelectedPanel(tp);
158  Tabpanel tps = getSelectedPanel();
159  if(tps != null) {
160  selections.remove(tps);
161  selections.push(tps);
162  }
163  }
164  }
165 
166 }
void setSelectedTooltiptext(String text)
void addContent(String label, String src, Map< String, Object > dynProps)
void addContent(String label, String src)
void addContent(PortalContainer container)