templates.model.v3
Class TemplateDesign

java.lang.Object
  extended by templates.model.v3.TemplateDesign
All Implemented Interfaces:
ides.api.core.Annotable, ides.api.plugin.model.DESModel, ides.api.plugin.model.DESModelPublisher, ides.api.plugin.model.DESModelSubscriber, ides.api.plugin.model.ParentModel, TemplateModel, TemplateModelPublisher

public class TemplateDesign
extends java.lang.Object
implements TemplateModel, ides.api.plugin.model.DESModelSubscriber

Implementation of TemplateModel.

Author:
Lenko Grigorov

Nested Class Summary
protected static class TemplateDesign.TemplateDesignDescriptor
          Descriptor of the template design type of model.
 
Field Summary
protected  java.util.Hashtable<java.lang.String,java.lang.Object> annotations
          A map with the annotations of this element.
protected  java.util.Set<TemplateComponent> components
          The set of TemplateComponents in the model.
protected  long freeComponentId
          Next available id for TemplateComponents.
protected  long freeLinkId
          Next available id for TemplateLinks.
protected  java.util.Set<TemplateLink> links
          The set of TemplateLinks in the model.
static TemplateDesign.TemplateDesignDescriptor myDescriptor
          Maintains an instance of the descriptor of the template design type.
protected  java.lang.String name
          The name of the model.
protected  boolean needsSave
          Keeps track if the model is "dirty", i.e., needs to be saved.
protected  ides.api.plugin.model.ParentModel parent
          Maintains a pointer to the parent model of this model.
 
Fields inherited from interface templates.model.TemplateModel
FSA_NAME_PREFIX
 
Fields inherited from interface ides.api.core.Annotable
COMPOSED_OF, COMPOSED_OF_NAMES, CONTROL_MAP, FILE, LAYOUT, TEXT_ANNOTATION
 
Constructor Summary
TemplateDesign(java.lang.String name)
          Construct a new template design with the given name.
 
Method Summary
 void addComponent(TemplateComponent component)
          Add a TemplateComponent to the model.
 void addLink(TemplateLink link)
          Add a TemplateLink to the model.
 void addSubscriber(ides.api.plugin.model.DESModelSubscriber subscriber)
           
 void addSubscriber(TemplateModelSubscriber subscriber)
          Attaches the given subscriber to this publisher.
 TemplateComponent assembleComponent()
          Create a new TemplateComponent which can be then added to the model without breaking the model consistency (e.g., it has a unique id).
 TemplateLink assembleLink(long leftId, long rightId)
          Create a new TemplateLink which can be then added to the model without breaking the model consistency (e.g., it has a unique id).
 void assignFSA(long componentId, ides.api.model.fsa.FSAModel fsa)
          Assign an FSAModel to the TemplateComponent with the given id.
protected  boolean containsComponentId(long id)
          Checks if the model contains a TemplateComponent with the given id.
protected  boolean containsLinkId(long id)
          Checks if the model contains a TemplateLink with the given id.
 TemplateComponent createComponent()
          Create a new TemplateComponent and add it to the model.
 TemplateLink createLink(long leftId, long rightId)
          Create a new TemplateLink and add it to the model.
 boolean existsLink(long channelId, long moduleId)
          Check if there is a TemplateLink between the TemplateComponents with the given ids.
 void fireTemplateModelStructureChanged(TemplateModelMessage message)
          Triggers a notification to all subscribers that the structure of the TemplateModel has changed.
 java.util.Collection<TemplateLink> getAdjacentLinks(long componentId)
          Retrieve all the TemplateLinks connected to the TemplateComponent with the given id.
 java.lang.Object getAnnotation(java.lang.String key)
           
 java.util.Collection<TemplateComponent> getChannels()
          Retrieve all the TemplateComponents in the model which are channels.
 ides.api.plugin.model.DESModel getChildModel(java.lang.String arg0)
           
 java.lang.String getChildModelId(ides.api.plugin.model.DESModel arg0)
           
 TemplateComponent getComponent(long id)
          Return the TemplateComponent with the given id.
 int getComponentCount()
          Return the number of TemplateComponents in the model.
 java.util.Collection<TemplateComponent> getComponents()
          Retrieve all the TemplateComponents in the model.
protected  TemplateComponent getComponentWithFSA(ides.api.model.fsa.FSAModel fsa)
          Retrieve the TemplateComponent containing the given FSAModel.
 java.util.Collection<TemplateComponent> getCover(long channelId)
          Retrieve all the modules linked to the channel with the given id.
 ides.api.plugin.model.DESModelSubscriber[] getDESModelSubscribers()
           
 ides.api.plugin.model.DESEventSet getEventSet()
           
 TemplateLink getLink(long id)
          Return the TemplateLink with the given id.
 java.util.Collection<TemplateLink> getLinks()
          Retrieve all the TemplateLinks in the model.
 java.util.Collection<TemplateLink> getLinks(long leftId, long rightId)
          Retrieve the TemplateLinks between the TemplateComponents with the given ids.
 ides.api.plugin.model.DESModelType getModelType()
           
 java.util.Collection<TemplateComponent> getModules()
          Retrieve all the TemplateComponents in the model which are modules.
 java.lang.String getName()
           
 ides.api.plugin.model.ParentModel getParentModel()
           
 TemplateModelSubscriber[] getTemplateModelSubscribers()
          Returns all current subscribers to this publisher.
 boolean hasAnnotation(java.lang.String key)
           
 void metadataChanged()
           
 void modelNameChanged(ides.api.plugin.model.DESModelMessage arg0)
           
 void modelSaved()
           
 boolean needsSave()
           
 void removeAnnotation(java.lang.String key)
           
 void removeComponent(long id)
          Remove the TemplateComponent with the given id.
 void removeFSA(long componentId)
          Remove the FSAModel assigned to the TemplateComponent with the given id.
 void removeLink(long id)
          Remove the TemplateLink with the given id.
 void removeSubscriber(ides.api.plugin.model.DESModelSubscriber subscriber)
           
 void removeSubscriber(TemplateModelSubscriber subscriber)
          Removes the given subscriber from this publisher.
 void saveStatusChanged(ides.api.plugin.model.DESModelMessage arg0)
           
 void setAnnotation(java.lang.String key, java.lang.Object annotation)
           
 void setComponentType(long componentId, int type)
          Set the type (module or channel) of the TemplateComponent with the given id.
 void setName(java.lang.String name)
           
protected  void setNeedsSave(boolean b)
          Set the "dirty" state of the model and announce to listeners if the state changed.
 void setParentModel(ides.api.plugin.model.ParentModel arg0)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

annotations

protected java.util.Hashtable<java.lang.String,java.lang.Object> annotations
A map with the annotations of this element.


needsSave

protected boolean needsSave
Keeps track if the model is "dirty", i.e., needs to be saved.


myDescriptor

public static TemplateDesign.TemplateDesignDescriptor myDescriptor
Maintains an instance of the descriptor of the template design type.


name

protected java.lang.String name
The name of the model.


components

protected java.util.Set<TemplateComponent> components
The set of TemplateComponents in the model.


links

protected java.util.Set<TemplateLink> links
The set of TemplateLinks in the model.


freeComponentId

protected long freeComponentId
Next available id for TemplateComponents.


freeLinkId

protected long freeLinkId
Next available id for TemplateLinks.


parent

protected ides.api.plugin.model.ParentModel parent
Maintains a pointer to the parent model of this model. Under normal circumstances should be null.

Constructor Detail

TemplateDesign

public TemplateDesign(java.lang.String name)
Construct a new template design with the given name.

Parameters:
name - the name for the new template design
Method Detail

getAnnotation

public java.lang.Object getAnnotation(java.lang.String key)
Specified by:
getAnnotation in interface ides.api.core.Annotable

hasAnnotation

public boolean hasAnnotation(java.lang.String key)
Specified by:
hasAnnotation in interface ides.api.core.Annotable

removeAnnotation

public void removeAnnotation(java.lang.String key)
Specified by:
removeAnnotation in interface ides.api.core.Annotable

setAnnotation

public void setAnnotation(java.lang.String key,
                          java.lang.Object annotation)
Specified by:
setAnnotation in interface ides.api.core.Annotable

addSubscriber

public void addSubscriber(ides.api.plugin.model.DESModelSubscriber subscriber)
Specified by:
addSubscriber in interface ides.api.plugin.model.DESModelPublisher

removeSubscriber

public void removeSubscriber(ides.api.plugin.model.DESModelSubscriber subscriber)
Specified by:
removeSubscriber in interface ides.api.plugin.model.DESModelPublisher

getDESModelSubscribers

public ides.api.plugin.model.DESModelSubscriber[] getDESModelSubscribers()
Specified by:
getDESModelSubscribers in interface ides.api.plugin.model.DESModelPublisher

addSubscriber

public void addSubscriber(TemplateModelSubscriber subscriber)
Description copied from interface: TemplateModelPublisher
Attaches the given subscriber to this publisher. The given subscriber will receive notifications of changes from this publisher.

Specified by:
addSubscriber in interface TemplateModelPublisher
Parameters:
subscriber - the subscriber to be added

removeSubscriber

public void removeSubscriber(TemplateModelSubscriber subscriber)
Description copied from interface: TemplateModelPublisher
Removes the given subscriber from this publisher. The given subscriber will no longer receive notifications of changes from this publisher.

Specified by:
removeSubscriber in interface TemplateModelPublisher
Parameters:
subscriber - the subscriber to be removed

getTemplateModelSubscribers

public TemplateModelSubscriber[] getTemplateModelSubscribers()
Description copied from interface: TemplateModelPublisher
Returns all current subscribers to this publisher.

Specified by:
getTemplateModelSubscribers in interface TemplateModelPublisher
Returns:
all current subscribers to this publisher

fireTemplateModelStructureChanged

public void fireTemplateModelStructureChanged(TemplateModelMessage message)
Description copied from interface: TemplateModelPublisher
Triggers a notification to all subscribers that the structure of the TemplateModel has changed.

Specified by:
fireTemplateModelStructureChanged in interface TemplateModelPublisher
Parameters:
message - message with additional info about the change

needsSave

public boolean needsSave()
Specified by:
needsSave in interface ides.api.plugin.model.DESModel

setNeedsSave

protected void setNeedsSave(boolean b)
Set the "dirty" state of the model and announce to listeners if the state changed.

Parameters:
b - the new "dirty" state of the model

getModelType

public ides.api.plugin.model.DESModelType getModelType()
Specified by:
getModelType in interface ides.api.plugin.model.DESModel

containsComponentId

protected boolean containsComponentId(long id)
Checks if the model contains a TemplateComponent with the given id.

Parameters:
id - the id of the component
Returns:
true if the model contains a TemplateComponent with the given id; false otherwise

containsLinkId

protected boolean containsLinkId(long id)
Checks if the model contains a TemplateLink with the given id.

Parameters:
id - the id of the link
Returns:
true if the model contains a TemplateLink with the given id; false otherwise

addComponent

public void addComponent(TemplateComponent component)
Description copied from interface: TemplateModel
Add a TemplateComponent to the model.

Specified by:
addComponent in interface TemplateModel
Parameters:
component - the TemplateComponent to be added

addLink

public void addLink(TemplateLink link)
Description copied from interface: TemplateModel
Add a TemplateLink to the model.

Specified by:
addLink in interface TemplateModel
Parameters:
link - the TemplateLink to be added

createLink

public TemplateLink createLink(long leftId,
                               long rightId)
Description copied from interface: TemplateModel
Create a new TemplateLink and add it to the model.

Specified by:
createLink in interface TemplateModel
Parameters:
leftId - the id of the first TemplateComponent to be linked
rightId - the id of the second TemplateComponent to be linked
Returns:
the new TemplateLink which was added to the model

createComponent

public TemplateComponent createComponent()
Description copied from interface: TemplateModel
Create a new TemplateComponent and add it to the model.

Specified by:
createComponent in interface TemplateModel
Returns:
the new TemplateComponent which was added to the model

getComponents

public java.util.Collection<TemplateComponent> getComponents()
Description copied from interface: TemplateModel
Retrieve all the TemplateComponents in the model.

Specified by:
getComponents in interface TemplateModel
Returns:
a collection of all the TemplateComponents in the model

getLinks

public java.util.Collection<TemplateLink> getLinks()
Description copied from interface: TemplateModel
Retrieve all the TemplateLinks in the model.

Specified by:
getLinks in interface TemplateModel
Returns:
a collection of all the TemplateLinks in the model

getComponent

public TemplateComponent getComponent(long id)
Description copied from interface: TemplateModel
Return the TemplateComponent with the given id.

Specified by:
getComponent in interface TemplateModel
Parameters:
id - the id of the TemplateComponent
Returns:
the TemplateComponent with the given id; null if there is no TemplateComponent with such an id

getModules

public java.util.Collection<TemplateComponent> getModules()
Description copied from interface: TemplateModel
Retrieve all the TemplateComponents in the model which are modules.

Specified by:
getModules in interface TemplateModel
Returns:
a collection of all the TemplateComponents in the model which are modules

getChannels

public java.util.Collection<TemplateComponent> getChannels()
Description copied from interface: TemplateModel
Retrieve all the TemplateComponents in the model which are channels.

Specified by:
getChannels in interface TemplateModel
Returns:
a collection of all the TemplateComponents in the model which are channels

getLink

public TemplateLink getLink(long id)
Description copied from interface: TemplateModel
Return the TemplateLink with the given id.

Specified by:
getLink in interface TemplateModel
Parameters:
id - the id of the TemplateLink
Returns:
the TemplateLink with the given id; null if there is no TemplateLink with such an id

getComponentCount

public int getComponentCount()
Description copied from interface: TemplateModel
Return the number of TemplateComponents in the model.

Specified by:
getComponentCount in interface TemplateModel
Returns:
the number of TemplateComponents in the model

removeComponent

public void removeComponent(long id)
Description copied from interface: TemplateModel
Remove the TemplateComponent with the given id.

Specified by:
removeComponent in interface TemplateModel
Parameters:
id - the id of the TemplateComponent to be removed

removeLink

public void removeLink(long id)
Description copied from interface: TemplateModel
Remove the TemplateLink with the given id.

Specified by:
removeLink in interface TemplateModel
Parameters:
id - the id of the TemplateLink to be removed

getName

public java.lang.String getName()
Specified by:
getName in interface ides.api.plugin.model.DESModel

metadataChanged

public void metadataChanged()
Specified by:
metadataChanged in interface ides.api.plugin.model.DESModel

modelSaved

public void modelSaved()
Specified by:
modelSaved in interface ides.api.plugin.model.DESModel

setName

public void setName(java.lang.String name)
Specified by:
setName in interface ides.api.plugin.model.DESModel

existsLink

public boolean existsLink(long channelId,
                          long moduleId)
Description copied from interface: TemplateModel
Check if there is a TemplateLink between the TemplateComponents with the given ids.

Specified by:
existsLink in interface TemplateModel
Parameters:
channelId - the id of the first TemplateComponent
moduleId - the id of the second TemplateComponent
Returns:
true if there is a TemplateLink between the TemplateComponents with the given ids; false otherwise

getAdjacentLinks

public java.util.Collection<TemplateLink> getAdjacentLinks(long componentId)
Description copied from interface: TemplateModel
Retrieve all the TemplateLinks connected to the TemplateComponent with the given id.

Specified by:
getAdjacentLinks in interface TemplateModel
Parameters:
componentId - the id of the TemplateComponent
Returns:
all the TemplateLinks connected to the TemplateComponent with the given id

getCover

public java.util.Collection<TemplateComponent> getCover(long channelId)
Description copied from interface: TemplateModel
Retrieve all the modules linked to the channel with the given id.

Specified by:
getCover in interface TemplateModel
Parameters:
channelId - the id of the channel TemplateComponent
Returns:
all the modules linked to the channel with the given id; an empty collection if the TemplateComponent with the given id is not a channel

getLinks

public java.util.Collection<TemplateLink> getLinks(long leftId,
                                                   long rightId)
Description copied from interface: TemplateModel
Retrieve the TemplateLinks between the TemplateComponents with the given ids.

Specified by:
getLinks in interface TemplateModel
Parameters:
leftId - the id of the first TemplateComponent
rightId - the id of the second TemplateComponent
Returns:
all the TemplateLinks between the TemplateComponents with the given ids

getComponentWithFSA

protected TemplateComponent getComponentWithFSA(ides.api.model.fsa.FSAModel fsa)
Retrieve the TemplateComponent containing the given FSAModel.

Parameters:
fsa - the FSAModel to be used in the search
Returns:
the TemplateComponent containing the given FSAModel (if more than one TemplateComponents contains the FSAModel, returns one of them arbitrarily); null if not TemplateComponent contains the given FSAModel

assignFSA

public void assignFSA(long componentId,
                      ides.api.model.fsa.FSAModel fsa)
Description copied from interface: TemplateModel
Assign an FSAModel to the TemplateComponent with the given id.

Specified by:
assignFSA in interface TemplateModel
Parameters:
componentId - the id of the TemplateComponent
fsa - the FSAModel to be assigned

removeFSA

public void removeFSA(long componentId)
Description copied from interface: TemplateModel
Remove the FSAModel assigned to the TemplateComponent with the given id.

Specified by:
removeFSA in interface TemplateModel
Parameters:
componentId - the id of the TemplateComponent whose FSAModel is to be removed

assembleComponent

public TemplateComponent assembleComponent()
Description copied from interface: TemplateModel
Create a new TemplateComponent which can be then added to the model without breaking the model consistency (e.g., it has a unique id).

Specified by:
assembleComponent in interface TemplateModel
Returns:
a new TemplateComponent which can be then added to the model without breaking the model consistency

assembleLink

public TemplateLink assembleLink(long leftId,
                                 long rightId)
Description copied from interface: TemplateModel
Create a new TemplateLink which can be then added to the model without breaking the model consistency (e.g., it has a unique id).

Specified by:
assembleLink in interface TemplateModel
Parameters:
leftId - the id of the first TemplateComponent to be linked
rightId - the id of the second TemplateComponent to be linked
Returns:
a new TemplateLink which can be then added to the model without breaking the model consistency

getChildModel

public ides.api.plugin.model.DESModel getChildModel(java.lang.String arg0)
Specified by:
getChildModel in interface ides.api.plugin.model.ParentModel

getChildModelId

public java.lang.String getChildModelId(ides.api.plugin.model.DESModel arg0)
                                 throws java.lang.IllegalArgumentException
Specified by:
getChildModelId in interface ides.api.plugin.model.ParentModel
Throws:
java.lang.IllegalArgumentException

getParentModel

public ides.api.plugin.model.ParentModel getParentModel()
Specified by:
getParentModel in interface ides.api.plugin.model.DESModel

setParentModel

public void setParentModel(ides.api.plugin.model.ParentModel arg0)
Specified by:
setParentModel in interface ides.api.plugin.model.DESModel

modelNameChanged

public void modelNameChanged(ides.api.plugin.model.DESModelMessage arg0)
Specified by:
modelNameChanged in interface ides.api.plugin.model.DESModelSubscriber

saveStatusChanged

public void saveStatusChanged(ides.api.plugin.model.DESModelMessage arg0)
Specified by:
saveStatusChanged in interface ides.api.plugin.model.DESModelSubscriber

setComponentType

public void setComponentType(long componentId,
                             int type)
Description copied from interface: TemplateModel
Set the type (module or channel) of the TemplateComponent with the given id.

Specified by:
setComponentType in interface TemplateModel
Parameters:
componentId - the id of the TemplateComponent whose type is to be changed
type - the type to be set (TemplateComponent.TYPE_MODULE or TemplateComponent.TYPE_CHANNEL)

getEventSet

public ides.api.plugin.model.DESEventSet getEventSet()
Specified by:
getEventSet in interface ides.api.plugin.model.DESModel