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) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panels.browser.client.swing; |
|
27 |
|
28 import java.util.List; |
|
29 import javax.swing.*; |
|
30 import com.oracle.solaris.vp.panel.common.action.StructuredAction; |
|
31 import com.oracle.solaris.vp.panel.common.control.*; |
|
32 import com.oracle.solaris.vp.panel.swing.action.LaunchManagedObjectAction; |
|
33 import com.oracle.solaris.vp.panel.swing.control.*; |
|
34 import com.oracle.solaris.vp.panel.swing.view.*; |
|
35 |
|
36 public class BrowserControl extends ListSelectorControl<BrowserPanelDescriptor, |
|
37 ListSelectorPanel, PanelManagedObject> |
|
38 { |
|
39 // |
|
40 // Static data |
|
41 // |
|
42 |
|
43 public static final String ID = "main"; |
|
44 |
|
45 // |
|
46 // Instance data |
|
47 // |
|
48 |
|
49 private DefaultListModel lm_ = new DefaultListModel(); |
|
50 |
|
51 private StructuredAction<List<PanelManagedObject>, ?, ?> launchAction_ = |
|
52 new LaunchManagedObjectAction<PanelManagedObject>(this) { |
|
53 |
|
54 @Override |
|
55 public Navigable[] getRuntimeInput(List<PanelManagedObject> selection, |
|
56 Navigable[] path) { |
|
57 |
|
58 // Assume valid selection |
|
59 PanelManagedObject obj = selection.get(0); |
|
60 |
|
61 return new Navigable[] { |
|
62 getNavigator().getPath().get(0), |
|
63 new SimpleNavigable(obj.getCustom().getName(), null) |
|
64 }; |
|
65 } |
|
66 }; |
|
67 |
|
68 // |
|
69 // Constructors |
|
70 // |
|
71 |
|
72 public BrowserControl(BrowserPanelDescriptor descriptor) { |
|
73 super(ID, null, descriptor); |
|
74 } |
|
75 |
|
76 // |
|
77 // Control methods |
|
78 // |
|
79 |
|
80 @Override |
|
81 public Navigable[] getForwardingPath(boolean childStopped) { |
|
82 return new Navigable[] { |
|
83 new SimpleNavigable(PanelControl.ID, null, |
|
84 PanelControl.PARAM_PANEL, "browser") |
|
85 }; |
|
86 } |
|
87 |
|
88 // |
|
89 // DefaultControl methods |
|
90 // |
|
91 |
|
92 @Override |
|
93 protected void ensureChildrenCreated() { |
|
94 if (children.size() == 0) { |
|
95 PanelControl ctl = new PanelControl(getPanelDescriptor()); |
|
96 addChildren(ctl); |
|
97 addToLayout(ctl); |
|
98 } |
|
99 } |
|
100 |
|
101 // |
|
102 // SwingControl methods |
|
103 // |
|
104 |
|
105 @Override |
|
106 protected void configComponent(ListSelectorPanel comp) { |
|
107 super.configComponent(comp); |
|
108 addDefaultCloseAction(true); |
|
109 getComponent().getSelectionComponent().setSelectionMode( |
|
110 ListSelectionModel.SINGLE_SELECTION); |
|
111 } |
|
112 |
|
113 @Override |
|
114 protected ListSelectorPanel createComponent() { |
|
115 ListSelectorPanel panel = new ListSelectorPanel(); |
|
116 |
|
117 JList list = panel.getSelectionComponent(); |
|
118 ManagedObjectCellRenderer<PanelManagedObject> renderer = |
|
119 new ManagedObjectCellRenderer<PanelManagedObject>(); |
|
120 renderer.configureFor(list); |
|
121 list.setCellRenderer(renderer); |
|
122 |
|
123 addAction(panel, launchAction_, true, true); |
|
124 |
|
125 return panel; |
|
126 } |
|
127 |
|
128 // |
|
129 // SelectorControl methods |
|
130 // |
|
131 |
|
132 @Override |
|
133 protected Navigable[] getPathForSelection( |
|
134 List<PanelManagedObject> selection) { |
|
135 |
|
136 if (selection.size() != 1) { |
|
137 return null; |
|
138 } |
|
139 |
|
140 PanelManagedObject panel = selection.get(0); |
|
141 |
|
142 return new Navigable[] { |
|
143 new SimpleNavigable(PanelControl.ID, panel.getName(), |
|
144 PanelControl.PARAM_PANEL, panel.getId()) |
|
145 }; |
|
146 } |
|
147 |
|
148 // |
|
149 // ListSelectorControl methods |
|
150 // |
|
151 |
|
152 @Override |
|
153 protected int getListIndexOf(Control child) { |
|
154 PanelManagedObject panel = ((PanelControl)child).getManagedObject(); |
|
155 return (lm_.indexOf(panel)); |
|
156 } |
|
157 |
|
158 @Override |
|
159 protected ListModel getListModel() { |
|
160 if (lm_.isEmpty()) { |
|
161 for (PanelManagedObject p : getPanelDescriptor().getChildren()) |
|
162 lm_.addElement(p); |
|
163 } |
|
164 return (lm_); |
|
165 } |
|
166 |
|
167 // |
|
168 // BrowserControl methods |
|
169 // |
|
170 |
|
171 void newConnection() { |
|
172 lm_.clear(); |
|
173 getListModel(); |
|
174 getNavigator().goToAsync(false, this); |
|
175 } |
|
176 } |
|