1 /*
2 * The contents of this file are subject to the BT "ZEUS" Open Source
3 * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file
4 * except in compliance with the Licence. You may obtain a copy of the Licence
5 * from $ZEUS_INSTALL/licence.html or alternatively from
6 * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7 *
8 * Except as stated in Clause 7 of the Licence, software distributed under the
9 * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the Licence for the specific language governing rights and
11 * limitations under the Licence.
12 *
13 * The Original Code is within the package zeus.*.
14 * The Initial Developer of the Original Code is British Telecommunications
15 * public limited company, whose registered office is at 81 Newgate Street,
16 * London, EC1A 7AJ, England. Portions created by British Telecommunications
17 * public limited company are Copyright 1996-9. All Rights Reserved.
18 *
19 * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20 */
21
22
23
24 package zeus.agentviewer.task;
25
26 import javax.swing.table.*;
27 import java.util.*;
28 import zeus.concepts.PrimitiveTask;
29 import zeus.concepts.Fact;
30 import zeus.actors.event.*;
31 import zeus.concepts.*;
32 import zeus.actors.*;
33
34
35
36 public class TaskTableModel extends AbstractTableModel implements TaskMonitor{
37
38 private String header = "Task";
39 private Vector data ;
40 private TaskDb taskDb;
41 //------------------------------------------------------------------------------
42 public TaskTableModel(AgentContext context){
43 data = new Vector();
44 taskDb = context.TaskDb();
45 taskDb.addTaskMonitor(this, TaskEvent.ADD_MASK | TaskEvent.DELETE_MASK,true);
46 }
47 //------------------------------------------------------------------------------
48 public int getRowCount() {
49 return data.size();
50 }
51 //------------------------------------------------------------------------------
52 public int getColumnCount(){
53 return 1;
54 }
55 //------------------------------------------------------------------------------
56 public Object getValueAt(int row, int col) {
57 PrimitiveTask task = (PrimitiveTask) data.elementAt(row);
58
59 switch (col){
60 case 0: return task.getName();
61 default: return new String("Error in TaskTableModel getValue");
62 }
63 }
64 //------------------------------------------------------------------------------
65 public String getColumnName(int col) {
66 return header;
67 }
68 //------------------------------------------------------------------------------
69 public void addTask(PrimitiveTask task){
70 if ( data.contains(task) )
71 return;
72
73 data.addElement(task);
74 fireTableDataChanged();
75
76 }
77 //------------------------------------------------------------------------------
78 public void removeTask(PrimitiveTask task){
79 if ( !data.contains(task) )
80 return;
81
82 data.removeElement(task);
83 fireTableDataChanged();
84 }
85
86 //------------------------------------------------------------------------------
87 public Fact[] getEffects(int row){
88 PrimitiveTask task = (PrimitiveTask) data.elementAt(row);
89 //return task.getProducedFacts();
90 return task.getPostconditions();
91 }
92 //------------------------------------------------------------------------------
93 public Fact[] getPreConditions(int row){
94 PrimitiveTask task = (PrimitiveTask) data.elementAt(row);
95 //return task.getConsumedFacts();
96 return task.getPreconditions();
97 }
98 //------------------------------------------------------------------------------
99 public void taskAddedEvent(TaskEvent event) {
100 if ( !((Task) event.getTask()).isPrimitive() )
101 return;
102 addTask((PrimitiveTask) event.getTask());
103 }
104 //------------------------------------------------------------------------------
105 public void taskModifiedEvent(TaskEvent event) {}
106 //------------------------------------------------------------------------------
107 public void taskDeletedEvent(TaskEvent event) {
108 removeTask((PrimitiveTask) event.getTask());
109 }
110 //------------------------------------------------------------------------------
111 public void taskAccessedEvent(TaskEvent event) {}
112
113 //------------------------------------------------------------------------------
114 public void removeZeusEventMonitors(){
115 taskDb.removeTaskMonitor(this, TaskEvent.ADD_MASK | TaskEvent.DELETE_MASK);
116
117 }
118 //------------------------------------------------------------------------------
119 public String getCost(int row) {
120 PrimitiveTask task = (PrimitiveTask) data.elementAt(row);
121 return task.getCostFn().toString();
122 }
123 //------------------------------------------------------------------------------
124 public String getTime(int row){
125 PrimitiveTask task = (PrimitiveTask) data.elementAt(row);
126 return task.getTimeFn().toString();
127 }
128
129
130 }