1
2
3
4
5
6
7 package net.kwfgrid.gwui.taskframework;
8
9 import java.awt.Graphics;
10 import java.awt.Component;
11 import java.awt.event.ActionEvent;
12 import java.util.Iterator;
13 import java.util.List;
14 import javax.swing.*;
15
16 import org.glassbox.graphview.NodeButtonSet;
17
18 import de.fzi.wim.guibase.graphview.graph.Node;
19
20 import net.kwfgrid.gwui.graphview.PlaceNode;
21 import net.kwfgrid.gworkflowdl.structure.Place;
22 import net.kwfgrid.gworkflowdl.structure.GenericProperties;
23
24 import org.apache.log4j.Logger;
25
26 public class NodeButton4Decision implements NodeButtonSet.Button {
27 private static final Logger logger = Logger.getLogger(NodeButton4Decision.class);
28
29 private Action ACTION = new AbstractAction() {
30 public void actionPerformed(ActionEvent e) {
31 PlaceNode pnode = (PlaceNode)e.getSource();
32 Place p = pnode.getPlace();
33 List tasks = _producer.getValidTasks(p);
34 if (tasks.size()>0) {
35 UserTask task = (UserTask)tasks.get(0);
36 task.execute();
37 }
38 }
39 };
40
41 private InputTaskProducer4Decision _producer;
42
43 public NodeButton4Decision(InputTaskProducer4Decision producer) {
44 _producer = producer;
45 }
46
47 public Action getAction() {
48 return ACTION;
49 }
50
51 public int getIconWidth() {
52 return InputTaskProducer4Decision.TASK_ICON.getIconWidth();
53 }
54
55 public int getIconHeight() {
56 return InputTaskProducer4Decision.TASK_ICON.getIconHeight();
57 }
58
59 public void paintIcon(Component c, Graphics g, int x, int y) {
60 InputTaskProducer4Decision.TASK_ICON.paintIcon(c, g, x, y);
61 }
62
63 public void paintPressedIcon(Component c, Graphics g, int x, int y) {
64 paintIcon(c, g, x, y);
65 }
66
67 public void paintRolloverIcon(Component c, Graphics g, int x, int y) {
68 paintIcon(c, g, x, y);
69 }
70
71 public boolean affectsNode(Node node) {
72 if (node instanceof PlaceNode) {
73 PlaceNode pnode = (PlaceNode)node;
74 Place p = pnode.getPlace();
75 boolean affects = _producer.hasValidTask(p);
76 return affects;
77 }
78 return false;
79 }
80
81 public String getToolTipText(Node node) {
82 PlaceNode pnode = (PlaceNode)node;
83 Place p = pnode.getPlace();
84 StringBuffer tt = new StringBuffer("<html>");
85 Iterator tasks = _producer.getValidTasks(p).iterator(); while (tasks.hasNext()) {
86 UserTask task = (UserTask)tasks.next();
87 tt.append(task.getTitle()).append(tasks.hasNext()?"<br>":"");
88 }
89 return tt.toString();
90 }
91 }