Source Code Cross Referenced for ServerVolumeCustomizer.java in  » 6.0-JDK-Core » j2eeserver » org » netbeans » modules » j2ee » deployment » impl » sharability » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
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
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » j2eeserver » org.netbeans.modules.j2ee.deployment.impl.sharability 
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.j2ee.deployment.impl.sharability;
043
044        import java.awt.Color;
045        import java.awt.Component;
046        import java.beans.Customizer;
047        import java.io.File;
048        import java.io.IOException;
049        import java.net.URL;
050        import java.net.MalformedURLException;
051        import java.net.URI;
052        import java.util.Collection;
053        import java.util.Arrays;
054        import javax.swing.DefaultListCellRenderer;
055        import javax.swing.JButton;
056        import javax.swing.JComponent;
057        import javax.swing.JFileChooser;
058        import javax.swing.JList;
059        import javax.swing.event.ListSelectionEvent;
060        import javax.swing.event.ListSelectionListener;
061        import javax.swing.filechooser.FileFilter;
062        import org.netbeans.api.project.ant.FileChooser;
063        import org.openide.ErrorManager;
064        import org.openide.filesystems.FileObject;
065        import org.openide.filesystems.FileUtil;
066        import org.openide.util.NbBundle;
067        import org.netbeans.spi.project.libraries.LibraryImplementation;
068        import org.netbeans.spi.project.libraries.LibraryStorageArea;
069        import org.netbeans.spi.project.libraries.support.LibrariesSupport;
070        import org.openide.DialogDisplayer;
071        import org.openide.NotifyDescriptor;
072
073        /**
074         *
075         * @author  tom
076         */
077        public class ServerVolumeCustomizer extends javax.swing.JPanel
078                implements  Customizer {
079
080            private String volumeType;
081            private LibraryImplementation impl;
082            private LibraryStorageArea area;
083            private ServerVolumeContentModel model;
084
085            /** Creates new form J2SEVolumeCustomizer */
086            ServerVolumeCustomizer(String volumeType) {
087                this .volumeType = volumeType;
088                initComponents();
089                postInitComponents();
090                this .setName(NbBundle.getMessage(ServerVolumeCustomizer.class,
091                        "ServerVolumeCustomizer.TXT_" + volumeType));
092            }
093
094            public void addNotify() {
095                super .addNotify();
096                this .addButton.requestFocus();
097            }
098
099            public void setEnabled(boolean enabled) {
100                super .setEnabled(enabled);
101                this .addButton.setEnabled(enabled);
102                if (this .addURLButton != null) {
103                    this .addURLButton.setEnabled(enabled);
104                }
105                int[] indices = content.getSelectedIndices();
106                this .removeButton.setEnabled(enabled && indices.length > 0);
107                this .downButton.setEnabled(enabled && indices.length > 0
108                        && indices[indices.length - 1] < model.getSize() - 1);
109                this .upButton.setEnabled(enabled && indices.length > 0
110                        && indices[0] > 0);
111            }
112
113            private void postInitComponents() {
114                this .content.setCellRenderer(new ContentRenderer());
115                this .upButton.setEnabled(false);
116                this .downButton.setEnabled(false);
117                this .removeButton.setEnabled(false);
118                if (!this .volumeType
119                        .equals(ServerLibraryTypeProvider.VOLUME_JAVADOC)
120                        && !this .volumeType
121                                .equals(ServerLibraryTypeProvider.VOLUME_SOURCE)) {
122                    this .addButton.setText(NbBundle.getMessage(
123                            ServerVolumeCustomizer.class,
124                            "ServerVolumeCustomizer.CTL_AddClassPath"));
125                    this .addButton.setMnemonic(NbBundle.getMessage(
126                            ServerVolumeCustomizer.class,
127                            "ServerVolumeCustomizer.MNE_AddClassPath")
128                            .charAt(0));
129                    this .message.setText(NbBundle.getMessage(
130                            ServerVolumeCustomizer.class,
131                            "ServerVolumeCustomizer.CTL_ContentClassPath"));
132                    this .message.setDisplayedMnemonic(NbBundle.getMessage(
133                            ServerVolumeCustomizer.class,
134                            "ServerVolumeCustomizer.MNE_ContentClassPath")
135                            .charAt(0));
136                    this .addButton
137                            .getAccessibleContext()
138                            .setAccessibleDescription(
139                                    NbBundle
140                                            .getMessage(
141                                                    ServerVolumeCustomizer.class,
142                                                    "ServerVolumeCustomizer.AD_AddClassPath"));
143                    this .message
144                            .getAccessibleContext()
145                            .setAccessibleDescription(
146                                    NbBundle
147                                            .getMessage(
148                                                    ServerVolumeCustomizer.class,
149                                                    "ServerVolumeCustomizer.AD_ContentClassPath"));
150                } else if (this .volumeType
151                        .equals(ServerLibraryTypeProvider.VOLUME_JAVADOC)) {
152                    this .addButton.setText(NbBundle.getMessage(
153                            ServerVolumeCustomizer.class,
154                            "ServerVolumeCustomizer.CTL_AddJavadoc"));
155                    this .addButton.setMnemonic(NbBundle.getMessage(
156                            ServerVolumeCustomizer.class,
157                            "ServerVolumeCustomizer.MNE_AddJavadoc").charAt(0));
158                    this .message.setText(NbBundle.getMessage(
159                            ServerVolumeCustomizer.class,
160                            "ServerVolumeCustomizer.CTL_ContentJavadoc"));
161                    this .message.setDisplayedMnemonic(NbBundle.getMessage(
162                            ServerVolumeCustomizer.class,
163                            "ServerVolumeCustomizer.MNE_ContentJavadoc")
164                            .charAt(0));
165                    this .addButton
166                            .getAccessibleContext()
167                            .setAccessibleDescription(
168                                    NbBundle
169                                            .getMessage(
170                                                    ServerVolumeCustomizer.class,
171                                                    "ServerVolumeCustomizer.AD_AddJavadoc"));
172                    this .message
173                            .getAccessibleContext()
174                            .setAccessibleDescription(
175                                    NbBundle
176                                            .getMessage(
177                                                    ServerVolumeCustomizer.class,
178                                                    "ServerVolumeCustomizer.AD_ContentJavadoc"));
179                } else if (this .volumeType
180                        .equals(ServerLibraryTypeProvider.VOLUME_SOURCE)) {
181                    this .addButton.setText(NbBundle.getMessage(
182                            ServerVolumeCustomizer.class,
183                            "ServerVolumeCustomizer.CTL_AddSources"));
184                    this .addButton.setMnemonic(NbBundle.getMessage(
185                            ServerVolumeCustomizer.class,
186                            "ServerVolumeCustomizer.MNE_AddSources").charAt(0));
187                    this .message.setText(NbBundle.getMessage(
188                            ServerVolumeCustomizer.class,
189                            "ServerVolumeCustomizer.CTL_ContentSources"));
190                    this .message.setDisplayedMnemonic(NbBundle.getMessage(
191                            ServerVolumeCustomizer.class,
192                            "ServerVolumeCustomizer.MNE_ContentSources")
193                            .charAt(0));
194                    this .addButton
195                            .getAccessibleContext()
196                            .setAccessibleDescription(
197                                    NbBundle
198                                            .getMessage(
199                                                    ServerVolumeCustomizer.class,
200                                                    "ServerVolumeCustomizer.AD_AddSources"));
201                    this .message
202                            .getAccessibleContext()
203                            .setAccessibleDescription(
204                                    NbBundle
205                                            .getMessage(
206                                                    ServerVolumeCustomizer.class,
207                                                    "ServerVolumeCustomizer.AD_ContentSources"));
208                }
209                this .content
210                        .addListSelectionListener(new ListSelectionListener() {
211                            public void valueChanged(ListSelectionEvent e) {
212                                if (e.getValueIsAdjusting())
213                                    return;
214                                int[] indices = content.getSelectedIndices();
215                                removeButton.setEnabled(indices.length > 0);
216                                downButton.setEnabled(indices.length > 0
217                                        && indices[indices.length - 1] < model
218                                                .getSize() - 1);
219                                upButton.setEnabled(indices.length > 0
220                                        && indices[0] > 0);
221                            }
222                        });
223            }
224
225            /** This method is called from within the constructor to
226             * initialize the form.
227             * WARNING: Do NOT modify this code. The content of this method is
228             * always regenerated by the Form Editor.
229             */
230            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
231            private void initComponents() {
232                java.awt.GridBagConstraints gridBagConstraints;
233
234                message = new javax.swing.JLabel();
235                jScrollPane1 = new javax.swing.JScrollPane();
236                content = new javax.swing.JList();
237                addButton = new javax.swing.JButton();
238                removeButton = new javax.swing.JButton();
239                upButton = new javax.swing.JButton();
240                downButton = new javax.swing.JButton();
241
242                setLayout(new java.awt.GridBagLayout());
243
244                message.setLabelFor(content);
245                org.openide.awt.Mnemonics.setLocalizedText(message,
246                        org.openide.util.NbBundle.getBundle(
247                                ServerVolumeCustomizer.class).getString(
248                                "ServerVolumeCustomizer.CTL_ContentMessage")); // NOI18N
249                gridBagConstraints = new java.awt.GridBagConstraints();
250                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
251                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
252                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
253                gridBagConstraints.weightx = 1.0;
254                gridBagConstraints.insets = new java.awt.Insets(6, 6, 2, 6);
255                add(message, gridBagConstraints);
256
257                jScrollPane1.setViewportView(content);
258
259                gridBagConstraints = new java.awt.GridBagConstraints();
260                gridBagConstraints.gridx = 0;
261                gridBagConstraints.gridy = 1;
262                gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
263                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
264                gridBagConstraints.weightx = 1.0;
265                gridBagConstraints.weighty = 1.0;
266                gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 6);
267                add(jScrollPane1, gridBagConstraints);
268
269                org.openide.awt.Mnemonics.setLocalizedText(addButton,
270                        org.openide.util.NbBundle.getBundle(
271                                ServerVolumeCustomizer.class).getString(
272                                "ServerVolumeCustomizer.CTL_AddContent")); // NOI18N
273                addButton
274                        .addActionListener(new java.awt.event.ActionListener() {
275                            public void actionPerformed(
276                                    java.awt.event.ActionEvent evt) {
277                                addResource(evt);
278                            }
279                        });
280                gridBagConstraints = new java.awt.GridBagConstraints();
281                gridBagConstraints.gridx = 1;
282                gridBagConstraints.gridy = 1;
283                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
284                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
285                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
286                gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 6);
287                add(addButton, gridBagConstraints);
288                addButton.getAccessibleContext().setAccessibleDescription(
289                        "null");
290
291                org.openide.awt.Mnemonics.setLocalizedText(removeButton,
292                        org.openide.util.NbBundle.getBundle(
293                                ServerVolumeCustomizer.class).getString(
294                                "ServerVolumeCustomizer.CTL_RemoveContent")); // NOI18N
295                removeButton
296                        .addActionListener(new java.awt.event.ActionListener() {
297                            public void actionPerformed(
298                                    java.awt.event.ActionEvent evt) {
299                                removeResource(evt);
300                            }
301                        });
302                gridBagConstraints = new java.awt.GridBagConstraints();
303                gridBagConstraints.gridx = 1;
304                gridBagConstraints.gridy = 3;
305                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
306                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
307                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
308                gridBagConstraints.insets = new java.awt.Insets(5, 6, 6, 6);
309                add(removeButton, gridBagConstraints);
310                removeButton.getAccessibleContext().setAccessibleDescription(
311                        org.openide.util.NbBundle.getBundle(
312                                ServerVolumeCustomizer.class).getString(
313                                "ServerVolumeCustomizer.AD_RemoveContent")); // NOI18N
314
315                org.openide.awt.Mnemonics.setLocalizedText(upButton,
316                        org.openide.util.NbBundle.getBundle(
317                                ServerVolumeCustomizer.class).getString(
318                                "ServerVolumeCustomizer.CTL_UpContent")); // NOI18N
319                upButton.addActionListener(new java.awt.event.ActionListener() {
320                    public void actionPerformed(java.awt.event.ActionEvent evt) {
321                        upResource(evt);
322                    }
323                });
324                gridBagConstraints = new java.awt.GridBagConstraints();
325                gridBagConstraints.gridx = 1;
326                gridBagConstraints.gridy = 4;
327                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
328                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
329                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
330                gridBagConstraints.insets = new java.awt.Insets(5, 6, 0, 6);
331                add(upButton, gridBagConstraints);
332                upButton.getAccessibleContext().setAccessibleDescription(
333                        org.openide.util.NbBundle.getBundle(
334                                ServerVolumeCustomizer.class).getString(
335                                "ServerVolumeCustomizer.AD_UpContent")); // NOI18N
336
337                org.openide.awt.Mnemonics.setLocalizedText(downButton,
338                        org.openide.util.NbBundle.getBundle(
339                                ServerVolumeCustomizer.class).getString(
340                                "ServerVolumeCustomizer.CTL_DownContent")); // NOI18N
341                downButton
342                        .addActionListener(new java.awt.event.ActionListener() {
343                            public void actionPerformed(
344                                    java.awt.event.ActionEvent evt) {
345                                downResource(evt);
346                            }
347                        });
348                gridBagConstraints = new java.awt.GridBagConstraints();
349                gridBagConstraints.gridx = 1;
350                gridBagConstraints.gridy = 5;
351                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
352                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
353                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
354                gridBagConstraints.insets = new java.awt.Insets(5, 6, 6, 6);
355                add(downButton, gridBagConstraints);
356                downButton.getAccessibleContext().setAccessibleDescription(
357                        org.openide.util.NbBundle.getBundle(
358                                ServerVolumeCustomizer.class).getString(
359                                "ServerVolumeCustomizer.AD_DownContent")); // NOI18N
360
361                getAccessibleContext()
362                        .setAccessibleDescription(
363                                org.openide.util.NbBundle
364                                        .getBundle(ServerVolumeCustomizer.class)
365                                        .getString(
366                                                "ServerVolumeCustomizer.AD_J2SEVolumeCustomizer")); // NOI18N
367            }// </editor-fold>//GEN-END:initComponents
368
369            private void downResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downResource
370                int[] indices = this .content.getSelectedIndices();
371                if (indices.length == 0 || indices[0] < 0
372                        || indices[indices.length - 1] >= model.getSize() - 1) {
373                    return;
374                }
375                this .model.moveDown(indices);
376                for (int i = 0; i < indices.length; i++) {
377                    indices[i] = indices[i] + 1;
378                }
379                this .content.setSelectedIndices(indices);
380            }//GEN-LAST:event_downResource
381
382            private void upResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upResource
383                int[] indices = this .content.getSelectedIndices();
384                if (indices.length == 0 || indices[0] <= 0) {
385                    return;
386                }
387                this .model.moveUp(indices);
388                for (int i = 0; i < indices.length; i++) {
389                    indices[i] = indices[i] - 1;
390                }
391                this .content.setSelectedIndices(indices);
392            }//GEN-LAST:event_upResource
393
394            private void removeResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeResource
395                int[] indices = this .content.getSelectedIndices();
396                if (indices.length == 0) {
397                    return;
398                }
399                this .model.removeResources(indices);
400                if (indices[indices.length - 1] - indices.length + 1 < this .model
401                        .getSize()) {
402                    this .content.setSelectedIndex(indices[indices.length - 1]
403                            - indices.length + 1);
404                } else if (indices[0] >= 1) {
405                    this .content.setSelectedIndex(indices[0] - 1);
406                }
407                //XXX don't know
408                //        if (this.volumeType.equals(J2SELibraryTypeProvider.VOLUME_TYPE_CLASSPATH)) {
409                //            impl.setContent(J2SELibraryTypeProvider.VOLUME_TYPE_MAVEN_POM, Collections.<URL>emptyList());
410                //        }
411            }//GEN-LAST:event_removeResource
412
413            private void addResource(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addResource
414                // TODO add your handling code here:
415                File baseFolder = null;
416                if (area != null) {
417                    baseFolder = new File(URI.create(area.getLocation()
418                            .toExternalForm())).getParentFile();
419                }
420                FileChooser chooser = new FileChooser(baseFolder, baseFolder);
421                FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
422                chooser.setAcceptAllFileFilterUsed(false);
423                if (!this .volumeType
424                        .equals(ServerLibraryTypeProvider.VOLUME_JAVADOC)
425                        && !this .volumeType
426                                .equals(ServerLibraryTypeProvider.VOLUME_SOURCE)) {
427                    chooser.setMultiSelectionEnabled(true);
428                    chooser.setDialogTitle(NbBundle.getMessage(
429                            ServerVolumeCustomizer.class,
430                            "ServerVolumeCustomizer.TXT_OpenClasses"));
431                    chooser
432                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
433                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
434                            .getMessage(ServerVolumeCustomizer.class,
435                                    "ServerVolumeCustomizer.TXT_Classpath"),
436                            new String[] { "ZIP", "JAR" })); //NOI18N
437                    chooser.setApproveButtonText(NbBundle.getMessage(
438                            ServerVolumeCustomizer.class,
439                            "ServerVolumeCustomizer.CTL_SelectCP"));
440                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
441                            ServerVolumeCustomizer.class,
442                            "ServerVolumeCustomizer.MNE_SelectCP").charAt(0));
443                } else if (this .volumeType
444                        .equals(ServerLibraryTypeProvider.VOLUME_JAVADOC)) {
445                    chooser.setMultiSelectionEnabled(true);
446                    chooser.setDialogTitle(NbBundle.getMessage(
447                            ServerVolumeCustomizer.class,
448                            "ServerVolumeCustomizer.TXT_OpenJavadoc"));
449                    chooser
450                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
451                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
452                            .getMessage(ServerVolumeCustomizer.class,
453                                    "ServerVolumeCustomizer.TXT_Javadoc"),
454                            new String[] { "ZIP", "JAR" })); //NOI18N
455                    chooser.setApproveButtonText(NbBundle.getMessage(
456                            ServerVolumeCustomizer.class,
457                            "ServerVolumeCustomizer.CTL_SelectJD"));
458                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
459                            ServerVolumeCustomizer.class,
460                            "ServerVolumeCustomizer.MNE_SelectJD").charAt(0));
461                } else if (this .volumeType
462                        .equals(ServerLibraryTypeProvider.VOLUME_SOURCE)) {
463                    chooser.setMultiSelectionEnabled(true);
464                    chooser.setDialogTitle(NbBundle.getMessage(
465                            ServerVolumeCustomizer.class,
466                            "ServerVolumeCustomizer.TXT_OpenSources"));
467                    chooser
468                            .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
469                    chooser.setFileFilter(new SimpleFileFilter(NbBundle
470                            .getMessage(ServerVolumeCustomizer.class,
471                                    "ServerVolumeCustomizer.TXT_Sources"),
472                            new String[] { "ZIP", "JAR" })); //NOI18N
473                    chooser.setApproveButtonText(NbBundle.getMessage(
474                            ServerVolumeCustomizer.class,
475                            "ServerVolumeCustomizer.CTL_SelectSRC"));
476                    chooser.setApproveButtonMnemonic(NbBundle.getMessage(
477                            ServerVolumeCustomizer.class,
478                            "ServerVolumeCustomizer.MNE_SelectSRC").charAt(0));
479                }
480                if (lastFolder != null) {
481                    chooser.setCurrentDirectory(lastFolder);
482                } else if (baseFolder != null) {
483                    chooser.setCurrentDirectory(baseFolder);
484                }
485                if (chooser.showOpenDialog(this ) == JFileChooser.APPROVE_OPTION) {
486                    try {
487                        lastFolder = chooser.getCurrentDirectory();
488                        addFiles(chooser.getSelectedPaths(),
489                                area != null ? area.getLocation() : null);
490                    } catch (MalformedURLException mue) {
491                        ErrorManager.getDefault().notify(mue);
492                    } catch (IOException ex) {
493                        ErrorManager.getDefault().notify(ex);
494                    }
495                }
496            }//GEN-LAST:event_addResource
497
498            //    private void addURLResource () {
499            //        DialogDescriptor.InputLine input = new DialogDescriptor.InputLine (
500            //                NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_AddJavadocURLMessage"),
501            //                NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_AddJavadocURLTitle"));
502            //        if (DialogDisplayer.getDefault().notify(input) == DialogDescriptor.OK_OPTION) {
503            //            try {
504            //                String value = input.getInputText();
505            //                URL url = new URL (value);
506            //                this.model.addResource(url);
507            //                this.content.setSelectedIndex(this.model.getSize()-1);
508            //            } catch (MalformedURLException mue) {
509            //                DialogDescriptor.Message message = new DialogDescriptor.Message (
510            //                        NbBundle.getMessage(J2SEVolumeCustomizer.class,"CTL_InvalidURLFormat"),
511            //                        DialogDescriptor.ERROR_MESSAGE
512            //                );
513            //                DialogDisplayer.getDefault().notify(message);
514            //            }
515            //        }
516            //    }
517
518            private void addFiles(String[] files, URL libraryLocation)
519                    throws MalformedURLException {
520                int firstIndex = this .model.getSize();
521                for (int i = 0; i < files.length; i++) {
522                    File f = new File(files[i]);
523                    //mkleint: issue 5075580 was fixed in 1.4 and 5.0u7(b01).
524                    //            //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
525                    //            // E.g. for /foo/src it returns /foo/src/src
526                    //            // Try to convert it back by removing last invalid name component
527                    //            if (!f.exists()) {
528                    //                File parent = f.getParentFile();
529                    //                if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
530                    //                    f = parent;
531                    //                }
532                    //            }
533                    URL url = LibrariesSupport.convertFilePathToURL(files[i]);
534                    File realFile = f;
535                    if (!f.isAbsolute()) {
536                        assert area != null;
537                        if (area != null) {
538                            realFile = FileUtil
539                                    .normalizeFile(new File(new File(URI
540                                            .create(area.getLocation()
541                                                    .toExternalForm()))
542                                            .getParentFile(), f.getPath()));
543                        }
544                    }
545                    if (FileUtil.isArchiveFile(realFile.toURI().toURL())) {
546                        url = FileUtil.getArchiveRoot(url);
547                    } else if (!url.toExternalForm().endsWith("/")) {
548                        try {
549                            url = new URL(url.toExternalForm() + "/");
550                        } catch (MalformedURLException mue) {
551                            ErrorManager.getDefault().notify(mue);
552                        }
553                    }
554
555                    if (this .volumeType
556                            .equals(ServerLibraryTypeProvider.VOLUME_JAVADOC)
557                            && !JavadocForBinaryQueryImpl
558                                    .isValidLibraryJavadocRoot(LibrariesSupport
559                                            .resolveLibraryEntryURL(
560                                                    libraryLocation, url))) {
561
562                        DialogDisplayer
563                                .getDefault()
564                                .notify(
565                                        new NotifyDescriptor.Message(
566                                                NbBundle
567                                                        .getMessage(
568                                                                ServerVolumeCustomizer.class,
569                                                                "ServerVolumeCustomizer.TXT_InvalidJavadocRoot",
570                                                                f.getPath()),
571                                                NotifyDescriptor.ERROR_MESSAGE));
572                        continue;
573                    }
574                    this .model.addResource(url);
575                }
576                int lastIndex = this .model.getSize() - 1;
577                if (firstIndex <= lastIndex) {
578                    int[] toSelect = new int[lastIndex - firstIndex + 1];
579                    for (int i = 0; i < toSelect.length; i++) {
580                        toSelect[i] = firstIndex + i;
581                    }
582                    this .content.setSelectedIndices(toSelect);
583                }
584                //XXX don't know        
585                //        if (this.volumeType.equals(J2SELibraryTypeProvider.VOLUME_TYPE_CLASSPATH)) {
586                //            if (impl != null) {
587                //                impl.setContent(J2SELibraryTypeProvider.VOLUME_TYPE_MAVEN_POM, Collections.<URL>emptyList());
588                //            }
589                //        }
590            }
591
592            public void setObject(Object bean) {
593                if (bean instanceof  LibraryStorageArea) {
594                    this .area = (LibraryStorageArea) bean;
595                } else {
596                    this .area = null;
597                }
598                if (bean instanceof  LibraryImplementation) {
599                    this .impl = (LibraryImplementation) bean;
600                    this .model = new ServerVolumeContentModel(this .impl,
601                            this .area, this .volumeType);
602                    this .content.setModel(model);
603                    if (this .model.getSize() > 0) {
604                        this .content.setSelectedIndex(0);
605                    }
606                } else {
607                    throw new IllegalArgumentException();
608                }
609            }
610
611            private static class SimpleFileFilter extends FileFilter {
612
613                private String description;
614                private Collection extensions;
615
616                public SimpleFileFilter(String description, String[] extensions) {
617                    this .description = description;
618                    this .extensions = Arrays.asList(extensions);
619                }
620
621                public boolean accept(File f) {
622                    if (f.isDirectory())
623                        return true;
624                    String name = f.getName();
625                    int index = name.lastIndexOf('.'); //NOI18N
626                    if (index <= 0 || index == name.length() - 1)
627                        return false;
628                    String extension = name.substring(index + 1).toUpperCase();
629                    return this .extensions.contains(extension);
630                }
631
632                public String getDescription() {
633                    return this .description;
634                }
635            }
636
637            private static File lastFolder = null;
638
639            // Variables declaration - do not modify//GEN-BEGIN:variables
640            private javax.swing.JButton addButton;
641            private javax.swing.JList content;
642            private javax.swing.JButton downButton;
643            private javax.swing.JScrollPane jScrollPane1;
644            private javax.swing.JLabel message;
645            private javax.swing.JButton removeButton;
646            private javax.swing.JButton upButton;
647            // End of variables declaration//GEN-END:variables
648            private JButton addURLButton;
649
650            private static class ContentRenderer extends
651                    DefaultListCellRenderer {
652
653                public Component getListCellRendererComponent(JList list,
654                        Object value, int index, boolean isSelected,
655                        boolean cellHasFocus) {
656                    String displayName = null;
657                    Color color = null;
658                    String toolTip = null;
659
660                    if (value instanceof  URL) {
661                        URL url = (URL) value;
662                        if ("jar".equals(url.getProtocol())) { //NOI18N
663                            url = FileUtil.getArchiveFile(url);
664                        }
665                        boolean broken = false;
666                        ServerVolumeContentModel model = (ServerVolumeContentModel) list
667                                .getModel();
668                        LibraryStorageArea area = model.getArea();
669                        FileObject fo = LibrariesSupport
670                                .resolveLibraryEntryFileObject(
671                                        area != null ? area.getLocation()
672                                                : null, url);
673                        if (fo == null) {
674                            broken = true;
675                            if ("file".equals(url.getProtocol())) { //NOI18N
676                                displayName = LibrariesSupport
677                                        .convertURLToFilePath(url);
678                            } else {
679                                displayName = url.toExternalForm();
680                            }
681                        } else {
682                            if (LibrariesSupport.isAbsoluteURL(url)) {
683                                displayName = FileUtil.getFileDisplayName(fo);
684                            } else {
685                                displayName = LibrariesSupport
686                                        .convertURLToFilePath(url);
687                                toolTip = FileUtil.getFileDisplayName(fo);
688                            }
689                        }
690                        if (broken) {
691                            color = new Color(164, 0, 0);
692                            toolTip = NbBundle.getMessage(
693                                    ServerVolumeCustomizer.class,
694                                    "ServerVolumeCustomizer.TXT_BrokenFile");
695                        }
696                    }
697                    Component c = super .getListCellRendererComponent(list,
698                            displayName, index, isSelected, cellHasFocus);
699                    if (c instanceof  JComponent) {
700                        if (color != null) {
701                            ((JComponent) c).setForeground(color);
702                        }
703                        if (toolTip != null) {
704                            ((JComponent) c).setToolTipText(toolTip);
705                        } else {
706                            ((JComponent) c).setToolTipText(null);
707                        }
708                    }
709                    return c;
710                }
711
712            }
713
714        }
ww___w._ja_v___a2__s___._com__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.