Source Code Cross Referenced for TemplatesPanel.java in  » IDE-Netbeans » project.ant » org » netbeans » modules » project » ui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » project.ant » org.netbeans.modules.project.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.project.ui;
043:
044:        import java.awt.Component;
045:        import java.awt.Cursor;
046:        import javax.swing.event.ChangeListener;
047:        import org.openide.ErrorManager;
048:        import org.openide.WizardDescriptor;
049:        import org.openide.filesystems.FileObject;
050:        import org.openide.loaders.DataFolder;
051:        import org.openide.loaders.DataObject;
052:        import org.openide.loaders.DataObjectNotFoundException;
053:        import org.openide.loaders.TemplateWizard;
054:        import org.openide.nodes.Children;
055:        import org.openide.nodes.FilterNode;
056:        import org.openide.nodes.Node;
057:        import org.openide.util.AsyncGUIJob;
058:        import org.openide.util.ChangeSupport;
059:        import org.openide.util.HelpCtx;
060:        import org.openide.util.NbBundle;
061:        import org.openide.util.Utilities;
062:
063:        /**
064:         *
065:         * @author  tom
066:         */
067:        public class TemplatesPanel implements 
068:                WizardDescriptor.Panel<WizardDescriptor> {
069:
070:            private final ChangeSupport changeSupport = new ChangeSupport(this );
071:            private TemplatesPanelGUI panel;
072:            private WarmupJob warmUp;
073:            private boolean warmUpActive;
074:            private boolean needsReselect = false; // WelcomeScreen hack, XXX Delete after WS is redesigned
075:
076:            /** Creates a new instance of TemplatesPanel */
077:            public TemplatesPanel() {
078:            }
079:
080:            public void readSettings(WizardDescriptor settings) {
081:                TemplateWizard wd = (TemplateWizard) settings;
082:                wd.putProperty("WizardPanel_contentSelectedIndex", new Integer(
083:                        0)); // NOI18N
084:                wd
085:                        .putProperty(
086:                                "WizardPanel_contentData",
087:                                new String[] { // NOI18N
088:                                        NbBundle
089:                                                .getBundle(TemplatesPanel.class)
090:                                                .getString(
091:                                                        "LBL_TemplatesPanel_Name"), // NOI18N
092:                                        NbBundle
093:                                                .getBundle(TemplatesPanel.class)
094:                                                .getString(
095:                                                        "LBL_TemplatesPanel_Dots") }); // NOI18N
096:                FileObject templatesFolder = (FileObject) wd
097:                        .getProperty(TemplatesPanelGUI.TEMPLATES_FOLDER);
098:
099:                // WelcomeScreen hack, XXX Delete after WS is redesigned
100:                String preselectedCategory = (String) wd
101:                        .getProperty("PRESELECT_CATEGORY");
102:                if (templatesFolder != null
103:                        && templatesFolder.isFolder()
104:                        && (wd.getTemplate() == null
105:                                || preselectedCategory != null || needsReselect)) {
106:
107:                    String preselectedTemplate = (String) wd
108:                            .getProperty("PRESELECT_TEMPLATE");
109:                    String template;
110:                    String selectedCategory = OpenProjectListSettings
111:                            .getInstance().getLastSelectedProjectCategory();
112:                    String selectedTemplate = OpenProjectListSettings
113:                            .getInstance().getLastSelectedProjectType();
114:
115:                    if (preselectedTemplate == null) {
116:                        template = preselectedCategory != null ? null
117:                                : selectedTemplate;
118:                    } else {
119:                        template = preselectedCategory != null ? preselectedTemplate
120:                                : selectedTemplate;
121:                    }
122:
123:                    TemplatesPanelGUI p = (TemplatesPanelGUI) this 
124:                            .getComponent();
125:                    if (isWarmUpActive()) {
126:                        WarmupJob wup = getWarmUp();
127:                        wup.setTemplatesFolder(templatesFolder);
128:                        wup
129:                                .setSelectedCategory(preselectedCategory != null ? preselectedCategory
130:                                        : selectedCategory);
131:                        wup.setSelectedTemplate(template);
132:                    } else {
133:                        p.setTemplatesFolder(templatesFolder);
134:                        p
135:                                .setSelectedCategoryByName(preselectedCategory != null ? preselectedCategory
136:                                        : selectedCategory);
137:                        p.setSelectedTemplateByName(template);
138:                    }
139:
140:                }
141:                // bugfix #44792: project wizard title always changes
142:                wd.putProperty("NewProjectWizard_Title", null); // NOI18N
143:            }
144:
145:            public void storeSettings(WizardDescriptor settings) {
146:                TemplateWizard wd = (TemplateWizard) settings;
147:
148:                // WelcomeScreen hack, XXX Delete after WS is redesigned
149:                String preselectedCategory = (String) wd
150:                        .getProperty("PRESELECT_CATEGORY");
151:
152:                TemplatesPanelGUI gui = (TemplatesPanelGUI) this .getComponent();
153:                FileObject fo = gui.getSelectedTemplate();
154:                if (fo != null) {
155:                    try {
156:                        wd.setTemplate(DataObject.find(fo));
157:                    } catch (DataObjectNotFoundException e) {
158:                        ErrorManager.getDefault().notify(e);
159:                    }
160:                }
161:                if (preselectedCategory == null) {
162:
163:                    String path = gui.getSelectedCategoryName();
164:                    if (path != null) {
165:                        OpenProjectListSettings.getInstance()
166:                                .setLastSelectedProjectCategory(path);
167:                    }
168:                    path = gui.getSelectedTemplateName();
169:                    if (path != null) {
170:                        OpenProjectListSettings.getInstance()
171:                                .setLastSelectedProjectType(path);
172:                    }
173:                    needsReselect = false;
174:                } else {
175:                    needsReselect = true;
176:                }
177:            }
178:
179:            public void addChangeListener(ChangeListener l) {
180:                changeSupport.addChangeListener(l);
181:            }
182:
183:            public void removeChangeListener(ChangeListener l) {
184:                changeSupport.removeChangeListener(l);
185:            }
186:
187:            public boolean isValid() {
188:                return ((TemplatesPanelGUI) this .getComponent())
189:                        .getSelectedTemplate() != null;
190:            }
191:
192:            public HelpCtx getHelp() {
193:                return new HelpCtx(TemplatesPanel.class);
194:            }
195:
196:            public synchronized Component getComponent() {
197:                if (this .panel == null) {
198:                    TemplatesPanelGUI.Builder firer = new Builder();
199:                    this .panel = new TemplatesPanelGUI(firer);
200:                    Utilities.attachInitJob(panel, getWarmUp());
201:                    this .warmUpActive = true;
202:                    this .panel.setName(NbBundle.getBundle(TemplatesPanel.class)
203:                            .getString("LBL_TemplatesPanel_Name")); // NOI18N
204:                }
205:                return this .panel;
206:            }
207:
208:            private synchronized WarmupJob getWarmUp() {
209:                if (this .warmUp == null) {
210:                    this .warmUp = new WarmupJob();
211:                }
212:                return this .warmUp;
213:            }
214:
215:            private synchronized boolean isWarmUpActive() {
216:                return warmUpActive;
217:            }
218:
219:            private static class CategoriesChildren extends
220:                    Children.Keys<DataObject> {
221:
222:                private DataFolder root;
223:
224:                public CategoriesChildren(DataFolder folder) {
225:                    this .root = folder;
226:                }
227:
228:                protected void addNotify() {
229:                    setKeys(root.getChildren());
230:                }
231:
232:                protected void removeNotify() {
233:                    this .setKeys(new DataObject[0]);
234:                }
235:
236:                protected Node[] createNodes(DataObject dobj) {
237:                    if (dobj instanceof  DataFolder) {
238:                        DataFolder folder = (DataFolder) dobj;
239:                        int type = 0; //Empty folder or File folder
240:                        for (DataObject child : folder.getChildren()) {
241:                            type = 1;
242:                            if (child.getPrimaryFile().isFolder()) {
243:                                type = 2; //Folder folder
244:                                break;
245:                            }
246:                        }
247:                        if (type == 1) {
248:                            return new Node[] { new FilterNode(dobj
249:                                    .getNodeDelegate(), Children.LEAF) };
250:                        } else if (type == 2) {
251:                            return new Node[] { new FilterNode(dobj
252:                                    .getNodeDelegate(), new CategoriesChildren(
253:                                    (DataFolder) dobj)) };
254:                        }
255:                    }
256:                    return new Node[0];
257:                }
258:            }
259:
260:            private static class TemplateChildren extends
261:                    Children.Keys<DataObject> {
262:
263:                private DataFolder folder;
264:
265:                public TemplateChildren(DataFolder folder) {
266:                    this .folder = folder;
267:                }
268:
269:                protected void addNotify() {
270:                    this .setKeys(this .folder.getChildren());
271:                }
272:
273:                protected void removeNotify() {
274:                    this .setKeys(new DataObject[0]);
275:                }
276:
277:                protected Node[] createNodes(DataObject dobj) {
278:                    if (dobj.isTemplate()) {
279:                        return new Node[] { new FilterNode(dobj
280:                                .getNodeDelegate(), Children.LEAF) };
281:                    } else {
282:                        return new Node[0];
283:                    }
284:                }
285:
286:            }
287:
288:            private class WarmupJob implements  AsyncGUIJob {
289:
290:                private FileObject templatesFolder;
291:                private String category;
292:                private String template;
293:
294:                public void construct() {
295:                    panel.warmUp(this .templatesFolder);
296:                }
297:
298:                public void finished() {
299:                    Cursor cursor = null;
300:                    try {
301:                        cursor = panel.getCursor();
302:                        panel.setCursor(Cursor
303:                                .getPredefinedCursor(Cursor.WAIT_CURSOR));
304:                        panel.doFinished(this .templatesFolder, this .category,
305:                                this .template);
306:                    } finally {
307:                        if (cursor != null) {
308:                            panel.setCursor(cursor);
309:                        }
310:                        synchronized (TemplatesPanel.this ) {
311:                            warmUpActive = false;
312:                        }
313:                    }
314:                }
315:
316:                void setTemplatesFolder(FileObject fo) {
317:                    this .templatesFolder = fo;
318:                }
319:
320:                void setSelectedCategory(String s) {
321:                    this .category = s;
322:                }
323:
324:                void setSelectedTemplate(String s) {
325:                    this .template = s;
326:                }
327:            }
328:
329:            private class Builder implements  TemplatesPanelGUI.Builder {
330:
331:                public org.openide.nodes.Children createCategoriesChildren(
332:                        DataFolder folder) {
333:                    assert folder != null : "Folder cannot be null."; //NOI18N
334:                    return new CategoriesChildren(folder);
335:                }
336:
337:                public org.openide.nodes.Children createTemplatesChildren(
338:                        DataFolder folder) {
339:                    return new TemplateChildren(folder);
340:                }
341:
342:                public String getCategoriesName() {
343:                    return NbBundle.getMessage(TemplatesPanel.class,
344:                            "CTL_Categories");
345:                }
346:
347:                public String getTemplatesName() {
348:                    return NbBundle.getMessage(TemplatesPanel.class,
349:                            "CTL_Projects");
350:                }
351:
352:                public void fireChange() {
353:                    changeSupport.fireChange();
354:                }
355:
356:            }
357:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.