Source Code Cross Referenced for ComponentVolumeCustomizer.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » project » jsf » libraries » provider » 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 » visualweb.api.designer » org.netbeans.modules.visualweb.project.jsf.libraries.provider 
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-2007 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.visualweb.project.jsf.libraries.provider;
043:
044:        import java.awt.Color;
045:        import java.awt.Component;
046:        import java.beans.Customizer;
047:        import java.io.File;
048:        import java.net.URL;
049:        import java.net.MalformedURLException;
050:        import java.util.Collection;
051:        import java.util.Arrays;
052:        import java.awt.*;
053:        import javax.swing.*;
054:        import javax.swing.DefaultListCellRenderer;
055:        import javax.swing.event.*;
056:        import org.openide.ErrorManager;
057:        import org.openide.filesystems.FileUtil;
058:        import org.openide.filesystems.URLMapper;
059:        import org.openide.util.NbBundle;
060:        import org.netbeans.spi.project.libraries.LibraryImplementation;
061:
062:        import javax.swing.filechooser.FileFilter;
063:        import org.netbeans.spi.project.libraries.LibraryStorageArea;
064:        import org.netbeans.spi.project.libraries.support.LibrariesSupport;
065:        import org.openide.filesystems.FileObject;
066:
067:        /**
068:         *
069:         * @author  tom
070:         */
071:        public class ComponentVolumeCustomizer extends javax.swing.JPanel
072:                implements  Customizer {
073:
074:            private String volumeType;
075:            private LibraryImplementation impl;
076:            private VolumeContentModel model;
077:            private LibraryStorageArea area;
078:
079:            /**
080:             * Creates new form ComponentVolumeCustomizer
081:             */
082:            ComponentVolumeCustomizer(String volumeType) {
083:                this .volumeType = volumeType;
084:                initComponents();
085:                postInitComponents();
086:                this .setName(NbBundle.getMessage(
087:                        ComponentVolumeCustomizer.class, "TXT_" + volumeType));
088:            }
089:
090:            public void addNotify() {
091:                super .addNotify();
092:                this .addButton.requestFocus();
093:            }
094:
095:            public void setEnabled(boolean enabled) {
096:                super .setEnabled(enabled);
097:                this .addButton.setEnabled(enabled);
098:                if (this .addURLButton != null) {
099:                    this .addURLButton.setEnabled(enabled);
100:                }
101:                int[] indices = content.getSelectedIndices();
102:                this .removeButton.setEnabled(enabled && indices.length > 0);
103:                this .downButton.setEnabled(enabled && indices.length > 0
104:                        && indices[indices.length - 1] < model.getSize() - 1);
105:                this .upButton.setEnabled(enabled && indices.length > 0
106:                        && indices[0] > 0);
107:            }
108:
109:            private void postInitComponents() {
110:                this .content.setCellRenderer(new ContentRenderer());
111:                this .upButton.setEnabled(false);
112:                this .downButton.setEnabled(false);
113:                this .removeButton.setEnabled(false);
114:                if (this .volumeType
115:                        .equals(ComponentLibraryTypeProvider.VOLUME_TYPE_CLASSPATH)) { //NOI18N
116:                    this .addButton.setText(NbBundle
117:                            .getMessage(ComponentVolumeCustomizer.class,
118:                                    "CTL_AddClassPath"));
119:                    this .addButton.setMnemonic(NbBundle
120:                            .getMessage(ComponentVolumeCustomizer.class,
121:                                    "MNE_AddClassPath").charAt(0));
122:                    this .message.setText(NbBundle.getMessage(
123:                            ComponentVolumeCustomizer.class,
124:                            "CTL_ContentClassPath"));
125:                    this .message.setDisplayedMnemonic(NbBundle.getMessage(
126:                            ComponentVolumeCustomizer.class,
127:                            "MNE_ContentClassPath").charAt(0));
128:                    this .addButton.getAccessibleContext()
129:                            .setAccessibleDescription(
130:                                    NbBundle.getMessage(
131:                                            ComponentVolumeCustomizer.class,
132:                                            "AD_AddClassPath"));
133:                    this .message.getAccessibleContext()
134:                            .setAccessibleDescription(
135:                                    NbBundle.getMessage(
136:                                            ComponentVolumeCustomizer.class,
137:                                            "AD_ContentClassPath"));
138:                } else if (this .volumeType
139:                        .equals(ComponentLibraryTypeProvider.VOLUME_TYPE_JAVADOC)) { //NOI18N
140:                    this .addButton.setText(NbBundle.getMessage(
141:                            ComponentVolumeCustomizer.class, "CTL_AddJavadoc"));
142:                    this .addButton.setMnemonic(NbBundle.getMessage(
143:                            ComponentVolumeCustomizer.class, "MNE_AddJavadoc")
144:                            .charAt(0));
145:                    this .message.setText(NbBundle.getMessage(
146:                            ComponentVolumeCustomizer.class,
147:                            "CTL_ContentJavadoc"));
148:                    this .message.setDisplayedMnemonic(NbBundle.getMessage(
149:                            ComponentVolumeCustomizer.class,
150:                            "MNE_ContentJavadoc").charAt(0));
151:                    this .addButton.getAccessibleContext()
152:                            .setAccessibleDescription(
153:                                    NbBundle.getMessage(
154:                                            ComponentVolumeCustomizer.class,
155:                                            "AD_AddJavadoc"));
156:                    this .message.getAccessibleContext()
157:                            .setAccessibleDescription(
158:                                    NbBundle.getMessage(
159:                                            ComponentVolumeCustomizer.class,
160:                                            "AD_ContentJavadoc"));
161:                    //            this.addURLButton = new JButton ();
162:                    //            this.addURLButton.setText(NbBundle.getMessage (ComponentVolumeCustomizer.class,"CTL_AddJavadocURL"));
163:                    //            this.addURLButton.setMnemonic(NbBundle.getMessage (ComponentVolumeCustomizer.class,"MNE_AddJavadocURL").charAt(0));
164:                    //            this.addURLButton.addActionListener (new ActionListener () {
165:                    //                public void actionPerformed(ActionEvent e) {
166:                    //                    addURLResource ();
167:                    //                }
168:                    //            });
169:                    //            GridBagConstraints c = new GridBagConstraints();
170:                    //            c.gridx = 1;
171:                    //            c.gridy = 2;
172:                    //            c.gridwidth = GridBagConstraints.REMAINDER;
173:                    //            c.gridheight = 1;
174:                    //            c.fill = GridBagConstraints.HORIZONTAL;
175:                    //            c.anchor = GridBagConstraints.NORTHWEST;
176:                    //            c.insets = new Insets (0,6,5,6);
177:                    //            ((GridBagLayout)this.getLayout()).setConstraints(this.addURLButton,c);
178:                    //            this.add (this.addURLButton);
179:                } else if (this .volumeType
180:                        .equals(ComponentLibraryTypeProvider.VOLUME_TYPE_SRC)) { //NOI18N
181:                    this .addButton.setText(NbBundle.getMessage(
182:                            ComponentVolumeCustomizer.class, "CTL_AddSources"));
183:                    this .addButton.setMnemonic(NbBundle.getMessage(
184:                            ComponentVolumeCustomizer.class, "MNE_AddSources")
185:                            .charAt(0));
186:                    this .message.setText(NbBundle.getMessage(
187:                            ComponentVolumeCustomizer.class,
188:                            "CTL_ContentSources"));
189:                    this .message.setDisplayedMnemonic(NbBundle.getMessage(
190:                            ComponentVolumeCustomizer.class,
191:                            "MNE_ContentSources").charAt(0));
192:                    this .addButton.getAccessibleContext()
193:                            .setAccessibleDescription(
194:                                    NbBundle.getMessage(
195:                                            ComponentVolumeCustomizer.class,
196:                                            "AD_AddSources"));
197:                    this .message.getAccessibleContext()
198:                            .setAccessibleDescription(
199:                                    NbBundle.getMessage(
200:                                            ComponentVolumeCustomizer.class,
201:                                            "AD_ContentSources"));
202:                } else if (this .volumeType
203:                        .equals(ComponentLibraryTypeProvider.VOLUME_TYPE_DESIGNTIME)) { //NOI18N
204:                    this .addButton.setText(NbBundle.getMessage(
205:                            ComponentVolumeCustomizer.class, "CTL_AddSources"));
206:                    this .addButton.setMnemonic(NbBundle.getMessage(
207:                            ComponentVolumeCustomizer.class, "MNE_AddSources")
208:                            .charAt(0));
209:                    this .message.setText(NbBundle.getMessage(
210:                            ComponentVolumeCustomizer.class,
211:                            "CTL_ContentSources"));
212:                    this .message.setDisplayedMnemonic(NbBundle.getMessage(
213:                            ComponentVolumeCustomizer.class,
214:                            "MNE_ContentSources").charAt(0));
215:                    this .addButton.getAccessibleContext()
216:                            .setAccessibleDescription(
217:                                    NbBundle.getMessage(
218:                                            ComponentVolumeCustomizer.class,
219:                                            "AD_AddSources"));
220:                    this .message.getAccessibleContext()
221:                            .setAccessibleDescription(
222:                                    NbBundle.getMessage(
223:                                            ComponentVolumeCustomizer.class,
224:                                            "AD_ContentSources"));
225:                }
226:                this .content
227:                        .addListSelectionListener(new ListSelectionListener() {
228:                            public void valueChanged(ListSelectionEvent e) {
229:                                if (e.getValueIsAdjusting())
230:                                    return;
231:                                int[] indices = content.getSelectedIndices();
232:                                removeButton.setEnabled(indices.length > 0);
233:                                downButton.setEnabled(indices.length > 0
234:                                        && indices[indices.length - 1] < model
235:                                                .getSize() - 1);
236:                                upButton.setEnabled(indices.length > 0
237:                                        && indices[0] > 0);
238:                            }
239:                        });
240:            }
241:
242:            /** This method is called from within the constructor to
243:             * initialize the form.
244:             * WARNING: Do NOT modify this code. The content of this method is
245:             * always regenerated by the Form Editor.
246:             */
247:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
248:            private void initComponents() {
249:                java.awt.GridBagConstraints gridBagConstraints;
250:
251:                message = new javax.swing.JLabel();
252:                jScrollPane1 = new javax.swing.JScrollPane();
253:                content = new javax.swing.JList();
254:                addButton = new javax.swing.JButton();
255:                removeButton = new javax.swing.JButton();
256:                upButton = new javax.swing.JButton();
257:                downButton = new javax.swing.JButton();
258:
259:                setLayout(new java.awt.GridBagLayout());
260:
261:                getAccessibleContext().setAccessibleDescription(null);
262:                message.setLabelFor(content);
263:                org.openide.awt.Mnemonics.setLocalizedText(message,
264:                        org.openide.util.NbBundle.getBundle(
265:                                ComponentVolumeCustomizer.class).getString(
266:                                "CTL_ContentMessage"));
267:                gridBagConstraints = new java.awt.GridBagConstraints();
268:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
269:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
271:                gridBagConstraints.weightx = 1.0;
272:                gridBagConstraints.insets = new java.awt.Insets(6, 12, 2, 6);
273:                add(message, gridBagConstraints);
274:
275:                jScrollPane1.setViewportView(content);
276:
277:                gridBagConstraints = new java.awt.GridBagConstraints();
278:                gridBagConstraints.gridx = 0;
279:                gridBagConstraints.gridy = 1;
280:                gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
281:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
282:                gridBagConstraints.weightx = 1.0;
283:                gridBagConstraints.weighty = 1.0;
284:                gridBagConstraints.insets = new java.awt.Insets(0, 12, 6, 6);
285:                add(jScrollPane1, gridBagConstraints);
286:
287:                org.openide.awt.Mnemonics.setLocalizedText(addButton,
288:                        org.openide.util.NbBundle.getBundle(
289:                                ComponentVolumeCustomizer.class).getString(
290:                                "CTL_AddContent"));
291:                addButton
292:                        .addActionListener(new java.awt.event.ActionListener() {
293:                            public void actionPerformed(
294:                                    java.awt.event.ActionEvent evt) {
295:                                addResource(evt);
296:                            }
297:                        });
298:
299:                gridBagConstraints = new java.awt.GridBagConstraints();
300:                gridBagConstraints.gridx = 1;
301:                gridBagConstraints.gridy = 1;
302:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
303:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
304:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
305:                gridBagConstraints.insets = new java.awt.Insets(3, 6, 5, 6);
306:                add(addButton, gridBagConstraints);
307:                addButton.getAccessibleContext().setAccessibleDescription(null);
308:
309:                org.openide.awt.Mnemonics.setLocalizedText(removeButton,
310:                        org.openide.util.NbBundle.getBundle(
311:                                ComponentVolumeCustomizer.class).getString(
312:                                "CTL_RemoveContent"));
313:                removeButton
314:                        .addActionListener(new java.awt.event.ActionListener() {
315:                            public void actionPerformed(
316:                                    java.awt.event.ActionEvent evt) {
317:                                removeResource(evt);
318:                            }
319:                        });
320:
321:                gridBagConstraints = new java.awt.GridBagConstraints();
322:                gridBagConstraints.gridx = 1;
323:                gridBagConstraints.gridy = 3;
324:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
325:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
326:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
327:                gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 6);
328:                add(removeButton, gridBagConstraints);
329:                removeButton.getAccessibleContext().setAccessibleDescription(
330:                        null);
331:
332:                org.openide.awt.Mnemonics.setLocalizedText(upButton,
333:                        org.openide.util.NbBundle.getBundle(
334:                                ComponentVolumeCustomizer.class).getString(
335:                                "CTL_UpContent"));
336:                upButton.addActionListener(new java.awt.event.ActionListener() {
337:                    public void actionPerformed(java.awt.event.ActionEvent evt) {
338:                        upResource(evt);
339:                    }
340:                });
341:
342:                gridBagConstraints = new java.awt.GridBagConstraints();
343:                gridBagConstraints.gridx = 1;
344:                gridBagConstraints.gridy = 4;
345:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
346:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
347:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
348:                gridBagConstraints.insets = new java.awt.Insets(5, 6, 0, 6);
349:                add(upButton, gridBagConstraints);
350:                upButton.getAccessibleContext().setAccessibleDescription(null);
351:
352:                org.openide.awt.Mnemonics.setLocalizedText(downButton,
353:                        org.openide.util.NbBundle.getBundle(
354:                                ComponentVolumeCustomizer.class).getString(
355:                                "CTL_DownContent"));
356:                downButton
357:                        .addActionListener(new java.awt.event.ActionListener() {
358:                            public void actionPerformed(
359:                                    java.awt.event.ActionEvent evt) {
360:                                downResource(evt);
361:                            }
362:                        });
363:
364:                gridBagConstraints = new java.awt.GridBagConstraints();
365:                gridBagConstraints.gridx = 1;
366:                gridBagConstraints.gridy = 5;
367:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
368:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
369:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
370:                gridBagConstraints.insets = new java.awt.Insets(5, 6, 6, 6);
371:                add(downButton, gridBagConstraints);
372:                downButton.getAccessibleContext()
373:                        .setAccessibleDescription(null);
374:
375:            }
376:
377:            // </editor-fold>//GEN-END:initComponents
378:
379:            private void downResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downResource
380:                int[] indices = this .content.getSelectedIndices();
381:                if (indices.length == 0 || indices[0] < 0
382:                        || indices[indices.length - 1] >= model.getSize() - 1) {
383:                    return;
384:                }
385:                this .model.moveDown(indices);
386:                for (int i = 0; i < indices.length; i++) {
387:                    indices[i] = indices[i] + 1;
388:                }
389:                this .content.setSelectedIndices(indices);
390:            }//GEN-LAST:event_downResource
391:
392:            private void upResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upResource
393:                int[] indices = this .content.getSelectedIndices();
394:                if (indices.length == 0 || indices[0] <= 0) {
395:                    return;
396:                }
397:                this .model.moveUp(indices);
398:                for (int i = 0; i < indices.length; i++) {
399:                    indices[i] = indices[i] - 1;
400:                }
401:                this .content.setSelectedIndices(indices);
402:            }//GEN-LAST:event_upResource
403:
404:            private void removeResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeResource
405:                int[] indices = this .content.getSelectedIndices();
406:                if (indices.length == 0) {
407:                    return;
408:                }
409:                this .model.removeResources(indices);
410:                if (indices[indices.length - 1] - indices.length + 1 < this .model
411:                        .getSize()) {
412:                    this .content.setSelectedIndex(indices[indices.length - 1]
413:                            - indices.length + 1);
414:                } else if (indices[0] >= 1) {
415:                    this .content.setSelectedIndex(indices[0] - 1);
416:                }
417:            }//GEN-LAST:event_removeResource
418:
419:            private void addResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addResource
420:                // TODO add your handling code here:
421:                JFileChooser chooser = new JFileChooser();
422:                FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
423:                chooser.setAcceptAllFileFilterUsed(false);
424:                if (this .volumeType
425:                        .equalsIgnoreCase(ComponentLibraryTypeProvider.VOLUME_TYPE_CLASSPATH)) { //NOI18N
426:                    chooser.setMultiSelectionEnabled(true);
427:                    chooser
428:                            .setDialogTitle(NbBundle.getMessage(
429:                                    ComponentVolumeCustomizer.class,
430:                                    "TXT_OpenClasses"));
431:                    chooser
432:                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
433:                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
434:                            .getMessage(ComponentVolumeCustomizer.class,
435:                                    "TXT_Classpath"), new String[] { "ZIP",
436:                            "JAR" })); //NOI18N
437:                    chooser.setApproveButtonText(NbBundle.getMessage(
438:                            ComponentVolumeCustomizer.class, "CTL_SelectCP"));
439:                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
440:                            ComponentVolumeCustomizer.class, "MNE_SelectCP")
441:                            .charAt(0));
442:                } else if (this .volumeType
443:                        .equalsIgnoreCase(ComponentLibraryTypeProvider.VOLUME_TYPE_JAVADOC)) { //NOI18N
444:                    chooser
445:                            .setDialogTitle(NbBundle.getMessage(
446:                                    ComponentVolumeCustomizer.class,
447:                                    "TXT_OpenJavadoc"));
448:                    chooser
449:                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
450:                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
451:                            .getMessage(ComponentVolumeCustomizer.class,
452:                                    "TXT_Javadoc"),
453:                            new String[] { "ZIP", "JAR" })); //NOI18N
454:                    chooser.setApproveButtonText(NbBundle.getMessage(
455:                            ComponentVolumeCustomizer.class, "CTL_SelectJD"));
456:                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
457:                            ComponentVolumeCustomizer.class, "MNE_SelectJD")
458:                            .charAt(0));
459:                } else if (this .volumeType
460:                        .equalsIgnoreCase(ComponentLibraryTypeProvider.VOLUME_TYPE_SRC)) { //NOI18N
461:                    chooser
462:                            .setDialogTitle(NbBundle.getMessage(
463:                                    ComponentVolumeCustomizer.class,
464:                                    "TXT_OpenSources"));
465:                    chooser
466:                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
467:                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
468:                            .getMessage(ComponentVolumeCustomizer.class,
469:                                    "TXT_Sources"),
470:                            new String[] { "ZIP", "JAR" })); //NOI18N
471:                    chooser.setApproveButtonText(NbBundle.getMessage(
472:                            ComponentVolumeCustomizer.class, "CTL_SelectSRC"));
473:                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
474:                            ComponentVolumeCustomizer.class, "MNE_SelectSRC")
475:                            .charAt(0));
476:                } else if (this .volumeType
477:                        .equalsIgnoreCase(ComponentLibraryTypeProvider.VOLUME_TYPE_DESIGNTIME)) { //NOI18N
478:                    chooser
479:                            .setDialogTitle(NbBundle.getMessage(
480:                                    ComponentVolumeCustomizer.class,
481:                                    "TXT_OpenSources"));
482:                    chooser
483:                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
484:                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
485:                            .getMessage(ComponentVolumeCustomizer.class,
486:                                    "TXT_Sources"),
487:                            new String[] { "ZIP", "JAR" })); //NOI18N
488:                    chooser.setApproveButtonText(NbBundle.getMessage(
489:                            ComponentVolumeCustomizer.class, "CTL_SelectSRC"));
490:                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
491:                            ComponentVolumeCustomizer.class, "MNE_SelectSRC")
492:                            .charAt(0));
493:                }
494:                if (lastFolder != null) {
495:                    chooser.setCurrentDirectory(lastFolder);
496:                }
497:                if (chooser.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
498:                    try {
499:                        lastFolder = chooser.getCurrentDirectory();
500:                        if (chooser.isMultiSelectionEnabled()) {
501:                            addFiles(chooser.getSelectedFiles());
502:                        } else {
503:                            addFiles(new File[] { chooser.getSelectedFile() });
504:                        }
505:                    } catch (MalformedURLException mue) {
506:                        ErrorManager.getDefault().notify(mue);
507:                    }
508:                }
509:            }//GEN-LAST:event_addResource
510:
511:            //    private void addURLResource () {
512:            //        DialogDescriptor.InputLine input = new DialogDescriptor.InputLine (
513:            //                NbBundle.getMessage(ComponentVolumeCustomizer.class,"CTL_AddJavadocURLMessage"),
514:            //                NbBundle.getMessage(ComponentVolumeCustomizer.class,"CTL_AddJavadocURLTitle"));
515:            //        if (DialogDisplayer.getDefault().notify(input) == DialogDescriptor.OK_OPTION) {
516:            //            try {
517:            //                String value = input.getInputText();
518:            //                URL url = new URL (value);
519:            //                this.model.addResource(url);
520:            //                this.content.setSelectedIndex(this.model.getSize()-1);
521:            //            } catch (MalformedURLException mue) {
522:            //                DialogDescriptor.Message message = new DialogDescriptor.Message (
523:            //                        NbBundle.getMessage(ComponentVolumeCustomizer.class,"CTL_InvalidURLFormat"),
524:            //                        DialogDescriptor.ERROR_MESSAGE
525:            //                );
526:            //                DialogDisplayer.getDefault().notify(message);
527:            //            }
528:            //        }
529:            //    }
530:
531:            private void addFiles(File[] files) throws MalformedURLException {
532:                int firstIndex = this .model.getSize();
533:                for (int i = 0; i < files.length; i++) {
534:                    File f = files[i];
535:                    //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
536:                    // E.g. for /foo/src it returns /foo/src/src
537:                    // Try to convert it back by removing last invalid name component
538:                    if (!f.exists()) {
539:                        File parent = f.getParentFile();
540:                        if (parent != null
541:                                && f.getName().equals(parent.getName())
542:                                && parent.exists()) {
543:                            f = parent;
544:                        }
545:                    }
546:                    URL url = f.toURI().toURL();
547:                    this .model.addResource(url);
548:                }
549:                int lastIndex = this .model.getSize() - 1;
550:                if (firstIndex <= lastIndex) {
551:                    int[] toSelect = new int[lastIndex - firstIndex + 1];
552:                    for (int i = 0; i < toSelect.length; i++) {
553:                        toSelect[i] = firstIndex + i;
554:                    }
555:                    this .content.setSelectedIndices(toSelect);
556:                }
557:            }
558:
559:            public void setObject(Object bean) {
560:                if (bean instanceof  LibraryStorageArea) {
561:                    this .area = (LibraryStorageArea) bean;
562:                } else {
563:                    this .area = null;
564:                }
565:                if (bean instanceof  LibraryImplementation) {
566:                    this .impl = (LibraryImplementation) bean;
567:                    this .model = new VolumeContentModel(this .impl, area,
568:                            this .volumeType);
569:                    this .content.setModel(model);
570:                    if (this .model.getSize() > 0) {
571:                        this .content.setSelectedIndex(0);
572:                    }
573:                } else {
574:                    throw new IllegalArgumentException();
575:                }
576:            }
577:
578:            private static class SimpleFileFilter extends FileFilter {
579:
580:                private String description;
581:                private Collection extensions;
582:
583:                public SimpleFileFilter(String description, String[] extensions) {
584:                    this .description = description;
585:                    this .extensions = Arrays.asList(extensions);
586:                }
587:
588:                public boolean accept(File f) {
589:                    if (f.isDirectory())
590:                        return true;
591:                    String name = f.getName();
592:                    int index = name.lastIndexOf('.'); //NOI18N
593:                    if (index <= 0 || index == name.length() - 1)
594:                        return false;
595:                    String extension = name.substring(index + 1).toUpperCase();
596:                    return this .extensions.contains(extension);
597:                }
598:
599:                public String getDescription() {
600:                    return this .description;
601:                }
602:            }
603:
604:            private static File lastFolder = null;
605:
606:            // Variables declaration - do not modify//GEN-BEGIN:variables
607:            private javax.swing.JButton addButton;
608:            private javax.swing.JList content;
609:            private javax.swing.JButton downButton;
610:            private javax.swing.JScrollPane jScrollPane1;
611:            private javax.swing.JLabel message;
612:            private javax.swing.JButton removeButton;
613:            private javax.swing.JButton upButton;
614:            // End of variables declaration//GEN-END:variables
615:            private JButton addURLButton;
616:
617:            private static class ContentRenderer extends
618:                    DefaultListCellRenderer {
619:
620:                public Component getListCellRendererComponent(JList list,
621:                        Object value, int index, boolean isSelected,
622:                        boolean cellHasFocus) {
623:                    String displayName = null;
624:                    Color color = null;
625:                    String toolTip = null;
626:
627:                    if (value instanceof  URL) {
628:                        URL url = (URL) value;
629:                        displayName = url.toExternalForm();
630:                        if ("jar".equals(url.getProtocol())) { //NOI18N
631:                            url = FileUtil.getArchiveFile(url);
632:                        }
633:                        VolumeContentModel model = (VolumeContentModel) list
634:                                .getModel();
635:                        LibraryStorageArea area = model.getArea();
636:                        FileObject fo = LibrariesSupport
637:                                .resolveLibraryEntryFileObject(
638:                                        area != null ? area.getLocation()
639:                                                : null, url);
640:                        if (fo == null) {
641:                            color = new Color(164, 0, 0);
642:                            toolTip = NbBundle.getMessage(
643:                                    ComponentVolumeCustomizer.class,
644:                                    "TXT_BrokenFile");
645:                        }
646:                    }
647:                    Component c = super .getListCellRendererComponent(list,
648:                            displayName, index, isSelected, cellHasFocus);
649:                    if (c instanceof  JComponent) {
650:                        if (color != null) {
651:                            ((JComponent) c).setForeground(color);
652:                        }
653:                        if (toolTip != null) {
654:                            ((JComponent) c).setToolTipText(toolTip);
655:                        }
656:                    }
657:                    return c;
658:                }
659:
660:            }
661:
662:        }
w___w_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.