Removed
Link Here
|
1 |
/* |
2 |
* The contents of this file are subject to the terms of the Common Development |
3 |
* and Distribution License (the License). You may not use this file except in |
4 |
* compliance with the License. |
5 |
* |
6 |
* You can obtain a copy of the License at http://www.netbeans.org/cddl.html |
7 |
* or http://www.netbeans.org/cddl.txt. |
8 |
* |
9 |
* When distributing Covered Code, include this CDDL Header Notice in each file |
10 |
* and include the License file at http://www.netbeans.org/cddl.txt. |
11 |
* If applicable, add the following below the CDDL Header, with the fields |
12 |
* enclosed by brackets [] replaced by your own identifying information: |
13 |
* "Portions Copyrighted [year] [name of copyright owner]" |
14 |
* |
15 |
* The Original Software is NetBeans. The Initial Developer of the Original |
16 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun |
17 |
* Microsystems, Inc. All Rights Reserved. |
18 |
*/ |
19 |
|
20 |
package org.netbeans.modules.ant.freeform.ui; |
21 |
|
22 |
import java.awt.BorderLayout; |
23 |
import java.awt.Component; |
24 |
import java.awt.Dimension; |
25 |
import java.awt.GridBagConstraints; |
26 |
import java.awt.Image; |
27 |
import java.beans.PropertyChangeEvent; |
28 |
import java.beans.PropertyChangeListener; |
29 |
import java.beans.PropertyVetoException; |
30 |
import java.util.ArrayList; |
31 |
import java.util.Arrays; |
32 |
import java.util.Collection; |
33 |
import java.util.Collections; |
34 |
import java.util.Comparator; |
35 |
import java.util.Iterator; |
36 |
import java.util.List; |
37 |
import javax.swing.JPanel; |
38 |
import javax.swing.tree.TreeSelectionModel; |
39 |
import org.netbeans.modules.ant.freeform.FreeformProject; |
40 |
import org.netbeans.modules.ant.freeform.Util; |
41 |
import org.netbeans.modules.ant.freeform.spi.ProjectNature; |
42 |
import org.netbeans.modules.ant.freeform.spi.ProjectPropertiesPanel; |
43 |
import org.netbeans.modules.ant.freeform.spi.TargetDescriptor; |
44 |
import org.netbeans.spi.project.AuxiliaryConfiguration; |
45 |
import org.netbeans.spi.project.support.ant.AntProjectHelper; |
46 |
import org.netbeans.spi.project.support.ant.PropertyEvaluator; |
47 |
import org.openide.DialogDescriptor; |
48 |
import org.openide.explorer.ExplorerManager; |
49 |
import org.openide.explorer.view.BeanTreeView; |
50 |
import org.openide.nodes.AbstractNode; |
51 |
import org.openide.nodes.Children; |
52 |
import org.openide.nodes.Node; |
53 |
import org.openide.util.HelpCtx; |
54 |
import org.openide.util.Utilities; |
55 |
|
56 |
/** |
57 |
* |
58 |
* @author Petr Hrebejk, David Konecny |
59 |
*/ |
60 |
public class ProjectCustomizer extends JPanel implements HelpCtx.Provider { |
61 |
|
62 |
private Component currentCustomizer; |
63 |
private GridBagConstraints fillConstraints; |
64 |
private List<ProjectPropertiesPanel> panels; |
65 |
private FreeformProject project; |
66 |
|
67 |
private DialogDescriptor dialogDescriptor; |
68 |
|
69 |
private static final String GENERAL_ICON = "general.gif"; // NOI18N |
70 |
|
71 |
public ProjectCustomizer(FreeformProject project) { |
72 |
this.project = project; |
73 |
initComponents(); |
74 |
HelpCtx.setHelpIDString( customizerPanel, "org.netbeans.modules.ant.freeform.ui.ProjectCustomizer." + Util.getMergedHelpIDFragments(project)); // NOI18N |
75 |
|
76 |
fillConstraints = new GridBagConstraints(); |
77 |
fillConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; |
78 |
fillConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; |
79 |
fillConstraints.fill = java.awt.GridBagConstraints.BOTH; |
80 |
fillConstraints.weightx = 1.0; |
81 |
fillConstraints.weighty = 1.0; |
82 |
createProjectCustomizerPanels(); |
83 |
categoryPanel.add(new CategoryView(createRootNode()), fillConstraints); |
84 |
} |
85 |
|
86 |
void save() { |
87 |
for (ProjectPropertiesPanel panel : panels) { |
88 |
panel.storeValues(); |
89 |
} |
90 |
} |
91 |
|
92 |
/** This method is called from within the constructor to |
93 |
* initialize the form. |
94 |
* WARNING: Do NOT modify this code. The content of this method is |
95 |
* always regenerated by the Form Editor. |
96 |
*/ |
97 |
private void initComponents() {//GEN-BEGIN:initComponents |
98 |
java.awt.GridBagConstraints gridBagConstraints; |
99 |
|
100 |
categoryPanel = new javax.swing.JPanel(); |
101 |
jPanel1 = new javax.swing.JPanel(); |
102 |
customizerPanel = new javax.swing.JPanel(); |
103 |
jLabel1 = new javax.swing.JLabel(); |
104 |
|
105 |
setLayout(new java.awt.GridBagLayout()); |
106 |
|
107 |
setPreferredSize(new java.awt.Dimension(750, 450)); |
108 |
getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSD_ProjectCustomizer")); |
109 |
categoryPanel.setLayout(new java.awt.GridBagLayout()); |
110 |
|
111 |
categoryPanel.setBorder(new javax.swing.border.EtchedBorder()); |
112 |
categoryPanel.setMinimumSize(new java.awt.Dimension(220, 4)); |
113 |
categoryPanel.setPreferredSize(new java.awt.Dimension(220, 4)); |
114 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
115 |
gridBagConstraints.gridx = 0; |
116 |
gridBagConstraints.gridy = 1; |
117 |
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; |
118 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
119 |
gridBagConstraints.weighty = 1.0; |
120 |
gridBagConstraints.insets = new java.awt.Insets(4, 8, 8, 8); |
121 |
add(categoryPanel, gridBagConstraints); |
122 |
categoryPanel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSN_ProjectCustomizer_categoryPanel")); |
123 |
categoryPanel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSD_ProjectCustomizer_categoryPanel")); |
124 |
|
125 |
jPanel1.setLayout(new java.awt.GridBagLayout()); |
126 |
|
127 |
customizerPanel.setLayout(new java.awt.GridBagLayout()); |
128 |
|
129 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
130 |
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; |
131 |
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; |
132 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
133 |
gridBagConstraints.weightx = 1.0; |
134 |
gridBagConstraints.weighty = 1.0; |
135 |
jPanel1.add(customizerPanel, gridBagConstraints); |
136 |
customizerPanel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSN_ProjectCustomizer_customizerPanel")); |
137 |
customizerPanel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "ACSD_ProjectCustomizer_customizerPanel")); |
138 |
|
139 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
140 |
gridBagConstraints.gridx = 1; |
141 |
gridBagConstraints.gridy = 1; |
142 |
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; |
143 |
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; |
144 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
145 |
gridBagConstraints.weightx = 1.0; |
146 |
gridBagConstraints.weighty = 1.0; |
147 |
gridBagConstraints.insets = new java.awt.Insets(4, 4, 8, 8); |
148 |
add(jPanel1, gridBagConstraints); |
149 |
|
150 |
jLabel1.setText(org.openide.util.NbBundle.getMessage(ProjectCustomizer.class, "LBL_Customizer_Categories")); |
151 |
gridBagConstraints = new java.awt.GridBagConstraints(); |
152 |
gridBagConstraints.gridx = 0; |
153 |
gridBagConstraints.gridy = 0; |
154 |
gridBagConstraints.gridwidth = 2; |
155 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
156 |
gridBagConstraints.insets = new java.awt.Insets(8, 8, 0, 0); |
157 |
add(jLabel1, gridBagConstraints); |
158 |
|
159 |
}//GEN-END:initComponents |
160 |
|
161 |
|
162 |
// Variables declaration - do not modify//GEN-BEGIN:variables |
163 |
private javax.swing.JPanel categoryPanel; |
164 |
private javax.swing.JPanel customizerPanel; |
165 |
private javax.swing.JLabel jLabel1; |
166 |
private javax.swing.JPanel jPanel1; |
167 |
// End of variables declaration//GEN-END:variables |
168 |
|
169 |
public void setDialogDescriptor( DialogDescriptor dialogDescriptor ) { |
170 |
this.dialogDescriptor = dialogDescriptor; |
171 |
} |
172 |
|
173 |
// HelpCtx.Provider implementation ----------------------------------------- |
174 |
|
175 |
public HelpCtx getHelpCtx() { |
176 |
if ( currentCustomizer != null ) { |
177 |
HelpCtx customizerCtx = HelpCtx.findHelp( currentCustomizer ); |
178 |
if (customizerCtx.getHelpID() != null) { |
179 |
return new HelpCtx(customizerCtx.getHelpID() + "." + Util.getMergedHelpIDFragments(project)); // NOI18N |
180 |
} else { |
181 |
return customizerCtx; |
182 |
} |
183 |
} else { |
184 |
return HelpCtx.findHelp( customizerPanel ); |
185 |
} |
186 |
} |
187 |
|
188 |
// Private innerclasses ---------------------------------------------------- |
189 |
|
190 |
private class CategoryView extends JPanel implements ExplorerManager.Provider { |
191 |
|
192 |
private ExplorerManager manager; |
193 |
private BeanTreeView btv; |
194 |
|
195 |
CategoryView( Node rootNode ) { |
196 |
|
197 |
// See #36315 |
198 |
manager = new ExplorerManager(); |
199 |
|
200 |
setLayout( new BorderLayout() ); |
201 |
|
202 |
Dimension size = new Dimension( 220, 4 ); |
203 |
btv = new BeanTreeView(); // Add the BeanTreeView |
204 |
btv.setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); |
205 |
btv.setPopupAllowed( false ); |
206 |
btv.setRootVisible( false ); |
207 |
btv.setDefaultActionAllowed( false ); |
208 |
btv.setMinimumSize( size ); |
209 |
btv.setPreferredSize( size ); |
210 |
btv.setMaximumSize( size ); |
211 |
btv.setDragSource (false); |
212 |
btv.setDragSource (false); |
213 |
this.add( btv, BorderLayout.CENTER ); |
214 |
manager.setRootContext( rootNode ); |
215 |
manager.addPropertyChangeListener( new ManagerChangeListener() ); |
216 |
selectFirstNode(); |
217 |
btv.expandAll(); |
218 |
|
219 |
} |
220 |
|
221 |
public ExplorerManager getExplorerManager() { |
222 |
return manager; |
223 |
} |
224 |
|
225 |
public void addNotify() { |
226 |
super.addNotify(); |
227 |
btv.expandAll(); |
228 |
} |
229 |
|
230 |
private void selectFirstNode() { |
231 |
|
232 |
Children ch = manager.getRootContext().getChildren(); |
233 |
if ( ch != null ) { |
234 |
Node nodes[] = ch.getNodes(); |
235 |
|
236 |
if ( nodes != null && nodes.length > 0 ) { |
237 |
try { |
238 |
manager.setSelectedNodes( new Node[] { nodes[0] } ); |
239 |
} |
240 |
catch ( PropertyVetoException e ) { |
241 |
// No node will be selected |
242 |
} |
243 |
} |
244 |
} |
245 |
|
246 |
} |
247 |
|
248 |
|
249 |
/** Listens to selection change and shows the customizers as |
250 |
* panels |
251 |
*/ |
252 |
|
253 |
private class ManagerChangeListener implements PropertyChangeListener { |
254 |
|
255 |
public void propertyChange(PropertyChangeEvent evt) { |
256 |
if(evt.getSource() != manager) { |
257 |
return; |
258 |
} |
259 |
|
260 |
if (ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { |
261 |
Node nodes[] = manager.getSelectedNodes(); |
262 |
if ( nodes == null || nodes.length <= 0 ) { |
263 |
return; |
264 |
} |
265 |
Node node = nodes[0]; |
266 |
|
267 |
if ( currentCustomizer != null ) { |
268 |
customizerPanel.remove( currentCustomizer ); |
269 |
} |
270 |
if ( node.hasCustomizer() ) { |
271 |
currentCustomizer = node.getCustomizer(); |
272 |
customizerPanel.add( currentCustomizer, fillConstraints ); |
273 |
customizerPanel.validate(); |
274 |
customizerPanel.repaint(); |
275 |
if ( ProjectCustomizer.this.dialogDescriptor != null ) { |
276 |
ProjectCustomizer.this.dialogDescriptor.setHelpCtx( ProjectCustomizer.this.getHelpCtx() ); |
277 |
} |
278 |
|
279 |
|
280 |
} |
281 |
else { |
282 |
currentCustomizer = null; |
283 |
} |
284 |
|
285 |
return; |
286 |
} |
287 |
} |
288 |
} |
289 |
} |
290 |
|
291 |
// Private methods --------------------------------------------------------- |
292 |
|
293 |
private List<ProjectPropertiesPanel> createProjectCustomizerPanels() { |
294 |
AuxiliaryConfiguration aux = project.getLookup().lookup(AuxiliaryConfiguration.class); |
295 |
AntProjectHelper helper = project.helper(); |
296 |
PropertyEvaluator eval = project.evaluator(); |
297 |
panels = new ArrayList<ProjectPropertiesPanel>(); |
298 |
List<TargetDescriptor> extraTargets = new ArrayList<TargetDescriptor>(); |
299 |
for (ProjectNature pn : FreeformProject.PROJECT_NATURES.allInstances()) { |
300 |
panels.addAll(pn.getCustomizerPanels(project, helper, eval, aux)); |
301 |
extraTargets.addAll(pn.getExtraTargets(project, helper, eval, aux)); |
302 |
} |
303 |
if (project.usesAntScripting()) { |
304 |
panels.add(new TargetMappingPanel.Panel(extraTargets, eval, helper)); |
305 |
} |
306 |
|
307 |
Collections.sort(panels, new PanelsComparator()); |
308 |
return panels; |
309 |
} |
310 |
|
311 |
private static class PanelsComparator implements Comparator<ProjectPropertiesPanel> { |
312 |
public int compare(ProjectPropertiesPanel p1, ProjectPropertiesPanel p2) { |
313 |
if (p1.getPreferredPosition() == p2.getPreferredPosition()) { |
314 |
return 0; |
315 |
} else { |
316 |
return p1.getPreferredPosition() - p2.getPreferredPosition(); |
317 |
} |
318 |
} |
319 |
} |
320 |
|
321 |
private Node createRootNode() { |
322 |
|
323 |
String ICON_FOLDER = "org/netbeans/modules/ant/freeform/resources/"; // NOI18N |
324 |
|
325 |
List<ConfigurationDescription> l = new ArrayList<ConfigurationDescription>(); |
326 |
for (ProjectPropertiesPanel panel : panels) { |
327 |
ConfigurationDescription cd = new ConfigurationDescription( |
328 |
panel.getDisplayName(), |
329 |
panel.getDisplayName(), |
330 |
ICON_FOLDER + GENERAL_ICON, |
331 |
panel, |
332 |
null); |
333 |
l.add(cd); |
334 |
} |
335 |
|
336 |
ConfigurationDescription rootDescription = new ConfigurationDescription( |
337 |
"InvisibleRoot", "InvisibleRoot", null, null, l.toArray(new ConfigurationDescription[l.size()])); // NOI18N |
338 |
|
339 |
return new ConfigurationNode( rootDescription ); |
340 |
} |
341 |
|
342 |
// Private innerclasses ---------------------------------------------------- |
343 |
|
344 |
/** Class describing the configuration node. Prototype of the |
345 |
* configuration node. |
346 |
*/ |
347 |
private static class ConfigurationDescription { |
348 |
|
349 |
|
350 |
private String name; |
351 |
private String displayName; |
352 |
private String iconResource; |
353 |
private ProjectPropertiesPanel panel; |
354 |
private ConfigurationDescription[] children; |
355 |
// XXX Add Node.Properties |
356 |
|
357 |
ConfigurationDescription( String name, |
358 |
String displayName, |
359 |
String iconResource, |
360 |
ProjectPropertiesPanel panel, |
361 |
ConfigurationDescription[] children ) { |
362 |
|
363 |
this.name = name; |
364 |
this.displayName = displayName; |
365 |
this.iconResource = iconResource; |
366 |
this.panel = panel; |
367 |
this.children = children; |
368 |
} |
369 |
|
370 |
} |
371 |
|
372 |
|
373 |
/** Node to be used for configuration |
374 |
*/ |
375 |
private static class ConfigurationNode extends AbstractNode { |
376 |
|
377 |
private ProjectPropertiesPanel panel; |
378 |
/** resource path to icon, or null */ |
379 |
private final String iconResource; |
380 |
|
381 |
public ConfigurationNode( ConfigurationDescription description ) { |
382 |
super( description.children == null ? Children.LEAF : new ConfigurationChildren( description.children ) ); |
383 |
setName( description.name ); |
384 |
setDisplayName( description.displayName ); |
385 |
this.iconResource = description.iconResource; |
386 |
this.panel = description.panel; |
387 |
} |
388 |
|
389 |
public boolean hasCustomizer() { |
390 |
return true; |
391 |
} |
392 |
|
393 |
public Component getCustomizer() { |
394 |
if (panel == null) { |
395 |
return null; |
396 |
} |
397 |
return panel.getComponent(); |
398 |
} |
399 |
|
400 |
public Image getIcon(int type) { |
401 |
if (iconResource != null) { |
402 |
return Utilities.loadImage(iconResource, true); |
403 |
} else { |
404 |
return super.getIcon(type); |
405 |
} |
406 |
} |
407 |
|
408 |
public Image getOpenedIcon(int type) { |
409 |
if (iconResource != null) { |
410 |
return Utilities.loadImage(iconResource, true); |
411 |
} else { |
412 |
return super.getOpenedIcon(type); |
413 |
} |
414 |
} |
415 |
|
416 |
} |
417 |
|
418 |
private static class ConfigurationChildren extends Children.Keys<ConfigurationDescription> { |
419 |
|
420 |
private ConfigurationDescription[] descriptions; |
421 |
|
422 |
public ConfigurationChildren(ConfigurationDescription[] descriptions) { |
423 |
this.descriptions = descriptions; |
424 |
} |
425 |
|
426 |
public void addNotify() { |
427 |
setKeys(descriptions); |
428 |
} |
429 |
|
430 |
public void removeNotify() { |
431 |
setKeys(new ConfigurationDescription[0]); |
432 |
} |
433 |
|
434 |
protected Node[] createNodes(ConfigurationDescription key) { |
435 |
return new Node[] {new ConfigurationNode(key)}; |
436 |
} |
437 |
} |
438 |
} |