View Javadoc

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.generator.code;
25  
26  import java.util.*;
27  import javax.swing.table.*;
28  import javax.swing.event.*;
29  
30  import zeus.util.*;
31  
32  public abstract class UtilityModel extends AbstractTableModel
33                                     implements ChangeListener {
34  
35    protected boolean changed = false;
36  
37    public abstract void addNewRow();
38    public abstract void removeRows(int[] rows);
39    protected abstract void refresh();
40  
41    protected String updateString(String prev, Object aValue, boolean mode) {
42       String value = updateString(prev,aValue);
43       if ( value != null )
44          return value;
45       else {
46          if ( mode )
47  	   return value;
48  	else {
49  	   changed = false;
50  	   return prev;
51          }
52       }
53    }
54    protected String updateString(String prev, Object aValue) {
55       String value;
56       changed = false;
57       if ( prev == null ) {
58          if ( aValue == null )
59             return prev;
60          else {
61             value = ((String)aValue).trim();
62             value = value.trim();
63             if ( value.equals("") )
64  	      return null;
65  	   else {
66  	      changed = true;
67  	      return value;
68             }
69          }
70       }
71       else {
72          if ( aValue == null ) {
73             changed = true;
74             return null;
75          }
76          else {
77             value = ((String)aValue).trim();
78             value = value.trim();
79             if ( value.equals("") ) {
80                changed = true;
81  	      return null;
82             }
83  	   else if ( prev.equals(value) ) {
84  	      return prev;
85             }
86             else {
87                changed = true;
88                return value;
89             }
90          }
91       }
92    }
93  
94    protected boolean updateBoolean(boolean prev, Object aValue) {
95       boolean curr = ((Boolean)aValue).booleanValue();
96       changed = (prev != curr);
97       return curr;
98    }
99  
100   public void stateChanged(ChangeEvent e) {
101     // generationPlan state changed recompute all entries;
102     refresh();
103   }
104 }