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 123552
Collapse All | Expand All

(-)remotefs/src/org/netbeans/modules/remotefs/ftpfs/FTPFileSystem.java (-137 / +337 lines)
Lines 39-129 Link Here
39
 *
39
 *
40
 * Contributor(s): Libor Martinek.
40
 * Contributor(s): Libor Martinek.
41
 */
41
 */
42
43
package org.netbeans.modules.remotefs.ftpfs;
42
package org.netbeans.modules.remotefs.ftpfs;
44
43
45
import java.beans.PropertyChangeEvent;
44
import java.beans.PropertyChangeEvent;
46
import java.beans.PropertyChangeListener;
45
import java.beans.PropertyChangeListener;
47
import java.beans.PropertyVetoException;
46
import java.beans.PropertyVetoException;
48
import java.io.*;
47
import java.io.File;
49
import java.text.MessageFormat;
48
import java.io.IOException;
50
import java.util.Enumeration;
51
import java.util.Hashtable;
52
import java.util.ResourceBundle;
53
import java.util.StringTokenizer;
54
import java.util.Date;
49
import java.util.Date;
55
import java.net.*;
50
import org.netbeans.modules.remotefs.core.LogInfo;
51
import org.netbeans.modules.remotefs.core.RemoteClient;
52
import org.netbeans.modules.remotefs.core.RemoteFileSystem;
56
53
57
import org.netbeans.modules.remotefs.core.*;
54
import org.netbeans.modules.remotefs.ftpclient.FTPClient;
58
import org.netbeans.modules.remotefs.ftpclient.*;
55
import org.netbeans.modules.remotefs.ftpclient.FTPLogInfo;
59
56
import org.openide.DialogDisplayer;
60
import org.openide.*;
57
import org.openide.NotifyDescriptor;
61
import org.openide.filesystems.*;
58
import org.openide.filesystems.FileObject;
62
import org.openide.options.*;
59
import org.openide.filesystems.FileUtil;
60
import org.openide.filesystems.Repository;
61
import org.openide.options.SystemOption;
63
import org.openide.util.Exceptions;
62
import org.openide.util.Exceptions;
64
import org.openide.util.NbBundle;
63
import org.openide.util.NbPreferences;
65
import org.openide.util.actions.SystemAction;
66
import org.openide.util.RequestProcessor;
67
64
68
65
/** 
69
/** FTP FIleSystem class
66
 * FTP FIleSystem class
70
 * @author Libor Martinek
67
 * @author Libor Martinek
71
 * @version 1.0
68
 * @version 1.0
72
 */
69
 */
73
public class FTPFileSystem extends RemoteFileSystem implements  FTPClient.Reconnect {
70
public class FTPFileSystem extends RemoteFileSystem implements FTPClient.Reconnect {
74
  static final long serialVersionUID = -981665601872580022L;
71
  static final long serialVersionUID = -981665601872580022L;
75
  
72
  
76
  private static final boolean DEBUG = true;
73
  private static final boolean DEBUG = true;
77
  
74
    /** Name of temporary directory (if user doesn't entry own one) */
78
  /** Name of temporary directoty (if user doesn't entry own one) */
75
    private static final String FTPWORK;// = Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject("ftpCache").getName();
79
  private static final String FTPWORK= System.getProperty("netbeans.user")+File.separator + "ftpcache";
76
    //System.getProperty("netbeans.user")+File.separator + "ftpcache";
80
81
  /** Whether user already entered cache directory. */
77
  /** Whether user already entered cache directory. */
82
  private boolean enteredcachedir = false;
78
  private boolean enteredcachedir = false;
83
  
84
  /** Global FTP FileSystem settings */
79
  /** Global FTP FileSystem settings */
85
  private FTPSettings ftpsettings = (FTPSettings) SystemOption.findObject(FTPSettings.class, true);
80
    private FTPSettings ftpsettings = FTPSettings.getInstance();
81
82
    static {
83
        // We need a default cache dir. 
84
        // The default is "ftpcache" in the filesystem's root. Must be created if it doens't exist.
85
        FileObject fr = Repository.getDefault().getDefaultFileSystem().getRoot();
86
        FileObject fo = fr.getFileObject("ftpCache");
87
        if (fo == null) {
88
            try {
89
                fo = FileUtil.createFolder(new File(System.getProperty("java.io.tmpdir")+File.separator+"ftpcache"));
90
            } catch (IOException e) {
91
                throw new RuntimeException(e);
92
            }
93
        } 
94
        FTPWORK = fo.getName();
95
    }
96
86
  /** Constructor.
97
  /** Constructor.
98
     * @param logInfo 
87
  */
99
  */
88
  public FTPFileSystem () {
100
    public FTPFileSystem(FTPLogInfo logInfo) {
89
    super();
101
    super();
90
    loginfo = new FTPLogInfo();
102
        try {
91
    setRefreshTime (getFTPSettings().getRefreshTime());
103
            this.setSystemName(logInfo.getUser() + "@" + logInfo.getHost());
104
        } catch (PropertyVetoException ex) {
105
            Exceptions.printStackTrace(ex);
106
        }
107
        this.loginfo = logInfo;
108
        setRefreshTime(getFTPSettings().getRefreshTime());
92
    cachedir = new File(getDefaultCache());
109
    cachedir = new File(getDefaultCache());
93
    
110
    
94
    getFTPSettings().addPropertyChangeListener(new PropertyChangeListener() {
111
    getFTPSettings().addPropertyChangeListener(new PropertyChangeListener() {
112
95
       public void propertyChange(PropertyChangeEvent event) {
113
       public void propertyChange(PropertyChangeEvent event) {
96
          ftpSettingsChanged(event);
114
          ftpSettingsChanged(event);
97
       }
115
       }
98
    });
116
    });
99
  }
117
  }
100
118
119
    public FTPFileSystem() {
120
        this(new FTPLogInfo());
121
    }
122
123
    /**
124
     * 
125
     * @param fs
126
     */
127
    @Override
101
  public void addedFS(org.openide.filesystems.FileSystem fs) {
128
  public void addedFS(org.openide.filesystems.FileSystem fs) {
102
     if (fs==this) { 
129
        if (fs == this) {
103
        try { if (!getSystemName().equals(computeSystemName())) 
130
            try {
131
                if (!getSystemName().equals(computeSystemName())) {
104
                     setSystemName(computeSystemName());   
132
                     setSystemName(computeSystemName());   
105
        }
133
        }
106
        catch (java.beans.PropertyVetoException e) {
134
            } catch (java.beans.PropertyVetoException e) {
107
           if (DEBUG) e.printStackTrace(); 
135
                if (DEBUG) {
136
                    e.printStackTrace();
108
        }
137
        }
138
            }
109
        super.addedFS(fs);    
139
        super.addedFS(fs);    
110
     }  
140
     }  
111
  }
141
  }
112
142
113
  /** Called when FTPSettings changed */
143
    /** Called when FTPSettings changed 
144
     * @param event 
145
     */
114
  protected void ftpSettingsChanged(PropertyChangeEvent event) {
146
  protected void ftpSettingsChanged(PropertyChangeEvent event) {
115
      // bugfix #18714, according to the general contract of PropertyChangeEvent, 
147
      // bugfix #18714, according to the general contract of PropertyChangeEvent, 
116
      // property name may be null if multiple properties have been changed.
148
      // property name may be null if multiple properties have been changed.
117
      if (event.getPropertyName() == null) return;
149
        if (event.getPropertyName() == null) {
150
            return;
151
        }
118
     if (event.getPropertyName().equals(FTPSettings.PROP_PASSIVE_MODE)) {
152
     if (event.getPropertyName().equals(FTPSettings.PROP_PASSIVE_MODE)) {
119
        if (client != null) ((FTPClient)client).setPassiveMode(((Boolean)(event.getNewValue())).booleanValue());
153
            if (client != null) {
154
                ((FTPClient) client).setPassiveMode(((Boolean) (event.getNewValue())).booleanValue());
120
     }
155
     }
156
        }
121
     if (event.getPropertyName().equals(FTPSettings.PROP_REFRESH_TIME)) {
157
     if (event.getPropertyName().equals(FTPSettings.PROP_REFRESH_TIME)) {
122
        setRefreshTime(((Integer)(event.getNewValue())).intValue());
158
            setRefreshTime(((Integer) (event.getNewValue())).intValue());
123
     }
159
     }
124
  }
160
  }
125
  
161
  
126
  /** Get FTPSettings object */
162
    /** Get FTPSettings object 
163
     * @return 
164
     */
127
  protected FTPSettings getFTPSettings() {
165
  protected FTPSettings getFTPSettings() {
128
    if (ftpsettings == null) {
166
    if (ftpsettings == null) {
129
           System.out.println("FTPSETTTNGS NULL");
167
           System.out.println("FTPSETTTNGS NULL");
Lines 137-167 Link Here
137
   */
175
   */
138
  private String computeSystemName() {
176
  private String computeSystemName() {
139
    //System.out.println("FTPFileSystem.prepareSystemName");
177
    //System.out.println("FTPFileSystem.prepareSystemName");
140
    return loginfo.displayName()+
178
        return loginfo.displayName() +
141
             ((startdir!=null && startdir.startsWith("/"))?"":"/")+startdir;
179
                ((startdir != null && startdir.startsWith("/")) ? "" : "/") + startdir;
142
  }  
180
  }  
143
181
144
  private String getDefaultCache() {
182
  private String getDefaultCache() {
145
    return FTPWORK + File.separator + ((FTPLogInfo)loginfo).getHost()+((((FTPLogInfo)loginfo).getPort()==FTPClient.DEFAULT_PORT)?"":("_"+String.valueOf(((FTPLogInfo)loginfo).getPort())))+"_"+((FTPLogInfo)loginfo).getUser();
183
        return FTPWORK + File.separator + ((FTPLogInfo) loginfo).getHost() + ((((FTPLogInfo) loginfo).getPort() == FTPClient.DEFAULT_PORT) ? "" : ("_" + String.valueOf(((FTPLogInfo) loginfo).getPort()))) + "_" + ((FTPLogInfo) loginfo).getUser();
146
  }
184
  }
147
  
185
  
148
  
149
  //****************************************************************************
186
  //****************************************************************************
150
  /** Set cache directory
187
  /** Set cache directory
151
  * @param 
188
     * @param r 
189
     * 
152
  * @exception PropertyVetoException 
190
  * @exception PropertyVetoException 
153
  * @exception IOException 
191
  * @exception IOException 
154
  */
192
  */
155
  public void setCache(File r) throws PropertyVetoException, IOException {
193
  public void setCache(File r) throws PropertyVetoException, IOException {
156
    if (r==null) throw new IOException("Cache root directory can't be null");
194
        if (r == null) {
195
            throw new IOException("Cache root directory can't be null");
196
        }
157
    if (!r.exists()) {
197
    if (!r.exists()) {
158
      if (!r.mkdirs())  
198
            if (!r.mkdirs()) {
159
             throw new IOException("Cache root directory can't be created");
199
             throw new IOException("Cache root directory can't be created");
160
    }
200
    }
161
    else if (!r.isDirectory())  
201
        } else if (!r.isDirectory()) {
162
              throw new IOException("Cache root is not director");
202
            throw new IOException("Cache root is not directory");
163
    if (!r.canWrite() || !r.canRead())
203
        }
204
        if (!r.canWrite() || !r.canRead()) {
164
              throw new IOException("Can't read from or write to cache directory");
205
              throw new IOException("Can't read from or write to cache directory");
206
        }
165
    cachedir = r;
207
    cachedir = r;
166
    enteredcachedir = true;
208
    enteredcachedir = true;
167
    firePropertyChange("cache", null, cachedir); // NOI18N
209
    firePropertyChange("cache", null, cachedir); // NOI18N
Lines 178-205 Link Here
178
   * @return Value of property server.
220
   * @return Value of property server.
179
   */
221
   */
180
  public String getServer() {
222
  public String getServer() {
181
    return ((FTPLogInfo)loginfo).getHost();
223
        return ((FTPLogInfo) loginfo).getHost();
182
  }
224
  }
225
183
  /** Set server name.
226
  /** Set server name.
184
   * @param server New value of property server.
227
   * @param server New value of property server.
185
   * @throws PropertyVetoException
228
   * @throws PropertyVetoException
186
   */
229
   */
187
  public void setServer(String server) throws java.beans.PropertyVetoException {
230
  public void setServer(String server) throws java.beans.PropertyVetoException {
188
    ((FTPLogInfo)loginfo).setHost(server);
231
        ((FTPLogInfo) loginfo).setHost(server);
189
    propChanged();
232
    propChanged();
190
  }
233
  }
234
191
  /** Get the number of port.
235
  /** Get the number of port.
192
   * @return Value of property port.
236
   * @return Value of property port.
193
   */
237
   */
194
  public int getPort() {
238
  public int getPort() {
195
    return ((FTPLogInfo)loginfo).getPort();
239
        return ((FTPLogInfo) loginfo).getPort();
196
  }
240
  }
241
197
  /** Set port number.
242
  /** Set port number.
198
   * @param port New value of property port.
243
   * @param port New value of property port.
199
   * @throws PropertyVetoException
244
   * @throws PropertyVetoException
200
   */
245
   */
201
  public void setPort(int port) throws java.beans.PropertyVetoException {
246
  public void setPort(int port) throws java.beans.PropertyVetoException {
202
    ((FTPLogInfo)loginfo).setPort(port);
247
        ((FTPLogInfo) loginfo).setPort(port);
203
    propChanged();
248
    propChanged();
204
  }
249
  }
205
250
Lines 207-232 Link Here
207
   * @return Value of property username.
252
   * @return Value of property username.
208
   */
253
   */
209
  public String getUsername() {
254
  public String getUsername() {
210
    return ((FTPLogInfo)loginfo).getUser();
255
        return ((FTPLogInfo) loginfo).getUser();
211
  }
256
  }
257
212
  /** Set user name.
258
  /** Set user name.
213
   * @param username New value of property username.
259
   * @param username New value of property username.
260
     * @throws java.beans.PropertyVetoException 
214
   */
261
   */
215
  public void setUsername(String username) throws PropertyVetoException {
262
  public void setUsername(String username) throws PropertyVetoException {
216
    ((FTPLogInfo)loginfo).setUser(username);
263
        ((FTPLogInfo) loginfo).setUser(username);
217
    propChanged();
264
    propChanged();
218
  }
265
  }
266
219
  /** Get password.
267
  /** Get password.
220
   * @return Value of property password.
268
   * @return Value of property password.
221
   */
269
   */
222
  public String getPassword() {
270
  public String getPassword() {
223
    return ((FTPLogInfo)loginfo).getPassword();
271
        return ((FTPLogInfo) loginfo).getPassword();
224
  }
272
  }
273
225
  /** Set password.
274
  /** Set password.
226
   * @param password
275
   * @param password
276
     * @throws java.beans.PropertyVetoException 
227
   */
277
   */
228
  public void setPassword(String password) throws PropertyVetoException {
278
  public void setPassword(String password) throws PropertyVetoException {
229
    ((FTPLogInfo)loginfo).setPassword(password);
279
        ((FTPLogInfo) loginfo).setPassword(password);
230
    propChanged();
280
    propChanged();
231
  }
281
  }
232
282
Lines 236-251 Link Here
236
  public String getStartdir() {
286
  public String getStartdir() {
237
    return startdir;
287
    return startdir;
238
  }
288
  }
289
239
  /** Set starting directory.
290
  /** Set starting directory.
240
   * @param startdir New value of property startdir.
291
   * @param startdir New value of property startdir.
241
   */
292
   */
242
  public void setStartdir(String startdir)  {
293
    public void setStartdir(String startdir) {
243
    String newstartdir = startdir;
294
    String newstartdir = startdir;
244
    if (startdir==null || startdir.equals("/") || startdir.equals("")) newstartdir="/";
295
        if (startdir == null || startdir.equals("/") || startdir.equals("")) {
245
    else { 
296
            newstartdir = "/";
246
       if (!startdir.startsWith("/")) newstartdir="/"+startdir;
297
        } else {
247
       if (newstartdir.endsWith("/")) newstartdir=newstartdir.substring(0, newstartdir.length()-1);
298
            if (!startdir.startsWith("/")) {
299
                newstartdir = "/" + startdir;
248
    }  
300
    }  
301
            if (newstartdir.endsWith("/")) {
302
                newstartdir = newstartdir.substring(0, newstartdir.length() - 1);
303
            }
304
        }
249
    this.startdir = newstartdir;
305
    this.startdir = newstartdir;
250
    removeClient();
306
    removeClient();
251
    /*if (isConnected()) {
307
    /*if (isConnected()) {
Lines 256-264 Link Here
256
    */
312
    */
257
  }
313
  }
258
  
314
  
259
  /** Called when some parameter was changed. If connection is established, it must be reconnected. */
315
    /** Called when some parameter was changed. If connection is established, it must be reconnected. 
316
     */
260
  private void propChanged() throws PropertyVetoException {
317
  private void propChanged() throws PropertyVetoException {
261
    if (!enteredcachedir) cachedir = new File(getDefaultCache());
318
        if (!enteredcachedir) {
319
            cachedir = new File(getDefaultCache());
320
        }
262
    removeClient();
321
    removeClient();
263
    if (isConnected()) {
322
    if (isConnected()) {
264
         connectOnBackground(true);
323
         connectOnBackground(true);
Lines 269-447 Link Here
269
            }
328
            }
270
          }
329
          }
271
        );
330
        );
272
*/    }
331
         */        }
273
  }  
332
  }  
274
    
333
    
275
  /** Creates FTPClient and sets its parameters */
334
    /** Creates FTPClient and sets its parameters 
335
     * @throws java.io.IOException 
336
     */
276
  public RemoteClient createClient(LogInfo loginfo, File cache) throws IOException {
337
  public RemoteClient createClient(LogInfo loginfo, File cache) throws IOException {
277
     if (!cachedir.exists()) cachedir.mkdirs();
338
        if (!cachedir.exists()) {
278
     File logfile = new File(cachedir.getPath()+".log");
339
            cachedir.mkdirs();
340
        }
341
        File logfile = new File(cachedir.getPath() + ".log");
279
     //RandomAccessFile logfile = new RandomAccessFile(cachedir.getPath()+".log","rw");
342
     //RandomAccessFile logfile = new RandomAccessFile(cachedir.getPath()+".log","rw");
280
     //logfile.seek(logfile.length());
343
     //logfile.seek(logfile.length());
281
     FTPClient client = new FTPClient((FTPLogInfo)loginfo);
344
        FTPClient lclient = new FTPClient((FTPLogInfo) loginfo);
282
     client.setLog(logfile);
345
        lclient.setLog(logfile);
283
     client.setReconnect(this);
346
        lclient.setReconnect(this);
284
     client.setPassiveMode(getFTPSettings().isPassiveMode());
347
        lclient.setPassiveMode(getFTPSettings().isPassiveMode());
285
     return client;
348
        return lclient;
286
  }
349
  }
287
350
288
  /** Human presentable name 
351
  /** Human presentable name 
289
   * @return
352
   * @return
290
   */
353
   */
291
  public String getDisplayName() {
354
  public String getDisplayName() {
292
    return  computeSystemName();
355
        return computeSystemName();
293
  }
356
  }
294
357
295
  /** Test whether filesystem is ready to write. If no, throws exception */
358
    /** Test whether filesystem is ready to write. If no, throws exception 
359
     * @throws java.io.IOException 
360
     */
296
  protected void isReadyToModify() throws IOException {
361
  protected void isReadyToModify() throws IOException {
297
     if (client == null || rootFile == null) 
362
        if (client == null || rootFile == null) {
298
         throw new IOException("Connection to server "+getServer()+" isn't established");
363
            throw new IOException("Connection to server " + getServer() + " isn't established");
299
     if (!isConnected() && !isOfflineChanges())
364
        }
365
        if (!isConnected() && !isOfflineChanges()) {
300
          throw new IOException("Modification in offline mode are not allowed");
366
          throw new IOException("Modification in offline mode are not allowed");
301
  }
367
  }
368
    }
302
369
303
  /** Test whether filesystem is ready to read. If no, throws exception */
370
    /** Test whether filesystem is ready to read. If no, throws exception 
371
     * @throws java.io.IOException 
372
     */
304
  protected void isReadyToRead() throws IOException {
373
  protected void isReadyToRead() throws IOException {
305
     if (client == null || rootFile == null) throw new IOException("Connection to server "+getServer()+" isn't established");
374
        if (client == null || rootFile == null) {
375
            throw new IOException("Connection to server " + getServer() + " isn't established");
306
  }
376
  }
377
    }
307
378
308
  /** Test whether filesystem is ready. */
379
    /** Test whether filesystem is ready. 
309
  protected boolean isReady()  {
380
     */
310
     if (client == null || rootFile == null) return false;
381
    protected boolean isReady() {
311
     else return true;
382
        if (client == null || rootFile == null) {
383
            return false;
384
        } else {
385
            return true;
312
  }
386
  }
387
    }
313
388
314
389
    /**
390
     * 
391
     * @param server
392
     * @return
393
     */
315
  protected int disconnectDialog(String server) {
394
  protected int disconnectDialog(String server) {
316
    return FTPDialogs.disconnect(server);
395
    return FTPDialogs.disconnect(server);
317
  }
396
  }
318
  
397
  
398
    /**
399
     * 
400
     * @param server
401
     * @return
402
     */
319
  protected boolean connectDialog(String server) {
403
  protected boolean connectDialog(String server) {
320
    return FTPDialogs.connect(server);
404
    return FTPDialogs.connect(server);
321
  }
405
  }
322
  
406
  
407
    /**
408
     * 
409
     * @param startdir
410
     * @param server
411
     */
323
  protected void startdirNotFound(String startdir, String server) {
412
  protected void startdirNotFound(String startdir, String server) {
324
    FTPDialogs.startdirNotFound(startdir,server);
413
        FTPDialogs.startdirNotFound(startdir, server);
325
  }
414
  }
326
     
415
     
327
  protected  void errorConnect(String error) {
416
    /**
417
     * 
418
     * @param error
419
     */
420
    protected void errorConnect(String error) {
328
    FTPDialogs.errorConnect(error);
421
    FTPDialogs.errorConnect(error);
329
  }
422
  }
330
 
423
 
424
    /**
425
     * 
426
     */
331
  public void notifyIncorrectPassword() {
427
  public void notifyIncorrectPassword() {
332
    FTPDialogs.incorrectPassword(getServer());
428
    FTPDialogs.incorrectPassword(getServer());
333
  }
429
  }
334
  
430
  
431
    /**
432
     * 
433
     * @param newcache
434
     * @return
435
     */
335
  public boolean notifyIncorrectCache(java.io.File newcache) {
436
  public boolean notifyIncorrectCache(java.io.File newcache) {
336
    return FTPDialogs.incorrectCache(getCache().getPath(), newcache.getPath(), getServer());
437
    return FTPDialogs.incorrectCache(getCache().getPath(), newcache.getPath(), getServer());
337
  }
438
  }
338
439
440
    /**
441
     * 
442
     * @param mess
443
     * @return
444
     */
339
  public boolean notifyReconnect(String mess) {
445
  public boolean notifyReconnect(String mess) {
340
      Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor("Connection to server "+getServer()+" lost: "+mess+"\nReconnect?",
446
        Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor("Connection to server " + getServer() + " lost: " + mess + "\nReconnect?",
341
        "Question",NotifyDescriptor.YES_NO_OPTION ,NotifyDescriptor.QUESTION_MESSAGE,null, null));
447
                "Question", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE, null, null));
342
      if (obj==NotifyDescriptor.YES_OPTION) 
448
        if (obj == NotifyDescriptor.YES_OPTION) {
343
           return true;
449
           return true;
344
      else return false;
450
        } else {
451
            return false;
345
  }    
452
  }    
453
    }
346
454
455
    /**
456
     * 
457
     * @param path
458
     * @param file1
459
     * @param size1
460
     * @param file2
461
     * @param size2
462
     * @return
463
     */
347
  public int notifyWhichFile(String path, Date file1, long size1, Date file2, long size2) {
464
  public int notifyWhichFile(String path, Date file1, long size1, Date file2, long size2) {
348
    int which = file1.before(file2)?0:1;
465
        int which = file1.before(file2) ? 0 : 1;
349
    if (!getFTPSettings().isAskWhichFile()) return which;
466
        if (!getFTPSettings().isAskWhichFile()) {
467
            return which;
468
        }
350
    Object ops[] = new String[2];
469
    Object ops[] = new String[2];
351
    ops[0] = "From Cache"; 
470
    ops[0] = "From Cache"; 
352
    ops[1] = "From FTPServer"; 
471
    ops[1] = "From FTPServer"; 
353
    javax.swing.JPanel panel = new javax.swing.JPanel(new java.awt.BorderLayout());
472
    javax.swing.JPanel panel = new javax.swing.JPanel(new java.awt.BorderLayout());
354
    javax.swing.JPanel textpanel = new javax.swing.JPanel(new java.awt.GridLayout(0,1));
473
        javax.swing.JPanel textpanel = new javax.swing.JPanel(new java.awt.GridLayout(0, 1));
355
    textpanel.add(new javax.swing.JLabel("Both files in FTP server and in cache exist."));
474
    textpanel.add(new javax.swing.JLabel("Both files in FTP server and in cache exist."));
356
    textpanel.add(new javax.swing.JLabel(computeSystemName().substring(0,computeSystemName().length()-1)+path+", size "+size1+" bytes, last modified "+file1.toString()));
475
        textpanel.add(new javax.swing.JLabel(computeSystemName().substring(0, computeSystemName().length() - 1) + path + ", size " + size1 + " bytes, last modified " + file1.toString()));
357
    textpanel.add(new javax.swing.JLabel(getCache().getPath()+path.replace('/',File.separatorChar)+", size "+size2+" bytes, last modified "+file2.toString()));
476
        textpanel.add(new javax.swing.JLabel(getCache().getPath() + path.replace('/', File.separatorChar) + ", size " + size2 + " bytes, last modified " + file2.toString()));
358
    textpanel.add(new javax.swing.JLabel("File in "+(which==0?"cache":"FTP server")+" seems to be newer. Which one do you want to use?"));
477
        textpanel.add(new javax.swing.JLabel("File in " + (which == 0 ? "cache" : "FTP server") + " seems to be newer. Which one do you want to use?"));
359
    textpanel.add(new javax.swing.JLabel("Attention: second one will be deleted."));
478
    textpanel.add(new javax.swing.JLabel("Attention: second one will be deleted."));
360
    panel.add(textpanel,java.awt.BorderLayout.NORTH);
479
        panel.add(textpanel, java.awt.BorderLayout.NORTH);
361
    javax.swing.JCheckBox chbox = new javax.swing.JCheckBox("Don't ask again. Always use newer file");
480
    javax.swing.JCheckBox chbox = new javax.swing.JCheckBox("Don't ask again. Always use newer file");
362
    chbox.setSelected(false);
481
    chbox.setSelected(false);
363
    panel.add(chbox);
482
    panel.add(chbox);
364
    Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor(panel,
483
    Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor(panel,
365
       "Question",NotifyDescriptor.YES_NO_OPTION ,NotifyDescriptor.QUESTION_MESSAGE,ops, ops[which]));
484
                "Question", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE, ops, ops[which]));
366
    if (chbox.isSelected()) getFTPSettings().setAskWhichFile(false);
485
        if (chbox.isSelected()) {
367
    if (obj == ops[0]) return 0;
486
            getFTPSettings().setAskWhichFile(false);
368
    else return 1;
369
  }
487
  }
488
        if (obj == ops[0]) {
489
            return 0;
490
        } else {
491
            return 1;
492
        }
493
    }
370
  
494
  
495
    /**
496
     * 
497
     * @param path
498
     * @param file1
499
     * @param size1
500
     * @param file2
501
     * @param size2
502
     * @return
503
     */
371
  public int notifyBothFilesChanged(String path, Date file1, long size1, Date file2, long size2) {
504
  public int notifyBothFilesChanged(String path, Date file1, long size1, Date file2, long size2) {
372
    Object ops[] = new String[2];
505
    Object ops[] = new String[2];
373
    ops[0] = "From Cache"; 
506
    ops[0] = "From Cache"; 
374
    ops[1] = "From FTPServer"; 
507
    ops[1] = "From FTPServer"; 
375
    int which = file1.before(file2)?0:1;
508
        int which = file1.before(file2) ? 0 : 1;
376
    //TODO: better message (branch, merge ...)
509
    //TODO: better message (branch, merge ...)
377
    Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor(
510
        Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor("Both files in FTP server and in cache were modified. It means that two diffrent version of this file exist.\n" +
378
       "Both files in FTP server and in cache were modified. It means that two diffrent version of this file exist.\n"+
511
                computeSystemName().substring(0, computeSystemName().length() - 1) + path + ", size " + size1 + " bytes, last modified " + file1.toString() + "\n" +
379
       computeSystemName().substring(0,computeSystemName().length()-1)+path+", size "+size1+" bytes, last modified "+file1.toString()+"\n"+
512
                getCache().getPath() + path.replace('/', File.separatorChar) + ", size " + size2 + " bytes, last modified " + file2.toString() + "\n" +
380
       getCache().getPath()+path.replace('/',File.separatorChar)+", size "+size2+" bytes, last modified "+file2.toString()+"\n"+
513
                "File in " + (which == 0 ? "cache" : "FTP server") + " seems to be newer. Which one do you want to use?\n" +
381
       "File in "+(which==0?"cache":"FTP server")+" seems to be newer. Which one do you want to use?\n"+
382
       "Attention: second one will be deleted!",
514
       "Attention: second one will be deleted!",
383
       "Files changed",NotifyDescriptor.YES_NO_OPTION ,NotifyDescriptor.WARNING_MESSAGE,ops, ops[which]));
515
                "Files changed", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.WARNING_MESSAGE, ops, ops[which]));
384
    if (obj == ops[0]) return 0;
516
        if (obj == ops[0]) {
385
    else return 1;
517
            return 0;
518
        } else {
519
            return 1;
386
  }
520
  }
521
    }
387
  
522
  
388
  
523
    /**
524
     * 
525
     * @return
526
     */
389
  public boolean isRefreshServer() { 
527
  public boolean isRefreshServer() { 
390
    return getFTPSettings().isRefreshServer();
528
    return getFTPSettings().isRefreshServer();
391
  }
529
  }
392
530
531
    /**
532
     * 
533
     * @return
534
     */
393
  public boolean isScanCache() {
535
  public boolean isScanCache() {
394
    return getFTPSettings().isScanCache();
536
    return getFTPSettings().isScanCache();
395
  }
537
  }
396
  
538
  
539
    /**
540
     * 
541
     * @return
542
     */
397
  public boolean isAlwaysRefresh() {
543
  public boolean isAlwaysRefresh() {
398
    return getFTPSettings().isRefreshAlways();
544
    return getFTPSettings().isRefreshAlways();
399
  }
545
  }
400
  
546
  
547
    /**
548
     * 
549
     * @param alwaysRefresh
550
     */
401
  public void setAlwaysRefresh(boolean alwaysRefresh) {
551
  public void setAlwaysRefresh(boolean alwaysRefresh) {
402
    getFTPSettings().setRefreshAlways(alwaysRefresh);
552
    getFTPSettings().setRefreshAlways(alwaysRefresh);
403
  }
553
  }
404
  
554
  
555
    /**
556
     * 
557
     * @return
558
     */
405
  public boolean isDownloadServerChangedFile() {
559
  public boolean isDownloadServerChangedFile() {
406
    return getFTPSettings().isDownloadServerChangedFile();
560
    return getFTPSettings().isDownloadServerChangedFile();
407
  }
561
  }
408
  
562
  
563
    /**
564
     * 
565
     * @return
566
     */
409
  public boolean isOfflineChanges() { 
567
  public boolean isOfflineChanges() { 
410
    return getFTPSettings().isOfflineChanges();
568
    return getFTPSettings().isOfflineChanges();
411
  }
569
  }
412
  
570
  
413
  public boolean notifyServerChanged(String path,Date file1,long size1,Date file2,long size2) {
571
    /**
414
    if (!getFTPSettings().isAskServerChangedFile()) return true; // I agree
572
     * 
573
     * @param path
574
     * @param file1
575
     * @param size1
576
     * @param file2
577
     * @param size2
578
     * @return
579
     */
580
    public boolean notifyServerChanged(String path, Date file1, long size1, Date file2, long size2) {
581
        if (!getFTPSettings().isAskServerChangedFile()) {
582
            return true;
583
        } // I agree
415
    javax.swing.JPanel panel = new javax.swing.JPanel(new java.awt.BorderLayout());
584
    javax.swing.JPanel panel = new javax.swing.JPanel(new java.awt.BorderLayout());
416
    javax.swing.JPanel textpanel = new javax.swing.JPanel(new java.awt.GridLayout(0,1));
585
        javax.swing.JPanel textpanel = new javax.swing.JPanel(new java.awt.GridLayout(0, 1));
417
    textpanel.add(new javax.swing.JLabel("I detected that the file in FTP server has been changed."));
586
    textpanel.add(new javax.swing.JLabel("I detected that the file in FTP server has been changed."));
418
    textpanel.add(new javax.swing.JLabel(computeSystemName().substring(0,computeSystemName().length()-1)+path+", size "+size1+" bytes, last modified "+file1.toString()));
587
        textpanel.add(new javax.swing.JLabel(computeSystemName().substring(0, computeSystemName().length() - 1) + path + ", size " + size1 + " bytes, last modified " + file1.toString()));
419
    textpanel.add(new javax.swing.JLabel(getCache().getPath().replace('/',File.separatorChar)+path+", size "+size2+" bytes, last modified "+file2.toString()));
588
        textpanel.add(new javax.swing.JLabel(getCache().getPath().replace('/', File.separatorChar) + path + ", size " + size2 + " bytes, last modified " + file2.toString()));
420
    textpanel.add(new javax.swing.JLabel("I will use this new file from server and delete the file in cache. Do you agree?"));
589
    textpanel.add(new javax.swing.JLabel("I will use this new file from server and delete the file in cache. Do you agree?"));
421
    textpanel.add(new javax.swing.JLabel("If you say No, the file from cache will be upload to server over changed one."));
590
    textpanel.add(new javax.swing.JLabel("If you say No, the file from cache will be upload to server over changed one."));
422
    panel.add(textpanel,java.awt.BorderLayout.NORTH);
591
        panel.add(textpanel, java.awt.BorderLayout.NORTH);
423
    javax.swing.JCheckBox chbox = new javax.swing.JCheckBox("Don't ask again. Always use new file from server");
592
    javax.swing.JCheckBox chbox = new javax.swing.JCheckBox("Don't ask again. Always use new file from server");
424
    chbox.setSelected(false);
593
    chbox.setSelected(false);
425
    panel.add(chbox);
594
    panel.add(chbox);
426
    Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor(panel,
595
    Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor(panel,
427
       "Question",NotifyDescriptor.YES_NO_OPTION ,NotifyDescriptor.QUESTION_MESSAGE,null,NotifyDescriptor.YES_OPTION));
596
                "Question", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE, null, NotifyDescriptor.YES_OPTION));
428
    if (chbox.isSelected()) getFTPSettings().setAskServerChangedFile(false);
597
        if (chbox.isSelected()) {
429
    if (obj == NotifyDescriptor.YES_OPTION) return true;
598
            getFTPSettings().setAskServerChangedFile(false);
430
    else return false;
431
  }
599
  }
600
        if (obj == NotifyDescriptor.YES_OPTION) {
601
            return true;
602
        } else {
603
            return false;
604
        }
605
    }
432
606
607
    /**
608
     * 
609
     * @param path
610
     * @param isDir
611
     * @return
612
     */
433
  public boolean notifyCacheExtDelete(String path, boolean isDir) {
613
  public boolean notifyCacheExtDelete(String path, boolean isDir) {
434
    if (!getFTPSettings().isAskCacheExternalDelete()) 
614
        if (!getFTPSettings().isAskCacheExternalDelete()) {
435
            return getFTPSettings().isCacheExternalDelete(); 
615
            return getFTPSettings().isCacheExternalDelete(); 
616
        }
436
    Object ops[] = new String[4];
617
    Object ops[] = new String[4];
437
    ops[0] = "Yes";
618
    ops[0] = "Yes";
438
    ops[1] = "No";
619
    ops[1] = "No";
439
    ops[2] = "Yes for All";
620
    ops[2] = "Yes for All";
440
    ops[3] = "No for All";
621
    ops[3] = "No for All";
441
    Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor(
622
        Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor((isDir ? "The directory " + path + " in cache was delete externally.\nDo you want to the delete directory and all the subdirectories also from server?\n" : "The file " + path + " in cache was delete externaly.\nDo you want to delete the file also from server?\n"),
442
       (isDir?"The directory "+path+" in cache was delete externally.\nDo you want to the delete directory and all the subdirectories also from server?\n":
623
                "External deletion", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE, ops, ops[1]));
443
        "The file "+path+" in cache was delete externaly.\nDo you want to delete the file also from server?\n"),
444
       "External deletion",NotifyDescriptor.YES_NO_OPTION ,NotifyDescriptor.QUESTION_MESSAGE,ops,ops[1]));  
445
    if (obj == ops[2]) { 
624
    if (obj == ops[2]) { 
446
         getFTPSettings().setAskCacheExternalDelete(false);
625
         getFTPSettings().setAskCacheExternalDelete(false);
447
         getFTPSettings().setCacheExternalDelete(true);
626
         getFTPSettings().setCacheExternalDelete(true);
Lines 450-470 Link Here
450
         getFTPSettings().setAskCacheExternalDelete(false);
629
         getFTPSettings().setAskCacheExternalDelete(false);
451
         getFTPSettings().setCacheExternalDelete(false);
630
         getFTPSettings().setCacheExternalDelete(false);
452
    }
631
    }
453
    if (obj == ops[0] || obj == ops[2]) return true;
632
        if (obj == ops[0] || obj == ops[2]) {
454
    else return false;
633
            return true;
634
        } else {
635
            return false;
455
  }
636
  }
637
    }
638
639
    /**
640
     * 
641
     * @param path
642
     * @param isDir
643
     * @return
644
     */
456
  public boolean notifyServerExtDelete(String path, boolean isDir) {
645
  public boolean notifyServerExtDelete(String path, boolean isDir) {
457
    if (!getFTPSettings().isAskServerExternalDelete()) 
646
        if (!getFTPSettings().isAskServerExternalDelete()) {
458
            return getFTPSettings().isServerExternalDelete(); 
647
            return getFTPSettings().isServerExternalDelete(); 
648
        }
459
    Object ops[] = new String[4];
649
    Object ops[] = new String[4];
460
    ops[0] = "Yes";
650
    ops[0] = "Yes";
461
    ops[1] = "No";
651
    ops[1] = "No";
462
    ops[2] = "Yes for All";
652
    ops[2] = "Yes for All";
463
    ops[3] = "No for All";
653
    ops[3] = "No for All";
464
    Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor(
654
        Object obj = DialogDisplayer.getDefault().notify(new NotifyDescriptor((isDir ? "The directory " + path + " on server was delete externally.\nDo you want to delete the directory and all the subdirectories also from cache?\n" : "The file " + path + " on server was delete externally.\nDo you want to delete the file also from cache?\n"),
465
      (isDir?"The directory "+path+" on server was delete externally.\nDo you want to delete the directory and all the subdirectories also from cache?\n":
655
                "External deletion", NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE, ops, ops[1]));
466
      "The file "+path+" on server was delete externally.\nDo you want to delete the file also from cache?\n"),
467
      "External deletion",NotifyDescriptor.YES_NO_OPTION ,NotifyDescriptor.QUESTION_MESSAGE,ops,ops[1]));  
468
    if (obj == ops[2]) { 
656
    if (obj == ops[2]) { 
469
         getFTPSettings().setAskServerExternalDelete(false);
657
         getFTPSettings().setAskServerExternalDelete(false);
470
         getFTPSettings().setServerExternalDelete(true);
658
         getFTPSettings().setServerExternalDelete(true);
Lines 473-489 Link Here
473
         getFTPSettings().setAskServerExternalDelete(false);
661
         getFTPSettings().setAskServerExternalDelete(false);
474
         getFTPSettings().setServerExternalDelete(false);
662
         getFTPSettings().setServerExternalDelete(false);
475
    }
663
    }
476
    if (obj == ops[0] || obj == ops[2]) return true;
664
        if (obj == ops[0] || obj == ops[2]) {
477
    else return false;
665
            return true;
666
        } else {
667
            return false;
478
  }
668
  }
669
    }
479
670
671
    /**
672
     * 
673
     * @param path
674
     */
480
  public void fileChanged(String path) {
675
  public void fileChanged(String path) {
481
    FileObject fo = findResource(path);
676
    FileObject fo = findResource(path);
482
    if (fo != null) fo.refresh();
677
        if (fo != null) {
678
            fo.refresh();
483
  }
679
  }
680
    }
484
681
682
    /**
683
     * 
684
     * @param e
685
     */
485
  public void notifyException(Exception e) {
686
  public void notifyException(Exception e) {
486
    Exceptions.printStackTrace(e);
687
    Exceptions.printStackTrace(e);
487
  }
688
  }
488
 
489
} 
689
} 

Return to bug 123552