Revision 972
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.spi/src/main/java/org/gvsig/tools/dynform/spi/dynformfield/DefaultObservableAction.java | ||
---|---|---|
1 |
package org.gvsig.tools.dynform.spi.dynformfield; |
|
2 |
|
|
3 |
import java.awt.event.ActionEvent; |
|
4 |
import java.beans.PropertyChangeListener; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
import javax.swing.Action; |
|
9 |
|
|
10 |
import org.gvsig.tools.observer.Observable; |
|
11 |
import org.gvsig.tools.observer.Observer; |
|
12 |
|
|
13 |
public class DefaultObservableAction implements ObservableAction{ |
|
14 |
|
|
15 |
protected List<Observer> observers = new ArrayList<Observer>(); |
|
16 |
private Action action; |
|
17 |
|
|
18 |
public DefaultObservableAction(Action act){ |
|
19 |
this.action = act; |
|
20 |
} |
|
21 |
|
|
22 |
public void addObserver(Observer o) { |
|
23 |
this.observers.add(o); |
|
24 |
} |
|
25 |
|
|
26 |
public synchronized void deleteObserver(Observer o) { |
|
27 |
this.observers.remove(o); |
|
28 |
} |
|
29 |
|
|
30 |
public synchronized void deleteObservers() { |
|
31 |
this.observers = new ArrayList<Observer>(); |
|
32 |
} |
|
33 |
|
|
34 |
public synchronized void notifyObservers(Observable observable, String tableName) { |
|
35 |
for(int i =0; i<this.observers.size(); i++ ) { |
|
36 |
Observer o = (Observer) this.observers.get(i); |
|
37 |
o.update(observable, tableName); |
|
38 |
} |
|
39 |
} |
|
40 |
|
|
41 |
public Action getAction() { |
|
42 |
return this.action; |
|
43 |
} |
|
44 |
|
|
45 |
public void addPropertyChangeListener(PropertyChangeListener arg0) { |
|
46 |
this.action.addPropertyChangeListener(arg0); |
|
47 |
} |
|
48 |
|
|
49 |
public Object getValue(String arg0) { |
|
50 |
return this.action.getValue(arg0); |
|
51 |
} |
|
52 |
|
|
53 |
public boolean isEnabled() { |
|
54 |
return this.action.isEnabled(); |
|
55 |
} |
|
56 |
|
|
57 |
public void putValue(String arg0, Object arg1) { |
|
58 |
this.action.putValue(arg0, arg1); |
|
59 |
} |
|
60 |
|
|
61 |
public void removePropertyChangeListener(PropertyChangeListener arg0) { |
|
62 |
this.action.removePropertyChangeListener(arg0); |
|
63 |
} |
|
64 |
|
|
65 |
public void setEnabled(boolean arg0) { |
|
66 |
this.action.setEnabled(arg0); |
|
67 |
} |
|
68 |
|
|
69 |
public void actionPerformed(ActionEvent arg0) { |
|
70 |
this.getAction().actionPerformed(arg0); |
|
71 |
this.notifyObservers(this, this.getName()); |
|
72 |
} |
|
73 |
|
|
74 |
public String getName() { |
|
75 |
return (String) this.getAction().getValue(Action.NAME); |
|
76 |
} |
|
77 |
|
|
78 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.spi/src/main/java/org/gvsig/tools/dynform/spi/dynformfield/AbstractJDynFormField.java | ||
---|---|---|
51 | 51 |
import org.slf4j.LoggerFactory; |
52 | 52 |
|
53 | 53 |
@SuppressWarnings({"rawtypes", "unchecked"}) |
54 |
public abstract class AbstractJDynFormField implements JDynFormField, Observer {
|
|
54 |
public abstract class AbstractJDynFormField implements JDynFormField{ |
|
55 | 55 |
|
56 | 56 |
protected static final Logger logger = LoggerFactory |
57 | 57 |
.getLogger(AbstractJDynFormField.class); |
... | ... | |
281 | 281 |
if(obj!=null){ |
282 | 282 |
Action act = (Action) obj; |
283 | 283 |
if(contents instanceof SupportPopupMenu) { |
284 |
ObservableAction sact = new DefaultObservableAction(act); |
|
285 |
sact.addObserver(this); |
|
284 |
DynFormFieldAction sact = new DynFormFieldAction(this, act); |
|
286 | 285 |
((SupportPopupMenu) this.contents).addActionToPopupMenu( |
287 | 286 |
sact.getName(), |
288 | 287 |
sact); |
... | ... | |
299 | 298 |
public void addActionToPopupMenu(String name, Action action) { |
300 | 299 |
if(contents != null){ |
301 | 300 |
if(contents instanceof SupportPopupMenu ) { |
302 |
ObservableAction sact = new DefaultObservableAction(action); |
|
303 |
sact.addObserver(this); |
|
301 |
DynFormFieldAction sact = new DynFormFieldAction(this,action); |
|
304 | 302 |
((SupportPopupMenu) this.contents).addActionToPopupMenu( |
305 | 303 |
sact.getName(), |
306 | 304 |
sact); |
... | ... | |
320 | 318 |
} |
321 | 319 |
} |
322 | 320 |
|
323 |
public void update(Observable obj, Object arg) { |
|
324 |
//TODO Do something with this function |
|
325 |
if(obj instanceof ObservableAction){ |
|
326 |
System.out.println("[AbstractJDynFormField -> update()] " |
|
327 |
+ "Action launched: "+arg.toString() |
|
328 |
+" for field: "+ this.getName() |
|
329 |
+ " (Type:" + this.getDefinition().getType() + ")"); |
|
330 |
} |
|
331 |
} |
|
332 | 321 |
} |
Also available in: Unified diff