1
1
package eclipsematrix .checkin .toolbar ;
2
2
3
+ import java .util .Random ;
4
+
3
5
import net .contentobjects .jnotify .JNotify ;
6
+ import net .contentobjects .jnotify .JNotifyException ;
4
7
5
8
import org .eclipse .core .commands .AbstractHandler ;
6
9
import org .eclipse .core .commands .ExecutionEvent ;
7
10
import org .eclipse .core .commands .ExecutionException ;
11
+ import org .eclipse .core .commands .HandlerEvent ;
8
12
import org .eclipse .jface .preference .IPreferenceStore ;
9
13
10
14
import eclipsematrix .EclipseMatrix ;
15
+ import eclipsematrix .notifier .NotificationType ;
16
+ import eclipsematrix .notifier .NotifierDialog ;
11
17
import eclipsematrix .preferences .PreferenceConstants ;
12
18
import eclipsematrix .utils .FileListener ;
13
19
14
20
public class MonitorFiles extends AbstractHandler {
15
- //private FileMonitor monitor = FileMonitor.getInstance();
16
- //private JPOFileListener jpoFileListener = new JPOFileListener();
17
-
21
+ // private FileMonitor monitor = FileMonitor.getInstance();
22
+ // private JPOFileListener jpoFileListener = new JPOFileListener();
23
+
18
24
boolean enabled = true ;
19
-
25
+
20
26
public Object execute (ExecutionEvent event ) throws ExecutionException {
21
- IPreferenceStore store = EclipseMatrix .getDefault ().getPreferenceStore ();
22
- //FIXME check prefs
23
- String jpoDir = store .getString (PreferenceConstants .P_JPOPATH );
24
- String uiDir = store .getString (PreferenceConstants .P_UIPATH );
25
- String dmDir = store .getString (PreferenceConstants .P_DMPATH );
26
-
27
+ IPreferenceStore store = EclipseMatrix .getDefault ()
28
+ .getPreferenceStore ();
29
+ // FIXME check prefs
30
+ String jpoDir = store .getString (PreferenceConstants .P_JPOPATH );
31
+ String uiDir = store .getString (PreferenceConstants .P_UIPATH );
32
+ String dmDir = store .getString (PreferenceConstants .P_DMPATH );
33
+
27
34
try {
28
35
setFilemonitor (jpoDir );
29
36
setFilemonitor (uiDir );
30
37
setFilemonitor (dmDir );
31
38
} catch (Exception e ) {
32
- // TODO Auto-generated catch block
33
39
e .printStackTrace ();
34
40
}
35
- // MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(
36
- // event).getShell(), "Info", "Files Monitored");
37
-
38
- //FIXME force refresh of command
41
+
42
+ // FIXME use notifier
43
+ // MessageDialog.openInformation(HandlerUtil.getActiveWorkbenchWindow(
44
+ // event).getShell(), "Info", "Files Monitored");
45
+
39
46
enabled = false ;
47
+ fireHandlerChanged (new HandlerEvent (this , true , false ));
40
48
return null ;
41
49
}
42
-
50
+
43
51
@ Override
44
52
public boolean isEnabled () {
45
53
boolean isEnabled = super .isEnabled ();
@@ -49,26 +57,25 @@ public boolean isEnabled() {
49
57
return enabled ;
50
58
}
51
59
60
+ public int setFilemonitor (String path ) {
61
+ int watchID = 0 ;
62
+ // watch mask, specify events you care about,
63
+ // or JNotify.FILE_ANY for all events.
64
+ int mask = JNotify .FILE_CREATED | JNotify .FILE_DELETED
65
+ | JNotify .FILE_MODIFIED | JNotify .FILE_RENAMED ;
52
66
67
+ // watch subtree?
68
+ boolean watchSubtree = true ;
53
69
54
-
55
- public void setFilemonitor (String path ) throws Exception {
56
- // watch mask, specify events you care about,
57
- // or JNotify.FILE_ANY for all events.
58
- int mask = JNotify .FILE_CREATED |
59
- JNotify .FILE_DELETED |
60
- JNotify .FILE_MODIFIED |
61
- JNotify .FILE_RENAMED ;
62
-
63
- // watch subtree?
64
- boolean watchSubtree = true ;
65
-
66
- // add actual watch
67
- int watchID = JNotify .addWatch (path , mask , watchSubtree , new FileListener ());
68
- // // to remove watch the watch
69
- // boolean res = JNotify.removeWatch(watchID);
70
- // if (!res) {
71
- // // invalid watch ID specified.
72
- // }
73
- }
70
+ // add actual watch
71
+ try {
72
+ watchID = JNotify .addWatch (path , mask , watchSubtree ,
73
+ new FileListener ());
74
+ } catch (JNotifyException e ) {
75
+ // FIXME Print error
76
+ // TODO Auto-generated catch block
77
+ e .printStackTrace ();
78
+ }
79
+ return watchID ;
80
+ }
74
81
}
0 commit comments