This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 242099
Collapse All | Expand All

(-)a/dlight.remote/src/org/netbeans/modules/remote/api/ui/FileChooserBuilder.java (+47 lines)
Lines 49-54 Link Here
49
import java.beans.PropertyChangeEvent;
49
import java.beans.PropertyChangeEvent;
50
import java.beans.PropertyChangeListener;
50
import java.beans.PropertyChangeListener;
51
import java.io.File;
51
import java.io.File;
52
import java.io.IOException;
52
import java.util.ArrayList;
53
import java.util.ArrayList;
53
import java.util.List;
54
import java.util.List;
54
import java.util.concurrent.Callable;
55
import java.util.concurrent.Callable;
Lines 64-69 Link Here
64
import javax.swing.plaf.FileChooserUI;
65
import javax.swing.plaf.FileChooserUI;
65
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
66
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
66
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
67
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironmentFactory;
68
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
69
import org.netbeans.modules.nativeexecution.api.util.HostInfoUtils;
67
import org.netbeans.modules.remote.spi.FileSystemProvider;
70
import org.netbeans.modules.remote.spi.FileSystemProvider;
68
import org.netbeans.modules.remote.support.RemoteLogger;
71
import org.netbeans.modules.remote.support.RemoteLogger;
69
import org.openide.filesystems.FileObject;
72
import org.openide.filesystems.FileObject;
Lines 96-101 Link Here
96
        public abstract void setCurrentDirectory(FileObject dir);
99
        public abstract void setCurrentDirectory(FileObject dir);
97
        public abstract FileObject getSelectedFileObject();
100
        public abstract FileObject getSelectedFileObject();
98
        public abstract FileObject[] getSelectedFileObjects();
101
        public abstract FileObject[] getSelectedFileObjects();
102
        
103
        /** 
104
         * Very close to getHomeDirectory, but isn't quite the same:
105
         * getHomePath()
106
         * - does not create file object, 
107
         * - does not fire event,
108
         * - is fast (in the case remote host info isn't avaliable, just returns  "/")
109
         * @return user home
110
         */
111
        /*package*/ abstract String getHomePath();
112
113
        /**
114
         * Used to determine whether "~" should be expanded to home directory
115
         * @return 
116
         */
117
        /*package*/ public abstract boolean isUnix();
99
118
100
        @Override
119
        @Override
101
        public final File getCurrentDirectory() {
120
        public final File getCurrentDirectory() {
Lines 228-233 Link Here
228
        }
247
        }
229
248
230
        @Override
249
        @Override
250
        public String getHomePath() {
251
            return System.getProperty("user.home");
252
        }
253
254
        @Override
255
        public boolean isUnix() {
256
            return Utilities.isUnix();
257
        }
258
259
        @Override
231
        public void setCurrentDirectory(FileObject dir) {
260
        public void setCurrentDirectory(FileObject dir) {
232
            if (dir != null && dir.isFolder()) {
261
            if (dir != null && dir.isFolder()) {
233
                File file = FileUtil.toFile(dir);
262
                File file = FileUtil.toFile(dir);
Lines 349-354 Link Here
349
                return result.toArray(new FileObject[result.size()]);
378
                return result.toArray(new FileObject[result.size()]);
350
            }
379
            }
351
        }
380
        }
381
        
382
        @Override
383
        public String getHomePath() {
384
            if (HostInfoUtils.isHostInfoAvailable(env)) {
385
                try {
386
                    return HostInfoUtils.getHostInfo(env).getUserDir();
387
                } catch (IOException ex) {
388
                    RemoteLogger.finest(ex);
389
                } catch (ConnectionManager.CancellationException ex) {
390
                }
391
            }
392
            return "/"; //NOI18N
393
        }        
394
395
        @Override
396
        public boolean isUnix() {
397
            return true;
398
        }
352
399
353
        @Override
400
        @Override
354
        protected void setup(FileSystemView view) {
401
        protected void setup(FileSystemView view) {
(-)a/dlight.remote/src/org/netbeans/modules/remote/api/ui/FileChooserUIImpl.java (-18 / +459 lines)
Lines 68-73 Link Here
68
import java.beans.PropertyChangeEvent;
68
import java.beans.PropertyChangeEvent;
69
import java.beans.PropertyChangeListener;
69
import java.beans.PropertyChangeListener;
70
import java.io.File;
70
import java.io.File;
71
import java.io.FileNotFoundException;
71
import java.io.IOException;
72
import java.io.IOException;
72
import java.lang.ref.WeakReference;
73
import java.lang.ref.WeakReference;
73
import java.lang.reflect.Constructor;
74
import java.lang.reflect.Constructor;
Lines 95-100 Link Here
95
import java.util.logging.Logger;
96
import java.util.logging.Logger;
96
import java.util.regex.Matcher;
97
import java.util.regex.Matcher;
97
import java.util.regex.Pattern;
98
import java.util.regex.Pattern;
99
import java.util.regex.PatternSyntaxException;
98
import javax.swing.AbstractAction;
100
import javax.swing.AbstractAction;
99
import javax.swing.AbstractListModel;
101
import javax.swing.AbstractListModel;
100
import javax.swing.Action;
102
import javax.swing.Action;
Lines 136-142 Link Here
136
import javax.swing.filechooser.FileSystemView;
138
import javax.swing.filechooser.FileSystemView;
137
import javax.swing.filechooser.FileView;
139
import javax.swing.filechooser.FileView;
138
import javax.swing.plaf.ActionMapUIResource;
140
import javax.swing.plaf.ActionMapUIResource;
139
import javax.swing.plaf.ComponentUI;
140
import javax.swing.plaf.UIResource;
141
import javax.swing.plaf.UIResource;
141
import javax.swing.plaf.basic.BasicFileChooserUI;
142
import javax.swing.plaf.basic.BasicFileChooserUI;
142
import javax.swing.tree.DefaultMutableTreeNode;
143
import javax.swing.tree.DefaultMutableTreeNode;
Lines 157-169 Link Here
157
import org.openide.util.NbPreferences;
158
import org.openide.util.NbPreferences;
158
import org.openide.util.RequestProcessor;
159
import org.openide.util.RequestProcessor;
159
import org.openide.util.Utilities;
160
import org.openide.util.Utilities;
161
import sun.awt.shell.ShellFolder;
162
import sun.swing.FilePane;
160
163
161
/**
164
/**
162
 * An implementation of a customized filechooser.
165
 * An implementation of a customized filechooser.
163
 *
166
 *
164
 * @author Soot Phengsy, inspired by Jeff Dinkins' Swing version
167
 * @author Soot Phengsy, inspired by Jeff Dinkins' Swing version
165
 */
168
 */
166
class FileChooserUIImpl extends BasicFileChooserUI{
169
final class FileChooserUIImpl extends BasicFileChooserUI{
167
    
170
    
168
    static final String USE_SHELL_FOLDER = "FileChooser.useShellFolder";//NOI18N
171
    static final String USE_SHELL_FOLDER = "FileChooser.useShellFolder";//NOI18N
169
    static final String NB_USE_SHELL_FOLDER = "nb.FileChooser.useShellFolder";//NOI18N
172
    static final String NB_USE_SHELL_FOLDER = "nb.FileChooser.useShellFolder";//NOI18N
Lines 184-189 Link Here
184
187
185
    private static final RequestProcessor COMMON_RP = new RequestProcessor("Cnd File Chooser Common Worker", 16); // NOI18N
188
    private static final RequestProcessor COMMON_RP = new RequestProcessor("Cnd File Chooser Common Worker", 16); // NOI18N
186
    private static final RequestProcessor UPDATE_RP = new RequestProcessor("Cnd File Chooser Update Worker"); // NOI18N
189
    private static final RequestProcessor UPDATE_RP = new RequestProcessor("Cnd File Chooser Update Worker"); // NOI18N
190
    private static final RequestProcessor APPROVE_RP = new RequestProcessor("Cnd File Chooser Update Worker"); // NOI18N
187
191
188
    private static final String TIMEOUT_KEY="nb.fileChooser.timeout"; // NOI18N
192
    private static final String TIMEOUT_KEY="nb.fileChooser.timeout"; // NOI18N
189
193
Lines 276-292 Link Here
276
    private final RequestProcessor.Task listFilesTask = UPDATE_RP.create(listFilesWorker);
280
    private final RequestProcessor.Task listFilesTask = UPDATE_RP.create(listFilesWorker);
277
    private volatile File curDir;
281
    private volatile File curDir;
278
282
279
    public static ComponentUI createUI(JComponent c) {
283
    private final Action approveSelectionAction;
280
        return new FileChooserUIImpl((JFileChooserEx) c);
284
    private final Action cancelSelectionAction;
281
    }
285
    private final AtomicBoolean cancelled = new AtomicBoolean(false);    
286
287
    private FileFilter actualFileFilter = null;
288
    private GlobFilter globFilter = null;
282
289
283
    public FileChooserUIImpl(FileChooserBuilder.JFileChooserEx filechooser) {
290
    public FileChooserUIImpl(FileChooserBuilder.JFileChooserEx filechooser) {
284
        super(filechooser);
291
        super(filechooser);
292
        approveSelectionAction = new ApproveSelectionAction();
293
        cancelSelectionAction = new CancelSelectionAction();
285
    }
294
    }
286
    
295
287
    @Override
296
    @Override
288
    public void installUI(JComponent c) {
297
    public void installUI(JComponent c) {
289
        super.installUI(c);
298
        super.installUI(c);
299
        fileChooser = (JFileChooserEx) c;
290
    }   
300
    }   
291
    
301
    
292
    @Override
302
    @Override
Lines 1409-1415 Link Here
1409
        AbstractAction escAction = new AbstractAction() {
1419
        AbstractAction escAction = new AbstractAction() {
1410
            @Override
1420
            @Override
1411
            public void actionPerformed(ActionEvent e) {
1421
            public void actionPerformed(ActionEvent e) {
1412
                getFileChooser().cancelSelection();
1422
                getCancelSelectionAction().actionPerformed(e);
1413
            }
1423
            }
1414
            @Override
1424
            @Override
1415
            public boolean isEnabled(){
1425
            public boolean isEnabled(){
Lines 2329-2345 Link Here
2329
            // #105801: completionPopup might not be ready when updateCompletions not called (empty text field)
2339
            // #105801: completionPopup might not be ready when updateCompletions not called (empty text field)
2330
            if (completionPopup != null && !completionPopup.isVisible()) {
2340
            if (completionPopup != null && !completionPopup.isVisible()) {
2331
                if (keyCode == KeyEvent.VK_ENTER) {
2341
                if (keyCode == KeyEvent.VK_ENTER) {
2332
                    File file = getFileChooser().getFileSystemView().createFileObject(filenameTextField.getText());
2342
                    getApproveSelectionAction().actionPerformed(new ActionEvent(evt.getSource(), evt.getID(), "")); //NOI18N
2333
                    if(file.exists() && file.isDirectory()) {
2343
                    evt.consume();
2334
                        setSelected(new File[] {file});
2344
                }               
2335
                        fileChooser.approveSelection();
2336
                        if (file.getParentFile() == null) {
2337
                            // this will hopefully prevent popup to take inappropriate action
2338
                            evt.consume();
2339
                        }
2340
                    }
2341
                }
2342
                
2343
                if ((keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_DOWN) ||
2345
                if ((keyCode == KeyEvent.VK_TAB || keyCode == KeyEvent.VK_DOWN) ||
2344
                    (keyCode == KeyEvent.VK_RIGHT && 
2346
                    (keyCode == KeyEvent.VK_RIGHT && 
2345
                    (filenameTextField.getCaretPosition() >= (filenameTextField.getDocument().getLength() - 1)))) {
2347
                    (filenameTextField.getCaretPosition() >= (filenameTextField.getDocument().getLength() - 1)))) {
Lines 3109-3113 Link Here
3109
        }
3111
        }
3110
3112
3111
    } // end of UpdateWorker
3113
    } // end of UpdateWorker
3114
3115
    @Override
3116
    public Action getApproveSelectionAction() {
3117
        return approveSelectionAction;
3118
    }
3119
3120
    @Override
3121
    public Action getCancelSelectionAction() {
3122
        return cancelSelectionAction;
3123
    }
3124
3125
    private class CancelSelectionAction extends AbstractAction {
3126
        public void actionPerformed(ActionEvent e) {
3127
            cancelled.set(true);
3128
            getFileChooser().cancelSelection();
3129
        }
3130
    }
3131
3132
    private class ApproveSelectionAction extends AbstractAction {
3133
3134
        protected ApproveSelectionAction() {
3135
            super(FilePane.ACTION_APPROVE_SELECTION);
3136
        }
3137
3138
        @Override
3139
        public void actionPerformed(final ActionEvent e) {
3140
            // most code here (and the following "if" is copied from
3141
            // BasicFileChoooserUI.ApproveSelectionAction.actionPerformed
3142
            // and adapted for our case
3143
            if (isDirectorySelected()) {
3144
                // exactly from BasicFileChoooserUI.ApproveSelectionAction.actionPerformed
3145
                File dir = getDirectory();
3146
                if (dir != null) {
3147
                    try {
3148
                        // Strip trailing ".."
3149
                        dir = ShellFolder.getNormalizedFile(dir);
3150
                    } catch (IOException ex) {
3151
                        // Ok, use f as is
3152
                    }
3153
                    changeDirectory(dir);
3154
                    return;
3155
                }
3156
            }
3157
3158
            String filename = getFileName();
3159
3160
            if (filename != null) {
3161
                // VK: why isn't it just trim() ? - do we really need leading spaces??
3162
                // Remove whitespaces from end of filename
3163
                int i = filename.length() - 1;
3164
                while (i >=0 && filename.charAt(i) <= ' ') {
3165
                    i--;
3166
                }
3167
                filename = filename.substring(0, i + 1);
3168
            }
3169
3170
            if (filename == null || filename.length() == 0) {
3171
                // no file selected, multiple selection off, therefore cancel the approve action
3172
                resetGlobFilter();
3173
                return;
3174
            }
3175
3176
            // Unix: Resolve '~' to user's home directory
3177
            if (fileChooser.isUnix()) {
3178
                if (filename.startsWith("~/")) {
3179
                    filename = fileChooser.getHomePath() + filename.substring(1);
3180
                } else if (filename.equals("~")) {
3181
                    filename = fileChooser.getHomePath();
3182
                }
3183
            }
3184
3185
            // in the case of single selectiom, use selectedFiles.get(0)
3186
            final List<File> selectedFiles = new ArrayList<>();
3187
3188
            enableAllButCancel(false);
3189
            ApproveSelectionFinisher finisher = new ApproveSelectionFinisher(e, filename, selectedFiles, cancelled);
3190
            ApproveSelectionThreadWorker worker = new ApproveSelectionThreadWorker(
3191
                    e, filename, fileChooser.isMultiSelectionEnabled(), 
3192
                    fileChooser.getCurrentDirectory(), fileChooser.getFileSystemView(), 
3193
                    selectedFiles, finisher);
3194
            APPROVE_RP.post(worker);
3195
        }
3196
    }
3197
    
3198
    /**
3199
     * To be called OUT of EDT to perform long selection approval tasks.
3200
     * Upon finishing its work, calls ApproveSelectionFinisher in EDT
3201
     */
3202
    
3203
    private static class ApproveSelectionThreadWorker implements Runnable {
3204
3205
        private final ActionEvent e;
3206
        private final String filename;
3207
        private final boolean multySelection;
3208
        private final File currentDir;        
3209
        private final FileSystemView fs;
3210
        private final List<File> selectedFiles;
3211
        private final ApproveSelectionFinisher finisher;
3212
3213
        public ApproveSelectionThreadWorker(ActionEvent e, String filename, boolean multySelection, File currentDir, FileSystemView fs, List<File> selectedFiles, ApproveSelectionFinisher finisher) {
3214
            this.e = e;
3215
            this.filename = filename;
3216
            this.multySelection = multySelection;
3217
            this.currentDir = currentDir;
3218
            this.fs = fs;
3219
            this.selectedFiles = selectedFiles;
3220
            this.finisher = finisher;
3221
        }
3222
3223
        @Override
3224
        public void run() {
3225
            try {
3226
                if (multySelection && filename.length() > 1 &&
3227
                        filename.charAt(0) == '"' && filename.charAt(filename.length() - 1) == '"') {
3228
3229
                    // VK: double space between \" breaks this?! 
3230
                    String[] files = filename.substring(1, filename.length() - 1).split("\" \"");
3231
                    // Optimize searching files by names in "children" array
3232
                    Arrays.sort(files);
3233
3234
                    File[] children = null;
3235
                    int childIndex = 0;
3236
3237
                    for (String str : files) {
3238
                        File file = fs.createFileObject(str);
3239
                        if (!file.isAbsolute()) {
3240
                            if (children == null) {
3241
                                children = fs.getFiles(currentDir, false);
3242
                                Arrays.sort(children);
3243
                            }
3244
                            for (int k = 0; k < children.length; k++) {
3245
                                int l = (childIndex + k) % children.length;
3246
                                if (children[l].getName().equals(str)) {
3247
                                    file = children[l];
3248
                                    childIndex = l + 1;
3249
                                    break;
3250
                                }
3251
                            }
3252
                        }
3253
                        selectedFiles.add(file);
3254
                    }
3255
                } else {
3256
                    File selectedFile = fs.createFileObject(filename);
3257
                    if (!selectedFile.isAbsolute()) {
3258
                        selectedFile = fs.getChild(currentDir, filename);
3259
                    }
3260
                    selectedFiles.add(selectedFile);
3261
                }
3262
            } finally {
3263
                SwingUtilities.invokeLater(finisher);
3264
            }
3265
        }        
3266
    }
3267
    
3268
    /**
3269
     * To be called in EDT to complete selection approval
3270
     */
3271
    private class ApproveSelectionFinisher implements Runnable {
3272
3273
        private final String filename;
3274
        private final List<File> selectedFiles;
3275
        private final ActionEvent e;
3276
        private final AtomicBoolean cancelled;
3277
3278
        public ApproveSelectionFinisher(ActionEvent e, String filename, List<File> selectedFiles, AtomicBoolean cancelled) {
3279
            this.e = e;
3280
            this.selectedFiles = selectedFiles;
3281
            this.filename = filename;
3282
            this.cancelled = cancelled;
3283
        }
3284
        
3285
        @Override
3286
        public void run() {
3287
            
3288
            if (cancelled.get()) {
3289
                return; 
3290
            }
3291
3292
            enableAllButCancel(true);
3293
            
3294
            JFileChooser chooser = getFileChooser();
3295
            resetGlobFilter();
3296
            
3297
            if (selectedFiles.size() == 1) {
3298
3299
                File selectedFile = selectedFiles.get(0);
3300
3301
                // check for wildcard pattern
3302
                FileFilter currentFilter = chooser.getFileFilter();
3303
                if (!selectedFile.exists() && isGlobPattern(filename)) {
3304
                    changeDirectory(selectedFile.getParentFile());
3305
                    if (globFilter == null) {
3306
                        globFilter = new GlobFilter();
3307
                    }
3308
                    try {
3309
                        globFilter.setPattern(selectedFile.getName());
3310
                        if (!(currentFilter instanceof GlobFilter)) {
3311
                            actualFileFilter = currentFilter;
3312
                        }
3313
                        chooser.setFileFilter(null);
3314
                        chooser.setFileFilter(globFilter);
3315
                        return;
3316
                    } catch (PatternSyntaxException pse) {
3317
                        // Not a valid glob pattern. Abandon filter.
3318
                    }
3319
                }
3320
                
3321
                // Check for directory change action
3322
                boolean isDir = (selectedFile != null && selectedFile.isDirectory());
3323
                boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile));
3324
                boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled();
3325
                boolean isFileSelEnabled = chooser.isFileSelectionEnabled();
3326
                boolean isCtrl = (e != null && (e.getModifiers() & 
3327
                        Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0);
3328
3329
                if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) {
3330
                    changeDirectory(selectedFile);
3331
                    return;
3332
                } else if ((isDir || !isFileSelEnabled)
3333
                        && (!isDir || !isDirSelEnabled)
3334
                        && (!isDirSelEnabled || selectedFile.exists())) {
3335
                    selectedFiles.clear();
3336
                }
3337
            }
3338
                
3339
            
3340
            if (!selectedFiles.isEmpty()) {
3341
                if (chooser.isMultiSelectionEnabled()) {
3342
                    final File[] selectedFilesArray = selectedFiles.toArray(new File[selectedFiles.size()]);
3343
                    chooser.setSelectedFiles(selectedFilesArray);
3344
                    // Do it again. This is a fix for bug 4949273 to force the
3345
                    // selected value in case the ListSelectionModel clears it
3346
                    // for non-existing file names.
3347
                    chooser.setSelectedFiles(selectedFilesArray);
3348
                } else {
3349
                    chooser.setSelectedFile(selectedFiles.get(0));
3350
                }
3351
                chooser.approveSelection();
3352
            } else {
3353
                if (chooser.isMultiSelectionEnabled()) {
3354
                    chooser.setSelectedFiles(null);
3355
                } else {
3356
                    chooser.setSelectedFile(null);
3357
                }
3358
                chooser.cancelSelection();
3359
            }
3360
        }        
3361
    }
3362
    
3363
    private void enableAllButCancel(boolean enable) {
3364
        FileChooserUIImpl.this.newFolderButton.setEnabled(enable);
3365
        FileChooserUIImpl.this.approveButton.setEnabled(enable);        
3366
//        FileChooserUIImpl.this.topCombo.setEnabled(enable);
3367
//        FileChooserUIImpl.this.filenameTextField.setEditable(enable);
3368
//        FileChooserUIImpl.this.filenameTextField.setEnabled(enable);
3369
//        FileChooserUIImpl.this.filterTypeComboBox.setEnabled(enable);
3370
//        FileChooserUIImpl.this.tree.setEnabled(enable);
3371
    }
3372
3373
    private void changeDirectory(File dir) {
3374
        JFileChooser fc = getFileChooser();
3375
        // Traverse shortcuts on Windows
3376
        if (dir != null && FilePane.usesShellFolder(fc)) {
3377
            try {
3378
                ShellFolder shellFolder = ShellFolder.getShellFolder(dir);
3379
3380
                if (shellFolder.isLink()) {
3381
                    File linkedTo = shellFolder.getLinkLocation();
3382
3383
                    // If linkedTo is null we try to use dir
3384
                    if (linkedTo != null) {
3385
                        if (fc.isTraversable(linkedTo)) {
3386
                            dir = linkedTo;
3387
                        } else {
3388
                            return;
3389
                        }
3390
                    } else {
3391
                        dir = shellFolder;
3392
                    }
3393
                }
3394
            } catch (FileNotFoundException ex) {
3395
                return;
3396
            }
3397
        }
3398
        fc.setCurrentDirectory(dir);
3399
        if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES &&
3400
            fc.getFileSystemView().isFileSystem(dir)) {
3401
3402
            setFileName(dir.getAbsolutePath());
3403
        }
3404
    }
3405
3406
    private void resetGlobFilter() {
3407
        if (actualFileFilter != null) {
3408
            JFileChooser chooser = getFileChooser();
3409
            FileFilter currentFilter = chooser.getFileFilter();
3410
            if (currentFilter != null && currentFilter.equals(globFilter)) {
3411
                chooser.setFileFilter(actualFileFilter);
3412
                chooser.removeChoosableFileFilter(globFilter);
3413
            }
3414
            actualFileFilter = null;
3415
        }
3416
    }    
3417
    
3418
    private static boolean isGlobPattern(String filename) {
3419
        return ((File.separatorChar == '\\' && (filename.indexOf('*') >= 0
3420
                                                  || filename.indexOf('?') >= 0))
3421
                || (File.separatorChar == '/' && (filename.indexOf('*') >= 0
3422
                                                  || filename.indexOf('?') >= 0
3423
                                                  || filename.indexOf('[') >= 0)));
3424
    }
3425
3426
3427
    /* A file filter which accepts file patterns containing
3428
     * the special wildcards *? on Windows and *?[] on Unix.
3429
     */
3430
    class GlobFilter extends FileFilter {
3431
        Pattern pattern;
3432
        String globPattern;
3433
3434
        public void setPattern(String globPattern) {
3435
            char[] gPat = globPattern.toCharArray();
3436
            char[] rPat = new char[gPat.length * 2];
3437
            boolean isWin32 = (File.separatorChar == '\\');
3438
            boolean inBrackets = false;
3439
            int j = 0;
3440
3441
            this.globPattern = globPattern;
3442
3443
            if (isWin32) {
3444
                // On windows, a pattern ending with *.* is equal to ending with *
3445
                int len = gPat.length;
3446
                if (globPattern.endsWith("*.*")) {
3447
                    len -= 2;
3448
                }
3449
                for (int i = 0; i < len; i++) {
3450
                    switch(gPat[i]) {
3451
                      case '*':
3452
                        rPat[j++] = '.';
3453
                        rPat[j++] = '*';
3454
                        break;
3455
3456
                      case '?':
3457
                        rPat[j++] = '.';
3458
                        break;
3459
3460
                      case '\\':
3461
                        rPat[j++] = '\\';
3462
                        rPat[j++] = '\\';
3463
                        break;
3464
3465
                      default:
3466
                        if ("+()^$.{}[]".indexOf(gPat[i]) >= 0) {
3467
                            rPat[j++] = '\\';
3468
                        }
3469
                        rPat[j++] = gPat[i];
3470
                        break;
3471
                    }
3472
                }
3473
            } else {
3474
                for (int i = 0; i < gPat.length; i++) {
3475
                    switch(gPat[i]) {
3476
                      case '*':
3477
                        if (!inBrackets) {
3478
                            rPat[j++] = '.';
3479
                        }
3480
                        rPat[j++] = '*';
3481
                        break;
3482
3483
                      case '?':
3484
                        rPat[j++] = inBrackets ? '?' : '.';
3485
                        break;
3486
3487
                      case '[':
3488
                        inBrackets = true;
3489
                        rPat[j++] = gPat[i];
3490
3491
                        if (i < gPat.length - 1) {
3492
                            switch (gPat[i+1]) {
3493
                              case '!':
3494
                              case '^':
3495
                                rPat[j++] = '^';
3496
                                i++;
3497
                                break;
3498
3499
                              case ']':
3500
                                rPat[j++] = gPat[++i];
3501
                                break;
3502
                            }
3503
                        }
3504
                        break;
3505
3506
                      case ']':
3507
                        rPat[j++] = gPat[i];
3508
                        inBrackets = false;
3509
                        break;
3510
3511
                      case '\\':
3512
                        if (i == 0 && gPat.length > 1 && gPat[1] == '~') {
3513
                            rPat[j++] = gPat[++i];
3514
                        } else {
3515
                            rPat[j++] = '\\';
3516
                            if (i < gPat.length - 1 && "*?[]".indexOf(gPat[i+1]) >= 0) {
3517
                                rPat[j++] = gPat[++i];
3518
                            } else {
3519
                                rPat[j++] = '\\';
3520
                            }
3521
                        }
3522
                        break;
3523
3524
                      default:
3525
                        //if ("+()|^$.{}<>".indexOf(gPat[i]) >= 0) {
3526
                        if (!Character.isLetterOrDigit(gPat[i])) {
3527
                            rPat[j++] = '\\';
3528
                        }
3529
                        rPat[j++] = gPat[i];
3530
                        break;
3531
                    }
3532
                }
3533
            }
3534
            this.pattern = Pattern.compile(new String(rPat, 0, j), Pattern.CASE_INSENSITIVE);
3535
        }
3536
3537
        @Override
3538
        public boolean accept(File f) {
3539
            if (f == null) {
3540
                return false;
3541
            }
3542
            if (f.isDirectory()) {
3543
                return true;
3544
            }
3545
            return pattern.matcher(f.getName()).matches();
3546
        }
3547
3548
        @Override
3549
        public String getDescription() {
3550
            return globPattern;
3551
        }
3552
    }
3112
    
3553
    
3113
}
3554
}
(-)a/dlight.remote/src/org/netbeans/modules/remote/api/ui/RemoteFileSystemView.java (-4 / +10 lines)
Lines 51-59 Link Here
51
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException;
51
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager.CancellationException;
52
import java.util.logging.Level;
52
import java.util.logging.Level;
53
import javax.swing.Icon;
53
import javax.swing.Icon;
54
import javax.swing.SwingUtilities;
54
import javax.swing.UIManager;
55
import javax.swing.UIManager;
55
import javax.swing.filechooser.FileSystemView;
56
import javax.swing.filechooser.FileSystemView;
56
import org.netbeans.modules.dlight.libs.common.PathUtilities;
57
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
57
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
58
import org.netbeans.modules.nativeexecution.api.HostInfo;
58
import org.netbeans.modules.nativeexecution.api.HostInfo;
59
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
59
import org.netbeans.modules.nativeexecution.api.util.ConnectionManager;
Lines 62-68 Link Here
62
import org.netbeans.modules.remote.support.RemoteLogger;
62
import org.netbeans.modules.remote.support.RemoteLogger;
63
import org.openide.filesystems.FileObject;
63
import org.openide.filesystems.FileObject;
64
import org.openide.filesystems.FileSystem;
64
import org.openide.filesystems.FileSystem;
65
import org.openide.util.Exceptions;
66
65
67
/**
66
/**
68
 *
67
 *
Lines 95-100 Link Here
95
94
96
    @Override
95
    @Override
97
    public File createFileObject(String path) {
96
    public File createFileObject(String path) {
97
        if (RemoteLogger.getInstance().isLoggable(Level.FINEST)) {
98
            if (SwingUtilities.isEventDispatchThread()) {
99
                RemoteLogger.finest(new IllegalStateException("RFSV: creating file in EDT " + path)); //NOI18N
100
            } else {
101
                RemoteLogger.getInstance().log(Level.FINEST, "RFSV: creating file for {0}", path);
102
            }
103
        }
98
        RemoteLogger.getInstance().log(Level.FINEST, "RFSV: creating file for {0}", path);
104
        RemoteLogger.getInstance().log(Level.FINEST, "RFSV: creating file for {0}", path);
99
        if (!path.isEmpty() && path.charAt(0) != '/') {
105
        if (!path.isEmpty() && path.charAt(0) != '/') {
100
            return factory.create(env, path);
106
            return factory.create(env, path);
Lines 152-160 Link Here
152
            HostInfo hostInfo = HostInfoUtils.getHostInfo(env);
158
            HostInfo hostInfo = HostInfoUtils.getHostInfo(env);
153
            return factory.create(env, fs.findResource(hostInfo.getUserDir()));
159
            return factory.create(env, fs.findResource(hostInfo.getUserDir()));
154
        } catch (IOException ex) {
160
        } catch (IOException ex) {
155
            Exceptions.printStackTrace(ex);
161
            RemoteLogger.finest(ex);
156
        } catch (CancellationException ex) {
162
        } catch (CancellationException ex) {
157
            Exceptions.printStackTrace(ex);
163
            // never report cancellation exception
158
        } finally {
164
        } finally {
159
            changeSupport.firePropertyChange(LOADING_STATUS, "${HOME}", null); // NOI18N
165
            changeSupport.firePropertyChange(LOADING_STATUS, "${HOME}", null); // NOI18N
160
        }
166
        }

Return to bug 242099