Source Code Cross Referenced for AntArtifactChooser.java in  » IDE-Netbeans » bpel » org » netbeans » modules » bpel » project » ui » customizer » 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 » bpel » org.netbeans.modules.bpel.project.ui.customizer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms of the Common Development
003:         * and Distribution License (the License). You may not use this file except in
004:         * compliance with the License.
005:         * 
006:         * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007:         * or http://www.netbeans.org/cddl.txt.
008:         * 
009:         * When distributing Covered Code, include this CDDL Header Notice in each file
010:         * and include the License file at http://www.netbeans.org/cddl.txt.
011:         * If applicable, add the following below the CDDL Header, with the fields
012:         * enclosed by brackets [] replaced by your own identifying information:
013:         * "Portions Copyrighted [year] [name of copyright owner]"
014:         * 
015:         * The Original Software is NetBeans. The Initial Developer of the Original
016:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017:         * Microsystems, Inc. All Rights Reserved.
018:         */
019:
020:        package org.netbeans.modules.bpel.project.ui.customizer;
021:
022:        import java.beans.PropertyChangeEvent;
023:        import java.beans.PropertyChangeListener;
024:        import java.io.File;
025:        import java.io.IOException;
026:        import java.net.URI;
027:        import javax.swing.DefaultListModel;
028:        import javax.swing.JFileChooser;
029:        import org.netbeans.api.project.Project;
030:        import org.netbeans.api.project.ProjectManager;
031:        import org.netbeans.api.project.ProjectUtils;
032:        import org.openide.filesystems.FileObject;
033:        import org.openide.filesystems.FileUtil;
034:        import org.openide.util.NbBundle;
035:        import org.openide.NotifyDescriptor;
036:        import org.openide.DialogDisplayer;
037:        import org.netbeans.api.project.ant.AntArtifact;
038:        import org.netbeans.spi.project.ui.support.ProjectChooser;
039:        import org.netbeans.spi.project.ant.AntArtifactProvider;
040:
041:        /** Accessory component used in the ProjectChooser for choosing project
042:         * artifacts.
043:         *
044:         * @author  phrebejk
045:         */
046:        public class AntArtifactChooser extends javax.swing.JPanel implements 
047:                PropertyChangeListener {
048:
049:            // XXX to become an array later
050:            private String artifactType;
051:
052:            /** Creates new form JarArtifactChooser */
053:            public AntArtifactChooser(String artifactType, JFileChooser chooser) {
054:                this .artifactType = artifactType;
055:
056:                initComponents();
057:                jListArtifacts.setModel(new DefaultListModel());
058:                chooser.addPropertyChangeListener(this );
059:            }
060:
061:            /** This method is called from within the constructor to
062:             * initialize the form.
063:             * WARNING: Do NOT modify this code. The content of this method is
064:             * always regenerated by the Form Editor.
065:             */
066:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
067:            private void initComponents() {
068:                jLabelName = new javax.swing.JLabel();
069:                jTextFieldName = new javax.swing.JTextField();
070:                jLabelJarFiles = new javax.swing.JLabel();
071:                jScrollPane1 = new javax.swing.JScrollPane();
072:                jListArtifacts = new javax.swing.JList();
073:
074:                setMinimumSize(new java.awt.Dimension(190, 80));
075:                setPreferredSize(new java.awt.Dimension(270, 187));
076:                jLabelName.setText(org.openide.util.NbBundle
077:                        .getMessage(AntArtifactChooser.class,
078:                                "LBL_AACH_ProjectName_JLabel"));
079:
080:                jTextFieldName.setEditable(false);
081:                jTextFieldName
082:                        .getAccessibleContext()
083:                        .setAccessibleDescription(
084:                                java.util.ResourceBundle
085:                                        .getBundle(
086:                                                "org/netbeans/modules/compapp/projects/base/ui/customizer/Bundle")
087:                                        .getString(
088:                                                "ACS_AACH_ProjectName_A11YDesc"));
089:
090:                org.openide.awt.Mnemonics.setLocalizedText(jLabelJarFiles,
091:                        org.openide.util.NbBundle.getMessage(
092:                                AntArtifactChooser.class,
093:                                "LBL_AACH_ProjectJarFiles_JLabel"));
094:
095:                jScrollPane1.setViewportView(jListArtifacts);
096:                jListArtifacts.getAccessibleContext().setAccessibleDescription(
097:                        org.openide.util.NbBundle.getBundle(
098:                                AntArtifactChooser.class).getString(
099:                                "ACS_AACH_ProjectJarFiles_A11YDesc"));
100:
101:                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
102:                        this );
103:                this .setLayout(layout);
104:                layout
105:                        .setHorizontalGroup(layout
106:                                .createParallelGroup(
107:                                        org.jdesktop.layout.GroupLayout.LEADING)
108:                                .add(
109:                                        layout
110:                                                .createSequentialGroup()
111:                                                .addContainerGap()
112:                                                .add(
113:                                                        layout
114:                                                                .createParallelGroup(
115:                                                                        org.jdesktop.layout.GroupLayout.LEADING)
116:                                                                .add(jLabelName)
117:                                                                .add(
118:                                                                        jTextFieldName,
119:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
120:                                                                        250,
121:                                                                        Short.MAX_VALUE)
122:                                                                .add(
123:                                                                        jLabelJarFiles)
124:                                                                .add(
125:                                                                        jScrollPane1,
126:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
127:                                                                        250,
128:                                                                        Short.MAX_VALUE))
129:                                                .addContainerGap()));
130:                layout
131:                        .setVerticalGroup(layout
132:                                .createParallelGroup(
133:                                        org.jdesktop.layout.GroupLayout.LEADING)
134:                                .add(
135:                                        layout
136:                                                .createSequentialGroup()
137:                                                .add(jLabelName)
138:                                                .addPreferredGap(
139:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
140:                                                .add(
141:                                                        jTextFieldName,
142:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
143:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
144:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
145:                                                .addPreferredGap(
146:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
147:                                                .add(jLabelJarFiles)
148:                                                .addPreferredGap(
149:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
150:                                                .add(
151:                                                        jScrollPane1,
152:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
153:                                                        110, Short.MAX_VALUE)
154:                                                .addContainerGap()));
155:            }// </editor-fold>//GEN-END:initComponents
156:
157:            public void propertyChange(PropertyChangeEvent e) {
158:
159:                if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(e
160:                        .getPropertyName())) {
161:                    // We have to update the Accessory
162:                    JFileChooser chooser = (JFileChooser) e.getSource();
163:                    File dir = chooser.getSelectedFile();
164:                    DefaultListModel spListModel = (DefaultListModel) jListArtifacts
165:                            .getModel();
166:
167:                    Project project = getProject(dir);
168:                    populateAccessory(project);
169:                }
170:            }
171:
172:            private Project getProject(File projectDir) {
173:
174:                try {
175:                    FileObject projectRoot = FileUtil.toFileObject(projectDir);
176:
177:                    if (projectRoot != null) {
178:                        Project project = ProjectManager.getDefault()
179:                                .findProject(projectRoot);
180:                        return project;
181:                    }
182:                } catch (IOException e) {
183:                    // Return null
184:                }
185:
186:                return null;
187:            }
188:
189:            private void populateAccessory(Project project) {
190:
191:                DefaultListModel model = (DefaultListModel) jListArtifacts
192:                        .getModel();
193:                model.clear();
194:                jTextFieldName.setText(project == null ? "" : ProjectUtils
195:                        .getInformation(project).getDisplayName()); //NOI18N
196:
197:                if (project != null) {
198:                    AntArtifactProvider prov = (AntArtifactProvider) project
199:                            .getLookup().lookup(AntArtifactProvider.class);
200:                    if (prov != null) {
201:                        AntArtifact[] artifacts = prov.getBuildArtifacts();
202:                        if ((artifacts != null) && (artifacts.length > 0)) {
203:                            //                    AntArtifact aa = artifacts[1];
204:                            //                    if (aa.getType().startsWith(artifactType)) {
205:                            //                        model.addElement( new ArtifactItem( aa));
206:                            //                    }
207:                            for (int i = 0; i < artifacts.length; i++) {
208:                                if (artifacts[i].getType().startsWith(
209:                                        artifactType)) {
210:                                    model.addElement(new ArtifactItem(
211:                                            artifacts[i]));
212:                                }
213:                            }
214:                        }
215:                    }
216:
217:                }
218:            }
219:
220:            // Variables declaration - do not modify//GEN-BEGIN:variables
221:            private javax.swing.JLabel jLabelJarFiles;
222:            private javax.swing.JLabel jLabelName;
223:            private javax.swing.JList jListArtifacts;
224:            private javax.swing.JScrollPane jScrollPane1;
225:            private javax.swing.JTextField jTextFieldName;
226:
227:            // End of variables declaration//GEN-END:variables
228:
229:            /** Shows dialog with the artifact chooser
230:             * @return null if canceled selected jars if some jars selected
231:             */
232:            public static AntArtifact[] showDialog(String artifactType,
233:                    DefaultListModel data, Project master) {
234:
235:                JFileChooser chooser = ProjectChooser.projectChooser();
236:                chooser.setDialogTitle(NbBundle.getMessage(
237:                        AntArtifactChooser.class, "LBL_AACH_Title")); // NOI18N
238:                chooser.setApproveButtonText(NbBundle.getMessage(
239:                        AntArtifactChooser.class, "LBL_AACH_SelectProject")); // NOI18N
240:
241:                AntArtifactChooser accessory = new AntArtifactChooser(
242:                        artifactType, chooser);
243:                chooser.setAccessory(accessory);
244:
245:                int option = chooser.showOpenDialog(null); // Show the chooser
246:
247:                if (option == JFileChooser.APPROVE_OPTION) {
248:
249:                    File dir = chooser.getSelectedFile();
250:                    dir = FileUtil.normalizeFile(dir);
251:                    Project selectedProject = accessory.getProject(dir);
252:
253:                    if (selectedProject == null) {
254:                        return null;
255:                    }
256:
257:                    if (selectedProject.getProjectDirectory().equals(
258:                            master.getProjectDirectory())) {
259:                        DialogDisplayer.getDefault().notify(
260:                                new NotifyDescriptor.Message(NbBundle
261:                                        .getMessage(AntArtifactChooser.class,
262:                                                "MSG_AACH_RefToItself"),
263:                                        NotifyDescriptor.INFORMATION_MESSAGE));
264:                        return null;
265:                    }
266:
267:                    if (data != null) {
268:                        for (int i = 0, size = data.getSize(); i < size; i++) {
269:                            VisualClassPathItem vi = (VisualClassPathItem) data
270:                                    .get(i);
271:                            if (vi != null) {
272:                                AntArtifact aa = (AntArtifact) vi.getObject();
273:                                if (selectedProject.equals(aa.getProject())) {
274:                                    DialogDisplayer
275:                                            .getDefault()
276:                                            .notify(
277:                                                    new NotifyDescriptor.Message(
278:                                                            NbBundle
279:                                                                    .getMessage(
280:                                                                            AntArtifactChooser.class,
281:                                                                            "MSG_AACH_AlreadySelected"),
282:                                                            NotifyDescriptor.INFORMATION_MESSAGE));
283:                                    return null;
284:                                }
285:                            }
286:                        }
287:                    }
288:
289:                    if (ProjectUtils.hasSubprojectCycles(master,
290:                            selectedProject)) {
291:                        DialogDisplayer.getDefault().notify(
292:                                new NotifyDescriptor.Message(NbBundle
293:                                        .getMessage(AntArtifactChooser.class,
294:                                                "MSG_AACH_Cycles"),
295:                                        NotifyDescriptor.INFORMATION_MESSAGE));
296:                        return null;
297:                    }
298:
299:                    DefaultListModel model = (DefaultListModel) accessory.jListArtifacts
300:                            .getModel();
301:
302:                    AntArtifact artifacts[] = new AntArtifact[model.size()];
303:
304:                    // XXX Adding references twice
305:
306:                    // XXX What about adding reference to itself
307:                    for (int i = 0; i < artifacts.length; i++) {
308:                        artifacts[i] = ((ArtifactItem) model.getElementAt(i))
309:                                .getArtifact();
310:                    }
311:
312:                    return artifacts;
313:
314:                } else {
315:                    return null;
316:                }
317:
318:            }
319:
320:            /** Shows dialog with the artifact chooser
321:             * @return null if canceled selected jars if some jars selected
322:             */
323:            public static AntArtifact[] showDialog(String artifactType,
324:                    Project p) {
325:
326:                JFileChooser chooser = ProjectChooser.projectChooser();
327:                chooser.setDialogTitle(NbBundle.getMessage(
328:                        AntArtifactChooser.class, "LBL_AACH_Title")); // NOI18N
329:                chooser.setApproveButtonText(NbBundle.getMessage(
330:                        AntArtifactChooser.class, "LBL_AACH_SelectProject")); // NOI18N
331:
332:                AntArtifactChooser accessory = new AntArtifactChooser(
333:                        artifactType, chooser);
334:                chooser.setAccessory(accessory);
335:                if (p != null) {
336:                    FileObject dobj = p.getProjectDirectory().getParent();
337:                    if (dobj != null) {
338:                        chooser.setCurrentDirectory(FileUtil.toFile(dobj));
339:                    }
340:                }
341:                int option = chooser.showOpenDialog(null); // Show the chooser
342:
343:                if (option == JFileChooser.APPROVE_OPTION) {
344:
345:                    DefaultListModel model = (DefaultListModel) accessory.jListArtifacts
346:                            .getModel();
347:
348:                    AntArtifact artifacts[] = new AntArtifact[model.size()];
349:
350:                    // XXX Adding references twice
351:
352:                    // XXX What about adding reference to itself
353:                    for (int i = 0; i < artifacts.length; i++) {
354:                        artifacts[i] = ((ArtifactItem) model.getElementAt(i))
355:                                .getArtifact();
356:                    }
357:
358:                    return artifacts;
359:
360:                } else {
361:                    return null;
362:                }
363:
364:            }
365:
366:            private static class ArtifactItem {
367:
368:                private AntArtifact artifact;
369:
370:                ArtifactItem(AntArtifact artifact) {
371:                    this .artifact = artifact;
372:                }
373:
374:                AntArtifact getArtifact() {
375:                    return artifact;
376:                }
377:
378:                public String toString() {
379:                    URI[] us = artifact.getArtifactLocations();
380:                    if ((us != null) && (us.length > 0)) {
381:                        return us[0].toString();
382:                    }
383:                    return null;
384:                }
385:            }
386:        }
ww__w_.__j__a___v__a_2___s__.c_o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.