net.fenyo.gnetwatch.GUI
Class VisualElement

java.lang.Object
  extended by net.fenyo.gnetwatch.GUI.VisualElement
Direct Known Subclasses:
Action, DataView, Queue, Target

public class VisualElement
extends java.lang.Object

Class derivated from VisualElement can be displayed in the main tree of the GNetWatch GUI.

Version:
$Id: VisualElement.java,v 1.60 2008/04/28 23:00:57 fenyo Exp $
Author:
Alexandre Fenyo

Field Summary
private  java.util.List<VisualElement> children
           
private  java.lang.String description
           
private  java.lang.Boolean disposed
           
private  GUI gui
           
private  java.lang.Long id
           
private  org.eclipse.swt.graphics.Image image
           
private  java.lang.Boolean initialized
           
private  boolean is_selected
           
private  java.lang.String item
           
private static Log log
           
private  java.util.List<VisualElement> parents
           
private  int progress
           
private  java.util.List<org.eclipse.swt.widgets.TreeItem> treeItems
           
private  java.lang.String type
           
 
Constructor Summary
VisualElement()
          Constructor.
 
Method Summary
private  void addChild(VisualElement child)
          Adds a sub element.
 void addParent(VisualElement parent)
          Adds a parent.
private  void addTreeItem(org.eclipse.swt.widgets.TreeItem treeItem)
          Adds a tree item to represent this element.
 boolean canManageThisChild(VisualElement visual_element)
          Checks that the parameter can be attached to this element.
 boolean contains(VisualElement elt)
          Checks that the parameter is a children.
protected  void disposed()
          Called when disposed.
private  void disposeSubItems(org.eclipse.swt.widgets.TreeItem item)
          Recursively detaches an item from this element and its descendants.
private  void duplicateTreeItem(java.util.List<org.eclipse.swt.widgets.TreeItem> destination_tree_items)
          Recursively duplicates this element and its descendants under each of the destination tree items.
 void duplicateTreeItemOnce(java.util.List<org.eclipse.swt.widgets.TreeItem> destination_tree_items)
          Duplicates this element under each of the destination tree items.
 void expandTreeItems(boolean doit)
          Expands or merge the associated tree items.
 java.util.List<VisualElement> getAllParents(java.lang.Class clazz)
          Returns every ascendant of this element, restricted to a given type.
private  void getAllParents(java.lang.Class clazz, java.util.List<VisualElement> elts)
          Returns every ascendant of this element, restricted to a given type.
 java.util.List<VisualElement> getChildren()
          Returns children elements.
 java.lang.String getDescription()
           
protected  GUI getGUI()
          Returns the current GUI instance.
 java.lang.Long getId()
           
 java.lang.String getItem()
          Returns the item name.
 java.util.List<VisualElement> getParents()
          Returns parents of this element.
 int getProgress()
          Gets the progress bar position for this visual element.
 java.util.List<VisualElement> getSubElements(java.lang.Class clazz)
          Gets sub elements of a given type.
private  void getSubElements(java.lang.Class clazz, java.util.List<VisualElement> elts)
          Gets sub elements of a given type.
static java.util.List<VisualElement> getSubElements(org.eclipse.swt.widgets.TreeItem item, java.lang.Class clazz)
          Gets sub elements of a given type.
private  java.util.List<Pair<VisualElement,VisualElement>> getSubGraph(VisualElement parent)
          Builds the subgraph rooted at the parent parameter.
private  void getSubGraph(VisualElement parent, java.util.List<Pair<VisualElement,VisualElement>> graph)
          Builds the subgraph rooted at the parent parameter.
private  java.util.List<Pair<VisualElement,VisualElement>> getSubGraphExceptLinks(VisualElement parent, java.util.List<Pair<VisualElement,VisualElement>> except_links)
          Builds the subgraph rooted at the parent parameter, but not containing some links of another graph.
private  void getSubGraphExceptLinks(VisualElement parent, java.util.List<Pair<VisualElement,VisualElement>> graph, java.util.List<Pair<VisualElement,VisualElement>> except_links)
          Builds the subgraph rooted at the parent parameter, but not containing some links of another graph.
 java.util.List<org.eclipse.swt.widgets.TreeItem> getTreeItems()
          Returns the list of tree items that represent this element.
 java.lang.String getType()
           
 void informSelected()
          Called when selected by the user.
protected  void initialize(GUI gui)
          Initializes this element.
 boolean isDisposed()
          Checks that this element is disposed.
protected  boolean isThisOurTreeItem(org.eclipse.swt.widgets.TreeItem item)
          Checks that a tree item represents this element.
 void removeVisualElements(VisualElement visual_parent)
          Detaches this element from one of its parents and removes children that have become orphan.
private  void removeVisualElements(VisualElement visual_parent, boolean bypass)
          Detaches this element from one of its parents and removes children that have become orphan.
 void selected()
          Called when this element has been selected.
 void setChildren(java.util.List<VisualElement> children)
           
 void setDescription(java.lang.String description)
          Sets the description.
 void setGUI(GUI gui)
           
protected  void setId(java.lang.Long id)
           
protected  void setImage(org.eclipse.swt.graphics.Image image)
          Sets the icon.
 void setImageExec()
          Sets the "exec" icon to this element.
 void setImageFolder()
          Sets the "folder" icon to this element.
 void setImageHost()
          Sets the "IPv4 host" icon to this element.
 void setImageHost6()
          Sets the "IPv6 host" icon to this element.
 void setImageHost6SNMP()
          Sets the "snmp ipv6 host" icon to this element.
 void setImageHostSNMP()
          Sets the "snmp ipv4 host" icon to this element.
 void setImageInterface()
          Sets the "inteface" icon to this element.
 void setImageMultiRow()
          Sets the "multirow" icon to this element.
 void setImageNetwork()
          Sets the "network" icon to this element.
 void setImageOscillo()
          Sets the "oscilloscope" icon to this element.
 void setImageQueue()
          Sets the "queue" icon to this element.
 void setImageWatch()
          Sets the "watch" icon to this element.
protected  void setItem(java.lang.String item)
          Sets the item name (displayed text).
protected  void setParent(GUI gui, org.eclipse.swt.widgets.Tree parent)
          Attaches this element to the root of a tree.
 void setParent(GUI gui, VisualElement parent)
          Attaches this item under another element.
 void setProgress(int progress)
          Sets the progress bar position.
 void setType(java.lang.String type)
          Sets the displayed type.
 void unselected()
          Called when this element has been unselected.
private  void unsetParent(VisualElement parent)
          Detaches this element from one of its parents.
private  void updateImage()
          Updates the displayed icon of this element.
private  void updateText()
          Updates the displayed text (item name) of this element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static Log log

id

private java.lang.Long id

initialized

private java.lang.Boolean initialized

gui

private GUI gui

disposed

private java.lang.Boolean disposed

treeItems

private java.util.List<org.eclipse.swt.widgets.TreeItem> treeItems

parents

private java.util.List<VisualElement> parents

children

private java.util.List<VisualElement> children

item

private java.lang.String item

type

private java.lang.String type

description

private java.lang.String description

image

private org.eclipse.swt.graphics.Image image

is_selected

private boolean is_selected

progress

private int progress
Constructor Detail

VisualElement

public VisualElement()
Constructor.

Parameters:
none. -
Method Detail

getId

public java.lang.Long getId()

setId

protected void setId(java.lang.Long id)

setChildren

public void setChildren(java.util.List<VisualElement> children)

initialize

protected void initialize(GUI gui)
Initializes this element.

Parameters:
gui - current GUI instance.

expandTreeItems

public void expandTreeItems(boolean doit)
Expands or merge the associated tree items.

Parameters:
doit - true to expand.

isDisposed

public boolean isDisposed()
Checks that this element is disposed.

Parameters:
none. -
Returns:
boolean true if this element is disposed.

getGUI

protected final GUI getGUI()
Returns the current GUI instance.

Parameters:
none. -
Returns:
GUI current GUI instance.

setGUI

public final void setGUI(GUI gui)

setImageExec

public void setImageExec()
Sets the "exec" icon to this element.

Parameters:
none. -

setImageFolder

public void setImageFolder()
Sets the "folder" icon to this element.

Parameters:
none. -

setImageOscillo

public void setImageOscillo()
Sets the "oscilloscope" icon to this element.

Parameters:
none. -

setImageMultiRow

public void setImageMultiRow()
Sets the "multirow" icon to this element.

Parameters:
none. -

setImageWatch

public void setImageWatch()
Sets the "watch" icon to this element.

Parameters:
none. -

setImageHost

public void setImageHost()
Sets the "IPv4 host" icon to this element.

Parameters:
none. -

setImageHost6

public void setImageHost6()
Sets the "IPv6 host" icon to this element.

Parameters:
none. -

setImageInterface

public void setImageInterface()
Sets the "inteface" icon to this element.

Parameters:
none. -

setImageQueue

public void setImageQueue()
Sets the "queue" icon to this element.

Parameters:
none. -

setImageNetwork

public void setImageNetwork()
Sets the "network" icon to this element.

Parameters:
none. -

setImageHostSNMP

public void setImageHostSNMP()
Sets the "snmp ipv4 host" icon to this element.

Parameters:
none. -

setImageHost6SNMP

public void setImageHost6SNMP()
Sets the "snmp ipv6 host" icon to this element.

Parameters:
none. -

getTreeItems

public java.util.List<org.eclipse.swt.widgets.TreeItem> getTreeItems()
Returns the list of tree items that represent this element.

Parameters:
none. -
Returns:
java.util.List list of tree items.

isThisOurTreeItem

protected boolean isThisOurTreeItem(org.eclipse.swt.widgets.TreeItem item)
Checks that a tree item represents this element.

Parameters:
item - tree item.
Returns:
boolean true if this tree item represents this element.

addTreeItem

private void addTreeItem(org.eclipse.swt.widgets.TreeItem treeItem)
Adds a tree item to represent this element.

Parameters:
treeItem - tree item to add.

duplicateTreeItem

private void duplicateTreeItem(java.util.List<org.eclipse.swt.widgets.TreeItem> destination_tree_items)
Recursively duplicates this element and its descendants under each of the destination tree items.

Parameters:
destination_tree_items - destination tree items.

duplicateTreeItemOnce

public void duplicateTreeItemOnce(java.util.List<org.eclipse.swt.widgets.TreeItem> destination_tree_items)
Duplicates this element under each of the destination tree items.

Parameters:
destination_tree_items - destination tree items.

setParent

protected void setParent(GUI gui,
                         org.eclipse.swt.widgets.Tree parent)
Attaches this element to the root of a tree.

Parameters:
gui - current GUI instance.
parent - root of the destination tree.

setParent

public void setParent(GUI gui,
                      VisualElement parent)
Attaches this item under another element.

Parameters:
gui - current GUI instance.
parent - parent element.

disposeSubItems

private void disposeSubItems(org.eclipse.swt.widgets.TreeItem item)
Recursively detaches an item from this element and its descendants.

Parameters:
item - item to detach.

unsetParent

private void unsetParent(VisualElement parent)
Detaches this element from one of its parents.

Parameters:
parent - parent.

addChild

private void addChild(VisualElement child)
Adds a sub element.

Parameters:
child - element to add.

getChildren

public java.util.List<VisualElement> getChildren()
Returns children elements.

Parameters:
none. -
Returns:
java.util.List children.

getParents

public java.util.List<VisualElement> getParents()
Returns parents of this element.

Returns:
java.util.List parents.

addParent

public void addParent(VisualElement parent)
Adds a parent.

Parameters:
parent - new parent.

contains

public boolean contains(VisualElement elt)
Checks that the parameter is a children.

Parameters:
elt - element to check.
Returns:
true if the parameter is a children.

updateText

private void updateText()
Updates the displayed text (item name) of this element.

Parameters:
none. -

updateImage

private void updateImage()
Updates the displayed icon of this element.

Parameters:
none. -

setItem

protected void setItem(java.lang.String item)
Sets the item name (displayed text).

Parameters:
item - item name.

getItem

public java.lang.String getItem()
Returns the item name.

Parameters:
none. -
Returns:
void.

getType

public java.lang.String getType()

getDescription

public java.lang.String getDescription()

setType

public void setType(java.lang.String type)
Sets the displayed type.

Parameters:
type - type to display.

setDescription

public void setDescription(java.lang.String description)
Sets the description.

Parameters:
description - description.

setImage

protected void setImage(org.eclipse.swt.graphics.Image image)
Sets the icon.

Parameters:
image - icon.

informSelected

public void informSelected()
Called when selected by the user.

Parameters:
none. -

disposed

protected void disposed()
Called when disposed.

Parameters:
none. -

getSubElements

private void getSubElements(java.lang.Class clazz,
                            java.util.List<VisualElement> elts)
Gets sub elements of a given type.

Parameters:
clazz - type.
elts - list that will be updated.

getSubElements

public java.util.List<VisualElement> getSubElements(java.lang.Class clazz)
Gets sub elements of a given type.

Parameters:
clazz - type.
Returns:
java.util.List elts list that will be updated.

getSubElements

public static java.util.List<VisualElement> getSubElements(org.eclipse.swt.widgets.TreeItem item,
                                                           java.lang.Class clazz)
Gets sub elements of a given type.

Parameters:
clazz - type.
Returns:
java.util.List elts list that will be updated.

getAllParents

private void getAllParents(java.lang.Class clazz,
                           java.util.List<VisualElement> elts)
Returns every ascendant of this element, restricted to a given type.

Parameters:
clazz - type.
elts - elts list that will be updated.

getAllParents

public java.util.List<VisualElement> getAllParents(java.lang.Class clazz)
Returns every ascendant of this element, restricted to a given type.

Parameters:
clazz - type.
Returns:
java.util.List elts list that will be updated to give the results.

canManageThisChild

public boolean canManageThisChild(VisualElement visual_element)
Checks that the parameter can be attached to this element.

Parameters:
visual_element - parameter to check.
Returns:
true if the parameter can be attached to this element.

getSubGraph

private void getSubGraph(VisualElement parent,
                         java.util.List<Pair<VisualElement,VisualElement>> graph)
Builds the subgraph rooted at the parent parameter.

Parameters:
parent - root of the subgraph.
graph - empty graph that will be updated to give the results.

getSubGraph

private java.util.List<Pair<VisualElement,VisualElement>> getSubGraph(VisualElement parent)
Builds the subgraph rooted at the parent parameter.

Parameters:
parent - root of the subgraph.
Returns:
java.util.List> resulting graph.

getSubGraphExceptLinks

private void getSubGraphExceptLinks(VisualElement parent,
                                    java.util.List<Pair<VisualElement,VisualElement>> graph,
                                    java.util.List<Pair<VisualElement,VisualElement>> except_links)
Builds the subgraph rooted at the parent parameter, but not containing some links of another graph.

Parameters:
parent - root of the subgraph.
graph - empty graph that will be updated to give the results.
except_links - another graph.

getSubGraphExceptLinks

private java.util.List<Pair<VisualElement,VisualElement>> getSubGraphExceptLinks(VisualElement parent,
                                                                                 java.util.List<Pair<VisualElement,VisualElement>> except_links)
Builds the subgraph rooted at the parent parameter, but not containing some links of another graph.

Parameters:
parent - root of the subgraph.
graph - empty graph that will be updated to give the results.
Returns:
java.util.List> resulting graph.

removeVisualElements

public void removeVisualElements(VisualElement visual_parent)
Detaches this element from one of its parents and removes children that have become orphan.

Parameters:
visual_parent - parent.

removeVisualElements

private void removeVisualElements(VisualElement visual_parent,
                                  boolean bypass)
Detaches this element from one of its parents and removes children that have become orphan.

Parameters:
visual_parent - parent.
bypass - bypass some verifications.

setProgress

public void setProgress(int progress)
Sets the progress bar position.

Parameters:
progress - position.

getProgress

public int getProgress()
Gets the progress bar position for this visual element.

Parameters:
none. -
Returns:
progress position.

selected

public void selected()
Called when this element has been selected.

Parameters:
none. -

unselected

public void unselected()
Called when this element has been unselected.

Parameters:
none. -