- Collapses the subtree rooted at in Java

Creation Data Matrix in Java - Collapses the subtree rooted at
- Collapses the subtree rooted at
Data Matrix ECC200 Creator In Java
Using Barcode creator for Java Control to generate, create Data Matrix ECC200 image in Java applications.
List-oriented Viewers
Barcode Generation In Java
Using Barcode maker for Java Control to generate, create bar code image in Java applications.
the given element to the given level
Bar Code Decoder In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
expandAll()
Generating ECC200 In C#.NET
Using Barcode printer for .NET framework Control to generate, create Data Matrix image in VS .NET applications.
- Expands all nodes of the viewer's tree, starting
Make Data Matrix 2d Barcode In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create ECC200 image in ASP.NET applications.
with the root
ECC200 Creation In .NET Framework
Using Barcode maker for .NET Control to generate, create DataMatrix image in VS .NET applications.
expandToLevel(int)
Generating Data Matrix 2d Barcode In VB.NET
Using Barcode printer for .NET framework Control to generate, create ECC200 image in Visual Studio .NET applications.
- Expands the root of the viewer's tree to
Paint Barcode In Java
Using Barcode printer for Java Control to generate, create barcode image in Java applications.
the given level
ECC200 Encoder In Java
Using Barcode drawer for Java Control to generate, create Data Matrix 2d barcode image in Java applications.
expandToLevel(Object, int)
Making Code-128 In Java
Using Barcode creator for Java Control to generate, create Code 128 Code Set A image in Java applications.
- Expands all ancestors of the given
Generating Code 39 In Java
Using Barcode generator for Java Control to generate, create Code 39 Full ASCII image in Java applications.
element so that the given element becomes visible in this viewer's tree control, and then expands the subtree rooted at the given element to the given level
GTIN - 128 Generator In Java
Using Barcode encoder for Java Control to generate, create GTIN - 128 image in Java applications.
getExpandedElements()
ANSI/AIM ITF 25 Creation In Java
Using Barcode creator for Java Control to generate, create Uniform Symbology Specification ITF image in Java applications.
- Returns a list of elements correspond-
Make EAN-13 In .NET Framework
Using Barcode printer for ASP.NET Control to generate, create EAN13 image in ASP.NET applications.
ing to expanded nodes in this viewer's tree, including currently hidden ones that are marked as expanded but are under a collapsed ancestor
Create Barcode In VS .NET
Using Barcode creator for .NET Control to generate, create bar code image in .NET applications.
getExpandedState(Object)
Scan Bar Code In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
- Returns whether the node corre-
Read EAN13 In Visual Studio .NET
Using Barcode decoder for .NET Control to read, scan read, scan image in VS .NET applications.
sponding to the given element is expanded or collapsed
Barcode Maker In VS .NET
Using Barcode creation for ASP.NET Control to generate, create barcode image in ASP.NET applications.
Tree getTree()
Encode USS Code 39 In VB.NET
Using Barcode creation for VS .NET Control to generate, create Code 39 Extended image in .NET framework applications.
- Returns this tree viewer's tree control - Gets the expanded elements that
Barcode Encoder In .NET
Using Barcode generation for ASP.NET Control to generate, create barcode image in ASP.NET applications.
getVisibleExpandedElements()
TT 5 JFace Viewers
are visible to the user
isExpandable(Object)
- Return whether the tree node represent-
ing the given element can be expanded
remove(Object)
- Removes the given element from the viewer - Removes the given elements from this
remove(Object[])
viewer
reveal(Object)
- Ensures that the given element is visible,
scrolling the viewer if necessary
scrollDown(int, int)
- Scrolls the viewer's control down by
one item from the given display-relative coordinates
scrollUp(int, int)
- Scrolls the viewer's control up by one
item from the given display-relative coordinates
setAutoExpandLevel(int)
- Sets the auto-expand level - The AbstractTreeViewer
setContentProvider(IContentProvider)
implementation of this method checks to ensure that the content provider is an ITreeContentProvider
setExpandedElements(Object[])
- Sets which nodes are expanded
List-oriented Viewers
in this viewer's tree
setExpandedState(Object, boolean)
- Sets whether the node cor-
responding to the given element is expanded or collapsed
setLabelProvider(IBaseLabelProvider)
- The tree viewer imple-
mentation of this Viewer framework method ensures that the given label provider is an instance of ILabelProvider
adds the following useful APIs:
CheckboxTreeViewer
addCheckStateListener(ICheckStateListener)
- Adds a listener
for changes to the checked state of elements in this viewer
getChecked(Object)
- Returns the checked state of the given
element
getCheckedElements()
- Returns a list of checked elements in
this viewer's tree, including currently hidden ones that are marked as checked but are under a collapsed ancestor
getGrayed(Object) -
Returns the grayed state of the given ele-
TT 5 JFace Viewers
ment
getGrayedElements()
- Returns a list of grayed elements in this
viewer's tree, including currently hidden ones that are marked as grayed but are under a collapsed ancestor
setChecked(Object, boolean)
- Sets the checked state for the
given element in this viewer
setCheckedElements(Object[])
- Sets which elements are
checked in this viewer's tree
setGrayChecked(Object, boolean)
- Check and gray the selection
rather than calling both setGrayed and setChecked as an optimization
setGrayed(Object, boolean)
- Sets the grayed state for the given
element in this viewer
setGrayedElements(Object[])
- Sets which elements are grayed
in this viewer's tree
setParentsGrayed(Object, boolean)
- Sets the grayed state for
the given element and its parents in this viewer
List-oriented Viewers
setSubtreeChecked(Object, boolean)
- Sets the checked state for
the given element and its visible children in this viewer
The following example creates a tree viewer with a label provider and content provider (see Figure 5-10)
Figure 5-10
TreeViewerExample
public class TreeViewerExample { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shellsetText("Tree Viewer Example"); shellsetBounds(100, 100, 200, 200); shellsetLayout(new FillLayout()); final TreeViewer treeViewer = new TreeViewer(shell, SWTSINGLE); treeViewersetLabelProvider( new PersonListLabelProvider()); treeViewersetContentProvider( new PersonTreeContentProvider()); treeViewersetInput(Personexample());
TT 5 JFace Viewers
shellopen(); while (!shellisDisposed()) { if (!displayreadAndDispatch()) displaysleep(); } displaydispose(); } }
After creating the tree viewer, the label provider is set using the setLabelProvider() Provider()
method and the content provider with the setContent-
method The content provider, PersonTreeContentProvider, re-
turns the parent and children of each item The class looks like this:
public class PersonTreeContentProvider extends ArrayContentProvider implements ITreeContentProvider { public Object[] getChildren(Object parentElement) { Person person = (Person) parentElement; return personchildren; } public Object getParent(Object) { Person person = (Person) element; return personparent; } public boolean hasChildren(Object) { Person person = (Person) element; return personchildrenlength > 0; } }
Text Viewers
52 TEXT VIEWERS
The TextViewer class wraps the StyledText widget (see Figure 5-11 for the
TextViewer
hierarchy) Individual runs of text may have different styles as-
sociated with them including foreground color, background color and bold
Figure 5-11
Text Viewer Hierarchy
Useful APIs include:
addTextListener(ITextListener)
- Adds a text listener to this
viewer
appendVerifyKeyListener(VerifyKeyListener)
- Appends a verify
key listener to the viewer's list of verify key listeners
canDoOperation(int)
- Returns whether the operation specified
by the given operation code can be performed
changeTextPresentation(TextPresentation, boolean)
- Applies
TT 5 JFace Viewers
the color information encoded in the given text presentation
doOperation(int)
- Performs the operation specified by the op-
eration code on the target
enableOperation(int, boolean)
- Enables/disabled the given text
operation
getSelectedRange()
- Returns the range of the current selection
in coordinates of this viewer's document
getSelection()
- Returns the current selection for this provider - Returns viewer's text widget
getTextWidget()
isEditable()
- Returns whether the shown text can be manipu-
lated
refresh()
- Refreshes this viewer completely with information
freshly obtained from this viewer's model
setDocument(IDocument) -
Sets the given document as the text
viewer's model and updates the presentation accordingly
setEditable(boolean)
- Sets the editable mode
Text Viewers
setInput(Object)
- Sets or clears the input for this viewer The
TextViewer
implementation of this method calls setDocuwith the input object if the input object is
ment(IDocument)
an instance of IDocument or with null if the input object is not
setRedraw(boolean)
- Enables/disables the redrawing of this text
viewer
setSelectedRange(int, int)
- Sets the selection to the specified
range
setSelection(ISelection, boolean)
- Sets a new selection for
this viewer and optionally makes it visible
setTextColor(Color)
- Applies the given color to this viewer's
selection
setTextColor(Color, int, int, boolean)
- Applies the given
color to the specified section of this viewer
setTextHover(ITextHover, String)
- Sets this viewer's text hover
for the given content type
TT 5 JFace Viewers
The following example creates a text viewer containing styled text (see Figure 5-12)
Figure 5-12
TextViewerExample
public class TextViewerExample { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shellsetText("Text Viewer Example"); shellsetBounds(100, 100, 225, 125); shellsetLayout(new FillLayout()); final TextViewer textViewer = new TextViewer(shell, SWTMULTI | SWTVSCROLL); String string = "This is plain text\n" + "This is bold text\n" + "This is red text"; Document document = new Document(string); textViewersetDocument(document); TextPresentation style = new TextPresentation(); styleaddStyleRange( new StyleRange(19, 17, null, null, SWTBOLD)); Color red = new Color(null, 255, 0, 0); styleaddStyleRange( new StyleRange(37, 16, red, null)); textViewerchangeTextPresentation(style, true); shellopen(); while (!shellisDisposed()) {
Summary
if (!displayreadAndDispatch()) displaysleep(); } displaydispose(); } }
After creating the text viewer, a Document object is created that holds a string of text and then assigned to the viewer Next, a TextPresentation object is created to hold the style ranges Two style ranges are added one that sets a range of text to bold and a second that sets a range of text to the color red The first argument to the StyleRange constructor is the index of the first character in the string that the style should apply to The second argument is the number of characters that should be affected by the style Finally, the style object is assigned to the viewer