Locating TreeObject in large Tree - eclipse

I have a large tree and I can 'select' (i.e.highlight) any node of it. But if I have a large tree with all nodes expanded the user still needs to manually scroll down or up in order to locate the highlighted element. Is there a way which not only highlights the selected element but also locates it by automatically scrolling up/down in the tree?
TreePath path = createTreePath(editorID, treeObject);
getTreeViewer().setSelection(new TreeSelection(path), true);
getTreeViewer().refresh();
getTreeViewer().jumpToSelectedElement(true); // I need something like this. I made up the name of this imaginary method.

Use
public void reveal(Object elementOrTreePath)
As its name suggests elementOrTreePath can be a tree path or just an element.

Related

Changing node icon to "folder" when adding child in fancyTree

It seems to me that the standard behaviour in fancyTree, when adding child nodes is NOT to change the parent node to have a folder icon.
For example, see http://wwwendt.de/tech/fancytree/demo/index.html#sample-multi-ext.html and try adding a child node.
How is it possible to dynamically change the icon of the parent to a "folder" when adding a child?
I thought that I could apply renderTitle() to the parent node, but this did not do anything.
This question Dynamically change icon in fancy tree is similar, but (a) I could not get it to work, and also (b) I wanted a solution that didn't involve having to create new icons.
Folders may be empty, so this status is defined by node.folder = true (not by the fact that children are present or not).
So you could set node.folder and call node.render().
Note that setting an additional class may give the same effect, but may get lost when the tree is updated.
In jquery.fancytree.edit.js I added the following line
newNode.parent.addClass("fancytree-ico-ef");
The code snippet is as follows:
newNode.makeVisible(/*{noAnimation: true}*/).done(function(){
$(newNode[tree.statusClassPropName]).addClass("fancytree-edit-new");
self.tree.ext.edit.relatedNode = self;
newNode.parent.addClass("fancytree-ico-ef");
newNode.editStart();
});

Jface ViewerFilter filtering full tree depth

I have a FilteredTree that displays many nodes, where each node can have multiple children and subchildren (n-depth).
The filter filters all nodes (and children in any depth) that match the pattern.
Now I want to add another search functionality:
Every node represent an object , each object has some fields, so i want to list the nodes that have fields that match the text.
I tired to use ViewerFilter.
The problem with it that it doesn't invoked for every node in the tree only for current opened branch.
public class TheFilter extends ViewerFilter {
private String searchString;
public void setSearchText(String s) {
}
public boolean select(Viewer viewer,
Object parentElement,
Object element) { //triggered Only for one level
return true;
}
}
Update:
When the searched item is found I want to show not just that node that contains the searched item but also it's parent (all parents).
FilteredTree accepts an org.eclipse.ui.dialogs.PatternFilter as argument to determine it's filter strategy.
You can achieve the desired result by subclassing PatternFilter and overriding it's isLeafMatch method.
For example:
PatternFilter filter = new PatternFilter() {
#Override
protected boolean isLeafMatch(Viewer viewer, Object element) {
String field = ((Node) element).getField();
if(field== null) {
return false;
}
return wordMatches(field);
}
};
FilteredTree tree = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL
| SWT.V_SCROLL, filter, true);
As I understand you want the search to be applied to all elements regardless of the fact that they are currently expanded or not. Although I am not sure why would you want the filtering to applied to the deepest leaf as well, is it because you want root nodes that will not show any children to disappear as well?
There could be several ways here, if you want to force your filter to be applied to all elements, you can expand all items in the tree using TreeViewer#expandAll, unless you are using a lazy content provider it should invoke filtering on all elements. You may collapse the tree again if you don't want to keep it expanded (may want to disable drawing while expanding and collapsing to avoid flicker through Tree#setRedraw(boolean)). Usually in trees when something is being searched, all filtered content is shown as expanded so that the deepest leaf that also matches the search criteria is also visible. If you want to maintain tree's expansion states of each element just as the user had done, it will require a little more work to expand all and then restore expansions.
Another approach is to implement the searching within the content provider. So your content provider can take the current search criterion and return only elements that match it. This means that you will have to manage yourself whether a certain parent should be visible or not. So on change of search field you only need to refresh tree and your content provider will ensure filtering.

Reordering Tree Node in GWT

I am using GWT 2.4. I am using Tree in my project. I want to move tree node up or down on Button click next to particular node. Is there any way to do so?
#Janki, You can try the following property of Tree to reorder TreeItems attached to it.
myTree.insertItem(beforeIndex, item);
This property inserts a child tree item at the specified index containing the specified
text, where beforeIndex is the index where the item will be inserted
& itemText is the text to be added.

How to set a selection in the GWT CellBrowser

somehow I have the feeling that I miss the forest for the trees. I have a CellBrowser filled with categorys and I have a search dialog to find the categorys by name. If I now select a category in the search dialog I also want it to be selected in the CellBrowser.
What I can already do is, find the node in the category tree. I also have the path from the root node to the leaf. I can open the nodes until the selected leaf (getCellBrowser().getRootTreeNode().setChildOpen(i, true). But how do I select the leaf itself?
And frankly speaking, is that the right way to do it? (I doubt it somehow)
Greetings Ole
Selecting an Object in the CellWidgets can be done by via the SelectionModel.
Assuming that you have defined a SelectionModel (i.e. SingleSelectionModel) for your CellBrowser/TreeViewModel you can just select a node in a CellBrowser by calling:
selectionModel.setSelected(MyObject, true);
MyObject is the object/type which is displayed as a node in your CellBrowser.
Note you can have different types/objects for each CellBrowser level.
SelectionModel will use either a KeyProvider or the equals function to select the object.

Loading two template files of same module in two positions

I am working on a new project and I am using Joomla version 1.5.22.
I need to display one horizontal search form in the middle of home page and the same search form in vertical style in all other pages but in left position.
So what I did is, I created two template files one for horizontal search(horizontal.php) and other for vertical search (vertical.php) and in mod_modulename.php I tried to load the respective modules based on a certain condition and changed the position left or middle according to it. The positions are changed in the database to get effected in the admin panel.
if(condition) {
modModulenameHelper::changeToVertical($position);//to change position in database to left
require( JModuleHelper::getLayoutPath( 'mod_modulename', 'vertical'));
}
else {
modModulenameHelper::changeToHorizontal($position);//to change position in database to middle
require( JModuleHelper::getLayoutPath( 'mod_modulename', 'horizontal'));
But I am not getting the correct output. It is loading the respective modules based on the condition. But the position is not assigned at first. And if I press Ctrl+F5 or refreshes, the page will be loaded with the desired output.
Why is this happening? Any Solution??
The problem is that you are changing the position after the fact. By the time you are changing the position, Joomla has already assigned the module to a position. It's an order of operations thing.
Instead, why not just use 2 instances of the module? Rather than going through this trouble, simply add a parameter to the module that allows you to select horizontal or vertical, then assign one to the home page menu item and another to the rest of the pages. This would also allow for putting the module in other positions instead of hard coding it in to the module.