KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > librarydescriptor > NewLibraryDescriptor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui.wizard.librarydescriptor;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Set JavaDoc;
24 import org.netbeans.api.project.libraries.Library;
25 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
26 import org.netbeans.modules.apisupport.project.layers.LayerUtils;
27 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
28 import org.openide.WizardDescriptor;
29 import org.openide.filesystems.FileSystem;
30
31 /**
32  * Wizard <em>J2SE Library Descriptor</em> for registering
33  * libraries for end users.
34  *
35  * @author Radek Matous
36  */

37 final class NewLibraryDescriptor extends BasicWizardIterator {
38     
39     NewLibraryDescriptor.DataModel data;
40     
41     public static NewLibraryDescriptor createIterator() {
42         return new NewLibraryDescriptor();
43     }
44     
45     public Set JavaDoc instantiate() throws IOException JavaDoc {
46         CreatedModifiedFiles cmf = data.getCreatedModifiedFiles();
47         cmf.run();
48         return getCreatedFiles(cmf, data.getProject());
49     }
50     
51     protected BasicWizardIterator.Panel[] createPanels(WizardDescriptor wiz) {
52         data = new NewLibraryDescriptor.DataModel(wiz);
53         return new BasicWizardIterator.Panel[] {
54             new SelectLibraryPanel(wiz,data ),
55                     new NameAndLocationPanel(wiz,data )
56         };
57     }
58     
59     public void uninitialize(WizardDescriptor wiz) {
60         super.uninitialize(wiz);
61         data = null;
62     }
63     
64     static final class DataModel extends BasicWizardIterator.BasicDataModel {
65         
66         private Library library;
67         private String JavaDoc libraryName;
68         private String JavaDoc libraryDisplayName;
69         
70         private CreatedModifiedFiles files;
71         
72         /** Creates a new instance of NewLibraryDescriptorData */
73         DataModel(WizardDescriptor wiz) {
74             super(wiz);
75         }
76         
77         public Library getLibrary() {
78             return library;
79         }
80         
81         public void setLibrary(Library library) {
82             this.library = library;
83         }
84         
85         public CreatedModifiedFiles getCreatedModifiedFiles() {
86             return files;
87         }
88         
89         public void setCreatedModifiedFiles(CreatedModifiedFiles files) {
90             this.files = files;
91         }
92                         
93         public String JavaDoc getLibraryName() {
94             return libraryName;
95         }
96         
97         public void setLibraryName(String JavaDoc libraryName) {
98             this.libraryName = libraryName;
99         }
100
101         public boolean isValidLibraryName() {
102             // XXX may need additional conditions, TBD (would need new message in that case)
103
return getLibraryName() != null &&
104                     getLibraryName().trim().length() != 0;
105         }
106         
107         public String JavaDoc getLibraryDisplayName() {
108             return libraryDisplayName;
109         }
110         
111         public void setLibraryDisplayName(String JavaDoc libraryDisplayName) {
112             this.libraryDisplayName = libraryDisplayName;
113         }
114         
115         public boolean isValidLibraryDisplayName() {
116             return getLibraryDisplayName() != null &&
117                     getLibraryDisplayName().trim().length() != 0;
118         }
119         
120         boolean libraryAlreadyExists() {
121             FileSystem layerFs = null;
122             LayerUtils.LayerHandle handle = LayerUtils.layerForProject(getProject());
123             layerFs = handle.layer(false);
124             return (layerFs != null) ? (layerFs.findResource(CreatedModifiedFilesProvider.getLibraryDescriptorEntryPath(getLibraryName())) != null) : false;
125         }
126                         
127         public NewLibraryDescriptor.DataModel cloneMe(WizardDescriptor wiz) {
128             NewLibraryDescriptor.DataModel d = new NewLibraryDescriptor.DataModel(wiz);
129             d.setLibrary(this.getLibrary());
130             d.setPackageName(this.getPackageName());
131             d.setCreatedModifiedFiles(this.getCreatedModifiedFiles());
132             d.setLibraryDisplayName(this.getLibraryDisplayName());
133             d.setLibraryName(this.getLibraryName());
134             return d;
135         }
136     }
137     
138 }
139
Popular Tags