org.gnogno.gui.dataset.binder
Class AbstractPropertyToComponentBinder<T>

java.lang.Object
  extended by org.gnogno.gui.dataset.binder.AbstractPropertyToComponentBinder<T>
All Implemented Interfaces:
PropertyAware, ResourceDataSetAware
Direct Known Subclasses:
CheckboxBinder, SwingPropertyToComponentBinder, SWTPropertyToComponentBinder

public abstract class AbstractPropertyToComponentBinder<T>
extends Object
implements PropertyAware

This class binds to a property of a ResourceDataSet. It listens for changes in the model, the resource or values of the property and fires the dataChanged event if these events occur. You can derive your own propertybinders and implemnet dataChanged as you like. $Id: AbstractPropertyToComponentBinder.java,v 1.1 2005/02/02 08:48:34 sauermann Exp $

Author:
leobard

Nested Class Summary
protected  class AbstractPropertyToComponentBinder.Listener
           
 
Field Summary
protected  T component
          the visual component that is bound.
private  ResourceDataSet dataset
           
private  org.ontoware.rdf2go.model.node.URI datatype
          the datatype of the property.
private  boolean datatypeDetected
          true, when the datatype was already detected.
private  boolean detectDatatype
          before getting/setting values, detect the correct datatype to use based on the ontology
private  AbstractPropertyToComponentBinder.Listener listener
           
protected  Logger log
          dynamic logger, depends on the implementing class
private  org.ontoware.rdf2go.model.node.URI property
           
private  int updatingComponent
           
private  int updatingRdf
           
private  boolean useOntology
          if true, information from the ontology (the RDFS Comment) may be used on the control.
 
Constructor Summary
AbstractPropertyToComponentBinder()
           
AbstractPropertyToComponentBinder(T component)
           
AbstractPropertyToComponentBinder(T component, ResourceDataSet dataset, org.ontoware.rdf2go.model.node.URI property)
          generate a new AbstractPropertyBinder.
 
Method Summary
protected  void addListenerOnDataSet()
          remove listeners on the dataset, if the dataset is !
protected  void beginDataUpdate()
          subclasses can use this to set the binder into updating state.
protected abstract  void bindComponent(T component)
          bind a listener to the component to listen for changes.
protected  void componentToResource()
          write the data from the component to the resource
 void dispose()
          dispose the object, set all related objects to null, unregister listeners.
protected abstract  void enableComponent(boolean enabled)
          set the component to enabled or disabled.
protected  void endDataUpdate()
          subclasses can use this to set the binder into updating state.
protected  void fireOntologyToComponent()
          update the tooltip and other properties of the component, if the useOntology is set
 T getComponent()
           
 org.ontoware.rdf2go.model.node.URI getDatatype()
          read the datatype of this property from the range value, from the ontology.
 GnoFactory getGnoFactory()
          convenience method getting the GnoFactory of the ModelDataSet
 ModelDataSet getModelDataSet()
          convenience method to access the modeldataset of the resourcedataset.
 org.ontoware.rdf2go.model.node.URI getProperty()
          get the property that this thing does visualize
 String getPropertyAsString()
          get property URI as String.
 ResourceDataSet getResourceDataSet()
          retrieve the resource data set that is the source of data of this component.
 boolean getUseOntology()
          true, when the rdfs-comment from the ontology should be used to set the tooltip of the component.
 boolean isDetectDatatype()
          before getting/setting values, detect the correct datatype to use based on the ontology
 boolean isOpen()
          return true, when all the necessary data is there to show something in the gui
protected  void ontologyToComponent(org.ontoware.rdf2go.model.node.URI prop)
          update the component based on the ontology info.
protected abstract  org.ontoware.rdf2go.model.node.Node readFromComponent(org.ontoware.rdf2go.model.Model model)
          The value in the control has changed, return the actual value from the control.
protected  void removeListenerOnDataSet()
          remove listeners on the dataset, if the dataset is !
protected  void resourceToComponent()
          write the data from the resource to the component Also enables/disables the component using enableComponent(boolean).
 void setComponent(T component)
           
 void setDatatype(org.ontoware.rdf2go.model.node.URI datatype)
          the datatype of the property.
 void setDetectDatatype(boolean detectDatatype)
          before getting/setting values, detect the correct datatype to use based on the ontology
 void setProperty(org.ontoware.rdf2go.model.node.URI property)
          set the property that this thing does visualise.
 void setPropertyAsString(String uri)
          set the property as String.
 void setResourceDataSet(ResourceDataSet dataset)
          set the resource data set.
abstract  void setToolTipTextOnComponent(String string)
          override this implementing the tooltip text on the component.
 void setUseOntology(boolean useOntology)
          set the value to true, so that the binder keeps the tooltip with the rdfs:comment of the property
protected  org.ontoware.rdf2go.model.node.Node stringToNode(String text, org.ontoware.rdf2go.model.node.URI dt)
          convert a string to a node, guessing the correct way using the datatype
protected abstract  void unbindComponent(T component)
          unbind previously registered change listeners
protected abstract  void writeToComponent(org.ontoware.rdf2go.model.node.Node node)
          The property of the resource has changed or is initalised.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listener

private AbstractPropertyToComponentBinder.Listener listener

log

protected Logger log
dynamic logger, depends on the implementing class


dataset

private ResourceDataSet dataset

property

private org.ontoware.rdf2go.model.node.URI property

component

protected T component
the visual component that is bound. This component may typically forward the functions to a PropertyBinder Usually, this is a javax.swing.JComponent


useOntology

private boolean useOntology
if true, information from the ontology (the RDFS Comment) may be used on the control.


updatingComponent

private int updatingComponent

updatingRdf

private int updatingRdf

datatypeDetected

private boolean datatypeDetected
true, when the datatype was already detected.


detectDatatype

private boolean detectDatatype
before getting/setting values, detect the correct datatype to use based on the ontology


datatype

private org.ontoware.rdf2go.model.node.URI datatype
the datatype of the property.

Constructor Detail

AbstractPropertyToComponentBinder

public AbstractPropertyToComponentBinder()

AbstractPropertyToComponentBinder

public AbstractPropertyToComponentBinder(T component)

AbstractPropertyToComponentBinder

public AbstractPropertyToComponentBinder(T component,
                                         ResourceDataSet dataset,
                                         org.ontoware.rdf2go.model.node.URI property)
generate a new AbstractPropertyBinder. Will be called by implementing classes

Parameters:
component -
dataset -
property -
Method Detail

addListenerOnDataSet

protected void addListenerOnDataSet()
remove listeners on the dataset, if the dataset is != null


beginDataUpdate

protected void beginDataUpdate()
subclasses can use this to set the binder into updating state. During update, messages received from the RDF backend will be ignored. You must call endDataUpdate() in a try ... finally statement, otherwise the property binder will be broken.


bindComponent

protected abstract void bindComponent(T component)
bind a listener to the component to listen for changes. If the data shown in the component is modified by the user, call componentToResource()

Parameters:
component - the component to bind (is not null)

componentToResource

protected void componentToResource()
write the data from the component to the resource


dispose

public void dispose()
dispose the object, set all related objects to null, unregister listeners. This does not call the set methods but calls removeListenerOnDataSet and unbindComponent directly.


enableComponent

protected abstract void enableComponent(boolean enabled)
set the component to enabled or disabled. There may be many subsequent calls with the same enabled value, each time the resource changes the component is enabled "again".

Parameters:
enabled - true, if the component should be enabled, false if it should be disabled

endDataUpdate

protected void endDataUpdate()
subclasses can use this to set the binder into updating state. During update, messages received from the RDF backend will be ignored.


fireOntologyToComponent

protected void fireOntologyToComponent()
update the tooltip and other properties of the component, if the useOntology is set


getComponent

public T getComponent()
Returns:
Returns the component.

getDatatype

public org.ontoware.rdf2go.model.node.URI getDatatype()
read the datatype of this property from the range value, from the ontology.

Returns:
the datatype to use to edit the property, read from the ontology. Or null, if nothing can be detected.

getGnoFactory

public GnoFactory getGnoFactory()
convenience method getting the GnoFactory of the ModelDataSet

Returns:
the GnoFactory or null.

getModelDataSet

public ModelDataSet getModelDataSet()
convenience method to access the modeldataset of the resourcedataset.

Returns:
the modeldataset of the resourcedataset.

getProperty

public org.ontoware.rdf2go.model.node.URI getProperty()
Description copied from interface: PropertyAware
get the property that this thing does visualize

Specified by:
getProperty in interface PropertyAware
Returns:
the property or null

getPropertyAsString

public String getPropertyAsString()
get property URI as String. Useful when you edit graphical components using Eclipse Visual Editor

Returns:
property uri or null

getResourceDataSet

public ResourceDataSet getResourceDataSet()
Description copied from interface: ResourceDataSetAware
retrieve the resource data set that is the source of data of this component.

Specified by:
getResourceDataSet in interface ResourceDataSetAware
Returns:
the ResourceDataSet or null, if not set

getUseOntology

public boolean getUseOntology()
true, when the rdfs-comment from the ontology should be used to set the tooltip of the component.

Returns:
Returns the useOntology.

isDetectDatatype

public boolean isDetectDatatype()
before getting/setting values, detect the correct datatype to use based on the ontology

Returns:
true, when the datatype is detected from the ontology

isOpen

public boolean isOpen()
return true, when all the necessary data is there to show something in the gui

Returns:
true if the data is open

ontologyToComponent

protected void ontologyToComponent(org.ontoware.rdf2go.model.node.URI prop)
update the component based on the ontology info. Passed is the property in the ontology model.


readFromComponent

protected abstract org.ontoware.rdf2go.model.node.Node readFromComponent(org.ontoware.rdf2go.model.Model model)
The value in the control has changed, return the actual value from the control. Use getDatatype() if you wish to work with datatypes.

Parameters:
component - the component from which to read the value
model - the model in which the node should be created
Returns:
the actual value as RDFNode

removeListenerOnDataSet

protected void removeListenerOnDataSet()
remove listeners on the dataset, if the dataset is != null


resourceToComponent

protected void resourceToComponent()
write the data from the resource to the component Also enables/disables the component using enableComponent(boolean).


setComponent

public void setComponent(T component)
Parameters:
component - The component to set.

setDatatype

public void setDatatype(org.ontoware.rdf2go.model.node.URI datatype)
the datatype of the property.

Parameters:
datatype - the datatype of the property.

setDetectDatatype

public void setDetectDatatype(boolean detectDatatype)
before getting/setting values, detect the correct datatype to use based on the ontology

Parameters:
detectDatatype - detect the datatype from the ontology

setProperty

public void setProperty(org.ontoware.rdf2go.model.node.URI property)
Description copied from interface: PropertyAware
set the property that this thing does visualise.

Specified by:
setProperty in interface PropertyAware
Parameters:
property - the property
See Also:
PropertyAware.setProperty(org.ontoware.rdf2go.model.node.URI)

setPropertyAsString

public void setPropertyAsString(String uri)
set the property as String. Useful when you edit graphical components using Eclipse Visual Editor

Parameters:
uri - the uri to use as property.

setResourceDataSet

public void setResourceDataSet(ResourceDataSet dataset)
Description copied from interface: ResourceDataSetAware
set the resource data set.

Specified by:
setResourceDataSet in interface ResourceDataSetAware
Parameters:
dataset - the dataset
See Also:
ResourceDataSetAware.setResourceDataSet(org.gnogno.gui.dataset.ResourceDataSet)

setToolTipTextOnComponent

public abstract void setToolTipTextOnComponent(String string)
override this implementing the tooltip text on the component.

Parameters:
string - this is extracted from the property's rdfs comment.

setUseOntology

public void setUseOntology(boolean useOntology)
set the value to true, so that the binder keeps the tooltip with the rdfs:comment of the property

Parameters:
useOntology - The useOntology to set.

stringToNode

protected org.ontoware.rdf2go.model.node.Node stringToNode(String text,
                                                           org.ontoware.rdf2go.model.node.URI dt)
convert a string to a node, guessing the correct way using the datatype

Parameters:
text - the text to convert
dt - the datatype to use (usually retrieved using getDatatype())
Returns:
the text as node

unbindComponent

protected abstract void unbindComponent(T component)
unbind previously registered change listeners

Parameters:
component - the component to unbind (is not null)

writeToComponent

protected abstract void writeToComponent(org.ontoware.rdf2go.model.node.Node node)
The property of the resource has changed or is initalised. Take the passed property value and write it to the control. Use getDatatype() if you wish to work with datatypes. The component can be retrieved via getComponent().

Parameters:
node - the node value to write, attention: the value may be null