1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.librarydescriptor; 21 22 import java.io.IOException ; 23 import java.util.Set ; 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 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 instantiate() throws IOException { 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 libraryName; 68 private String libraryDisplayName; 69 70 private CreatedModifiedFiles files; 71 72 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 getLibraryName() { 94 return libraryName; 95 } 96 97 public void setLibraryName(String libraryName) { 98 this.libraryName = libraryName; 99 } 100 101 public boolean isValidLibraryName() { 102 return getLibraryName() != null && 104 getLibraryName().trim().length() != 0; 105 } 106 107 public String getLibraryDisplayName() { 108 return libraryDisplayName; 109 } 110 111 public void setLibraryDisplayName(String 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 |