0
|
1 |
/*
|
|
2 |
* Copyright (c) 2000 - 2006 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.epdt.plugins.s60.securityconf;
|
|
19 |
|
|
20 |
/* java.awt */
|
|
21 |
import java.awt.Color;
|
|
22 |
import java.awt.SystemColor;
|
|
23 |
import java.awt.BorderLayout;
|
|
24 |
import java.awt.GridBagLayout;
|
|
25 |
import java.awt.GridBagConstraints;
|
|
26 |
import java.awt.event.ActionEvent;
|
|
27 |
import java.awt.event.ActionListener;
|
|
28 |
|
|
29 |
/* javax.swing */
|
|
30 |
import javax.swing.JTable;
|
|
31 |
import javax.swing.JPanel;
|
|
32 |
import javax.swing.JComboBox;
|
|
33 |
import javax.swing.JRadioButton;
|
|
34 |
import javax.swing.JScrollPane;
|
|
35 |
import javax.swing.ButtonGroup;
|
|
36 |
import javax.swing.DefaultCellEditor;
|
|
37 |
import javax.swing.border.EmptyBorder;
|
|
38 |
import javax.swing.table.TableColumn;
|
|
39 |
|
|
40 |
/* com.nokia.wtk.util.gui */
|
|
41 |
import com.nokia.wtk.util.gui.BorderPanel;
|
|
42 |
|
|
43 |
/**
|
|
44 |
* Security configuration UI class, main panel in the view.
|
|
45 |
*/
|
|
46 |
class SecConfMainPanel extends JPanel {
|
|
47 |
|
|
48 |
private static final int GAP = 6;
|
|
49 |
|
|
50 |
// Domain Selection combo
|
|
51 |
private JComboBox jDomainCombo;
|
|
52 |
|
|
53 |
// Permission bindings (settings) table
|
|
54 |
private JTable jBindingsTable;
|
|
55 |
|
|
56 |
// Data model for jBindingsTable
|
|
57 |
private PermTableModel permTableModel;
|
|
58 |
|
|
59 |
private SecurityConfPlugin parentPlugin;
|
|
60 |
private SecConfModel secConfModel;
|
|
61 |
private ProtectionDomain[] domains;
|
|
62 |
|
|
63 |
private static Color TABLE_ACTIVE_BGND = SystemColor.window;
|
|
64 |
private static Color TABLE_INACTIVE_BGND = SystemColor.control;
|
|
65 |
|
|
66 |
/**
|
|
67 |
* This is a constructor. In case if you haven't noticed :)
|
|
68 |
*/
|
|
69 |
SecConfMainPanel(SecurityConfPlugin aParentPlugin) {
|
|
70 |
super(new GridBagLayout());
|
|
71 |
parentPlugin = aParentPlugin;
|
|
72 |
secConfModel = parentPlugin.getSecConfModel();
|
|
73 |
domains = secConfModel.getProtectionDomains(false);
|
|
74 |
permTableModel = new PermTableModel(parentPlugin);
|
|
75 |
|
|
76 |
// Domain combo box initialization
|
|
77 |
jDomainCombo = new JComboBox(domains);
|
|
78 |
jDomainCombo.setSelectedItem(secConfModel.getSelectedDomain());
|
|
79 |
|
|
80 |
JRadioButton realLifeRadio = new JRadioButton(
|
|
81 |
"Run MIDlets within security domain specified by their certificates");
|
|
82 |
JRadioButton emulatedRadio = new JRadioButton(
|
|
83 |
"Run MIDlets within the following domain:");
|
|
84 |
|
|
85 |
ButtonGroup bg = new ButtonGroup();
|
|
86 |
bg.add(realLifeRadio);
|
|
87 |
bg.add(emulatedRadio);
|
|
88 |
if (secConfModel.isEmulatedSecurityMode()) {
|
|
89 |
realLifeRadio.setSelected(false);
|
|
90 |
emulatedRadio.setSelected(true);
|
|
91 |
jDomainCombo.setEnabled(true);
|
|
92 |
} else {
|
|
93 |
realLifeRadio.setSelected(true);
|
|
94 |
emulatedRadio.setSelected(false);
|
|
95 |
jDomainCombo.setEnabled(false);
|
|
96 |
}
|
|
97 |
|
|
98 |
jDomainCombo.addActionListener(new DomainSelectionListener());
|
|
99 |
realLifeRadio.addActionListener(new RealLifeRadioListener());
|
|
100 |
emulatedRadio.addActionListener(new EmulatedRadioListener());
|
|
101 |
|
|
102 |
BorderPanel bp = new BorderPanel(emulatedRadio);
|
|
103 |
bp.getContentPanel().add(createConfigurationsPanel());
|
|
104 |
|
|
105 |
ProtectionDomain d = secConfModel.getSelectedDomain();
|
|
106 |
if (d != null && d.isUserDefined() && secConfModel.isEmulatedSecurityMode()) {
|
|
107 |
jBindingsTable.setEnabled(true);
|
|
108 |
jBindingsTable.setBackground(TABLE_ACTIVE_BGND);
|
|
109 |
} else {
|
|
110 |
jBindingsTable.setEnabled(false);
|
|
111 |
jBindingsTable.setBackground(TABLE_INACTIVE_BGND);
|
|
112 |
}
|
|
113 |
|
|
114 |
// We could use BorderLayout and this:
|
|
115 |
//
|
|
116 |
// add(getJRealLifeRadio(), BorderLayout.NORTH);
|
|
117 |
// add(bp, BorderLayout.CENTER);
|
|
118 |
//
|
|
119 |
// would be ALMOST perfect, except that radio buttons wouldn't be
|
|
120 |
// aligned horizontally. With GridBagLayout we can manipulate insets
|
|
121 |
// of each cell, which allows us to aligh the radio buttons. A little
|
|
122 |
// bit more complicated, but looks better.
|
|
123 |
|
|
124 |
GridBagConstraints gbc = new GridBagConstraints();
|
|
125 |
gbc.weightx = 1.0;
|
|
126 |
gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
127 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
128 |
gbc.anchor = GridBagConstraints.NORTH;
|
|
129 |
gbc.insets.left = bp.getBorder().getBorderInsets(bp).left +
|
|
130 |
BorderPanel.COMPONENT_INSET_H;
|
|
131 |
add(realLifeRadio, gbc);
|
|
132 |
|
|
133 |
gbc.weighty = 1.0;
|
|
134 |
gbc.insets.left = 0;
|
|
135 |
gbc.fill = GridBagConstraints.BOTH;
|
|
136 |
gbc.gridheight = GridBagConstraints.REMAINDER;
|
|
137 |
add(bp, gbc);
|
|
138 |
|
|
139 |
// Final touches
|
|
140 |
setBorder(new EmptyBorder(GAP,GAP,GAP,GAP));
|
|
141 |
jBindingsTable.setPreferredScrollableViewportSize(
|
|
142 |
jBindingsTable.getPreferredSize());
|
|
143 |
}
|
|
144 |
|
|
145 |
private JPanel createConfigurationsPanel() {
|
|
146 |
jBindingsTable = new JTable(permTableModel);
|
|
147 |
jBindingsTable.setShowGrid(true);
|
|
148 |
jBindingsTable.getTableHeader().setReorderingAllowed(false);
|
|
149 |
|
|
150 |
JComboBox permCombo = new JComboBox(new Permission [] {
|
|
151 |
Permission.Allowed,
|
|
152 |
Permission.Denied,
|
|
153 |
Permission.Session,
|
|
154 |
Permission.OneShot
|
|
155 |
});
|
|
156 |
|
|
157 |
TableColumn permColumn = jBindingsTable.getColumnModel().getColumn(1);
|
|
158 |
permColumn.setCellEditor(new DefaultCellEditor(permCombo));
|
|
159 |
jBindingsTable.setBackground(TABLE_ACTIVE_BGND);
|
|
160 |
jBindingsTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
|
|
161 |
|
|
162 |
JPanel p = new JPanel(new BorderLayout(GAP, GAP));
|
|
163 |
p.add(jDomainCombo, BorderLayout.NORTH);
|
|
164 |
p.add(new JScrollPane(jBindingsTable), BorderLayout.CENTER);
|
|
165 |
p.setBorder(new EmptyBorder(0,GAP,GAP,GAP));
|
|
166 |
return p;
|
|
167 |
}
|
|
168 |
|
|
169 |
private class DomainSelectionListener implements ActionListener {
|
|
170 |
public void actionPerformed(ActionEvent aEvent) {
|
|
171 |
ProtectionDomain d = (ProtectionDomain)jDomainCombo.getSelectedItem();
|
|
172 |
if (secConfModel.getSelectedDomain() != d) {
|
|
173 |
|
|
174 |
// Selection has changed
|
|
175 |
secConfModel.setSelectedDomain(d);
|
|
176 |
parentPlugin.pluginModelChangedAction();
|
|
177 |
|
|
178 |
// Notify table about the update
|
|
179 |
permTableModel.fireTableDataChanged();
|
|
180 |
jBindingsTable.getColumnModel().getColumn(1).
|
|
181 |
getCellEditor().cancelCellEditing();
|
|
182 |
|
|
183 |
// If selected domain is editable and security is emulated
|
|
184 |
if (d.isUserDefined() &&
|
|
185 |
secConfModel.isEmulatedSecurityMode()) {
|
|
186 |
jBindingsTable.setEnabled(true);
|
|
187 |
jBindingsTable.setBackground(TABLE_ACTIVE_BGND);
|
|
188 |
} else {
|
|
189 |
jBindingsTable.setEnabled(false);
|
|
190 |
jBindingsTable.setBackground(TABLE_INACTIVE_BGND);
|
|
191 |
}
|
|
192 |
}
|
|
193 |
}
|
|
194 |
}
|
|
195 |
|
|
196 |
private class RealLifeRadioListener implements ActionListener {
|
|
197 |
public void actionPerformed(ActionEvent aEvent) {
|
|
198 |
if (secConfModel.isEmulatedSecurityMode()) {
|
|
199 |
// Radio button's state has changed
|
|
200 |
secConfModel.setEmulatedSecurityMode(false);
|
|
201 |
jDomainCombo.setEnabled(false);
|
|
202 |
jBindingsTable.setEnabled(false);
|
|
203 |
jBindingsTable.clearSelection();
|
|
204 |
jBindingsTable.setBackground(TABLE_INACTIVE_BGND);
|
|
205 |
jBindingsTable.getColumnModel().getColumn(1).
|
|
206 |
getCellEditor().cancelCellEditing();
|
|
207 |
parentPlugin.pluginModelChangedAction();
|
|
208 |
}
|
|
209 |
}
|
|
210 |
}
|
|
211 |
|
|
212 |
private class EmulatedRadioListener implements ActionListener {
|
|
213 |
public void actionPerformed(ActionEvent aEvent) {
|
|
214 |
if (!secConfModel.isEmulatedSecurityMode()) {
|
|
215 |
// Radio button's state has changed
|
|
216 |
secConfModel.setEmulatedSecurityMode(true);
|
|
217 |
jDomainCombo.setEnabled(true);
|
|
218 |
ProtectionDomain d = secConfModel.getSelectedDomain();
|
|
219 |
if (d != null && d.isUserDefined() &&
|
|
220 |
secConfModel.isEmulatedSecurityMode()) {
|
|
221 |
jBindingsTable.setEnabled(true);
|
|
222 |
jBindingsTable.setBackground(TABLE_ACTIVE_BGND);
|
|
223 |
}
|
|
224 |
parentPlugin.pluginModelChangedAction();
|
|
225 |
}
|
|
226 |
}
|
|
227 |
}
|
|
228 |
}
|