KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > freeform > ui > ProjectCustomizerProvider


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ant.freeform.ui;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.awt.event.WindowAdapter JavaDoc;
26 import java.awt.event.WindowEvent JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30 import org.netbeans.api.project.Project;
31 import org.netbeans.api.project.ProjectManager;
32 import org.netbeans.api.project.ProjectUtils;
33 import org.netbeans.modules.ant.freeform.FreeformProject;
34 import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
35 import org.netbeans.spi.project.AuxiliaryConfiguration;
36 import org.netbeans.spi.project.ui.CustomizerProvider;
37 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
38 import org.openide.util.Lookup;
39 import org.openide.util.NbBundle;
40 import org.openide.util.lookup.AbstractLookup;
41 import org.openide.util.lookup.InstanceContent;
42
43 /**
44  *
45  * @author Petr Hrebejk, David Konecny
46  */

47 public class ProjectCustomizerProvider implements CustomizerProvider {
48     
49     private final FreeformProject project;
50     
51     public static final String JavaDoc CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-ant-freeform/Customizer"; //NO18N
52

53     private static Map JavaDoc<Project,Dialog JavaDoc> project2Dialog = new HashMap JavaDoc<Project,Dialog JavaDoc>();
54     
55     public ProjectCustomizerProvider(FreeformProject project) {
56         this.project = project;
57     }
58             
59     public void showCustomizer() {
60         Dialog JavaDoc dialog = project2Dialog.get (project);
61         if ( dialog != null ) {
62             dialog.setVisible(true);
63             return;
64         }
65         else {
66             InstanceContent ic = new InstanceContent();
67             Lookup context = new AbstractLookup(ic);
68             ic.add(project);
69             ic.add(project.getLookup().lookup(ProjectAccessor.class));
70             ic.add(project.getLookup().lookup(AuxiliaryConfiguration.class));
71             //TODO replace with generic apis..
72
ic.add(ic);
73             
74             OptionListener listener = new OptionListener( project );
75             dialog = ProjectCustomizer.createCustomizerDialog(CUSTOMIZER_FOLDER_PATH, context, null, listener, null );
76             dialog.addWindowListener( listener );
77             dialog.setTitle( MessageFormat.format(
78                     NbBundle.getMessage( ProjectCustomizerProvider.class, "LBL_Customizer_Title" ), // NOI18N
79
new Object JavaDoc[] { ProjectUtils.getInformation(project).getDisplayName() } ) );
80
81             project2Dialog.put(project, dialog);
82             dialog.setVisible(true);
83         }
84     }
85     
86
87     /** Listens to the actions on the Customizer's option buttons */
88     private class OptionListener extends WindowAdapter JavaDoc implements ActionListener JavaDoc {
89     
90         private Project project;
91         
92         OptionListener( Project project) {
93             this.project = project;
94         }
95         
96         // Listening to OK button ----------------------------------------------
97

98         public void actionPerformed( ActionEvent JavaDoc e ) {
99 //#95952 some users experience this assertion on a fairly random set of changes in
100
// the customizer, that leads me to assume that a project can be already marked
101
// as modified before the project customizer is shown.
102
// assert !ProjectManager.getDefault().isModified(project) :
103
// "Some of the customizer panels has written the changed data before OK Button was pressed. Please file it as bug."; //NOI18N
104

105             // Close & dispose the the dialog
106
Dialog JavaDoc dialog = project2Dialog.get( project );
107             if ( dialog != null ) {
108                 dialog.setVisible(false);
109                 dialog.dispose();
110             }
111         }
112         
113         // Listening to window events ------------------------------------------
114

115         public void windowClosed( WindowEvent JavaDoc e) {
116             project2Dialog.remove( project );
117         }
118         
119         public void windowClosing (WindowEvent JavaDoc e) {
120             //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
121
//may not be called
122
Dialog JavaDoc dialog = project2Dialog.get( project );
123             if ( dialog != null ) {
124                 dialog.setVisible(false);
125                 dialog.dispose();
126             }
127         }
128     }
129                             
130 }
131
Popular Tags