1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package ch.elca.el4j.services.gui.swing;
18
19 import javax.swing.JComponent;
20 import javax.swing.JPanel;
21
22 import org.noos.xing.mydoggy.Content;
23 import org.noos.xing.mydoggy.ContentManager;
24 import org.noos.xing.mydoggy.DockedTypeDescriptor;
25 import org.noos.xing.mydoggy.ToolWindow;
26 import org.noos.xing.mydoggy.ToolWindowActionHandler;
27 import org.noos.xing.mydoggy.ToolWindowAnchor;
28 import org.noos.xing.mydoggy.ToolWindowManager;
29 import org.noos.xing.mydoggy.ToolWindowTab;
30 import org.noos.xing.mydoggy.ToolWindowType;
31 import org.noos.xing.mydoggy.plaf.MyDoggyToolWindowManager;
32 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
33
34 import ch.elca.el4j.services.gui.swing.frames.ApplicationFrame;
35 import ch.elca.el4j.services.gui.swing.frames.ContentApplicationFrame;
36 import ch.elca.el4j.services.gui.swing.frames.ContentConfiguration;
37 import ch.elca.el4j.services.gui.swing.frames.ToolWindowTabApplicationFrame;
38 import ch.elca.el4j.services.gui.swing.frames.ToolWindowTabConfiguration;
39 import ch.elca.el4j.services.gui.swing.wrapper.ContentWrapperFactory;
40 import ch.elca.el4j.services.gui.swing.wrapper.ToolWindowWrapperFactory;
41
42
43
44
45
46
47
48
49 public abstract class DockingApplication extends GUIApplication {
50
51
52
53 protected ToolWindowManager toolWindowManager = null;
54
55
56
57
58 public ToolWindowManager getToolWindowManager() {
59 if (toolWindowManager == null) {
60
61 toolWindowManager = new MyDoggyToolWindowManager();
62 }
63 return toolWindowManager;
64 }
65
66
67 @Override
68 public void show(JComponent component) {
69 show(ContentWrapperFactory.wrap(component));
70 }
71
72
73 @Override
74 public void show(ApplicationFrame frame) {
75 if (frame instanceof ContentApplicationFrame) {
76 showContent((ContentApplicationFrame) frame);
77 }
78 }
79
80
81
82
83
84
85 public void show(String beanName, String toolWindowId, ToolWindowAnchor anchor)
86 throws NoSuchBeanDefinitionException {
87
88 if (!springContext.containsBean(beanName)) {
89 throw new NoSuchBeanDefinitionException(beanName);
90 }
91 show((JPanel) springContext.getBean(beanName), toolWindowId, anchor);
92 }
93
94
95
96
97
98
99 public void show(JComponent component, String toolWindowId, ToolWindowAnchor anchor) {
100 ToolWindowTabApplicationFrame frame = ToolWindowWrapperFactory.wrap(component);
101 frame.getConfiguration().setId(toolWindowId);
102 frame.getConfiguration().setAnchor(anchor);
103 showToolWindow(frame);
104 }
105
106
107
108
109
110 public void showContent(ContentApplicationFrame frame) {
111 ContentManager contentManager = toolWindowManager.getContentManager();
112 Content content = (Content) frame.getFrame();
113 if (content == null) {
114 ContentConfiguration config = frame.getConfiguration();
115 content = contentManager.addContent(config.getId(), config.getTitle(),
116 config.getIcon(), config.getComponent(), config.getToolTip(), config.getConstraints());
117
118 content.getContentUI().setMinimizable(false);
119 content.getContentUI().setDetachable(false);
120
121 frame.setFrame(content);
122 frame.setContent(config.getComponent());
123 }
124
125 super.show(frame);
126
127 frame.setSelected(true);
128 }
129
130
131
132
133
134 public void showToolWindow(final ToolWindowTabApplicationFrame frame) {
135 if (frame.getFrame() == null) {
136 ToolWindowTab toolWindowTab = null;
137 ToolWindowTabConfiguration config = frame.getConfiguration();
138 ToolWindow toolWindow = toolWindowManager.getToolWindow(config.getId());
139 if (toolWindow == null) {
140 toolWindow = toolWindowManager.registerToolWindow(config.getId(), config.getTitle(),
141 config.getIcon(), config.getComponent(), config.getAnchor());
142
143 DockedTypeDescriptor typeDescriptor = (DockedTypeDescriptor)
144 toolWindow.getTypeDescriptor(ToolWindowType.DOCKED);
145
146
147 typeDescriptor.setToolWindowActionHandler(new ToolWindowActionHandler() {
148 public void onHideButtonClick(ToolWindow toolWindow) {
149 frame.close();
150 toolWindowManager.unregisterToolWindow(toolWindow.getId());
151 }
152 });
153 toolWindowTab = toolWindow.getToolWindowTabs()[0];
154 } else {
155 toolWindowTab = toolWindow.addToolWindowTab(
156 ((ToolWindowTab) ToolWindowWrapperFactory.wrap(frame.getContent()).getFrame()).getOwner());
157 }
158 toolWindow.setAvailable(true);
159
160 frame.setFrame(toolWindowTab);
161 }
162 }
163 }