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.firewall.client.swing; |
|
27 |
|
28 import java.awt.Component; |
|
29 import java.util.List; |
|
30 import javax.swing.*; |
|
31 import com.oracle.solaris.vp.panel.common.control.*; |
|
32 import com.oracle.solaris.vp.panel.common.model.ManagedObject; |
|
33 import com.oracle.solaris.vp.panel.swing.control.*; |
|
34 import com.oracle.solaris.vp.panel.swing.view.ListSelectorPanel; |
|
35 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
36 import com.oracle.solaris.vp.util.swing.SimpleCellRenderer; |
|
37 |
|
38 public class MainControl extends ListSelectorControl<FirewallPanelDescriptor, |
|
39 ListSelectorPanel, ManagedObject> { |
|
40 |
|
41 // |
|
42 // Static data |
|
43 // |
|
44 |
|
45 public static final String ID = "main"; |
|
46 |
|
47 // |
|
48 // Instance data |
|
49 // |
|
50 |
|
51 private ListModel model; |
|
52 |
|
53 // |
|
54 // Constructors |
|
55 // |
|
56 |
|
57 public MainControl(FirewallPanelDescriptor descriptor) { |
|
58 super(ID, null, descriptor); |
|
59 } |
|
60 |
|
61 // |
|
62 // Control methods |
|
63 // |
|
64 |
|
65 @Override |
|
66 public void childStarted(Control child) { |
|
67 super.childStarted(child); |
|
68 |
|
69 if (child instanceof ServiceEditControl) { |
|
70 getComponent().getChangeableAggregator().addChangeables( |
|
71 ((SettingsControl<?, ?>)child).getComponent(). |
|
72 getChangeableAggregator()); |
|
73 } else { |
|
74 getComponent().getChangeableAggregator().addChangeables( |
|
75 ((GlobalControl)child).getChangeableAggregator()); |
|
76 } |
|
77 } |
|
78 |
|
79 @Override |
|
80 public void childStopped(Control child) { |
|
81 super.childStopped(child); |
|
82 |
|
83 if (child instanceof ServiceEditControl) { |
|
84 getComponent().getChangeableAggregator().removeChangeable( |
|
85 ((SettingsControl<?, ?>)child).getComponent(). |
|
86 getChangeableAggregator()); |
|
87 } else { |
|
88 getComponent().getChangeableAggregator().removeChangeable( |
|
89 ((GlobalControl)child).getChangeableAggregator()); |
|
90 } |
|
91 } |
|
92 |
|
93 @Override |
|
94 public Navigable[] getForwardingPath(boolean childStopped) { |
|
95 return new Navigable[] { |
|
96 new SimpleNavigable(GlobalControl.ID, null) |
|
97 }; |
|
98 } |
|
99 |
|
100 @Override |
|
101 public String getHelpMapID() { |
|
102 return "firewall-panel"; |
|
103 } |
|
104 |
|
105 // |
|
106 // DefaultControl methods |
|
107 // |
|
108 |
|
109 @Override |
|
110 protected void ensureChildrenCreated() { |
|
111 if (children.size() == 0) { |
|
112 FirewallPanelDescriptor descriptor = getPanelDescriptor(); |
|
113 SwingControl[] controls = { |
|
114 new GlobalControl(descriptor), |
|
115 new ServiceEditControl(descriptor) |
|
116 }; |
|
117 |
|
118 addChildren(controls); |
|
119 |
|
120 // Add the Components of these children to the UI now, so that the |
|
121 // UI will be sized to fit the largest Component |
|
122 addToLayout(controls); |
|
123 } |
|
124 } |
|
125 |
|
126 // |
|
127 // SwingControl methods |
|
128 // |
|
129 |
|
130 @Override |
|
131 protected void configComponent(ListSelectorPanel panel) { |
|
132 super.configComponent(panel); |
|
133 addDefaultApplyAction(); |
|
134 addDefaultCancelAction(true); |
|
135 addDefaultOkayAction(true); |
|
136 addDefaultHelpAction(); |
|
137 } |
|
138 |
|
139 @Override |
|
140 protected ListSelectorPanel createComponent() { |
|
141 ListSelectorPanel panel = new ListSelectorPanel(); |
|
142 panel.setSelectionTitle(Finder.getString("policy.list.title")); |
|
143 |
|
144 JList list = panel.getSelectionComponent(); |
|
145 SimpleCellRenderer renderer = new MainListCellRenderer(); |
|
146 renderer.configureFor(list); |
|
147 list.setCellRenderer(renderer); |
|
148 |
|
149 addAction(panel, new AddServiceAction(this), true, true); |
|
150 addAction(panel, new RemoveServiceAction(this), true, true); |
|
151 |
|
152 return panel; |
|
153 } |
|
154 |
|
155 // |
|
156 // ListSelectorControl methods |
|
157 // |
|
158 |
|
159 @Override |
|
160 protected int getListIndexOf(Control child) { |
|
161 if (child instanceof GlobalControl) |
|
162 return 0; |
|
163 |
|
164 FirewallPanelDescriptor descriptor = getPanelDescriptor(); |
|
165 ServiceManagedObject service = |
|
166 ((ServiceEditControl) child).getManagedService(); |
|
167 |
|
168 int cIndex = descriptor.indexOf(service); |
|
169 assert cIndex >= 0; |
|
170 |
|
171 // Add offset for global policy at item 0 |
|
172 cIndex++; |
|
173 |
|
174 ListModel model = getComponent().getSelectionComponent().getModel(); |
|
175 ServiceManagedObject modelService = |
|
176 (ServiceManagedObject) model.getElementAt(cIndex); |
|
177 assert (modelService.getId().equals(service.getId())); |
|
178 |
|
179 return cIndex; |
|
180 } |
|
181 |
|
182 @Override |
|
183 protected ListModel getListModel() { |
|
184 if (model == null) { |
|
185 model = new MainListModel(getPanelDescriptor()); |
|
186 } |
|
187 |
|
188 return model; |
|
189 } |
|
190 |
|
191 @Override |
|
192 protected Navigable[] getPathForSelection(List<ManagedObject> selection) { |
|
193 if (selection.size() != 1) { |
|
194 return null; |
|
195 } |
|
196 |
|
197 ManagedObject selected = selection.get(0); |
|
198 Navigable navigable; |
|
199 |
|
200 if (selected instanceof FirewallPanelDescriptor) { |
|
201 navigable = new SimpleNavigable(GlobalControl.ID, |
|
202 MainListCellRenderer.TEXT_GLOBAL); |
|
203 } else { |
|
204 ServiceManagedObject sobj = (ServiceManagedObject)selected; |
|
205 |
|
206 navigable = new SimpleNavigable(ServiceEditControl.ID, |
|
207 sobj.getName(), ServiceEditControl.PARAM_SVC, sobj.getId()); |
|
208 } |
|
209 return new Navigable[] {navigable}; |
|
210 } |
|
211 } |
|