Commits

Anonymous committed 652a3b2

Implement directory browsing in customizer panel for JAR libraries and fix some problem with absolute paths.

Comments (0)

Files changed (3)

project/src/org/netbeans/modules/android/project/JarLibsModel.java

     if (libsDir == null) {
       libsFO = null;
     } else {
-      File f = new File(project.getProjectDirectoryFile(), libsDir);
-      libsFO = FileUtil.toFileObject(FileUtil.normalizeFile(f));
+      libsFO = FileUtil.toFileObject(FileUtil.normalizeFile(libsDirAsFile()));
     }
   }
 
+  private File libsDirAsFile() {
+    File f = new File(libsDir);
+    if (!f.isAbsolute()) {
+      f = new File(project.getProjectDirectoryFile(), libsDir);
+    }
+    return f;
+  }
+
   @Override
   public boolean apply(final AndroidProject project) {
     Logger.getLogger(JarLibsModel.class.getName()).log(
         } else {
           String relativePath = PropertyUtils.relativizeFile(
               project.getProjectDirectoryFile(),
-              FileUtil.normalizeFile(new File(project.getProjectDirectoryFile(), libsDir)));
+              FileUtil.normalizeFile(libsDirAsFile()));
           propertyHelper.setProperty(ProjectProperties.PropertyType.BUILD,
               PropertyName.JAR_LIBS_DIR.getName(), relativePath);
         }

project/src/org/netbeans/modules/android/project/ui/customizer/CustomizerJARs.form

       <Properties>
         <Property name="text" type="java.lang.String" value="Browse"/>
       </Properties>
+      <Events>
+        <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButtonLibsFolderBrowseActionPerformed"/>
+      </Events>
     </Component>
   </SubComponents>
 </Form>

project/src/org/netbeans/modules/android/project/ui/customizer/CustomizerJARs.java

 
 package org.netbeans.modules.android.project.ui.customizer;
 
+import java.io.File;
 import org.netbeans.modules.android.project.JarLibsModel;
 import java.util.logging.Logger;
 import javax.swing.JPanel;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 import javax.swing.table.DefaultTableModel;
+import org.openide.filesystems.FileChooserBuilder;
 
 /** 
  * Customizer for Android libraries.
     org.openide.awt.Mnemonics.setLocalizedText(jLabelLibsFolder, "Location of JAR libraries");
 
     org.openide.awt.Mnemonics.setLocalizedText(jButtonLibsFolderBrowse, "Browse");
+    jButtonLibsFolderBrowse.addActionListener(new java.awt.event.ActionListener() {
+      public void actionPerformed(java.awt.event.ActionEvent evt) {
+        jButtonLibsFolderBrowseActionPerformed(evt);
+      }
+    });
 
     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
     this.setLayout(layout);
   private void jRadioButtonCustomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonCustomActionPerformed
     updateData();
   }//GEN-LAST:event_jRadioButtonCustomActionPerformed
+
+  private void jButtonLibsFolderBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonLibsFolderBrowseActionPerformed
+    File libsDirectory = new FileChooserBuilder(CustomizerJARs.class)
+        .setDirectoriesOnly(true)
+        .setTitle("Select directory with JAR libraries")
+        .showOpenDialog();
+    if (libsDirectory != null) {
+      jTextFieldLibsFolder.setText(libsDirectory.getAbsolutePath());
+      updateData();
+    }
+
+  }//GEN-LAST:event_jButtonLibsFolderBrowseActionPerformed
     
   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.ButtonGroup buttonGroupJARs;
     jarLibsModel.setLibsDir(jTextFieldLibsFolder.getText());
 
     jTextFieldLibsFolder.setEnabled(!jarLibsModel.isUseDefaultLocation());
+    jButtonLibsFolderBrowse.setEnabled(!jarLibsModel.isUseDefaultLocation());
 
     libsTableModel.setRowCount(0);
     for (String library : jarLibsModel.getLibNames()) {