|
1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.client.swing; |
|
27 |
|
28 import java.awt.Window; |
|
29 import java.io.IOException; |
|
30 import java.util.Map; |
|
31 import java.util.logging.Level; |
|
32 import javax.help.HelpSet; |
|
33 import com.oracle.solaris.rad.ObjectException; |
|
34 import com.oracle.solaris.rad.jmx.IncompatibleVersionException; |
|
35 import com.oracle.solaris.vp.client.common.*; |
|
36 import com.oracle.solaris.vp.panel.common.*; |
|
37 import com.oracle.solaris.vp.panel.common.action.ActionAbortedException; |
|
38 import com.oracle.solaris.vp.panel.common.api.panel.*; |
|
39 import com.oracle.solaris.vp.panel.common.control.*; |
|
40 import com.oracle.solaris.vp.panel.common.model.PanelDescriptor; |
|
41 import com.oracle.solaris.vp.panel.swing.control.SwingNavigator; |
|
42 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
43 import com.oracle.solaris.vp.util.swing.GUIUtil; |
|
44 |
|
45 public class AppRootControl extends DefaultControl<PanelDescriptor> { |
|
46 // |
|
47 // Static data |
|
48 // |
|
49 |
|
50 public static final String ID = "vp"; |
|
51 |
|
52 // |
|
53 // Instance data |
|
54 // |
|
55 |
|
56 private PanelDescriptorFactory factory; |
|
57 private HelpSet helpSet; |
|
58 private PanelMXBeanTracker panelBeanTracker; |
|
59 |
|
60 // |
|
61 // Constructors |
|
62 // |
|
63 |
|
64 public AppRootControl(ClientContext context) { |
|
65 super(ID, null, context); |
|
66 |
|
67 PanelResourceManager manager = new AppPanelResourceManager(context); |
|
68 factory = new SwingPanelDescriptorFactory(context, manager); |
|
69 } |
|
70 |
|
71 // |
|
72 // Control methods |
|
73 // |
|
74 |
|
75 @Override |
|
76 public void childStarted(Control control) { |
|
77 super.childStarted(control); |
|
78 |
|
79 PanelDescriptor descriptor = getChildPanelDescriptor(); |
|
80 helpSet = descriptor == null ? null : descriptor.getHelpSet(); |
|
81 if (helpSet != null) { |
|
82 getClientContext().getHelpBroker().getHelpSet().add(helpSet); |
|
83 } |
|
84 } |
|
85 |
|
86 @Override |
|
87 public void childStopped(Control control) { |
|
88 super.childStopped(control); |
|
89 |
|
90 if (helpSet != null) { |
|
91 getClientContext().getHelpBroker().getHelpSet().remove(helpSet); |
|
92 } |
|
93 } |
|
94 |
|
95 @Override |
|
96 public Control getChildControl(String id) { |
|
97 Control child = super.getChildControl(id); |
|
98 if (child == null) { |
|
99 ClientContext context = getClientContext(); |
|
100 |
|
101 try { |
|
102 CustomPanel panel = panelBeanTracker.getBean().getPanel( |
|
103 id, null); |
|
104 if (panel != null) { |
|
105 child = factory.getPanelDescriptor(panel).getControl(); |
|
106 addChildren(child); |
|
107 } |
|
108 |
|
109 } catch (ActionAbortedException e) { |
|
110 // No need to display this error |
|
111 getLog().log(Level.SEVERE, "download cancelled", e); |
|
112 |
|
113 } catch (PanelResourceException e) { |
|
114 showError(e.getMessage(), e.getCause()); |
|
115 |
|
116 // Assume invalid panel name |
|
117 } catch (ObjectException e) { |
|
118 } |
|
119 } |
|
120 |
|
121 return child; |
|
122 } |
|
123 |
|
124 @Override |
|
125 public void start(Navigator navigator, Map<String, String> parameters) |
|
126 throws NavigationAbortedException, InvalidParameterException, |
|
127 NavigationFailedException { |
|
128 |
|
129 super.start(navigator, parameters); |
|
130 |
|
131 try { |
|
132 panelBeanTracker = new PanelMXBeanTracker(getClientContext()); |
|
133 |
|
134 } catch (TrackerException e) { |
|
135 String message = null; |
|
136 Throwable cause = e.getCause(); |
|
137 |
|
138 if (cause instanceof IncompatibleVersionException) { |
|
139 IncompatibleVersionException ive = |
|
140 (IncompatibleVersionException)cause; |
|
141 |
|
142 message = Finder.getString("panelproxy.error.version", |
|
143 ive.getClientVersion(), ive.getServerVersion(), |
|
144 ive.getInterfaceClass().getSimpleName()); |
|
145 } else if (cause instanceof IOException) { |
|
146 message = Finder.getString("panelproxy.error.io"); |
|
147 } else { |
|
148 message = Finder.getString("panelproxy.error.general"); |
|
149 } |
|
150 |
|
151 throw new NavigationFailedException(message, cause); |
|
152 } |
|
153 } |
|
154 |
|
155 @Override |
|
156 public void stop(boolean isCancel) throws NavigationAbortedException { |
|
157 super.stop(isCancel); |
|
158 panelBeanTracker.dispose(); |
|
159 panelBeanTracker = null; |
|
160 } |
|
161 |
|
162 // |
|
163 // AppRootControl methods |
|
164 // |
|
165 |
|
166 protected void showError(final String message, |
|
167 final Throwable cause) { |
|
168 getLog().log(Level.SEVERE, message, cause); |
|
169 |
|
170 // May be null |
|
171 final Window window = SwingNavigator.getFirstWindow( |
|
172 getClientContext().getNavigator()); |
|
173 |
|
174 GUIUtil.invokeAndWait( |
|
175 new Runnable() { |
|
176 @Override |
|
177 public void run() { |
|
178 GUIUtil.showError(window, null, message); |
|
179 } |
|
180 }); |
|
181 } |
|
182 |
|
183 // |
|
184 // Private methods |
|
185 // |
|
186 |
|
187 private PanelDescriptor getChildPanelDescriptor() { |
|
188 Control child = getRunningChild(); |
|
189 if (child != null && child instanceof DefaultControl) { |
|
190 return ((DefaultControl)child).getPanelDescriptor(); |
|
191 } |
|
192 return null; |
|
193 } |
|
194 } |