com.pnp.xfeature.models
Class FeatureDiagramModel

java.lang.Object
  extended by com.pnp.xfeature.models.AbstractComponentModel
      extended by com.pnp.xfeature.models.FeatureDiagramModel

public class FeatureDiagramModel
extends AbstractComponentModel

Class representing a feature model. It contains method that manipulates the feature model and provides information about the model

Author:
Kamil Ekstein, created on 21.9.2004, totally redesigned in 2005 by Ondrej Rohlik

Field Summary
static int HORIZONTAL_GAP_BETWEEN_SIBLINGS
          horizontal space bewtween two nodes
static int HORIZONTAL_TEXT_EXTENT_MARGIN
          space around the text inside the node
static java.lang.String PROPERTY_CONNECTION
          event identifier
static java.lang.String PROPERTY_FILE_LOADED
          event identifier
static java.lang.String PROPERTY_NODE_ADDED
          event identifier
static java.lang.String PROPERTY_NODE_AND_CONNECTION_ADDED
          event identifier
static java.lang.String PROPERTY_NODE_REMOVED
          event identifier
 SchemaParser schemaParser
          parser of the meta-model
static int TV_LEFTMARGIN
          Left margin to shift the tree to right
static int TV_NODEHEIGHT
          default node height
static int TV_NODEWIDTH
          default node width
static int VERTICAL_GAP
          vertical space bewtween parent and child
static int VERTICAL_TEXT_EXTENT_MARGIN
          space around the text inside the node
 
Constructor Summary
FeatureDiagramModel()
          creates feature model and instantiates XML parser
 
Method Summary
 org.w3c.dom.Element addCardinality(FeatureNodeModel parent, java.lang.String newNodeType, int nodePosition)
          Adds a cardinality to the parent node.
 void addComponent(java.lang.Object component)
          adds node to list of all nodes
 org.w3c.dom.Element addConstraint(org.w3c.dom.Node parent, java.lang.String newNodeType, int nodePosition)
          Adds a new ExcludesConstraint.
 org.w3c.dom.Element addConstraintElement(org.w3c.dom.Node parentNode, org.w3c.dom.Element addedFeatureNodeModelElement, int constraintPathType)
           
 FeatureNodeModel addNode(FeatureNodeModel parent, java.lang.String newNodeType, int nodePosition, java.lang.String propertySet)
          Adds a new node.
 org.w3c.dom.Element addProperty(org.w3c.dom.Node parent, java.lang.String newNodeType, int nodePosition, java.lang.String propertySet, org.w3c.dom.Node propertySetNode)
          Adds a new property.
 org.w3c.dom.Element addPropertySet(org.w3c.dom.Node parent, java.lang.String newNodeType, int nodePosition)
          Adds a new property set.
 void addUniqueId(org.w3c.dom.Document doc)
          adds temporal attribute to every element in the DOM model, this attribute is not saved to the XML file when performing doSave() or doSaveAs() operations
 boolean cutSubtree(FeatureNodeModel root)
          removes node from the feature model and calls removeSubtree() to remove all its children too
 boolean displayNode(java.lang.String nodeName)
          states whether the passed node name specifies a displayable node
 void domTreeToList(org.w3c.dom.Node node, java.util.List list, FeatureNodeModel parent, boolean recursiveCall)
          Linearizes the DOM tree whose root is the passed node.
 java.lang.String elementToXPath(org.w3c.dom.Element current)
           
 boolean expandCollapseNode(FeatureNodeModel node)
          repaints the node with transparet-like color and hides the subtree of the node
 java.util.List getComponents()
          getter method
 org.w3c.dom.Document getDiagramModel()
          getter method
 org.w3c.dom.Document getDisplayModel()
          getter method
 int getDOMTreeWidth(org.w3c.dom.Node node, boolean recursiveCall)
          returns the width of the DOM tree whose root is the passed node, calls recursively itself
 FeatureNodeModel getFeatureNodeModel(long id)
          searches for and returns a node specified by its unique ID
 java.lang.String getFileName()
          getter method
 org.w3c.dom.Document getGlobalConstraintsDocument()
          getter method
 org.w3c.dom.Element getGlobalConstraintsElement()
          getter method; if the globalConstraints Document doesnt exist, it creates one
 java.util.List getChildren()
          returns the root element of the feature model
 org.w3c.dom.Document getMetaModel()
          getter method
 java.lang.String getName()
          getter method
 org.w3c.dom.Element idToElement(long id)
          return DOM Element of the node that has xfeatureUniqueId attribute value equal to the parameter
 org.w3c.dom.Element idToElement(java.lang.String id)
          return DOM Element of the node that has xfeatureUniqueId attribute value equal to the parameter
 boolean insertNodeToDomAt(org.w3c.dom.Element child, org.w3c.dom.Node parent, int nodePosition)
          inserts W3C DOM Element object to specifed index int the list of child elements of the parent node
 boolean insertNodeToDomAt(FeatureNodeModel child, FeatureNodeModel parent, int nodePosition)
          inserts XML representation of the node to specifed index int the list of child elements of the parent node
 boolean isDirty()
           
 void linearize(org.w3c.dom.Document diagram, java.util.List list)
          takes a DOM tree produced by a XML parser and transforms it into a list of FeatureNodeModel objects - each holding a reference to its corresponding DOM tree node
 boolean load(IPath location)
          loads the whole feature model, i.e. the model file itself, the metamodel, the display model, and possible layout file (.pos)
 void loadConstraints(IPath location)
          loads the layout of the feature model diagram from the *.pos file
 boolean loadDisplayModel(java.lang.String filename)
          loads the display model specified by the filename
 boolean loadGlobalConstraintsModel(java.lang.String filename)
          loads the display model specified by the filename
 boolean loadMetaModel(java.lang.String filename)
          loads the meta-model specified by the filename
 boolean loadSubtreeConstraints(java.io.DataInputStream sin, org.w3c.dom.Node node)
          reads the position and size of nodes from *.pos file
 org.w3c.dom.Document loadXMLDocument(java.lang.String uri)
          reads the XML document specified by its name and parses it and saves it to an internal structure W3C DOM Document object
 boolean pasteSubtree(FeatureNodeModel node, FeatureNodeModel parent, int nodePosition)
          inserts the node to the feature model as a child node of the selcted parent node and fires an event to update the graphical and outline views
 int removeCardinality(org.w3c.dom.Node node, FeatureNodeModel parent)
          Removes a cardinality from the node.
 boolean removeConnection(FeatureNodeModel node, FeatureNodeModel parent)
          removes connection between two nodes of the feature model
 org.w3c.dom.Element removeConstraint(org.w3c.dom.Element constraint)
          removes constraint Element from the root element of the globalConstrant Document
 boolean removeNode(FeatureNodeModel node)
          Removes an existing node from the model.
 int removeProperty(org.w3c.dom.Node node, FeatureNodeModel parent, java.lang.String propertySet)
          Removes a property from the node.
 int removePropertySet(org.w3c.dom.Node node, FeatureNodeModel parent)
          Removes a property set from the node.
 void removeSubtree(FeatureNodeModel root, int level)
          removes the children and itself from the feature model
 void returnCardinality(org.w3c.dom.Element returnedNode, FeatureNodeModel parentNode, int elementLastPosition)
          Returns the cardinality to its original position in the DOM model, updates the feature model and fires an event to inform Eclipse that graphical, outline and property views must be updated
 void returnConstraint(org.w3c.dom.Element constraint, org.w3c.dom.Element parent, org.w3c.dom.Element next)
           
 void returnNode(FeatureNodeModel returnedNode, FeatureNodeModel parentNode)
          returns previously deletd constraint Element back to the root element of the globalConstrant Document
 void returnProperty(org.w3c.dom.Element returnedNode, FeatureNodeModel parentNode, int elementLastPosition, java.lang.String propertySet)
          Returns the property to its original position in the DOM model and updates the feature model
 void returnPropertySet(org.w3c.dom.Element returnedNode, FeatureNodeModel parentNode, int elementLastPosition)
          Returns the cardinality to its original position in the DOM model and updates the feature model.
 void saveConstraints(IPath location)
          saves the feature model diagram layout to a *.pos file
 void saveModel(IPath location)
          Saves the model, i.e. serializes the diagramModel XML document.
 boolean saveSubtreeConstraints(java.io.DataOutputStream sout, org.w3c.dom.Node node)
          saves position and size of nodes to *.pos file
 void setDirty(boolean dirty)
           
 void setFileName(java.lang.String fileName)
          setter method
 void setName(java.lang.String name)
          setter method
 java.lang.String toString()
          returns name of the feature model
 int unAddCardinality(org.w3c.dom.Element removedNode, FeatureNodeModel parentNode)
          calls removeCardinality() method
 void unAddNode(FeatureNodeModel removedNode, FeatureNodeModel parentNode)
          Removes the newly added node.
 int unAddProperty(org.w3c.dom.Element removedNode, FeatureNodeModel parentNode, java.lang.String propertySet)
          calls removeProperty() method
 int unAddPropertySet(org.w3c.dom.Element removedNode, FeatureNodeModel parentNode)
           
 boolean uncutSubtree(FeatureNodeModel node, FeatureNodeModel parent)
          returns the node to the DOM model and feature model, then calls recusive method unremoveSubtree() to return all its children too
 boolean unpasteSubtree(FeatureNodeModel root)
          removes the node from it parent, calls recursive method removeSubtree(), and fires an event to update the graphical and outline views
 void unremoveSubtree(FeatureNodeModel node, FeatureNodeModel parent, int level)
          returns previously removed nodes to the feature model and calls itself recursively to return children too
 void updateModel(org.w3c.dom.Document diagram, java.util.List list)
          Deprecated.  
 
Methods inherited from class com.pnp.xfeature.models.AbstractComponentModel
addPropertyChangeListener, firePropertyChange, getEditableValue, getPropertyDescriptors, getPropertyValue, isPropertySet, removePropertyChangeListener, resetPropertyValue, setPropertyValue
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TV_LEFTMARGIN

public static final int TV_LEFTMARGIN
Left margin to shift the tree to right

See Also:
Constant Field Values

TV_NODEWIDTH

public static final int TV_NODEWIDTH
default node width

See Also:
Constant Field Values

TV_NODEHEIGHT

public static final int TV_NODEHEIGHT
default node height

See Also:
Constant Field Values

HORIZONTAL_TEXT_EXTENT_MARGIN

public static final int HORIZONTAL_TEXT_EXTENT_MARGIN
space around the text inside the node

See Also:
Constant Field Values

VERTICAL_TEXT_EXTENT_MARGIN

public static final int VERTICAL_TEXT_EXTENT_MARGIN
space around the text inside the node

See Also:
Constant Field Values

HORIZONTAL_GAP_BETWEEN_SIBLINGS

public static final int HORIZONTAL_GAP_BETWEEN_SIBLINGS
horizontal space bewtween two nodes

See Also:
Constant Field Values

VERTICAL_GAP

public static final int VERTICAL_GAP
vertical space bewtween parent and child

See Also:
Constant Field Values

PROPERTY_NODE_ADDED

public static final java.lang.String PROPERTY_NODE_ADDED
event identifier

See Also:
Constant Field Values

PROPERTY_NODE_REMOVED

public static final java.lang.String PROPERTY_NODE_REMOVED
event identifier

See Also:
Constant Field Values

PROPERTY_FILE_LOADED

public static final java.lang.String PROPERTY_FILE_LOADED
event identifier

See Also:
Constant Field Values

PROPERTY_CONNECTION

public static final java.lang.String PROPERTY_CONNECTION
event identifier

See Also:
Constant Field Values

PROPERTY_NODE_AND_CONNECTION_ADDED

public static final java.lang.String PROPERTY_NODE_AND_CONNECTION_ADDED
event identifier

See Also:
Constant Field Values

schemaParser

public SchemaParser schemaParser
parser of the meta-model

Constructor Detail

FeatureDiagramModel

public FeatureDiagramModel()
creates feature model and instantiates XML parser

Method Detail

getName

public java.lang.String getName()
getter method


setName

public void setName(java.lang.String name)
setter method


addComponent

public void addComponent(java.lang.Object component)
adds node to list of all nodes


getComponents

public java.util.List getComponents()
getter method


getDisplayModel

public org.w3c.dom.Document getDisplayModel()
getter method


getMetaModel

public org.w3c.dom.Document getMetaModel()
getter method


getDiagramModel

public org.w3c.dom.Document getDiagramModel()
getter method


loadXMLDocument

public org.w3c.dom.Document loadXMLDocument(java.lang.String uri)
reads the XML document specified by its name and parses it and saves it to an internal structure W3C DOM Document object


load

public boolean load(IPath location)
loads the whole feature model, i.e. the model file itself, the metamodel, the display model, and possible layout file (.pos)


addUniqueId

public void addUniqueId(org.w3c.dom.Document doc)
adds temporal attribute to every element in the DOM model, this attribute is not saved to the XML file when performing doSave() or doSaveAs() operations


loadDisplayModel

public boolean loadDisplayModel(java.lang.String filename)
loads the display model specified by the filename


loadGlobalConstraintsModel

public boolean loadGlobalConstraintsModel(java.lang.String filename)
loads the display model specified by the filename


idToElement

public org.w3c.dom.Element idToElement(java.lang.String id)
return DOM Element of the node that has xfeatureUniqueId attribute value equal to the parameter

Parameters:
id -
Returns:

idToElement

public org.w3c.dom.Element idToElement(long id)
return DOM Element of the node that has xfeatureUniqueId attribute value equal to the parameter

Parameters:
id -
Returns:

elementToXPath

public java.lang.String elementToXPath(org.w3c.dom.Element current)

loadMetaModel

public boolean loadMetaModel(java.lang.String filename)
loads the meta-model specified by the filename


linearize

public void linearize(org.w3c.dom.Document diagram,
                      java.util.List list)
takes a DOM tree produced by a XML parser and transforms it into a list of FeatureNodeModel objects - each holding a reference to its corresponding DOM tree node


getDOMTreeWidth

public int getDOMTreeWidth(org.w3c.dom.Node node,
                           boolean recursiveCall)
returns the width of the DOM tree whose root is the passed node, calls recursively itself


domTreeToList

public void domTreeToList(org.w3c.dom.Node node,
                          java.util.List list,
                          FeatureNodeModel parent,
                          boolean recursiveCall)
Linearizes the DOM tree whose root is the passed node. The recursiveCall parameter can only be "true" if the method is called from within itself i.e. recursively. If called from other parts of code the recursiveCall param must be "false".

Parameters:
node - current DOM node; root at the first call; inner node later
list - resulting list (which is most likely the components variable passed of the class itself (FeatureDiagramModel)
parent - parent node of the first parameter node
recursiveCall - parameter that control the initialization

displayNode

public boolean displayNode(java.lang.String nodeName)
states whether the passed node name specifies a displayable node


addNode

public FeatureNodeModel addNode(FeatureNodeModel parent,
                                java.lang.String newNodeType,
                                int nodePosition,
                                java.lang.String propertySet)
Adds a new node. It creates new FeatureNodeModel object and W3C DOM Element object representing the node. Then the node is inserted to the list of children of its parent. finally the event is fire to inform the feature model editpart that graphical view and outline view has to be updated.


unAddNode

public void unAddNode(FeatureNodeModel removedNode,
                      FeatureNodeModel parentNode)
Removes the newly added node. A reverse operation to addNode(). DO NOT MISMATCH WITH removeNode().


removeNode

public boolean removeNode(FeatureNodeModel node)
Removes an existing node from the model. Saves the position and size of the node. Position and size is saved within the node instance as its constraint property.


removeConstraint

public org.w3c.dom.Element removeConstraint(org.w3c.dom.Element constraint)
removes constraint Element from the root element of the globalConstrant Document

Parameters:
constraint -
Returns:
the element the nextSibling of the removed element or null

returnConstraint

public void returnConstraint(org.w3c.dom.Element constraint,
                             org.w3c.dom.Element parent,
                             org.w3c.dom.Element next)

returnNode

public void returnNode(FeatureNodeModel returnedNode,
                       FeatureNodeModel parentNode)
returns previously deletd constraint Element back to the root element of the globalConstrant Document


saveModel

public void saveModel(IPath location)
Saves the model, i.e. serializes the diagramModel XML document. First saves the document with the xfeatureUniqueId attributes with extension 'tmp'. Then saves a copy of the document without the attribute xfeatureUniqueId with extension 'xfm'. Finaly the temporary file is deleted.


getFeatureNodeModel

public FeatureNodeModel getFeatureNodeModel(long id)
searches for and returns a node specified by its unique ID


loadSubtreeConstraints

public boolean loadSubtreeConstraints(java.io.DataInputStream sin,
                                      org.w3c.dom.Node node)
reads the position and size of nodes from *.pos file


saveSubtreeConstraints

public boolean saveSubtreeConstraints(java.io.DataOutputStream sout,
                                      org.w3c.dom.Node node)
saves position and size of nodes to *.pos file


saveConstraints

public void saveConstraints(IPath location)
saves the feature model diagram layout to a *.pos file


loadConstraints

public void loadConstraints(IPath location)
loads the layout of the feature model diagram from the *.pos file


updateModel

public void updateModel(org.w3c.dom.Document diagram,
                        java.util.List list)
Deprecated. 

deprecated method


toString

public java.lang.String toString()
returns name of the feature model

Overrides:
toString in class java.lang.Object

getChildren

public java.util.List getChildren()
returns the root element of the feature model


getFileName

public java.lang.String getFileName()
getter method


setFileName

public void setFileName(java.lang.String fileName)
setter method


removeConnection

public boolean removeConnection(FeatureNodeModel node,
                                FeatureNodeModel parent)
removes connection between two nodes of the feature model


insertNodeToDomAt

public boolean insertNodeToDomAt(FeatureNodeModel child,
                                 FeatureNodeModel parent,
                                 int nodePosition)
inserts XML representation of the node to specifed index int the list of child elements of the parent node


insertNodeToDomAt

public boolean insertNodeToDomAt(org.w3c.dom.Element child,
                                 org.w3c.dom.Node parent,
                                 int nodePosition)
inserts W3C DOM Element object to specifed index int the list of child elements of the parent node


addCardinality

public org.w3c.dom.Element addCardinality(FeatureNodeModel parent,
                                          java.lang.String newNodeType,
                                          int nodePosition)
Adds a cardinality to the parent node. It creates new W3C DOM Element object representing the cardinality. Then the node is inserted to the list of children of its parent at the position spocified by parameter nodePosition. Finally the event is fire to inform the feature model editpart that graphical view has to be updated.


unAddCardinality

public int unAddCardinality(org.w3c.dom.Element removedNode,
                            FeatureNodeModel parentNode)
calls removeCardinality() method


removeCardinality

public int removeCardinality(org.w3c.dom.Node node,
                             FeatureNodeModel parent)
Removes a cardinality from the node. Saves the position of the cardinality in the parent node of "undo" operation.


returnCardinality

public void returnCardinality(org.w3c.dom.Element returnedNode,
                              FeatureNodeModel parentNode,
                              int elementLastPosition)
Returns the cardinality to its original position in the DOM model, updates the feature model and fires an event to inform Eclipse that graphical, outline and property views must be updated


addPropertySet

public org.w3c.dom.Element addPropertySet(org.w3c.dom.Node parent,
                                          java.lang.String newNodeType,
                                          int nodePosition)
Adds a new property set. It creates new W3C DOM Element object representing the property set. Then the element is inserted to the list of children of its parent. Finally, the event is fired to inform the Eclpse that properties view has to be updated.


unAddPropertySet

public int unAddPropertySet(org.w3c.dom.Element removedNode,
                            FeatureNodeModel parentNode)

removePropertySet

public int removePropertySet(org.w3c.dom.Node node,
                             FeatureNodeModel parent)
Removes a property set from the node. Saves the position of the property set in the parent node of "undo" operation.


returnPropertySet

public void returnPropertySet(org.w3c.dom.Element returnedNode,
                              FeatureNodeModel parentNode,
                              int elementLastPosition)
Returns the cardinality to its original position in the DOM model and updates the feature model.


addProperty

public org.w3c.dom.Element addProperty(org.w3c.dom.Node parent,
                                       java.lang.String newNodeType,
                                       int nodePosition,
                                       java.lang.String propertySet,
                                       org.w3c.dom.Node propertySetNode)
Adds a new property. It creates new W3C DOM Element object representing the property. Then the element is inserted to the list of children of its parent. Finally the event is fire to inform the the Eclipse that properties view has to be updated.


unAddProperty

public int unAddProperty(org.w3c.dom.Element removedNode,
                         FeatureNodeModel parentNode,
                         java.lang.String propertySet)
calls removeProperty() method


removeProperty

public int removeProperty(org.w3c.dom.Node node,
                          FeatureNodeModel parent,
                          java.lang.String propertySet)
Removes a property from the node. Saves the position of the property in the parent node of "undo" operation.


returnProperty

public void returnProperty(org.w3c.dom.Element returnedNode,
                           FeatureNodeModel parentNode,
                           int elementLastPosition,
                           java.lang.String propertySet)
Returns the property to its original position in the DOM model and updates the feature model


expandCollapseNode

public boolean expandCollapseNode(FeatureNodeModel node)
repaints the node with transparet-like color and hides the subtree of the node


cutSubtree

public boolean cutSubtree(FeatureNodeModel root)
removes node from the feature model and calls removeSubtree() to remove all its children too


removeSubtree

public void removeSubtree(FeatureNodeModel root,
                          int level)
removes the children and itself from the feature model


uncutSubtree

public boolean uncutSubtree(FeatureNodeModel node,
                            FeatureNodeModel parent)
returns the node to the DOM model and feature model, then calls recusive method unremoveSubtree() to return all its children too


unremoveSubtree

public void unremoveSubtree(FeatureNodeModel node,
                            FeatureNodeModel parent,
                            int level)
returns previously removed nodes to the feature model and calls itself recursively to return children too


pasteSubtree

public boolean pasteSubtree(FeatureNodeModel node,
                            FeatureNodeModel parent,
                            int nodePosition)
inserts the node to the feature model as a child node of the selcted parent node and fires an event to update the graphical and outline views


unpasteSubtree

public boolean unpasteSubtree(FeatureNodeModel root)
removes the node from it parent, calls recursive method removeSubtree(), and fires an event to update the graphical and outline views


addConstraintElement

public org.w3c.dom.Element addConstraintElement(org.w3c.dom.Node parentNode,
                                                org.w3c.dom.Element addedFeatureNodeModelElement,
                                                int constraintPathType)

addConstraint

public org.w3c.dom.Element addConstraint(org.w3c.dom.Node parent,
                                         java.lang.String newNodeType,
                                         int nodePosition)
Adds a new ExcludesConstraint. It creates new W3C DOM Element object representing the ExcludesConstraint. Then the element is inserted to the list constraints. Then name subelelement fo the constraint is inserted. Finally, the event is fired to inform the Eclipse that properties view has to be updated.


getGlobalConstraintsElement

public org.w3c.dom.Element getGlobalConstraintsElement()
getter method; if the globalConstraints Document doesnt exist, it creates one

Returns:

getGlobalConstraintsDocument

public org.w3c.dom.Document getGlobalConstraintsDocument()
getter method

Returns:

isDirty

public boolean isDirty()

setDirty

public void setDirty(boolean dirty)


Copyright © 2004 - 2008 ETH Zurich and P&P Software GmbH, All Rights Reserved.