cz.cuni.pogamut.shed.presenter
Class PrimitivePresenter<PRIMITIVE_TYPE extends PoshElement & INamedElement>

Package class diagram package PrimitivePresenter
java.lang.Object
  extended by cz.cuni.pogamut.shed.presenter.PrimitivePresenter<PRIMITIVE_TYPE>
Type Parameters:
PRIMITIVE_TYPE - Either Sense or TriggeredAction depending on which primitive is used.
All Implemented Interfaces:
ILapChainListener, PoshElementListener<PRIMITIVE_TYPE>, IPresenter, PropertyChangeListener, EventListener

public abstract class PrimitivePresenter<PRIMITIVE_TYPE extends PoshElement & INamedElement>
extends Object
implements PoshElementListener<PRIMITIVE_TYPE>, ILapChainListener

Base class presenter for primitives, i.e. actions and senses. Since both actions and senses presenters are quite similar, use this class as base class for both of them.

Author:
Honza

Field Summary
protected  ShedPresenter presenter
          Presenter that is mainly used to modify the scene
protected  PRIMITIVE_TYPE primitive
          The primitive that is being presented by this presenter.
protected  LapChain primitiveChain
          Chain of variables from the root to the primitive.
protected  ShedVariableWidget primitiveWidget
          Widget that represents the primitive in the scene.
protected  ShedScene scene
          Scene this presenter is modifying.
 
Constructor Summary
protected PrimitivePresenter(ShedScene scene, ShedPresenter presenter, PRIMITIVE_TYPE primitive, ShedVariableWidget primitiveWidget, LapChain primitiveChain)
          Create new presenter for @primitive, detect and project all changes on the @primitive and @primitiveChain to the @primitiveWidget.
 
Method Summary
 void childElementAdded(PRIMITIVE_TYPE parent, PoshElement child)
           
 void childElementMoved(PRIMITIVE_TYPE parent, PoshElement child, int oldIndex, int newIndex)
           
 void childElementRemoved(PRIMITIVE_TYPE parent, PoshElement child, int removedChildIndex)
           
protected  TriggeredAction extractAction(List<TriggeredAction> actions, PoshElement action)
           
protected  ActionPattern extractActionPattern(List<ActionPattern> actionPatterns, PoshElement actionPattern)
          Assert that @actionPattern is in the @actionPatterns and return it.
protected  CompetenceElement extractChoice(List<CompetenceElement> choices, PoshElement choice)
          Assert that @choice is in the @choices and return it.
protected  Competence extractCompetence(List<Competence> competences, PoshElement competence)
          Assert that @competence is in the @competences and return it.
protected  DriveElement extractDrive(List<DriveElement> drives, PoshElement drive)
           
protected  Sense extractSense(Trigger<?> trigger, PoshElement sense)
          Assert that sense is a part of the trigger and return it.
 AbstractAcceptAction[] getAcceptProviders()
          Get array of accept providers of this
protected
<T extends PoshElement>
int
getPosition(List<T> list, T element)
          Get position of the element in the list.
protected abstract  String getTitleText()
          Method used by the updateWidget() to
protected  boolean isAction(PoshElement element)
           
protected  boolean isActionPattern(PoshElement element)
          Is the element ActionPattern?
protected  boolean isChoice(PoshElement element)
          Is the element CompetenceElement?
protected  boolean isCompetence(PoshElement element)
          Is the element Competence?
protected  boolean isDrive(PoshElement element)
           
protected  boolean isSense(PoshElement element)
          Is passed element a Sense?
 void nameMapChanged(String key, String oldName, String newName)
          Notify the listener that mapping for the @key has changed.
 void notifyLinkChanged()
          When some link of the @primitiveChain is changed, this method is notified and it will update the widget.
 void register()
          Register its listeners into the lap tree.
 void unregister()
          Unregister its listeners that were registered in the IPresenter.register() method.
protected  void updateWidget()
          Update widget to reflect current state of the #action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.beans.PropertyChangeListener
propertyChange
 
Methods inherited from interface cz.cuni.pogamut.shed.presenter.IPresenter
getEditAction, getMenuActions
 

Field Detail

primitive

protected final PRIMITIVE_TYPE extends PoshElement & INamedElement primitive
The primitive that is being presented by this presenter.


primitiveWidget

protected final ShedVariableWidget primitiveWidget
Widget that represents the primitive in the scene.


primitiveChain

protected final LapChain primitiveChain
Chain of variables from the root to the primitive.


scene

protected final ShedScene scene
Scene this presenter is modifying.


presenter

protected final ShedPresenter presenter
Presenter that is mainly used to modify the scene

Constructor Detail

PrimitivePresenter

protected PrimitivePresenter(ShedScene scene,
                             ShedPresenter presenter,
                             PRIMITIVE_TYPE primitive,
                             ShedVariableWidget primitiveWidget,
                             LapChain primitiveChain)
Create new presenter for @primitive, detect and project all changes on the @primitive and @primitiveChain to the @primitiveWidget.

Parameters:
scene - Scene that will be manipulated by this presenter
presenter - The basic presenter
primitive - The primitiver that is being presented.
primitiveWidget - Widget that is representing the @primitive in the
primitiveChain - Chain of variables from the root to the @primitive
Method Detail

register

public void register()
Description copied from interface: IPresenter
Register its listeners into the lap tree. Presenter must react to wide array of events in the tree. E.g. expanded action must listen not only to the name property of the action, but also to all competences and AP in the tree.

Specified by:
register in interface IPresenter

unregister

public void unregister()
Description copied from interface: IPresenter
Unregister its listeners that were registered in the IPresenter.register() method.

Specified by:
unregister in interface IPresenter

childElementAdded

public final void childElementAdded(PRIMITIVE_TYPE parent,
                                    PoshElement child)
Specified by:
childElementAdded in interface PoshElementListener<PRIMITIVE_TYPE extends PoshElement & INamedElement>

childElementMoved

public final void childElementMoved(PRIMITIVE_TYPE parent,
                                    PoshElement child,
                                    int oldIndex,
                                    int newIndex)
Specified by:
childElementMoved in interface PoshElementListener<PRIMITIVE_TYPE extends PoshElement & INamedElement>

childElementRemoved

public final void childElementRemoved(PRIMITIVE_TYPE parent,
                                      PoshElement child,
                                      int removedChildIndex)
Specified by:
childElementRemoved in interface PoshElementListener<PRIMITIVE_TYPE extends PoshElement & INamedElement>

nameMapChanged

public final void nameMapChanged(String key,
                                 String oldName,
                                 String newName)
Notify the listener that mapping for the @key has changed.

Parameters:
key - FQN of a class
oldName - What was the original human readable name for the key
newName - Waht is the new human readable name for the key.

notifyLinkChanged

public final void notifyLinkChanged()
When some link of the @primitiveChain is changed, this method is notified and it will update the widget.

Specified by:
notifyLinkChanged in interface ILapChainListener

getTitleText

protected abstract String getTitleText()
Method used by the updateWidget() to

Returns:

updateWidget

protected final void updateWidget()
Update widget to reflect current state of the #action.


isSense

protected final boolean isSense(PoshElement element)
Is passed element a Sense?

Parameters:
element - element to check.
Returns:
true if element is sense, false if not.

extractSense

protected final Sense extractSense(Trigger<?> trigger,
                                   PoshElement sense)
Assert that sense is a part of the trigger and return it.

Parameters:
trigger - Trigger against which the method is testing.
sense - tested sense
Returns:
properly typed sense

isAction

protected final boolean isAction(PoshElement element)

extractAction

protected final TriggeredAction extractAction(List<TriggeredAction> actions,
                                              PoshElement action)

isDrive

protected final boolean isDrive(PoshElement element)

extractDrive

protected final DriveElement extractDrive(List<DriveElement> drives,
                                          PoshElement drive)

isChoice

protected final boolean isChoice(PoshElement element)
Is the element CompetenceElement?

Parameters:
element - Tested element
Returns:
true if the @element is CompetenceElement or its subclass, false otherwise.

extractChoice

protected final CompetenceElement extractChoice(List<CompetenceElement> choices,
                                                PoshElement choice)
Assert that @choice is in the @choices and return it.

Parameters:
choices - List of choices that must contain the @choice.
choice - Choice must be contained in the @choices
Returns:
Properly casted @choice.

isActionPattern

protected final boolean isActionPattern(PoshElement element)
Is the element ActionPattern?

Parameters:
element - Tested element
Returns:
true if the @element is ActionPattern or its subclass, false otherwise.

extractActionPattern

protected final ActionPattern extractActionPattern(List<ActionPattern> actionPatterns,
                                                   PoshElement actionPattern)
Assert that @actionPattern is in the @actionPatterns and return it. Basically a checked type conversion from PoshElement to ActionPattern.

Parameters:
actionPatterns - List of ActionPatterns that must contain the @actionPattern.
actionPattern - The ActionPattern that must be contained in the @actionPatterns
Returns:
Properly casted @actionPattern.

isCompetence

protected final boolean isCompetence(PoshElement element)
Is the element Competence?

Parameters:
element - Tested element
Returns:
true if the @element is Competence or its subclass, false otherwise.

extractCompetence

protected final Competence extractCompetence(List<Competence> competences,
                                             PoshElement competence)
Assert that @competence is in the @competences and return it. Basically a checked type conversion from PoshElement to Competence.

Parameters:
competences - List of Competences that must contain the
competence - The Competence that must be contained in the
Returns:
Properly casted @competence.

getPosition

protected final <T extends PoshElement> int getPosition(List<T> list,
                                                        T element)
Get position of the element in the list.

Type Parameters:
T - Type of element
Parameters:
list - list in which we determine position of the elemnt.
element - The element for whic we want position in the list. Must be there, otherwise assert error.
Returns:
Found position.

getAcceptProviders

public AbstractAcceptAction[] getAcceptProviders()
Description copied from interface: IPresenter
Get array of accept providers of this

Specified by:
getAcceptProviders in interface IPresenter
Returns:
Array of accept providers. If null, no accept provider.


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.