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