SAM

org.topcased.modeler.sam.dialogs
Class CheckboxTreeAndListGroup

java.lang.Object
  extended by org.eclipse.core.commands.common.EventManager
      extended by org.topcased.modeler.sam.dialogs.CheckboxTreeAndListGroup
All Implemented Interfaces:
org.eclipse.jface.viewers.ICheckStateListener, org.eclipse.jface.viewers.ISelectionChangedListener, org.eclipse.jface.viewers.ITreeViewerListener

public class CheckboxTreeAndListGroup
extends org.eclipse.core.commands.common.EventManager
implements org.eclipse.jface.viewers.ICheckStateListener, org.eclipse.jface.viewers.ISelectionChangedListener, org.eclipse.jface.viewers.ITreeViewerListener

Workbench-level composite that combines a CheckboxTreeViewer and CheckboxListViewer. All viewer selection-driven interactions are handled within this object


Constructor Summary
CheckboxTreeAndListGroup(org.eclipse.swt.widgets.Composite parent, java.lang.Object rootObject, org.eclipse.jface.viewers.ITreeContentProvider treeContentProvider, org.eclipse.jface.viewers.ILabelProvider treeLabelProvider, org.eclipse.jface.viewers.IStructuredContentProvider listContentProvider, org.eclipse.jface.viewers.ILabelProvider listLabelProvider, int style, int width, int height)
          Create an instance of this class.
 
Method Summary
 void aboutToOpen()
          This method must be called just before this window becomes visible.
 void addCheckStateListener(org.eclipse.jface.viewers.ICheckStateListener listener)
          Add the passed listener to self's collection of clients that listen for changes to element checked states
protected  boolean areAllChildrenWhiteChecked(java.lang.Object treeElement)
          Return a boolean indicating whether all children of the passed tree element are currently white-checked
protected  boolean areAllElementsChecked(java.lang.Object treeElement)
          Return a boolean indicating whether all list elements associated with the passed tree element are currently checked
protected  void checkNewTreeElements(java.lang.Object[] elements)
          Iterate through the passed elements which are being realized for the first time and check each one in the tree viewer as appropriate
 void checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent event)
          An item was checked in one of self's two views.
protected  void createContents(org.eclipse.swt.widgets.Composite parent, int width, int height, int style)
          Lay out and initialize self's visual components.
protected  void createListViewer(org.eclipse.swt.widgets.Composite parent, int width, int height)
          Create this group's list viewer.
protected  void createTreeViewer(org.eclipse.swt.widgets.Composite parent, int width, int height)
          Create this group's tree viewer.
protected  boolean determineShouldBeAtLeastGrayChecked(java.lang.Object treeElement)
          Returns a boolean indicating whether the passed tree element should be at LEAST gray-checked.
protected  boolean determineShouldBeWhiteChecked(java.lang.Object treeElement)
          Returns a boolean indicating whether the passed tree item should be white-checked.
protected  void determineWhiteCheckedDescendents(java.lang.Object treeElement)
          Recursively add appropriate tree elements to the collection of known white-checked tree elements.
 void expandAll()
          Cause the tree viewer to expand all its items
 java.util.Iterator getAllCheckedListItems()
          Answer a flat collection of all of the checked elements in the list portion of self
 java.util.Set getAllCheckedTreeItems()
          Answer a collection of all of the checked elements in the tree portion of self
 int getCheckedElementCount()
          Answer the number of elements that have been checked by the user.
protected  int getListItemsSize(java.lang.Object treeElement)
          Return a count of the number of list items associated with a given tree item.
 org.eclipse.swt.widgets.Table getListTable()
          Get the table the list viewer uses.
protected  void grayCheckHierarchy(java.lang.Object treeElement)
          Logically gray-check all ancestors of treeItem by ensuring that they appear in the checked table
 void initialCheckListItem(java.lang.Object element)
          Set the initial checked state of the passed list element to true.
 void initialCheckTreeItem(java.lang.Object element)
          Set the initial checked state of the passed element to true, as well as to all of its children and associated list elements
protected  void initialize()
          Initialize this group's viewers after they have been laid out.
protected  void listItemChecked(java.lang.Object listElement, boolean state, boolean updatingFromSelection)
          Callback that's invoked when the checked status of an item in the list is changed by the user.
protected  void notifyCheckStateChangeListeners(org.eclipse.jface.viewers.CheckStateChangedEvent event)
          Notify all checked state listeners that the passed element has had its checked state changed to the passed state
protected  void populateListViewer(java.lang.Object treeElement)
          Set the contents of the list viewer based upon the specified selected tree element.
 void removeCheckStateListener(org.eclipse.jface.viewers.ICheckStateListener listener)
          Remove the passed listener from self's collection of clients that listen for changes to element checked states
 void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
          Handle the selection of an item in the tree viewer
 void setAllSelections(boolean selection)
          Select or deselect all of the elements in the tree depending on the value of the selection boolean.
 void setListComparator(org.eclipse.jface.viewers.ViewerComparator comparator)
          Set the comparator that is to be applied to self's list viewer
 void setListProviders(org.eclipse.jface.viewers.IStructuredContentProvider contentProvider, org.eclipse.jface.viewers.ILabelProvider labelProvider)
          Set the list viewer's providers to those passed
 void setRoot(java.lang.Object newRoot)
          Set the root of the widget to be new Root.
protected  void setTreeChecked(java.lang.Object treeElement, boolean state)
          Set the checked state of the passed tree element appropriately, and do so recursively to all of its child tree elements as well
 void setTreeComparator(org.eclipse.jface.viewers.ViewerComparator comparator)
          Set the comparator that is to be applied to self's tree viewer
 void setTreeProviders(org.eclipse.jface.viewers.ITreeContentProvider contentProvider, org.eclipse.jface.viewers.ILabelProvider labelProvider)
          Set the tree viewer's providers to those passed
protected  void setWhiteChecked(java.lang.Object treeElement, boolean isWhiteChecked)
          Adjust the collection of references to white-checked tree elements appropriately.
 void treeCollapsed(org.eclipse.jface.viewers.TreeExpansionEvent event)
          Handle the collapsing of an element in a tree viewer
 void treeExpanded(org.eclipse.jface.viewers.TreeExpansionEvent event)
          Handle the expansionsion of an element in a tree viewer
protected  void treeItemChecked(java.lang.Object treeElement, boolean state)
          Callback that's invoked when the checked status of an item in the tree is changed by the user.
protected  void ungrayCheckHierarchy(java.lang.Object treeElement)
          Logically un-gray-check all ancestors of treeItem iff appropriate.
protected  void updateHierarchy(java.lang.Object treeElement)
          Set the checked state of self and all ancestors appropriately
 void updateSelections(java.util.Map items)
          Update the selections of the tree elements in items to reflect the new selections provided.
 
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CheckboxTreeAndListGroup

public CheckboxTreeAndListGroup(org.eclipse.swt.widgets.Composite parent,
                                java.lang.Object rootObject,
                                org.eclipse.jface.viewers.ITreeContentProvider treeContentProvider,
                                org.eclipse.jface.viewers.ILabelProvider treeLabelProvider,
                                org.eclipse.jface.viewers.IStructuredContentProvider listContentProvider,
                                org.eclipse.jface.viewers.ILabelProvider listLabelProvider,
                                int style,
                                int width,
                                int height)
Create an instance of this class. Use this constructor if you wish to specify the width and/or height of the combined widget (to only hardcode one of the sizing dimensions, specify the other dimension's value as -1)

Parameters:
parent -
rootObject -
treeContentProvider -
treeLabelProvider -
listContentProvider -
listLabelProvider -
style -
width -
height -
Method Detail

aboutToOpen

public void aboutToOpen()
This method must be called just before this window becomes visible.


addCheckStateListener

public void addCheckStateListener(org.eclipse.jface.viewers.ICheckStateListener listener)
Add the passed listener to self's collection of clients that listen for changes to element checked states

Parameters:
listener - ICheckStateListener

areAllChildrenWhiteChecked

protected boolean areAllChildrenWhiteChecked(java.lang.Object treeElement)
Return a boolean indicating whether all children of the passed tree element are currently white-checked

Parameters:
treeElement - java.lang.Object
Returns:
boolean

areAllElementsChecked

protected boolean areAllElementsChecked(java.lang.Object treeElement)
Return a boolean indicating whether all list elements associated with the passed tree element are currently checked

Parameters:
treeElement - java.lang.Object
Returns:
boolean

checkNewTreeElements

protected void checkNewTreeElements(java.lang.Object[] elements)
Iterate through the passed elements which are being realized for the first time and check each one in the tree viewer as appropriate


checkStateChanged

public void checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent event)
An item was checked in one of self's two views. Determine which view this occurred in and delegate appropriately

Specified by:
checkStateChanged in interface org.eclipse.jface.viewers.ICheckStateListener
Parameters:
event - CheckStateChangedEvent

createContents

protected void createContents(org.eclipse.swt.widgets.Composite parent,
                              int width,
                              int height,
                              int style)
Lay out and initialize self's visual components.

Parameters:
parent - org.eclipse.swt.widgets.Composite
width - int
height - int

createListViewer

protected void createListViewer(org.eclipse.swt.widgets.Composite parent,
                                int width,
                                int height)
Create this group's list viewer.


createTreeViewer

protected void createTreeViewer(org.eclipse.swt.widgets.Composite parent,
                                int width,
                                int height)
Create this group's tree viewer.


determineShouldBeAtLeastGrayChecked

protected boolean determineShouldBeAtLeastGrayChecked(java.lang.Object treeElement)
Returns a boolean indicating whether the passed tree element should be at LEAST gray-checked. Note that this method does not consider whether it should be white-checked, so a specified tree item which should be white-checked will result in a true answer from this method. To determine whether a tree item should be white-checked use method #determineShouldBeWhiteChecked(Object).

Parameters:
treeElement - java.lang.Object
Returns:
boolean
See Also:
determineShouldBeWhiteChecked(java.lang.Object)

determineShouldBeWhiteChecked

protected boolean determineShouldBeWhiteChecked(java.lang.Object treeElement)
Returns a boolean indicating whether the passed tree item should be white-checked.

Parameters:
treeElement - java.lang.Object
Returns:
boolean

determineWhiteCheckedDescendents

protected void determineWhiteCheckedDescendents(java.lang.Object treeElement)
Recursively add appropriate tree elements to the collection of known white-checked tree elements.

Parameters:
treeElement - java.lang.Object

expandAll

public void expandAll()
Cause the tree viewer to expand all its items


getAllCheckedListItems

public java.util.Iterator getAllCheckedListItems()
Answer a flat collection of all of the checked elements in the list portion of self

Returns:
java.util.Vector

getAllCheckedTreeItems

public java.util.Set getAllCheckedTreeItems()
Answer a collection of all of the checked elements in the tree portion of self

Returns:
java.util.Vector

getCheckedElementCount

public int getCheckedElementCount()
Answer the number of elements that have been checked by the user.

Returns:
int

getListItemsSize

protected int getListItemsSize(java.lang.Object treeElement)
Return a count of the number of list items associated with a given tree item.

Parameters:
treeElement - java.lang.Object
Returns:
int

getListTable

public org.eclipse.swt.widgets.Table getListTable()
Get the table the list viewer uses.

Returns:
org.eclipse.swt.widgets.Table

grayCheckHierarchy

protected void grayCheckHierarchy(java.lang.Object treeElement)
Logically gray-check all ancestors of treeItem by ensuring that they appear in the checked table


initialCheckListItem

public void initialCheckListItem(java.lang.Object element)
Set the initial checked state of the passed list element to true.

Parameters:
element - the element in the list to select

initialCheckTreeItem

public void initialCheckTreeItem(java.lang.Object element)
Set the initial checked state of the passed element to true, as well as to all of its children and associated list elements

Parameters:
element - the element in the tree to select

initialize

protected void initialize()
Initialize this group's viewers after they have been laid out.


listItemChecked

protected void listItemChecked(java.lang.Object listElement,
                               boolean state,
                               boolean updatingFromSelection)
Callback that's invoked when the checked status of an item in the list is changed by the user. Do not try and update the hierarchy if we are building the initial list.


notifyCheckStateChangeListeners

protected void notifyCheckStateChangeListeners(org.eclipse.jface.viewers.CheckStateChangedEvent event)
Notify all checked state listeners that the passed element has had its checked state changed to the passed state


populateListViewer

protected void populateListViewer(java.lang.Object treeElement)
Set the contents of the list viewer based upon the specified selected tree element. This also includes checking the appropriate list items.

Parameters:
treeElement - java.lang.Object

removeCheckStateListener

public void removeCheckStateListener(org.eclipse.jface.viewers.ICheckStateListener listener)
Remove the passed listener from self's collection of clients that listen for changes to element checked states

Parameters:
listener - ICheckStateListener

selectionChanged

public void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
Handle the selection of an item in the tree viewer

Specified by:
selectionChanged in interface org.eclipse.jface.viewers.ISelectionChangedListener
Parameters:
event - SelectionChangedEvent

setAllSelections

public void setAllSelections(boolean selection)
Select or deselect all of the elements in the tree depending on the value of the selection boolean. Be sure to update the displayed files as well.

Parameters:
selection - boolean indicating whether or not to select all elements

setListProviders

public void setListProviders(org.eclipse.jface.viewers.IStructuredContentProvider contentProvider,
                             org.eclipse.jface.viewers.ILabelProvider labelProvider)
Set the list viewer's providers to those passed

Parameters:
contentProvider - ITreeContentProvider
labelProvider - ILabelProvider

setListComparator

public void setListComparator(org.eclipse.jface.viewers.ViewerComparator comparator)
Set the comparator that is to be applied to self's list viewer

Parameters:
comparator - the comparator for the list viewer

setRoot

public void setRoot(java.lang.Object newRoot)
Set the root of the widget to be new Root. Regenerate all of the tables and lists from this value.

Parameters:
newRoot -

setTreeChecked

protected void setTreeChecked(java.lang.Object treeElement,
                              boolean state)
Set the checked state of the passed tree element appropriately, and do so recursively to all of its child tree elements as well


setTreeProviders

public void setTreeProviders(org.eclipse.jface.viewers.ITreeContentProvider contentProvider,
                             org.eclipse.jface.viewers.ILabelProvider labelProvider)
Set the tree viewer's providers to those passed

Parameters:
contentProvider - ITreeContentProvider
labelProvider - ILabelProvider

setTreeComparator

public void setTreeComparator(org.eclipse.jface.viewers.ViewerComparator comparator)
Set the comparator that is to be applied to self's tree viewer

Parameters:
comparator - the comparator for the tree

setWhiteChecked

protected void setWhiteChecked(java.lang.Object treeElement,
                               boolean isWhiteChecked)
Adjust the collection of references to white-checked tree elements appropriately.

Parameters:
treeElement - java.lang.Object
isWhiteChecked - boolean

treeCollapsed

public void treeCollapsed(org.eclipse.jface.viewers.TreeExpansionEvent event)
Handle the collapsing of an element in a tree viewer

Specified by:
treeCollapsed in interface org.eclipse.jface.viewers.ITreeViewerListener

treeExpanded

public void treeExpanded(org.eclipse.jface.viewers.TreeExpansionEvent event)
Handle the expansionsion of an element in a tree viewer

Specified by:
treeExpanded in interface org.eclipse.jface.viewers.ITreeViewerListener

treeItemChecked

protected void treeItemChecked(java.lang.Object treeElement,
                               boolean state)
Callback that's invoked when the checked status of an item in the tree is changed by the user.


ungrayCheckHierarchy

protected void ungrayCheckHierarchy(java.lang.Object treeElement)
Logically un-gray-check all ancestors of treeItem iff appropriate.


updateHierarchy

protected void updateHierarchy(java.lang.Object treeElement)
Set the checked state of self and all ancestors appropriately


updateSelections

public void updateSelections(java.util.Map items)
Update the selections of the tree elements in items to reflect the new selections provided.

Parameters:
items - Map with keys of Object (the tree element) and values of List (the selected list elements).

SAM

Copyright (c) 2005 TOPCASED Contributors 2005 - 2007. All rights reserved.