001 /*
002 * PropertyDetailsTableModel.java
003 *
004 * Niraj Aswani, 09/March/07
005 *
006 * $Id: PropertyDetailsTableModel.html,v 1.0 2007/03/09 16:13:01 niraj Exp $
007 */
008 package gate.gui.ontology;
009
010 import gate.creole.ontology.*;
011
012 import java.util.*;
013
014 import javax.swing.table.AbstractTableModel;
015
016 /**
017 * A DataModel that is created when a node is selected in the ontology
018 * property tree. It contains information such as direct/all sub/super
019 * properties, equivalent properties, domain/range of each property and
020 * property values and so on. The information from this model is then
021 * shown in the right hand side panel of the ontology editor.
022 *
023 * @author niraj
024 *
025 */
026 public class PropertyDetailsTableModel extends AbstractTableModel {
027 public PropertyDetailsTableModel() {
028 resourceInfo = new DetailsGroup("Resource Information", true, null);
029 directSuperProps = new DetailsGroup("Direct Super Properties", true, null);
030 allSuperProps = new DetailsGroup("All Super Properties", true, null);
031 directSubProps = new DetailsGroup("Direct Sub Properties", true, null);
032 allSubProps = new DetailsGroup("All Sub Properties", true, null);
033 equivalentProps = new DetailsGroup("Equivalent Properties", true, null);
034 domain = new DetailsGroup("Domain", true, null);
035 range = new DetailsGroup("Range", true, null);
036 propertyTypes = new DetailsGroup("Properties", true, null);
037 propertyValues = new DetailsGroup("PropertyValues", true, null);
038 detailGroups = new DetailsGroup[0];
039 itemComparator = new OntologyItemComparator();
040 }
041
042 public int getColumnCount() {
043 return COLUMN_COUNT;
044 }
045
046 public int getRowCount() {
047 int i = detailGroups.length;
048 for(int j = 0; j < detailGroups.length; j++)
049 if(detailGroups[j].isExpanded()) i += detailGroups[j].getSize();
050 return i;
051 }
052
053 public String getColumnName(int i) {
054 switch(i) {
055 case 0: // '\0'
056 return "";
057 case 1: // '\001'
058 return "";
059 case 2:
060 return "";
061 case 3:
062 return "";
063 }
064 return "";
065 }
066
067 public Class getColumnClass(int i) {
068 switch(i) {
069 case 0:
070 return Boolean.class;
071 case 1:
072 return Object.class;
073 case 2:
074 return Object.class;
075 case 3:
076 return Object.class;
077 }
078 return Object.class;
079 }
080
081 public boolean isCellEditable(int i, int j) {
082 Object obj = getItemForRow(i);
083 //if(obj instanceof PropertyValue && j == 2) return true;
084 return false;
085 }
086
087 public void setValueAt(Object obj, int i, int j) {
088 Object obj1 = getItemForRow(i);
089 if(j == 0 && (obj1 instanceof DetailsGroup)) {
090 DetailsGroup detailsgroup = (DetailsGroup)obj1;
091 detailsgroup.setExpanded(((Boolean)obj).booleanValue());
092 }
093 fireTableDataChanged();
094 }
095
096 protected Object getItemForRow(int i) {
097 int j = 0;
098 for(int k = 0; j <= i; k++) {
099 if(j == i) return detailGroups[k];
100 int l = 1 + (detailGroups[k].isExpanded() ? detailGroups[k].getSize() : 0);
101 if(j + l > i) return detailGroups[k].getValueAt(i - j - 1);
102 j += l;
103 }
104 return null;
105 }
106
107 public Object getValueAt(int i, int j) {
108 Object obj = getItemForRow(i);
109 switch(j) {
110 case 0:
111 return (obj instanceof DetailsGroup) ? new Boolean(((DetailsGroup)obj)
112 .isExpanded()) : null;
113 case 1:
114 return obj;
115 case 2:
116 return obj;
117 case 3:
118 return obj;
119 }
120 return null;
121 }
122
123 public void setItem(Object obj) {
124 detailGroups = (new DetailsGroup[] {resourceInfo, directSuperProps, allSuperProps,
125 directSubProps, allSubProps, equivalentProps, domain, range,
126 propertyTypes, propertyValues});
127
128 RDFProperty property = (RDFProperty)obj;
129 resourceInfo.getValues().clear();
130 directSuperProps.getValues().clear();
131 allSuperProps.getValues().clear();
132 directSubProps.getValues().clear();
133 allSubProps.getValues().clear();
134 equivalentProps.getValues().clear();
135 domain.getValues().clear();
136 range.getValues().clear();
137 propertyTypes.getValues().clear();
138 propertyValues.getValues().clear();
139
140 resourceInfo.getValues().clear();
141 resourceInfo.getValues().add(property);
142 resourceInfo.getValues().add(new KeyValuePair(property, "URI", property.getURI().toString(), false));
143
144 Set<RDFProperty> dprops = property.getPropertiesWithResourceAsDomain();
145 propertyTypes.getValues().addAll(dprops);
146 Collections.sort(propertyTypes.getValues(), itemComparator);
147
148 // for(RDFProperty prop : dprops) {
149 // propertyTypes.getValues().addAll(Utils.getDetailsToAdd(prop));
150 // }
151
152 Set<AnnotationProperty> props = property.getSetAnnotationProperties();
153 if(props != null) {
154 Iterator<AnnotationProperty> apIter = props.iterator();
155 while(apIter.hasNext()) {
156 AnnotationProperty ap = apIter.next();
157 List<Literal> literals = property.getAnnotationPropertyValues(ap);
158 for(int i = 0; i < literals.size(); i++) {
159 PropertyValue pv = new PropertyValue(ap, literals.get(i));
160 propertyValues.getValues().add(pv);
161 }
162 }
163 }
164
165 if(property instanceof AnnotationProperty) {
166 resourceInfo.getValues().add(new KeyValuePair(property, "TYPE", "Annotation Property", false));
167 } else if(property instanceof DatatypeProperty) {
168 resourceInfo.getValues().add(new KeyValuePair(property, "TYPE", "Datatype Property", false));
169 } else if(property instanceof SymmetricProperty) {
170 resourceInfo.getValues().add(new KeyValuePair(property, "TYPE", "Symmetric Property", false));
171 } else if(property instanceof TransitiveProperty) {
172 resourceInfo.getValues().add(new KeyValuePair(property, "TYPE", "Transitive Property", false));
173 } else {
174 resourceInfo.getValues().add(new KeyValuePair(property, "TYPE", "Object Property", false));
175 }
176
177 if(property instanceof AnnotationProperty) {
178 fireTableDataChanged();
179 return;
180 }
181 // else provide further details
182
183 Set<RDFProperty> set = property
184 .getSuperProperties(OConstants.Closure.DIRECT_CLOSURE);
185 if(set != null) {
186 directSuperProps.getValues().addAll(set);
187 Collections.sort(directSuperProps.getValues(), itemComparator);
188 }
189
190 set = property.getSuperProperties(OConstants.Closure.TRANSITIVE_CLOSURE);
191 if(set != null) {
192 allSuperProps.getValues().addAll(set);
193 Collections.sort(allSuperProps.getValues(), itemComparator);
194 }
195 set = property.getSubProperties(OConstants.Closure.DIRECT_CLOSURE);
196 if(set != null) {
197 directSubProps.getValues().addAll(set);
198 Collections.sort(directSubProps.getValues(), itemComparator);
199 }
200 set = property.getSubProperties(OConstants.Closure.TRANSITIVE_CLOSURE);
201 if(set != null) {
202 allSubProps.getValues().addAll(set);
203 Collections.sort(allSubProps.getValues(), itemComparator);
204 }
205
206 set = property.getEquivalentPropertyAs();
207 if(set != null) {
208 equivalentProps.getValues().addAll(set);
209 Collections.sort(equivalentProps.getValues(), itemComparator);
210 }
211
212 Set set1 = property.getDomain();
213 if(set1 != null) {
214 domain.getValues().addAll(set1);
215 Collections.sort(domain.getValues(), itemComparator);
216
217 // Iterator iterator = set1.iterator();
218 // while(iterator.hasNext()) {
219 // OResource resource = (OResource)iterator.next();
220 // domain.getValues().addAll(Utils.getDetailsToAdd(resource));
221 // }
222 }
223
224 // TODO: this used getXmlSchemaURI originally -- test if this breaks
225 // anything!
226 if(property instanceof DatatypeProperty) {
227 range.getValues().add(new KeyValuePair(property, "DATATYPE",
228 ((DatatypeProperty)property).getDataType().getXmlSchemaURIString(), false));
229 fireTableDataChanged();
230 return;
231 }
232
233 Set set2 = property.getRange();
234 if(set2 != null) {
235 range.getValues().addAll(set2);
236 Collections.sort(range.getValues(), itemComparator);
237
238 // Iterator iterator = set2.iterator();
239 // while(iterator.hasNext()) {
240 // OResource resource = (OResource)iterator.next();
241 // range.getValues().addAll(Utils.getDetailsToAdd(resource));
242 // }
243 }
244
245 fireTableDataChanged();
246 }
247
248 protected DetailsGroup resourceInfo;
249
250 protected DetailsGroup directSuperProps;
251
252 protected DetailsGroup allSuperProps;
253
254 protected DetailsGroup directSubProps;
255
256 protected DetailsGroup equivalentProps;
257
258 protected DetailsGroup allSubProps;
259
260 protected DetailsGroup domain;
261
262 protected DetailsGroup range;
263
264 protected DetailsGroup propertyTypes;
265
266 protected DetailsGroup propertyValues;
267
268 protected DetailsGroup detailGroups[];
269
270 protected OntologyItemComparator itemComparator;
271
272 public static final int COLUMN_COUNT = 4;
273
274 public static final int EXPANDED_COLUMN = 0;
275
276 public static final int LABEL_COLUMN = 1;
277
278 public static final int VALUE_COLUMN = 2;
279
280 public static final int DELETE_COLUMN = 3;
281 }
|