1 19 20 package org.netbeans.modules.form.palette; 21 22 import java.io.*; 23 import javax.swing.JFileChooser ; 24 import javax.swing.BorderFactory ; 25 import javax.swing.event.*; 26 import java.beans.*; 27 import java.util.*; 28 import java.net.URI ; 29 30 import org.openide.WizardDescriptor; 31 import org.openide.ErrorManager; 32 import org.openide.filesystems.*; 33 import org.netbeans.api.project.ant.*; 34 import org.netbeans.api.project.*; 35 import org.netbeans.spi.project.ui.support.ProjectChooser; 36 37 44 45 class ChooseProjectWizardPanel implements WizardDescriptor.Panel { 46 47 private JFileChooser projectChooser; 48 private static String lastDirectoryUsed; 49 50 private EventListenerList listenerList; 51 52 55 public java.awt.Component getComponent() { 56 if (projectChooser == null) { projectChooser = ProjectChooser.projectChooser(); 58 projectChooser.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 59 60 projectChooser.setName(PaletteUtils.getBundleString("CTL_SelectProject_Caption")); projectChooser.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (0)); 64 65 if (lastDirectoryUsed != null) 66 projectChooser.setCurrentDirectory(new File(lastDirectoryUsed)); 67 projectChooser.setControlButtonsAreShown(false); 68 69 projectChooser.addPropertyChangeListener(new PropertyChangeListener() { 70 public void propertyChange(PropertyChangeEvent ev) { 71 String propName = ev.getPropertyName(); 72 if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(propName) 73 || JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(propName)) 74 fireStateChanged(); 75 } 76 }); 77 } 78 79 return projectChooser; 80 } 81 82 public org.openide.util.HelpCtx getHelp() { 83 return new org.openide.util.HelpCtx("beans.adding"); } 86 87 public boolean isValid() { 88 if (projectChooser != null) { 89 File file = projectChooser.getSelectedFile(); 90 if (file != null) { 91 file = FileUtil.normalizeFile(file); 92 FileObject projectDir = FileUtil.toFileObject(file); 93 try { 94 Project project = ProjectManager.getDefault() 95 .findProject(projectDir); 96 if (project != null) { lastDirectoryUsed = projectChooser.getCurrentDirectory() 98 .getAbsolutePath(); 99 return true; 100 } 101 } 102 catch (IOException ex) {} } 104 } 105 return false; 106 } 107 108 public void readSettings(Object settings) { 109 } 110 111 public void storeSettings(Object settings) { 112 if (projectChooser == null) 113 return; 114 115 File file = projectChooser.getSelectedFile(); 116 if (file == null) 117 return; 118 file = FileUtil.normalizeFile(file); 119 120 Project project = null; 121 try { 122 project = ProjectManager.getDefault().findProject( 123 FileUtil.toFileObject(file)); 124 } 125 catch (IOException ex) { 126 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 127 } 128 if (project == null) 129 return; 130 131 List fileList = new ArrayList(); 132 AntArtifact[] artifacts = 133 AntArtifactQuery.findArtifactsByType(project, "jar"); 135 for (int i=0; i < artifacts.length; i++) { 136 URI scriptLocation = artifacts[i].getScriptLocation().toURI(); 137 URI [] artifactLocations = artifacts[i].getArtifactLocations(); 138 for (int j=0; j < artifactLocations.length; j++) { 139 File outputFile = new File(scriptLocation.resolve(artifactLocations[j]).normalize()); 140 fileList.add(outputFile); 141 } 142 } 143 144 File[] outputFiles = new File[fileList.size()]; 145 fileList.toArray(outputFiles); 146 ((AddToPaletteWizard)settings).setJARFiles(outputFiles); 147 } 148 149 public void addChangeListener(ChangeListener listener) { 150 if (listenerList == null) 151 listenerList = new EventListenerList(); 152 listenerList.add(ChangeListener.class, listener); 153 } 154 155 public void removeChangeListener(ChangeListener listener) { 156 if (listenerList != null) 157 listenerList.remove(ChangeListener.class, listener); 158 } 159 160 162 void fireStateChanged() { 163 if (listenerList == null) 164 return; 165 166 ChangeEvent e = null; 167 Object [] listeners = listenerList.getListenerList(); 168 for (int i=listeners.length-2; i >= 0; i-=2) { 169 if (listeners[i] == ChangeListener.class) { 170 if (e == null) 171 e = new ChangeEvent(this); 172 ((ChangeListener)listeners[i+1]).stateChanged(e); 173 } 174 } 175 } 176 } 177 | Popular Tags |