--- a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/CustomizerPanel.java Fri Nov 07 12:28:02 2008 -0500 +++ a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/CustomizerPanel.java Thu Nov 20 02:46:26 2008 +0000 @@ -60,7 +60,6 @@ import java.util.List; import java.util.Properties; import javax.swing.DefaultListModel; -import javax.swing.JFileChooser; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -72,6 +71,7 @@ import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; +import org.openide.filesystems.FileChooserBuilder; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; @@ -95,7 +95,6 @@ public static final String PROF_PROP = "kvem.profiler.enable"; // NOI18N public static final String FALSE = "false"; // NOI18N - String fileChooserValue; J2MEPlatform platform; DefaultListModel mSources; DefaultListModel mJavaDocs; @@ -209,8 +208,6 @@ if (platform == null) return; - if (fileChooserValue == null) - fileChooserValue = platform.getHomePath(); final DefaultListModel mDevices = new DefaultListModel(); final J2MEPlatform.Device[] devices = platform.getDevices(); if (devices != null) { @@ -348,43 +345,34 @@ bJavaDocMoveUp.setEnabled(lJavaDocPaths.getSelectedIndex() > 0); bJavaDocMoveDown.setEnabled(lJavaDocPaths.getSelectedIndex() >= 0 && lJavaDocPaths.getSelectedIndex() < mJavaDocs.getSize() - 1); } - - private String browseArchive(final String oldValue, final String title) { - final JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); - chooser.setFileFilter(new FileFilter() { - public boolean accept(File f) { - return (f.exists() && f.canRead() && (f.isDirectory() || (f.getName().endsWith(".zip") || f.getName().endsWith(".jar")))); // NOI18N - } - public String getDescription() { - return NbBundle.getMessage(CustomizerPanel.class,"TXT_Customizer_ZipFilter"); // NOI18N - } - }); - if (oldValue != null) - chooser.setSelectedFile(new File(oldValue)); - chooser.setDialogTitle(title); - if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - return chooser.getSelectedFile().getAbsolutePath(); + + private String browseArchive(final String title) { + File f; + if ((f = new FileChooserBuilder(CustomizerPanel.class). + setFilesOnly(true).setFileFilter(new ArchiveFilter()). + setTitle(title).showOpenDialog()) != null) { + return f.getAbsolutePath(); } return null; } + + private static final class FolderFilter extends FileFilter { + public boolean accept(File f) { + return f.exists() && f.canRead() && f.isDirectory(); + } + public String getDescription() { + return NbBundle.getMessage(CustomizerPanel.class,"TXT_Customizer_FolderFilter"); // NOI18N + } + } - private String browseFolder(final String oldValue, final String title) { - final JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - chooser.setFileFilter(new FileFilter() { - public boolean accept(File f) { - return f.exists() && f.canRead() && f.isDirectory(); - } - public String getDescription() { - return NbBundle.getMessage(CustomizerPanel.class,"TXT_Customizer_FolderFilter"); // NOI18N - } - }); - if (oldValue != null) - chooser.setSelectedFile(new File(oldValue)); - chooser.setDialogTitle(title); - if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - return chooser.getSelectedFile().getAbsolutePath(); + private String browseFolder(final String title) { + File defPath = platform.getHomePath() == null ? null : + new File(platform.getHomePath()); + File f; + if ((f = new FileChooserBuilder (getClass().getName() + ".fld"). + setFileFilter(new FolderFilter()).setTitle(title). + setDefaultWorkingDirectory(defPath).showOpenDialog()) != null) { + return f.getAbsolutePath(); } return null; } @@ -1016,10 +1004,9 @@ private void bJavaDocAddFolderActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bJavaDocAddFolderActionPerformed if (platform == null) return; - final String value = browseFolder(fileChooserValue, NbBundle.getMessage(CustomizerPanel.class, "TITLE_Customizer_SelectJavaDocFolder")); // NOI18N + final String value = browseFolder(NbBundle.getMessage(CustomizerPanel.class, "TITLE_Customizer_SelectJavaDocFolder")); // NOI18N if (value == null) return; - fileChooserValue = value; final URL o = J2MEPlatform.localfilepath2url(value); if (o != null) { mJavaDocs.addElement(new ListItem(o)); @@ -1038,10 +1025,9 @@ private void bSourceAddFolderActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSourceAddFolderActionPerformed if (platform == null) return; - final String value = browseFolder(fileChooserValue, NbBundle.getMessage(CustomizerPanel.class, "TITLE_Customizer_SelectSourceFolder")); // NOI18N + final String value = browseFolder(NbBundle.getMessage(CustomizerPanel.class, "TITLE_Customizer_SelectSourceFolder")); // NOI18N if (value == null) return; - fileChooserValue = value; final FileObject o = platform.resolveRelativePathToFileObject(value); if (o != null) { mSources.addElement(new ListItem(o)); @@ -1068,10 +1054,9 @@ private void bJavaDocAddArchiveActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bJavaDocAddArchiveActionPerformed if (platform == null) return; - final String value = browseArchive(fileChooserValue, NbBundle.getMessage(CustomizerPanel.class, "TITLE_Customizer_SelectJavaDocArchive")); // NOI18N + final String value = browseArchive(NbBundle.getMessage(CustomizerPanel.class, "TITLE_Customizer_SelectJavaDocArchive")); // NOI18N if (value == null) return; - fileChooserValue = value; final URL o = J2MEPlatform.localfilepath2url(value); if (o != null) { mJavaDocs.addElement(new ListItem(o)); @@ -1090,10 +1075,9 @@ private void bSourceAddArchiveActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSourceAddArchiveActionPerformed if (platform == null) return; - final String value = browseArchive(fileChooserValue, NbBundle.getMessage(CustomizerPanel.class, "TITLE_Customizer_SelectSourceArchive")); // NOI18N + final String value = browseArchive(NbBundle.getMessage(CustomizerPanel.class, "TITLE_Customizer_SelectSourceArchive")); // NOI18N if (value == null) return; - fileChooserValue = value; final FileObject o = platform.resolveRelativePathToFileObject(value); if (o != null) { mSources.addElement(new ListItem(o)); --- a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/SrcDocPathsPanel.java Fri Nov 07 12:28:02 2008 -0500 +++ a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/SrcDocPathsPanel.java Thu Nov 20 02:46:26 2008 +0000 @@ -51,17 +51,16 @@ import java.util.ArrayList; import java.util.List; import javax.swing.DefaultListModel; -import javax.swing.JFileChooser; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.filechooser.FileFilter; import org.openide.filesystems.FileObject; import org.openide.filesystems.URLMapper; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.WizardDescriptor; +import org.openide.filesystems.FileChooserBuilder; /** * @@ -74,7 +73,6 @@ J2MEPlatform platform; DefaultListModel srcModel; DefaultListModel docModel; - String fileChooserValue; /** Creates new form SrcDocPathsPanel */ public SrcDocPathsPanel() { @@ -87,14 +85,12 @@ docModel = new DefaultListModel(); lDocPaths.setModel(docModel); platform = null; - fileChooserValue = null; } public void readData(final WizardDescriptor object) { platform = (J2MEPlatform) object.getProperty(DetectPanel.PLATFORM); if (platform == null) return; - fileChooserValue = platform.getHomePath(); final FileObject[] al = platform.getSourceFolders().getRoots(); srcModel.clear(); if (al != null) @@ -129,23 +125,13 @@ u.add(((ListItem)osa).getObject()); platform.setJavadocFolders(u); } - - private String browse(final String oldValue, final String title) { - final JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - chooser.setFileFilter(new FileFilter() { - public boolean accept(File f) { - return (f.exists() && f.canRead() && (f.isDirectory() || (f.getName().endsWith( ".zip") || f.getName().endsWith(".jar")))); //NOI18N - } - public String getDescription() { - return NbBundle.getMessage(SrcDocPathsPanel.class,"TXT_ZipFilter"); // NOI18N - } - }); - if (oldValue != null) - chooser.setSelectedFile(new File(oldValue)); - chooser.setDialogTitle(title); - if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - return chooser.getSelectedFile().getAbsolutePath(); + + private String browse(final String title) { + File f; + if ((f = new FileChooserBuilder(SrcDocPathsPanel.class). + setFileFilter(new ArchiveFilter()). + setTitle(title).showOpenDialog()) != null) { + return f.getAbsolutePath(); } return null; } @@ -316,10 +302,9 @@ private void bDocAddActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bDocAddActionPerformed if (platform == null) return; - final String value = browse(fileChooserValue, NbBundle.getMessage(SrcDocPathsPanel.class, "TITLE_SDPathsPanel_SelectJavaDoc")); // NOI18N + final String value = browse(NbBundle.getMessage(SrcDocPathsPanel.class, "TITLE_SDPathsPanel_SelectJavaDoc")); // NOI18N if (value == null) return; - fileChooserValue = value; final URL o = J2MEPlatform.localfilepath2url(value); if (o != null) { final ListItem item = new ListItem(o); @@ -332,10 +317,9 @@ private void bSrcAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bSrcAddActionPerformed if (platform == null) return; - final String value = browse(fileChooserValue, NbBundle.getMessage(SrcDocPathsPanel.class, "TITLE_SDPathsPanel_SelectSource")); // NOI18N + final String value = browse(NbBundle.getMessage(SrcDocPathsPanel.class, "TITLE_SDPathsPanel_SelectSource")); // NOI18N if (value == null) return; - fileChooserValue = value; final FileObject o = platform.resolveRelativePathToFileObject(value); if (o != null) { final ListItem item = new ListItem(o); --- a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/customwizard/ClasspathPanel.java Fri Nov 07 12:28:02 2008 -0500 +++ a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/customwizard/ClasspathPanel.java Thu Nov 20 02:46:26 2008 +0000 @@ -50,11 +50,12 @@ import javax.swing.text.html.HTMLEditorKit; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.filechooser.FileFilter; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.netbeans.modules.mobility.cldcplatform.ArchiveFilter; +import org.openide.filesystems.FileChooserBuilder; /** * @@ -66,7 +67,6 @@ final private DefaultListModel classpathListModel = new DefaultListModel(); private WizardPanel wizardPanel; - private String fileChooserValue; private J2MEPlatform.J2MEProfile[] profiles; /** Creates new form ClasspathPanel */ @@ -221,7 +221,6 @@ public void readSettings(final WizardDescriptor wizardDescriptor) { final J2MEPlatform platform = (J2MEPlatform) wizardDescriptor.getProperty(DetectPanel.PLATFORM); - fileChooserValue = platform.getHomePath(); final J2MEPlatform.Device previous = platform.getDevices()[0]; final J2MEPlatform.J2MEProfile[] profiles = previous.getProfiles(); if (profiles.length > 0) { @@ -360,26 +359,7 @@ } private File[] browse(final String title) { - final String oldValue = fileChooserValue; - final JFileChooser chooser = new JFileChooser(); - chooser.setMultiSelectionEnabled(true); - chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - chooser.setFileFilter(new FileFilter() { - public boolean accept(File f) { - return (f.exists() && f.canRead() && (f.isDirectory() || (f.getName().endsWith(".zip") || f.getName().endsWith(".jar")))); //NOI18N - } - - public String getDescription() { - return NbBundle.getMessage(CommandLinesPanel.class, "TXT_ZipFilter"); // NOI18N - } - }); - if (oldValue != null) - chooser.setSelectedFile(new File(oldValue)); - chooser.setDialogTitle(title); - if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - fileChooserValue = chooser.getSelectedFile().getAbsolutePath(); - return chooser.getSelectedFiles(); - } - return null; + return new FileChooserBuilder(getClass()).setTitle(title). + setFileFilter(new ArchiveFilter()).showMultiOpenDialog(); } } --- a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/customwizard/CommandLinesPanel.java Fri Nov 07 12:28:02 2008 -0500 +++ a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/customwizard/CommandLinesPanel.java Thu Nov 20 02:46:26 2008 +0000 @@ -64,6 +64,7 @@ import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.io.*; +import org.openide.filesystems.FileChooserBuilder; /** * @@ -72,7 +73,6 @@ public class CommandLinesPanel extends javax.swing.JPanel implements WizardPanel.ComponentDescriptor { protected WizardPanel wizardPanel; - private String fileChooserValue; private static final Set INVALID_CHARACTERS = new HashSet(); { for (char c : "\\^$?*+-!.;:,=<>|/\"'[]{}()".toCharArray()) INVALID_CHARACTERS.add(c); //NOI18N @@ -472,26 +472,21 @@ return false; } - + private static final class FolderFilter extends FileFilter { + public boolean accept(File f) { + return f.exists() && f.canRead() && f.isDirectory(); + } + + public String getDescription() { + return NbBundle.getMessage(CommandLinesPanel.class, "TXT_FolderFilter"); // NOI18N + } + } + private String browseFolder(final String title) { - final String oldValue = fileChooserValue; - final JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - chooser.setFileFilter(new FileFilter() { - public boolean accept(File f) { - return f.exists() && f.canRead() && f.isDirectory(); - } - - public String getDescription() { - return NbBundle.getMessage(CommandLinesPanel.class, "TXT_FolderFilter"); // NOI18N - } - }); - if (oldValue != null) - chooser.setSelectedFile(new File(oldValue)); - chooser.setDialogTitle(title); - if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - fileChooserValue = chooser.getSelectedFile().getAbsolutePath(); - return fileChooserValue; + File f; + if ((f = new FileChooserBuilder(getClass()).setTitle(title). + setDirectoriesOnly(true).setFileFilter(new FolderFilter()).showOpenDialog()) != null) { + return f.getAbsolutePath(); } return null; } --- a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/wizard/DetectPanel.java Fri Nov 07 12:28:02 2008 -0500 +++ a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/wizard/DetectPanel.java Thu Nov 20 02:46:26 2008 +0000 @@ -57,6 +57,7 @@ import org.openide.WizardDescriptor; import org.openide.filesystems.FileObject; import org.openide.filesystems.URLMapper; +import org.openide.filesystems.FileChooserBuilder; import org.openide.util.HelpCtx; import org.openide.util.Lookup; import org.openide.util.RequestProcessor; @@ -104,8 +105,6 @@ protected static final Color COLOR_GRAY = UIManager.getColor("Label.disabledForeground"); //NOI18N protected static final Color COLOR_RED = new Color(192, 0, 0); - - private String fileChooserValue; protected DetectWizardPanel wizardPanel; private WizardDescriptor wizardDescriptor; @@ -694,26 +693,24 @@ sb.append(NbBundle.getMessage(DetectPanel.class, "Msg_DetectPanel_None")); //NOI18N } } + + private static final class BrowseFilter extends FileFilter { + public boolean accept(File f) { + return (f.exists() && f.canRead() && (f.isDirectory() || (f.getName().endsWith(".zip") || f.getName().endsWith(".jar")))); //NOI18N + } + + public String getDescription() { + return NbBundle.getMessage(DetectPanel.class, "TXT_ZipFilter"); // NOI18N + } + } private String browse(final String title) { - final String oldValue = fileChooserValue; - final JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); - chooser.setFileFilter(new FileFilter() { - public boolean accept(File f) { - return (f.exists() && f.canRead() && (f.isDirectory() || (f.getName().endsWith(".zip") || f.getName().endsWith(".jar")))); //NOI18N - } + File f; + if ((f = new FileChooserBuilder(getClass()). + setFileFilter(new BrowseFilter()). + setTitle(title).showOpenDialog()) != null) { - public String getDescription() { - return NbBundle.getMessage(DetectPanel.class, "TXT_ZipFilter"); // NOI18N - } - }); - if (oldValue != null) - chooser.setSelectedFile(new File(oldValue)); - chooser.setDialogTitle(title); - if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { - fileChooserValue = chooser.getSelectedFile().getAbsolutePath(); - return fileChooserValue; + return f.getAbsolutePath(); } return null; } --- a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/wizard/FindPanel.java Fri Nov 07 12:28:02 2008 -0500 +++ a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/wizard/FindPanel.java Thu Nov 20 02:46:26 2008 +0000 @@ -58,14 +58,20 @@ import java.awt.event.KeyEvent; import java.io.File; import java.util.*; +import javax.swing.filechooser.FileFilter; +import org.netbeans.modules.mobility.cldcplatform.J2MEPlatform; +import org.netbeans.spi.mobility.cldcplatform.CustomCLDCPlatformConfigurator; +import org.openide.filesystems.FileChooserBuilder; +import org.openide.filesystems.FileStateInvalidException; +import org.openide.util.ImageUtilities; +import org.openide.util.Lookup; +import org.openide.util.Utilities; /** * * @author Adam Sotona */ final public class FindPanel extends javax.swing.JPanel implements SearchRunnable.Notifier { - - static File DEFAULT_DIR = null; static final String PROP_PLATFORM_FOLDERS = "PlatformFolders"; // NOI18N @@ -166,23 +172,105 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed if (searchTask != null && !searchTask.isFinished()) return; - if (DEFAULT_DIR == null) { - final File[] roots = File.listRoots(); - if (roots.length > 0) DEFAULT_DIR = roots[0]; - } - final LocationChooser jfc = new LocationChooser(DEFAULT_DIR); - jfc.setDialogType(JFileChooser.OPEN_DIALOG); - jfc.setControlButtonsAreShown(true); - jfc.setDialogTitle(NbBundle.getMessage(FindPanel.class, "Title_FindPanel_Choose_To_Search")); //NOI18N - if (jfc.showDialog(this, NbBundle.getMessage(FindPanel.class, "LBL_FindPanel_Search")) == JFileChooser.APPROVE_OPTION) { //NOI18N - searchRunnable = new SearchRunnable(this, jfc.getSelectedFile(), -1); + String aDescription = NbBundle.getMessage(FindPanel.class, "AD_LocationChooser"); //NOI18N + String title = NbBundle.getMessage(FindPanel.class, "Title_FindPanel_Choose_To_Search"); //NOI18N + Badger badger = new Badger(); + File dir; + if ((dir = new FileChooserBuilder(getClass().getName()).setDirectoriesOnly(true). + setTitle(title). + setAccessibleDescription(aDescription). + setBadgeProvider(badger). + setDefaultWorkingDirectory(File.listRoots().length > 0 ? File.listRoots()[0] : null). + setFileFilter(badger).showOpenDialog()) != null) { + + searchRunnable = new SearchRunnable(this, dir, -1); jButton1.setEnabled(false); showError(NbBundle.getMessage(FindPanel.class, "WARN_SearchInProgress"));//NOI18N searchTask = RequestProcessor.getDefault().post(searchRunnable); } - DEFAULT_DIR = jfc.getSelectedFile(); }//GEN-LAST:event_jButton1ActionPerformed - + + private static final class Badger extends FileFilter implements FileChooserBuilder.BadgeProvider { + final Icon badge = new ImageIcon (ImageUtilities.loadImage( + "org/netbeans/modules/java/platform/resources/platformBadge.gif")); + + public boolean accept(File f) { + return f.isDirectory(); + } + + public String getDescription() { + return NbBundle.getMessage(Badger.class, "TXT_PlatformFolder"); //NOI18N + } + + public Icon getBadge(File file) { + if (isPlatformDir (file)) { + return badge; + } + return null; + } + + public int getXOffset() { + return -1; + } + + public int getYOffset() { + return -1; + } + + private boolean isPlatformDir(File f) { + //XXX: Workaround of hard NFS mounts on Solaris. + final int osId = Utilities.getOperatingSystem(); + if (osId == Utilities.OS_SOLARIS || osId == Utilities.OS_SUNOS) { + return false; + } + FileObject fo = (f != null) ? convertToValidDir(f) : null; + if (fo != null) { + //XXX: Workaround of /net folder on Unix, the folders in the root are not badged as platforms. + // User can still select them. + try { + if (Utilities.isUnix() && (fo.getParent() == null || + fo.getFileSystem().getRoot().equals(fo.getParent()))) { + return false; + } + } catch (FileStateInvalidException e) { + return false; + } + return isPossibleJ2MEPlatform(FileUtil.toFile(fo)); + } + return false; + } + + public boolean isPossibleJ2MEPlatform(final File directory) { + Collection customConfigurators = Lookup.getDefault().lookupAll(CustomCLDCPlatformConfigurator.class); + for ( CustomCLDCPlatformConfigurator pc : customConfigurators ) + if (pc.isPossiblePlatform(directory)) return true; + final FileObject dir = FileUtil.toFileObject(directory); + return dir != null && J2MEPlatform.findTool("emulator", Collections.singletonList(dir)) != null // NOI18N + && J2MEPlatform.findTool("preverify", Collections.singletonList(dir)) != null; //NOI18N + } + + private static FileObject convertToValidDir(File f) { + FileObject fo; + File testFile = new File(f.getPath()); + if (testFile == null || testFile.getParent() == null) { + // BTW this means that roots of file systems can't be project + // directories. + return null; + } + + /**ATTENTION: on Windows may occure dir.isDirectory () == dir.isFile () == true then + * its used testFile instead of dir. + */ + if (!testFile.isDirectory()) { + return null; + } + + fo = FileUtil.toFileObject(FileUtil.normalizeFile(f)); + return fo; + } + + } + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; --- a/mobility.cldcplatform/src/org/netbeans/modules/mobility/cldcplatform/wizard/LocationChooser.java Fri Nov 07 12:28:02 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,281 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * If you wish your version of this file to be governed by only the CDDL - * or only the GPL Version 2, indicate your decision by adding - * "[Contributor] elects to include this software in this distribution - * under the [CDDL or GPL Version 2] license." If you do not indicate a - * single choice of license, a recipient has the option to distribute - * your version of this file under either the CDDL, the GPL Version 2 or - * to extend the choice of license to its licensees as provided above. - * However, if you add GPL Version 2 code and therefore, elected the GPL - * Version 2 license, then the option applies only if the new code is - * made subject to such option by the copyright holder. - */ -package org.netbeans.modules.mobility.cldcplatform.wizard; - -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Window; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.io.File; -import java.util.Collection; -import java.util.Collections; -import javax.swing.AbstractAction; -import javax.swing.BorderFactory; -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.JFileChooser; -import javax.swing.KeyStroke; -import javax.swing.filechooser.FileFilter; -import javax.swing.filechooser.FileSystemView; -import javax.swing.filechooser.FileView; -import org.netbeans.modules.mobility.cldcplatform.J2MEPlatform; -import org.netbeans.spi.java.platform.PlatformInstall; -import org.netbeans.spi.mobility.cldcplatform.CustomCLDCPlatformConfigurator; -import org.openide.WizardDescriptor; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileStateInvalidException; -import org.openide.filesystems.FileUtil; -import org.openide.util.ChangeSupport; -import org.openide.util.ImageUtilities; -import org.openide.util.Lookup; -import org.openide.util.NbBundle; -import org.openide.util.Utilities; - -/** - * Copied from Java Platform - * @author sd99038, Tomas Zezula - */ -public class LocationChooser extends JFileChooser implements PropertyChangeListener { - - private static final Dimension PREFERRED_SIZE = new Dimension(600, 340); - private WizardDescriptor.InstantiatingIterator iterator; - private final ChangeSupport cs = new ChangeSupport(this); - private PlatformFileView platformFileView; - - public LocationChooser(File dir) { - super(dir); - this.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - this.setName(NbBundle.getMessage(LocationChooser.class, "Title_FindPanel_Choose_To_Search")); - this.setFileSelectionMode(DIRECTORIES_ONLY); - this.setMultiSelectionEnabled(false); - this.setControlButtonsAreShown(false); - this.setFileFilter(new PlatformFileFilter()); - this.platformFileView = new PlatformFileView(this.getFileSystemView()); - this.setFileView(this.platformFileView); - this.addPropertyChangeListener(this); - this.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(LocationChooser.class, "AD_LocationChooser")); - - //XXX JFileChooser workaround - getActionMap().put("cancel", - new AbstractAction() { - - public void actionPerformed(ActionEvent e) { - Container parent = LocationChooser.this.getParent(); - do { - parent = parent.getParent(); - } while (parent != null && !(parent instanceof Window)); - if (parent != null) { - ((Window) parent).setVisible(false); - } - } - }); - getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); - this.setBorder(null); - } - - @Override - public Dimension getPreferredSize() { - return PREFERRED_SIZE; - } - - public void propertyChange(PropertyChangeEvent evt) { - if (SELECTED_FILE_CHANGED_PROPERTY.equals(evt.getPropertyName())) { - this.iterator = null; - File file = this.getSelectedFile(); - if (file != null) { - file = FileUtil.normalizeFile(file); - FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(file)); - if (fo != null) { - PlatformInstall install = this.platformFileView.getPlatformInstall(); - if (install != null && install.accept(fo)) { - this.iterator = install.createIterator(fo); - } - } - } - cs.fireChange(); - } - } - - private static class PlatformFileFilter extends FileFilter { - - public boolean accept(File f) { - return f.isDirectory(); - } - - public String getDescription() { - return NbBundle.getMessage(LocationChooser.class, "TXT_PlatformFolder"); - } - } - private static class MergedIcon implements Icon { - - private Icon icon1; - private Icon icon2; - private int xMerge; - private int yMerge; - - MergedIcon(Icon icon1, Icon icon2, int xMerge, int yMerge) { - - this.icon1 = icon1; - this.icon2 = icon2; - - if (xMerge == -1) { - xMerge = icon1.getIconWidth() - icon2.getIconWidth(); - } - - if (yMerge == -1) { - yMerge = icon1.getIconHeight() - icon2.getIconHeight(); - } - - this.xMerge = xMerge; - this.yMerge = yMerge; - } - - public int getIconHeight() { - return Math.max(icon1.getIconHeight(), yMerge + icon2.getIconHeight()); - } - - public int getIconWidth() { - return Math.max(icon1.getIconWidth(), yMerge + icon2.getIconWidth()); - } - - public void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y) { - icon1.paintIcon(c, g, x, y); - icon2.paintIcon(c, g, x + xMerge, y + yMerge); - } - } - - private static class PlatformFileView extends FileView { - - private final Icon BADGE = new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/java/platform/resources/platformBadge.gif")); // NOI18N - private final Icon EMPTY = new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/java/platform/resources/empty.gif")); // NOI18N - private FileSystemView fsv; - private Icon lastOriginal; - private Icon lastMerged; - private PlatformInstall platformInstall; - - public PlatformFileView(FileSystemView fsv) { - this.fsv = fsv; - } - - public - @Override - Icon getIcon( File _f) { - File f = FileUtil.normalizeFile(_f); - Icon original = fsv.getSystemIcon(f); - if (original == null) { - // L&F (e.g. GTK) did not specify any icon. - original = EMPTY; - } - if (isPlatformDir(f)) { - if (original.equals(lastOriginal)) { - return lastMerged; - } - lastOriginal = original; - lastMerged = new MergedIcon(original, BADGE, -1, -1); - return lastMerged; - } else { - return original; - } - } - - public void setPlatformInstall(PlatformInstall platformInstall) { - this.platformInstall = platformInstall; - } - - public PlatformInstall getPlatformInstall() { - return this.platformInstall; - } - - private boolean isPlatformDir(File f) { - //XXX: Workaround of hard NFS mounts on Solaris. - final int osId = Utilities.getOperatingSystem(); - if (osId == Utilities.OS_SOLARIS || osId == Utilities.OS_SUNOS) { - return false; - } - FileObject fo = (f != null) ? convertToValidDir(f) : null; - if (fo != null) { - //XXX: Workaround of /net folder on Unix, the folders in the root are not badged as platforms. - // User can still select them. - try { - if (Utilities.isUnix() && (fo.getParent() == null || fo.getFileSystem().getRoot().equals(fo.getParent()))) { - return false; - } - } catch (FileStateInvalidException e) { - return false; - } - return isPossibleJ2MEPlatform(FileUtil.toFile(fo)); - } - return false; - } - - public boolean isPossibleJ2MEPlatform(final File directory) { - Collection customConfigurators = Lookup.getDefault().lookupAll(CustomCLDCPlatformConfigurator.class); - for ( CustomCLDCPlatformConfigurator pc : customConfigurators ) - if (pc.isPossiblePlatform(directory)) return true; - final FileObject dir = FileUtil.toFileObject(directory); - return dir != null && J2MEPlatform.findTool("emulator", Collections.singletonList(dir)) != null // NOI18N - && J2MEPlatform.findTool("preverify", Collections.singletonList(dir)) != null; //NOI18N - } - - private static FileObject convertToValidDir(File f) { - FileObject fo; - File testFile = new File(f.getPath()); - if (testFile == null || testFile.getParent() == null) { - // BTW this means that roots of file systems can't be project - // directories. - return null; - } - - /**ATTENTION: on Windows may occure dir.isDirectory () == dir.isFile () == true then - * its used testFile instead of dir. - */ - if (!testFile.isDirectory()) { - return null; - } - - fo = FileUtil.toFileObject(FileUtil.normalizeFile(f)); - return fo; - } - } -} --- a/openide.util/src/org/openide/util/Utilities.java Fri Nov 07 12:28:02 2008 -0500 +++ a/openide.util/src/org/openide/util/Utilities.java Thu Nov 20 02:46:26 2008 +0000 @@ -2061,6 +2061,7 @@ * @param parent * @param approveButtonText * @deprecated Not needed in JDK 1.4. + * @see @org-openide-filesystems@FileChooserBuilder */ @Deprecated public static final int showJFileChooser( --- a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/wizard/ProjectSelectionPanel.java Fri Nov 07 12:28:02 2008 -0500 +++ a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/wizard/ProjectSelectionPanel.java Thu Nov 20 02:46:26 2008 +0000 @@ -77,6 +77,7 @@ import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; +import org.openide.filesystems.FileChooserBuilder; /** * Represent "Project to import" step(panel) in the Eclipse importer wizard. @@ -588,12 +589,10 @@ getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectSelectionPanel.class, "ACSD_ProjectSelectionPanel_NA")); // NOI18N }// //GEN-END:initComponents - private void chooseDestButtonActionPerformed(java.awt.event.ActionEvent evt) { - JFileChooser chooser = new JFileChooser(); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - int ret = chooser.showOpenDialog(this); - if (ret == JFileChooser.APPROVE_OPTION) { - destination.setText(chooser.getSelectedFile().getAbsolutePath()); + private void chooseDestButtonActionPerformed(java.awt.event.ActionEvent evt) { + File dest = new FileChooserBuilder(getClass()).setDirectoriesOnly(true).showOpenDialog(); + if (dest != null) { + destination.setText (dest.getAbsolutePath()); } } --- a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/wizard/SelectionPanel.form Fri Nov 07 12:28:02 2008 -0500 +++ a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/wizard/SelectionPanel.form Thu Nov 20 02:46:26 2008 +0000 @@ -16,6 +16,7 @@ + @@ -30,13 +31,13 @@ - - + + - + --- a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/wizard/SelectionPanel.java Fri Nov 07 12:28:02 2008 -0500 +++ a/projectimport.eclipse.core/src/org/netbeans/modules/projectimport/eclipse/core/wizard/SelectionPanel.java Thu Nov 20 02:46:26 2008 +0000 @@ -47,6 +47,7 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.netbeans.modules.projectimport.eclipse.core.EclipseUtils; +import org.openide.filesystems.FileChooserBuilder; import org.openide.filesystems.FileUtil; /** @@ -314,12 +315,9 @@ getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SelectionPanel.class, "ACSD_SelectionPanel_NA")); // NOI18N }// //GEN-END:initComponents private void projectDestBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_projectDestBrowseActionPerformed - JFileChooser chooser = new JFileChooser(projectDestDir.getText()); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - chooser.setFileHidingEnabled(false); - int ret = chooser.showOpenDialog(this); - if (ret == JFileChooser.APPROVE_OPTION) { - projectDestDir.setText(chooser.getSelectedFile().getAbsolutePath()); + File dir = new FileChooserBuilder(getClass()).setDirectoriesOnly(true).showOpenDialog(); + if (dir != null) { + projectDestDir.setText(dir.getAbsolutePath()); }//GEN-LAST:event_projectDestBrowseActionPerformed } @@ -350,22 +348,16 @@ } private void projectBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_projectBrowseActionPerformed - JFileChooser chooser = new JFileChooser(projectDir.getText()); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - chooser.setFileHidingEnabled(false); - int ret = chooser.showOpenDialog(this); - if (ret == JFileChooser.APPROVE_OPTION) { - projectDir.setText(chooser.getSelectedFile().getAbsolutePath()); + File file = new FileChooserBuilder(getClass()).setDirectoriesOnly(true).forceUseOfDefaultWorkingDirectory(true).showOpenDialog(); + if (file != null) { + projectDir.setText (file.getAbsolutePath()); }//GEN-LAST:event_projectBrowseActionPerformed } private void worskpaceBrowseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_worskpaceBrowseActionPerformed - JFileChooser chooser = new JFileChooser(getWorkspaceDir()); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - chooser.setFileHidingEnabled(false); - int ret = chooser.showOpenDialog(this); - if (ret == JFileChooser.APPROVE_OPTION) { - workspaceDir.setText(chooser.getSelectedFile().getAbsolutePath()); + File file = new FileChooserBuilder(getClass()).setDirectoriesOnly(true).showOpenDialog(); + if (file != null) { + workspaceDir.setText(file.getAbsolutePath()); }//GEN-LAST:event_worskpaceBrowseActionPerformed } --- a/projectuiapi/src/org/netbeans/modules/project/uiapi/ProjectCopyPanel.java Fri Nov 07 12:28:02 2008 -0500 +++ a/projectuiapi/src/org/netbeans/modules/project/uiapi/ProjectCopyPanel.java Thu Nov 20 02:46:26 2008 +0000 @@ -52,6 +52,7 @@ import org.netbeans.api.project.Project; import org.netbeans.spi.project.support.ProjectOperations; import org.netbeans.api.project.ProjectUtils; +import org.openide.filesystems.FileChooserBuilder; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.ChangeSupport; @@ -264,16 +265,13 @@ private void browseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseActionPerformed // TODO add your handling code here: - File current = new File(projectLocation.getText()); - JFileChooser chooser = new JFileChooser(current); - - chooser.setMultiSelectionEnabled(false); - chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - chooser.setDialogTitle(NbBundle.getMessage(ProjectCopyPanel.class, "TITLE_BrowseProjectLocation")); - chooser.setApproveButtonText(NbBundle.getMessage(ProjectCopyPanel.class, "LBL_BrowseProjectLocation_OK_Button")); - - if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { - projectLocation.setText(chooser.getSelectedFile().getAbsolutePath()); + String dlgTitle = NbBundle.getMessage(ProjectCopyPanel.class, "TITLE_BrowseProjectLocation"); + String okText = NbBundle.getMessage(ProjectCopyPanel.class, "LBL_BrowseProjectLocation_OK_Button"); + File dir = new FileChooserBuilder(getClass()).setDefaultWorkingDirectory( + new File(projectLocation.getText())).setDirectoriesOnly( + true).setTitle(dlgTitle).setApproveText(okText).showOpenDialog(); + if (dir != null) { + projectLocation.setText(dir.getAbsolutePath()); } }//GEN-LAST:event_browseActionPerformed