Drop on TreeGrid highlight issue

A small feature request: it seems that in the TreeGrid, when you are dragging items from a ListGrid onto a TreeGrid the TreeGrid does not highlight the item in the tree that will currently be dropped on if you let go of the mouse. It does provide a over icon capability, so you can show a different icon when the mouse is over, but it would be nice if the control also highlighted the text in a different color so the user can clearly see where their items will be dropped onto when they let go.

Is there a easy way to do this already?

Override getBaseStyle to return a different style series for the row that the mouse is currently over (getEventRow()) during a drag and drop interaction (EH.getDragTarget() != null is one way to detect this). Add a dropMove handler that calls refreshRow every time a new row is entered.

Hello,

Did this work ?

I am using smartgwt 2.2 and looking for some code to do this (highlight the treegrid folder during drag and drop).

I tried using the below event handlers, but none of them seem to work:

  1. DragMoveHandler :

    treeGrid.addDragMoveHandler(new DragMoveHandler() {

    public void onDragMove(DragMoveEvent event) {
    treeGrid.getDropFolder().setCustomStyle(“treeCellSelectedOver”);
    }});

This doesnt work.

  1. RowOverHandler :

treeGrid.addRowOverHandler(new RowOverHandler() {

public void onRowOver(RowOverEvent event) {
ListGridRecord rec = event.getRecord();
TreeNode dropFolder = treeGrid.getDropFolder();
					
if(rec.getAttributeAsInt(""id).intValue() == dropFolder.getAttributeAsInt("id").intValue())
	dropFolder.setCustomStyle("treeCellSelectedOver");
}

});

This doesnt work.

  1. FolderOpenedHandler :

treeGrid.addFolderOpenedHandler(new FolderOpenedHandler() {

public void onFolderOpened(FolderOpenedEvent event) {

if(treeGrid.getDropFolder().equals(event.getNode()))
event.getNode().setCustomStyle(“treeCellSelectedOver”);

}
});

This works only when the folder already has few nodes, as folderOpenEvent is only fired when it has nodes under it.
Also, this has a limitation of changing style when the user simply tries to open a folder, even after putting the condition treeGrid.getDropFolder().equals(event.getNode()).

Other events like DragRepositionMove also don’t seem to work.Can somebody suggest any ways of implementing the requirement,please ?

Regards.

Basically you need to refresh the row as well as setting the custom style.
If you add a call to refreshRow() or markForRedraw() or redraw() to your first implementation it should work.

Also note that rather than calling ‘setCustomStyle()’, you may want to override ‘getCellStyle’ or ‘getBaseStyle’ or ‘getCellCSSText’ to return your custom styling if the row in question is the drop target folder. This method will be reevaluated whenever the row is refreshed so is “dynamic”.
If you use ‘setCustomStyle()’ you would have to take an additional step of resetting the style back to the default once the folder is no longer the drop target.

Hello,

Thanks for the help.As advised, I tried the below piece of code:

treeGrid = new TreeGrid(){
					
	protected String getBaseStyle(ListGridRecord record, int rowNum, int colNum) {
		String baseStyle = super.getBaseStyle(record, rowNum, colNum);
		TreeNode dropFolder = treeGrid.getDropFolder();

		if (null != dropFolder && null != record) {
			int id = dropFolder.getAttributeAsInt("id").intValue();
			int recId = record.getAttributeAsInt("id").intValue();
			if (id == recId)
				baseStyle = "treeCellSelectedOver";
		}
		return baseStyle;
	}					
};

treeGrid.addDragMoveHandler(new DragMoveHandler() {
					
	public void onDragMove(DragMoveEvent event) {
		int id = treeGrid.getDropFolder().getAttributeAsInt("id");
		treeGrid.refreshRow(getTreeNodeRowNumber(id));
	}
});

This works fine most of the times. However, I see an issue in one of the scenarios as mentioend below:

  1. Create a new folder in the tree.
  2. Using mouse, hover over the different nodes and this folder.
  3. Most of the times, the style returned by “getBaseStyle” is “treeCell” and all the nodes and folder show style “treeCellSelectedOver” when overed upon
  4. At one instance, when we hover upon the newly created folder, treeGrid.getDropFolder() returns the newly created folder, making the “getBaseStyle” method return “treeCellSelectedOver” and the folder in UI shows “treeCellSelectedOverSelectedOver” applied to it, which shows distorted text.
    Please note that dragging has not started yet and treeGrid.getDropFolder returns the newly created folder.

I suspect it to be an issue with the API TreeGrid.getDropFolder. Please confirm if I am correct and suggest any corrections needed here.

Thanks.

getBaseStyle will have styling suffixes (“selected”, “over” etc) applied to it.
This means if you return “treeCellSelectedOver”, and the row in question is selected / has the mouse over, you’ll get additional suffixes as you’re describing.
For this case where you want the complete style (not just the base style), use getCellStyle() and return this style name.

Thanks. Using getCellStyle to return “treeCellSelectedOver” only during drag and drop and returning super.getCellStyle otherwise works.

Regards