/** * Copyright 1999-2009 The Pegadi Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.pegadi.storysketch.views; import org.pegadi.storysketch.XMLUtil; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import javax.swing.table.AbstractTableModel; import java.util.Vector; public class RDFTableModel extends AbstractTableModel { Vector list; public RDFTableModel() { list = new Vector(); } public void clear() { list = new Vector(); fireTableDataChanged(); } public void addItem(RDFItem item) { list.add(item); fireTableDataChanged(); } public void removeItem(RDFItem item) { list.removeElement(item); fireTableDataChanged(); } public boolean contains(Object o) { return list.contains(o); } public String getColumnName(int col) { return "Artikler"; } public void loadRDF(Element rdf) { clear(); NodeList nl = rdf.getElementsByTagName("item"); for(int i = 0; i < nl.getLength(); i++) { Element element = (Element) nl.item(i); String id = element.getAttribute("rdf:about"); String title = XMLUtil.extractValue(element, "title"); String description = XMLUtil.extractValue(element, "description"); String date = XMLUtil.extractValue(element, "dc:date"); RDFItem item = new RDFItem(id, title, description, date); list.add(item); } } public int getColumnCount() { return 1; } public int getRowCount() { return list.size(); } public Object getValueAt(int row, int col) { return ((RDFItem[]) list.toArray(new RDFItem[list.size()]))[row]; } public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); } }