/* PropertiesWindow.java * * Copyright (c) 2003 by Benja Fallenstein * * This file is part of Fenfire. * * Fenfire is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Fenfire is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Fenfire; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * */ /* * Written by Benja Fallenstein */ package org.fenfire.loom; import gzz.client.AbstractUpdateManager; import java.awt.*; import java.awt.event.*; import java.util.*; import com.hp.hpl.mesa.rdf.jena.model.*; /** A list box allowing properties from a model * to be selected and unselected. * Shows all properties in a model (rdf:_n are * shown as a single entry). By selecting and unselecting * individual properties, the user can influence * what is shown on the screen. *
* The list box is associated with a StatementSelector
* which chooses only statements whose property is selected
* in the box.
*
* A
* This cannot be an
* This is relevant for the unit tests.
*/
public void refresh() {
Set showProperties = new HashSet();
boolean showNumericProperties = false;
int[] indexes = getSelectedIndexes();
for(int i=0; iNamespaceMap
is used to preprocess property names
* before showing them on the screen. After this preprocessing,
* the properties are shown in alphabetical order.
*/
public class PropertiesBox extends java.awt.List {
protected PropertySetSelector selector;
protected java.util.List properties;
/** A special tag representing the rdf:_n properties
* in the properties
list.
*/
protected static final Object numericProperties = new Object();
public PropertiesBox() {
setMultipleMode(true);
selector = new PropertySetSelector();
}
/** Set the model from which properties are shown.
* Initially, all properties are selected.
*/
public void setModel(Model model, NamespaceMap names)
throws RDFException {
removeAll();
selector.setProperties(null, true);
properties = new ArrayList(ModelUtil.getProperties(model));
Collections.sort(properties, names.getComparator());
int n = 0;
boolean haveNumericProperties = false;
for(Iterator i = properties.iterator(); i.hasNext();) {
Property p = (Property)i.next();
if(RDFVocab.isNumericProperty(p)) {
i.remove();
haveNumericProperties = true;
} else {
add(names.getAbbrev(p.toString()));
}
}
if(haveNumericProperties) {
properties.add(0, numericProperties);
add("rdf:_n properties", 0);
}
for(int i=0; irefresh()
.
*/
protected void processItemEvent(ItemEvent e) {
try {
super.processItemEvent(e);
} finally {
refresh();
}
}
/** Re-read the set of shown properties from the selections
* in this list box. This ensures that the StatementSelector
* related to this box really accepts exactly those
* properties selected in the list box.
* ItemListener
because
* the select()
and deselect()
* methods do not generate ItemEvent
s.
* When the selection is changed through these methods,
* refresh()
must be called for the changes
* to take effect.
*