edu.cs.ai.kreator.ui.gui.components.controller
Class QueryPreviewGuideController

java.lang.Object
  extended by edu.cs.ai.kreator.ui.gui.components.controller.QueryPreviewGuideController
Direct Known Subclasses:
EvidencePreviewGuideController

public class QueryPreviewGuideController
extends java.lang.Object

This class is a Mediator on a set of controls defined in PreviewGuideControls. It previews and observes the construction of a query. The user can click hyperlinks in the html Preview Pane or use the keyboard to navigate between different states of construction and items in the "workList". Subclasses defining new states should overload at least the following methods to ensure correct navigation: - applyWorkListSelection - processStateNavigation - onHyperlinkEvent to extend functionality overloading the following methods is important: - isValid - switchState - checkStateValid - reset(String reason) to customize output of the subclass can use the default output structure and overload the methods: - buildPreviewOutput - buildGuideOutput - buildErrorOutput also see protected member: doLabel but if you want a real custom output without the structure defined by the base class overload: - updateOutput See EvidencePreviewGuideController for an example sub class implementation.

Author:
Tim Janus
See Also:
PreviewGuideControls

Nested Class Summary
protected  class QueryPreviewGuideController.KeyListener
          KeyListner class for extended keyboard interpretation.
protected  class QueryPreviewGuideController.ParameterPair
          Implementation of a pair: It connect a parameter type and a constant to a complete parameter.
 
Field Summary
static int ACTION_CHANGED
           
static int ACTION_DO
           
protected  boolean allowConstantAppending
           
protected  java.lang.String doLabel
           
protected  boolean internalStateChange
           
protected  LanguageFactory language
          reference to the actual used language
protected static java.lang.String LINK_ID_DO
          Url for link to execute a valid query.
protected static java.lang.String LINK_ID_PREDICATE
          Url for link to switch into select a predicate state.
protected static java.lang.String LINK_ID_PREFIX_PARAMETER
          Url prefix for a link to switch to select parameter state, the index of the predicate will be added to the end of the prefix.
protected  javax.swing.JEditorPane outputPane
           
protected  java.util.List<QueryPreviewGuideController.ParameterPair> parameters
          List of selected parameters of the actual predicate.
protected  GeneralizedPredicate predicate
          reference to the actual selected predicate
protected  int state
          The current state of the controller.
protected static int STATE_NO_KNOWLEDGEBASE
          State_ID: No valid knowledge base is selected yet.
protected static int STATE_PREDICATE
          State_ID: User selects a query predicate.
protected  UserAppendRemoveList workList
           
 
Constructor Summary
QueryPreviewGuideController(PreviewGuideControls controls)
           
 
Method Summary
 boolean addActionListener(java.awt.event.ActionListener listener)
           
protected  boolean applyWorkListSelection()
          This method apply the selection change in the work list.
protected  java.lang.String buildErrorOutput()
          Proofs if a error occurs if this the case builds an output string Overload this method for your custom error message output.
protected  java.lang.String buildGuideOutput()
          Builds the guide line output helping the user performing the next step.
protected  java.lang.String buildPreviewOutput()
          Builds the preview output string showing the user what he had constructed so far.
protected  void changeWorkListContent(java.util.List<?> content)
          Helper method: Changes the content of the workList and preselects a parameter object.
protected  void checkStateValid(int newState)
           
 Query getQuery()
           
protected  int getStateCount()
           
protected  void informActionListener(int id)
           
 boolean isValid()
           
protected  void onHyperlinkEvent(javax.swing.event.HyperlinkEvent e)
          Decide what to do if the user clicks a hyperlink Sub classes defining more hyperlinks should override this method to add the wished functionality when the user clicks on the link.
protected  void processStateNavigation(java.awt.event.KeyEvent event)
          Navigate through different states by a given KeyEvent.
 boolean removeActionListener(java.awt.event.ActionListener listener)
           
 void reset()
          Resets the state of the preview guide
 void reset(LanguageFactory language)
           
 void reset(java.lang.String reason)
           
 void setLanguage(LanguageFactory language)
          Changes the language this query preview guide is working with.
protected  void setParameter(Constant c)
          Helper method: Sets a new parameter.
protected  void switchState(int newState)
          Switch the current state to newState
protected  void updateOutput()
          Updates the output of the QueryOutput Pane.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

language

protected LanguageFactory language
reference to the actual used language


predicate

protected GeneralizedPredicate predicate
reference to the actual selected predicate


parameters

protected java.util.List<QueryPreviewGuideController.ParameterPair> parameters
List of selected parameters of the actual predicate.


state

protected int state
The current state of the controller. State 0..k-1 are allowed where k is the actual count of parameters in the selected predicate. As an example: If the state is 1 the user selects a constant for the second parameter of the predicate. This member can also be set to negative values, see the static final members with the prefix STATE for more details. USE: switchState method to change this member.


doLabel

protected java.lang.String doLabel

outputPane

protected javax.swing.JEditorPane outputPane

workList

protected UserAppendRemoveList workList

allowConstantAppending

protected boolean allowConstantAppending

internalStateChange

protected boolean internalStateChange

ACTION_DO

public static final int ACTION_DO
See Also:
Constant Field Values

ACTION_CHANGED

public static final int ACTION_CHANGED
See Also:
Constant Field Values

STATE_NO_KNOWLEDGEBASE

protected static final int STATE_NO_KNOWLEDGEBASE
State_ID: No valid knowledge base is selected yet.

See Also:
Constant Field Values

STATE_PREDICATE

protected static final int STATE_PREDICATE
State_ID: User selects a query predicate.

See Also:
Constant Field Values

LINK_ID_PREDICATE

protected static final java.lang.String LINK_ID_PREDICATE
Url for link to switch into select a predicate state.

See Also:
Constant Field Values

LINK_ID_PREFIX_PARAMETER

protected static final java.lang.String LINK_ID_PREFIX_PARAMETER
Url prefix for a link to switch to select parameter state, the index of the predicate will be added to the end of the prefix.

See Also:
Constant Field Values

LINK_ID_DO

protected static final java.lang.String LINK_ID_DO
Url for link to execute a valid query.

See Also:
Constant Field Values
Constructor Detail

QueryPreviewGuideController

public QueryPreviewGuideController(PreviewGuideControls controls)
Method Detail

addActionListener

public boolean addActionListener(java.awt.event.ActionListener listener)

removeActionListener

public boolean removeActionListener(java.awt.event.ActionListener listener)

getStateCount

protected int getStateCount()

setLanguage

public void setLanguage(LanguageFactory language)
Changes the language this query preview guide is working with.

Parameters:
language - reference to the new language

reset

public void reset()
Resets the state of the preview guide


reset

public void reset(java.lang.String reason)

reset

public void reset(LanguageFactory language)

getQuery

public Query getQuery()

isValid

public boolean isValid()

informActionListener

protected void informActionListener(int id)

switchState

protected void switchState(int newState)
Switch the current state to newState

Parameters:
newState -

checkStateValid

protected void checkStateValid(int newState)

buildErrorOutput

protected java.lang.String buildErrorOutput()
Proofs if a error occurs if this the case builds an output string Overload this method for your custom error message output.

Returns:
An string describing the error if an error occured otherwise null.

buildPreviewOutput

protected java.lang.String buildPreviewOutput()
Builds the preview output string showing the user what he had constructed so far. Using html links for mouse click navigation. Overload this method for showing the user the custom object he's actually constructing.

Returns:
html formatted string with preview output.

buildGuideOutput

protected java.lang.String buildGuideOutput()
Builds the guide line output helping the user performing the next step. Overload this method for custom guide output.

Returns:
html formatted string with guide output.

updateOutput

protected void updateOutput()
Updates the output of the QueryOutput Pane. You can overload this method if you want a completely different output. Otherwise overload: buildError- buildPreviw- buildGuide- Output methods.


setParameter

protected void setParameter(Constant c)
Helper method: Sets a new parameter. The index is already saved in the state member of this instance.

Parameters:
c - new constant for the parameter.

changeWorkListContent

protected void changeWorkListContent(java.util.List<?> content)
Helper method: Changes the content of the workList and preselects a parameter object.

Parameters:
content - new list content

applyWorkListSelection

protected boolean applyWorkListSelection()
This method apply the selection change in the work list. This means it sets a new predicate to the query if a predicate was select. Subclasses defining new states should overload this method to switch automatically in a new state if the work of the previous one is done.

Returns:
true if a state change occurred after work list selection change was applied otherwise false.

processStateNavigation

protected void processStateNavigation(java.awt.event.KeyEvent event)
Navigate through different states by a given KeyEvent. Sub classes defining more states should override this method, so that the user is able to select the new states with the keyboard too.

Parameters:
event - reference to the KeyEvent

onHyperlinkEvent

protected void onHyperlinkEvent(javax.swing.event.HyperlinkEvent e)
Decide what to do if the user clicks a hyperlink Sub classes defining more hyperlinks should override this method to add the wished functionality when the user clicks on the link.

Parameters:
e - Reference to the HyperLinkEvent