org.infai.emo.matcher.editor
Class ModelMatcherTreeViewer

java.lang.Object
  extended by org.infai.emo.matcher.editor.ModelMatcherTreeViewer
All Implemented Interfaces:
org.eclipse.jface.viewers.ISelectionChangedListener

public class ModelMatcherTreeViewer
extends java.lang.Object
implements org.eclipse.jface.viewers.ISelectionChangedListener

This class includes a TreeViewer and a TableViewer.
The TreeViewer is used to display a model that was part of the comparison.
The TableViewer is used to display the properties of a selected item of the TreeViewer, e.g. name, id, ...

Version:
1.0.0
Author:
Stanley Hillner
See Also:
TreeViewer, TableViewer, ISelectionChangedListener

Field Summary
private  org.eclipse.swt.widgets.Composite comp
          The composite on which the TreeViewer and the tableViewer are placed.
private  org.eclipse.swt.graphics.Color currentSelectionColor
          This is the color for the highlight and is determined by the line-color of the selected line on the canvas.
private  ModelMatcherEditor editor
          The editor which contains this "TreeViewer" as a component.
private  Matching match
          This is the matching that contains the element-tuples and the matching-value for each tuple.
private  org.eclipse.swt.widgets.TreeItem root
          This is the root-item of the tree (the very first TreeItem).
private  org.eclipse.swt.events.PaintListener selectionHighlight
          This is the PaintListener for the current highlighted TreeItem.
private  org.eclipse.swt.widgets.Table table
          The table that lies under the TableViewer and contains the entries.
private  org.eclipse.jface.viewers.TableViewer tableV
          The TableViewer that displays the properties of a selected TreeItem.
private  org.eclipse.swt.widgets.Tree tree
          The tree that lies under the TreeViewer and contains the entries.
private  byte treeID
          The ID for this Tree.
private  Model treeModel
          The model that contains all elements to be displayed in this tree.
private  org.eclipse.jface.viewers.TreeViewer treeV
          the TreeViewer that displays the model.
private  int treeV_OldHBarSelection
          The position of the horizontal ScrollBar of the TreeViewer.
private  int treeV_OldVBarSelection
          The position of the vertical ScrollBar of the TreeViewer.
private  int yPosHighlight
          This variable contains the y-coordinate of the selected item.
 
Constructor Summary
ModelMatcherTreeViewer(ModelMatcherEditor editor, org.eclipse.swt.widgets.Composite parent, int style, byte treeID)
          The constructor for initializing this component by setting the editor, the style and the treeID.
 
Method Summary
 void createGUI()
          Creates the graphical appearance of the treeViewer and the table.
private  java.lang.String createItemName(org.eclipse.emf.ecore.EObject item)
          Create a name for the given object.
 void createTableItems(org.eclipse.emf.ecore.EObject object)
          This method creates the tableItems for a given EObject.
private  void createTableItems(org.eclipse.swt.widgets.TreeItem treeItem)
          This method creates the tableItems for a selected TreeItem.
private  void createTreeItem(org.eclipse.swt.widgets.TreeItem parent, org.eclipse.emf.ecore.EObject element)
          Creates a TreeItem from the given EObject.
private  java.util.Vector<org.eclipse.swt.widgets.TreeItem> getAllTreeItems(org.eclipse.swt.widgets.TreeItem parent)
          This method reads out all TreeItems of this tree.
 Matching getMatch()
           
 int getTreeID()
           
 Model getTreeModel()
           
 org.eclipse.jface.viewers.TreeViewer getTreeViewer()
           
 void highlightItem(int y, org.eclipse.swt.graphics.Color color)
          Method for highlighting a TreeItem if a matching-line is selected.
 void initInput(Model model, java.lang.String path)
          This method initializes the tree with the given model that resulted of the path given for this model.
private  void initTree(org.eclipse.emf.ecore.resource.Resource res, java.lang.String filePath)
          Method adds all the other TreeItems to the root-item.
 void removeHighlight()
          Method removes the highlight of the currently highlighted TreeItem.
 void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
          This method is called if the selection on the Tree has changed.
 void setLayoutData(java.lang.Object layoutData)
          Sets the CellEditor.LayoutData to the underlying Composite.
 void setMatch(Matching match)
           
private  void visualizeMatchingOnItem(org.eclipse.swt.widgets.TreeItem selection, double threshold)
          This method is responsible for drawing the matching-lines between the TreeItem that was selected in this tree and all the matched TreeItems in the opposite tree.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

treeV

private org.eclipse.jface.viewers.TreeViewer treeV
the TreeViewer that displays the model.

See Also:
TreeViewer

tableV

private org.eclipse.jface.viewers.TableViewer tableV
The TableViewer that displays the properties of a selected TreeItem.

See Also:
TableViewer

root

private org.eclipse.swt.widgets.TreeItem root
This is the root-item of the tree (the very first TreeItem).

See Also:
TreeItem

table

private org.eclipse.swt.widgets.Table table
The table that lies under the TableViewer and contains the entries.

See Also:
Table

tree

private org.eclipse.swt.widgets.Tree tree
The tree that lies under the TreeViewer and contains the entries.

See Also:
Tree

comp

private org.eclipse.swt.widgets.Composite comp
The composite on which the TreeViewer and the tableViewer are placed.

See Also:
Composite

editor

private ModelMatcherEditor editor
The editor which contains this "TreeViewer" as a component.

See Also:
ModelMatcherEditor

match

private Matching match
This is the matching that contains the element-tuples and the matching-value for each tuple.

See Also:
Matching

treeModel

private Model treeModel
The model that contains all elements to be displayed in this tree.

See Also:
Model

treeID

private byte treeID
The ID for this Tree. The ID represents the position of the tree.


treeV_OldVBarSelection

private int treeV_OldVBarSelection
The position of the vertical ScrollBar of the TreeViewer.
It is used to calculate the amount of change between the old and the new position for updating the matching-lines on the canvas.


treeV_OldHBarSelection

private int treeV_OldHBarSelection
The position of the horizontal ScrollBar of the TreeViewer.
It is used to calculate the amount of change between the old and the new position for updating the matching-lines on the canvas.


selectionHighlight

private org.eclipse.swt.events.PaintListener selectionHighlight
This is the PaintListener for the current highlighted TreeItem. This PaintListener contains the rectangle around the selected TreeItem.

See Also:
PaintListener

yPosHighlight

private int yPosHighlight
This variable contains the y-coordinate of the selected item.
This value is needed to draw the lines on the canvas.


currentSelectionColor

private org.eclipse.swt.graphics.Color currentSelectionColor
This is the color for the highlight and is determined by the line-color of the selected line on the canvas.

See Also:
Color
Constructor Detail

ModelMatcherTreeViewer

public ModelMatcherTreeViewer(ModelMatcherEditor editor,
                              org.eclipse.swt.widgets.Composite parent,
                              int style,
                              byte treeID)
The constructor for initializing this component by setting the editor, the style and the treeID.
The constructor also creates the user-interface for the editor.

Parameters:
editor - the editor that contains this component as a treeViewer.
parent - the editors Container on which the GUI-components can be placed.
style - the style for the Composite that holds the components.
treeI - the treeID for that tree.
See Also:
ModelMatcherEditor, Composite, SWT, getTreeID()
Method Detail

createGUI

public void createGUI()
Creates the graphical appearance of the treeViewer and the table.


initInput

public void initInput(Model model,
                      java.lang.String path)
This method initializes the tree with the given model that resulted of the path given for this model.

Parameters:
model - the model of which the tree will be built.
path - the path of the file out of which the model was read.
See Also:
Model

initTree

private void initTree(org.eclipse.emf.ecore.resource.Resource res,
                      java.lang.String filePath)
Method adds all the other TreeItems to the root-item.

Parameters:
res - the model-resource.
filePath - the file path of the model.
See Also:
root, Resource

createTreeItem

private void createTreeItem(org.eclipse.swt.widgets.TreeItem parent,
                            org.eclipse.emf.ecore.EObject element)
Creates a TreeItem from the given EObject.
Therefore the method reads out all the children and calls itself recursively so that the items on every level will be created.

Parameters:
parent - the TreeItem to append all the read items as children.
element - the model-element of the TreeItem thats children shall be read.
See Also:
TreeItem, EObject

createItemName

private java.lang.String createItemName(org.eclipse.emf.ecore.EObject item)
Create a name for the given object. This name depends on the name-feature of EMF.
If there is no name-feature or the name is not set then the name for the element equals the name of the EClass.

Parameters:
item - the item to create the name for.
Returns:
the name for the TreeItem.
See Also:
EClass, EStructuralFeature, EObject

createTableItems

private void createTableItems(org.eclipse.swt.widgets.TreeItem treeItem)
This method creates the tableItems for a selected TreeItem.
The table will contain the structural features (the properties) with name and value of that EObject.

Parameters:
treeItem - the selected TreeItem which's Data-Object is the EObject from which the TreeItem was built.
See Also:
EObject, table, TreeItem, Widget.getData()

createTableItems

public void createTableItems(org.eclipse.emf.ecore.EObject object)
This method creates the tableItems for a given EObject.
So the method will fill the table with the structural features of that EObject.

Parameters:
object - the EObject which contains the informations for the table.
See Also:
table, EObject

setLayoutData

public void setLayoutData(java.lang.Object layoutData)
Sets the CellEditor.LayoutData to the underlying Composite.

Parameters:
layoutData - the LayoutData for the Composite.

selectionChanged

public void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
This method is called if the selection on the Tree has changed.
So the highlights on this and the opposite tree as well as the matching-lines on the canvas have to be removed.
Finally the new matching-lines must be drawn and the table also has to be refilled.

Specified by:
selectionChanged in interface org.eclipse.jface.viewers.ISelectionChangedListener
Parameters:
event - the event that contains the source of the change.
See Also:
SelectionChangedEvent

visualizeMatchingOnItem

private void visualizeMatchingOnItem(org.eclipse.swt.widgets.TreeItem selection,
                                     double threshold)
This method is responsible for drawing the matching-lines between the TreeItem that was selected in this tree and all the matched TreeItems in the opposite tree.
The method determines the position of the item and all matched treeItems and calls the methods that are required for drawing the lines.

Parameters:
selection - the selected TreeItem.
threshold - the threshold for drawing the lines.
See Also:
TreeItem

getAllTreeItems

private java.util.Vector<org.eclipse.swt.widgets.TreeItem> getAllTreeItems(org.eclipse.swt.widgets.TreeItem parent)
This method reads out all TreeItems of this tree.
Therefore this method calls itself recursively.

Parameters:
parent - the TreeItem that shall be the entry-point for tree.
This item doesn't have to be the first element of the tree you can also begin reading the items i.e. from a level-3-item.
Returns:
a vector containing all the items in a fixed order determined by the trees structure.
See Also:
TreeItem, Vector

getMatch

public Matching getMatch()
Returns:
the matching between the models.
See Also:
Matching

setMatch

public void setMatch(Matching match)
Parameters:
match - the matching between the models.
See Also:
Matching

getTreeID

public int getTreeID()
Returns:
the treeID.
See Also:
treeID

getTreeViewer

public org.eclipse.jface.viewers.TreeViewer getTreeViewer()
Returns:
the treeViewer that contains the tree.
See Also:
TreeViewer, Tree

getTreeModel

public Model getTreeModel()
Returns:
the Model from which tree was built.
See Also:
Model, treeModel

highlightItem

public void highlightItem(int y,
                          org.eclipse.swt.graphics.Color color)
Method for highlighting a TreeItem if a matching-line is selected.
The item is given by the y-coordinate in the tree.

Parameters:
y - the y-coordinate of the matching-line that was selected so that the corresponding TreeItem can be found.
color - the color of the line so that this color can also be used for the highlight.
See Also:
Color

removeHighlight

public void removeHighlight()
Method removes the highlight of the currently highlighted TreeItem.