1
2
3
4
5 package de.mindcrimeilab.xsanalyzer.model;
6
7 import java.beans.PropertyChangeEvent;
8 import java.beans.PropertyChangeListener;
9
10 import javax.swing.tree.TreePath;
11
12 import org.springframework.binding.value.ValueModel;
13 import org.springframework.richclient.core.Guarded;
14
15
16
17
18
19
20
21 public abstract class AbstractTreeSelectionGuard implements PropertyChangeListener {
22
23 private final ValueModel selectionHolder;
24
25 private final Guarded guarded;
26
27 public AbstractTreeSelectionGuard(ValueModel selectionHolder, Guarded guarded) {
28 this.selectionHolder = selectionHolder;
29 this.selectionHolder.addValueChangeListener(this);
30 this.guarded = guarded;
31 propertyChange(null);
32 }
33
34
35
36
37
38
39 @Override
40 public void propertyChange(PropertyChangeEvent evt) {
41 TreePath[] selected = (TreePath[]) selectionHolder.getValue();
42 guarded.setEnabled(shouldEnable(selected));
43
44 }
45
46 public Guarded getGuarded() {
47 return guarded;
48 }
49
50 public ValueModel getSelectionHolder() {
51 return selectionHolder;
52 }
53
54 protected abstract boolean shouldEnable(TreePath[] selected);
55 }