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