1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 /******************************************************************************
25 * RestrictionTableModel.java
26 *
27 * The local model for the Restriction Table
28 *****************************************************************************/
29
30 package zeus.ontology.restrictions;
31
32 import java.util.*;
33 import javax.swing.event.*;
34 import javax.swing.table.*;
35
36 import zeus.concepts.*;
37 import zeus.ontology.*;
38 import zeus.gui.editors.*;
39
40
41 public class RestrictionTableModel extends AbstractTableModel
42 implements ChangeListener, ValidatingModel {
43
44 protected String[] columnNames = { "Name", "Type", "Restrictions" };
45 protected String[][] data = null;
46 protected boolean[][] validityInfo = null;
47 protected OntologyDb model = null;
48
49 static final int NAME = 0;
50 static final int TYPE = 1;
51 static final int RESTRICTION = 2;
52
53 public RestrictionTableModel(OntologyDb model) {
54 this.model = model;
55 model.addChangeListener(this);
56 refresh();
57 }
58
59 void refresh() {
60 data = model.getAllRestrictions();
61 validityInfo = model.getAllRestrictionValidityInfo();
62 fireTableStructureChanged();
63 }
64
65 public int getColumnCount() { return columnNames.length; }
66 public int getRowCount() { return (data != null) ? data.length : 0; }
67 public String[] getRow(int row) { return data[row]; }
68
69 public boolean isCellEditable(int r, int c) { return true;}
70 public String getColumnName(int c) { return columnNames[c]; }
71 public Object getValueAt(int r, int c) { return data[r][c]; }
72 public boolean isValidEntry(int r, int c) { return validityInfo[r][c]; }
73
74 public void setValueAt(Object aValue, int row, int col) {
75 String value;
76 if ( aValue == null )
77 value = "";
78 else
79 value = ((String)aValue).trim();
80
81 if ( data[row][col].equals(value) )
82 return;
83
84 String result = model.setRestrictionData(data[row][NAME],col,value);
85 data[row][col] = result;
86 validityInfo[row] = model.isRestrictionValid(data[row][NAME]);
87 fireTableCellUpdated(row,col);
88 }
89
90 public void stateChanged(ChangeEvent e) {
91 OntologyDbChangeEvent evt = (OntologyDbChangeEvent)e;
92 if ( evt.getEventType() == OntologyDb.RELOAD )
93 refresh();
94 }
95
96 void addNewRow() {
97 model.addNewRestriction();
98 refresh();
99 }
100 void deleteRows(int[] rows) {
101 String[] names = new String[rows.length];
102 for(int i = 0; i < rows.length; i++ )
103 names[i] = data[rows[i]][NAME];
104 model.deleteRestrictions(names);
105 refresh();
106 }
107 void addRows(String[][] input) {
108 model.addRestrictions(input);
109 refresh();
110 }
111 String[][] getRows(int[] input) {
112 String[][] result = new String[input.length][columnNames.length];
113 for(int i = 0; i < result.length; i++ )
114 for(int j = 0; j < result[i].length; j++)
115 result[i][j] = data[input[i]][j];
116 return result;
117 }
118 }