Lines 41-54
Link Here
|
41 |
|
41 |
|
42 |
package org.netbeans.modules.autoupdate.ui.wizards; |
42 |
package org.netbeans.modules.autoupdate.ui.wizards; |
43 |
|
43 |
|
|
|
44 |
import java.awt.event.ActionEvent; |
45 |
import java.text.MessageFormat; |
46 |
import java.util.ArrayList; |
44 |
import java.util.Collection; |
47 |
import java.util.Collection; |
45 |
import java.util.Collections; |
48 |
import java.util.Collections; |
46 |
import java.util.HashMap; |
|
|
47 |
import java.util.HashSet; |
49 |
import java.util.HashSet; |
48 |
import java.util.Map; |
50 |
import java.util.List; |
49 |
import java.util.Set; |
51 |
import java.util.Set; |
|
|
52 |
import javax.swing.DefaultComboBoxModel; |
53 |
import javax.swing.SwingUtilities; |
50 |
import org.netbeans.api.autoupdate.UpdateElement; |
54 |
import org.netbeans.api.autoupdate.UpdateElement; |
51 |
import org.openide.util.NbBundle; |
55 |
import org.openide.util.NbBundle; |
|
|
56 |
import org.openide.util.RequestProcessor; |
52 |
|
57 |
|
53 |
/** |
58 |
/** |
54 |
* |
59 |
* |
Lines 56-62
Link Here
|
56 |
*/ |
61 |
*/ |
57 |
public class LicenseApprovalPanel extends javax.swing.JPanel { |
62 |
public class LicenseApprovalPanel extends javax.swing.JPanel { |
58 |
public static final String LICENSE_APPROVED = "license-approved"; |
63 |
public static final String LICENSE_APPROVED = "license-approved"; |
59 |
private Map<String, Set<String>> license4plugins; |
64 |
private List<UpdateElement> license4plugins; |
60 |
|
65 |
|
61 |
/** Creates new form LicenseApprovalPanel */ |
66 |
/** Creates new form LicenseApprovalPanel */ |
62 |
public LicenseApprovalPanel (InstallUnitWizardModel model, boolean isApproved) { |
67 |
public LicenseApprovalPanel (InstallUnitWizardModel model, boolean isApproved) { |
Lines 66-72
Link Here
|
66 |
writeLicenses(model); |
71 |
writeLicenses(model); |
67 |
} else { |
72 |
} else { |
68 |
cbAccept.setEnabled (false); |
73 |
cbAccept.setEnabled (false); |
69 |
taLicenses.setEnabled (false); |
74 |
taLicense.setEnabled (false); |
70 |
} |
75 |
} |
71 |
} |
76 |
} |
72 |
|
77 |
|
Lines 75-99
Link Here
|
75 |
if (license4plugins == null && license4plugins.isEmpty ()) { |
80 |
if (license4plugins == null && license4plugins.isEmpty ()) { |
76 |
return Collections.emptyList (); |
81 |
return Collections.emptyList (); |
77 |
} |
82 |
} |
78 |
return license4plugins.keySet (); |
83 |
Set<String> licenses = new HashSet<String>(); |
79 |
} |
84 |
for (UpdateElement el : license4plugins) { |
80 |
|
85 |
licenses.add(el.getLicence()); |
|
|
86 |
} |
87 |
return licenses; |
88 |
} |
89 |
|
81 |
private void goOverLicenses (InstallUnitWizardModel model) { |
90 |
private void goOverLicenses (InstallUnitWizardModel model) { |
82 |
for (UpdateElement el : model.getAllUpdateElements ()) { |
91 |
for (UpdateElement el : model.getAllUpdateElements ()) { |
83 |
if (el.getLicence () != null) { |
92 |
if (el.getLicence () != null) { |
84 |
if (license4plugins == null) { |
93 |
if (license4plugins == null) { |
85 |
license4plugins = new HashMap<String, Set<String>> (); |
94 |
license4plugins = new ArrayList<UpdateElement> (); |
86 |
} |
95 |
} |
87 |
if (license4plugins.containsKey (el.getLicence ())) { |
96 |
|
88 |
// add plugin |
97 |
license4plugins.add(el); |
89 |
license4plugins.get (el.getLicence ()).add (el.getDisplayName ()); |
|
|
90 |
} else { |
91 |
// license |
92 |
Set<String> plugins = new HashSet<String> (); |
93 |
plugins.add (el.getDisplayName ()); |
94 |
license4plugins.put (el.getLicence (), plugins); |
95 |
} |
96 |
//licenses.put (el.getDisplayName (), el.getLicence ()); |
97 |
} |
98 |
} |
98 |
} |
99 |
} |
99 |
} |
100 |
} |
Lines 111-119
Link Here
|
111 |
private void initComponents() { |
112 |
private void initComponents() { |
112 |
|
113 |
|
113 |
taTitle = new javax.swing.JTextArea(); |
114 |
taTitle = new javax.swing.JTextArea(); |
114 |
spLicenses = new javax.swing.JScrollPane(); |
|
|
115 |
taLicenses = new javax.swing.JTextArea(); |
116 |
cbAccept = new javax.swing.JCheckBox(); |
115 |
cbAccept = new javax.swing.JCheckBox(); |
|
|
116 |
cbPlugins = new javax.swing.JComboBox(); |
117 |
spLicense = new javax.swing.JScrollPane(); |
118 |
taLicense = new javax.swing.JTextArea(); |
119 |
lbPlugins = new javax.swing.JLabel(); |
117 |
|
120 |
|
118 |
taTitle.setEditable(false); |
121 |
taTitle.setEditable(false); |
119 |
taTitle.setLineWrap(true); |
122 |
taTitle.setLineWrap(true); |
Lines 122-137
Link Here
|
122 |
taTitle.setMargin(new java.awt.Insets(0, 4, 0, 0)); |
125 |
taTitle.setMargin(new java.awt.Insets(0, 4, 0, 0)); |
123 |
taTitle.setOpaque(false); |
126 |
taTitle.setOpaque(false); |
124 |
|
127 |
|
125 |
taLicenses.setColumns(20); |
|
|
126 |
taLicenses.setEditable(false); |
127 |
taLicenses.setLineWrap(true); |
128 |
taLicenses.setRows(5); |
129 |
taLicenses.setWrapStyleWord(true); |
130 |
taLicenses.setMargin(new java.awt.Insets(0, 4, 0, 4)); |
131 |
spLicenses.setViewportView(taLicenses); |
132 |
taLicenses.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(LicenseApprovalPanel.class, "LicenseApprovalPanel_taLicenses_ACN")); // NOI18N |
133 |
taLicenses.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(LicenseApprovalPanel.class, "LicenseApprovalPanel_taLicenses_ACD")); // NOI18N |
134 |
|
135 |
org.openide.awt.Mnemonics.setLocalizedText(cbAccept, org.openide.util.NbBundle.getMessage(LicenseApprovalPanel.class, "LicenseApprovalPanel.cbAccept.text")); // NOI18N |
128 |
org.openide.awt.Mnemonics.setLocalizedText(cbAccept, org.openide.util.NbBundle.getMessage(LicenseApprovalPanel.class, "LicenseApprovalPanel.cbAccept.text")); // NOI18N |
136 |
cbAccept.addActionListener(new java.awt.event.ActionListener() { |
129 |
cbAccept.addActionListener(new java.awt.event.ActionListener() { |
137 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
130 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
Lines 139-144
Link Here
|
139 |
} |
132 |
} |
140 |
}); |
133 |
}); |
141 |
|
134 |
|
|
|
135 |
cbPlugins.addActionListener(new java.awt.event.ActionListener() { |
136 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
137 |
cbPluginsActionPerformed(evt); |
138 |
} |
139 |
}); |
140 |
|
141 |
taLicense.setColumns(20); |
142 |
taLicense.setEditable(false); |
143 |
taLicense.setLineWrap(true); |
144 |
taLicense.setRows(5); |
145 |
taLicense.setWrapStyleWord(true); |
146 |
taLicense.setMargin(new java.awt.Insets(0, 4, 0, 4)); |
147 |
spLicense.setViewportView(taLicense); |
148 |
taLicense.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(LicenseApprovalPanel.class, "LicenseApprovalPanel_taLicenses_ACN")); // NOI18N |
149 |
taLicense.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(LicenseApprovalPanel.class, "LicenseApprovalPanel_taLicenses_ACD")); // NOI18N |
150 |
|
151 |
lbPlugins.setLabelFor(cbPlugins); |
152 |
org.openide.awt.Mnemonics.setLocalizedText(lbPlugins, org.openide.util.NbBundle.getMessage(LicenseApprovalPanel.class, "LicenseApprovalPanel.lbPlugins.text")); // NOI18N |
153 |
|
142 |
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); |
154 |
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); |
143 |
this.setLayout(layout); |
155 |
this.setLayout(layout); |
144 |
layout.setHorizontalGroup( |
156 |
layout.setHorizontalGroup( |
Lines 146-163
Link Here
|
146 |
.add(layout.createSequentialGroup() |
158 |
.add(layout.createSequentialGroup() |
147 |
.addContainerGap() |
159 |
.addContainerGap() |
148 |
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
160 |
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
149 |
.add(cbAccept) |
161 |
.add(taTitle) |
150 |
.add(org.jdesktop.layout.GroupLayout.TRAILING, taTitle, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE) |
162 |
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() |
151 |
.add(spLicenses, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 461, Short.MAX_VALUE)) |
163 |
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) |
152 |
.addContainerGap()) |
164 |
.add(layout.createSequentialGroup() |
|
|
165 |
.add(lbPlugins, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE) |
166 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
167 |
.add(cbPlugins, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 405, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) |
168 |
.add(org.jdesktop.layout.GroupLayout.LEADING, cbAccept)) |
169 |
.add(48, 48, 48)) |
170 |
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() |
171 |
.add(spLicense, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 506, Short.MAX_VALUE) |
172 |
.addContainerGap()))) |
153 |
); |
173 |
); |
154 |
layout.setVerticalGroup( |
174 |
layout.setVerticalGroup( |
155 |
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
175 |
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) |
156 |
.add(layout.createSequentialGroup() |
176 |
.add(layout.createSequentialGroup() |
157 |
.add(taTitle, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 45, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
177 |
.add(taTitle, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 45, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
158 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
178 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
159 |
.add(spLicenses) |
179 |
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) |
|
|
180 |
.add(cbPlugins, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) |
181 |
.add(lbPlugins)) |
160 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
182 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) |
|
|
183 |
.add(spLicense, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE) |
184 |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) |
161 |
.add(cbAccept) |
185 |
.add(cbAccept) |
162 |
.addContainerGap()) |
186 |
.addContainerGap()) |
163 |
); |
187 |
); |
Lines 165-197
Link Here
|
165 |
cbAccept.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(LicenseApprovalPanel.class, "LicenseApprovalPanel_cbAccept_ACN")); // NOI18N |
189 |
cbAccept.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(LicenseApprovalPanel.class, "LicenseApprovalPanel_cbAccept_ACN")); // NOI18N |
166 |
}// </editor-fold>//GEN-END:initComponents |
190 |
}// </editor-fold>//GEN-END:initComponents |
167 |
|
191 |
|
168 |
private void cbAcceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAcceptActionPerformed |
192 |
private void cbAcceptActionPerformed(ActionEvent evt) {//GEN-FIRST:event_cbAcceptActionPerformed |
169 |
firePropertyChange (LICENSE_APPROVED, null, cbAccept.isSelected ()); |
193 |
firePropertyChange (LICENSE_APPROVED, null, cbAccept.isSelected ()); |
170 |
}//GEN-LAST:event_cbAcceptActionPerformed |
194 |
}//GEN-LAST:event_cbAcceptActionPerformed |
171 |
|
195 |
|
172 |
|
196 |
private void cbPluginsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPluginsActionPerformed |
|
|
197 |
// This is designed on purpose to make the user feel that |
198 |
// license do refresh when new plugin is selected |
199 |
taLicense.setText(""); |
200 |
final int delay = 100; |
201 |
RequestProcessor.getDefault().post(new Runnable() { |
202 |
|
203 |
public void run() { |
204 |
SwingUtilities.invokeLater(new Runnable() { |
205 |
|
206 |
public void run() { |
207 |
UpdateElement el = license4plugins.get(cbPlugins.getSelectedIndex()); |
208 |
taLicense.setText(el.getLicence()); |
209 |
taLicense.setCaretPosition(0); |
210 |
} |
211 |
}); |
212 |
} |
213 |
}, delay); |
214 |
}//GEN-LAST:event_cbPluginsActionPerformed |
215 |
|
173 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
216 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
174 |
private javax.swing.JCheckBox cbAccept; |
217 |
private javax.swing.JCheckBox cbAccept; |
175 |
private javax.swing.JScrollPane spLicenses; |
218 |
private javax.swing.JComboBox cbPlugins; |
176 |
private javax.swing.JTextArea taLicenses; |
219 |
private javax.swing.JLabel lbPlugins; |
|
|
220 |
private javax.swing.JScrollPane spLicense; |
221 |
private javax.swing.JTextArea taLicense; |
177 |
private javax.swing.JTextArea taTitle; |
222 |
private javax.swing.JTextArea taTitle; |
178 |
// End of variables declaration//GEN-END:variables |
223 |
// End of variables declaration//GEN-END:variables |
179 |
|
224 |
|
180 |
private void writeLicenses (InstallUnitWizardModel model) { |
225 |
private void writeLicenses(InstallUnitWizardModel model) { |
181 |
goOverLicenses (model); |
226 |
goOverLicenses(model); |
182 |
StringBuffer content = new StringBuffer (); |
227 |
List<String> pluginsModel = new ArrayList<String>(); |
183 |
for (String lic : license4plugins.keySet ()) { |
228 |
String fmt = NbBundle.getMessage(LicenseApprovalPanel.class, |
184 |
StringBuffer title = new StringBuffer (); |
229 |
"LicenseApprovalPanel_cbPlugins_ItemFormat"); |
185 |
for (String plugin : license4plugins.get (lic)) { |
230 |
for (UpdateElement el : license4plugins) { |
186 |
title.append ((title.length () == 0 ? "" : |
231 |
String formatted = MessageFormat.format(fmt, |
187 |
NbBundle.getMessage (LicenseApprovalPanel.class, "LicenseApprovalPanel_tpLicense_Delimeter")) + plugin); // NOI18N |
232 |
new Object[]{el.getDisplayName(), el.getSpecificationVersion()}); |
188 |
} |
233 |
pluginsModel.add(formatted); |
189 |
content.append (NbBundle.getMessage (LicenseApprovalPanel.class, "LicenseApprovalPanel_tpLicense_Head", title)); // NOI18N |
234 |
} |
190 |
content.append ("\n"); // NOI18N |
235 |
|
191 |
content.append (lic); |
236 |
cbPlugins.setModel(new DefaultComboBoxModel(pluginsModel.toArray())); |
192 |
content.append (NbBundle.getMessage (LicenseApprovalPanel.class, "LicenseApprovalPanel_tpLicense_Separator")); // NOI18N |
237 |
cbPlugins.setSelectedIndex(0); |
193 |
} |
238 |
} |
194 |
taLicenses.setText (content.toString ()); |
239 |
|
195 |
taLicenses.setCaretPosition (0); |
|
|
196 |
} |
197 |
} |
240 |
} |