tree context menu with drag and drop new items

I’ve created a custom tree in which whatever you drag from the first branch to the second, you create a copy, if it doesn’t already exist, and if you drag from the second to the first, you delete the dragged. The problem arose when i wanted context menus for the copies.

What happends is as soon as i drop the item in the second branch, addItem() gets called, which in return fires the fireContentsChange() which in turn paints the content, which calls getActions(). At that point there’s no parent set for my item naturally and because i differentiate by parent, as seen in the code below, the logic fails.

The question is how can i work around this and set the parent before getActions() gets called, or call getActions() after i set the parent.

Added the war for your convenience to import in Eclipse or deploy on Tomcat.

P.S. I did call getActions right after i set the parent to try and fix it, with a requestRepaint, but it’s the same, doesn’t work.

((FilterTree)tree).getActions(itemId, null);
				tree.requestRepaint();
@Override
	public Action[] getActions(Object target, Object sender) {
		[color=#00AE0A]
if(hc.getParent(target) == null)
			return null;
[/color]
		else if (hc.getParent(target).equals(0))
			return PASSIVES;
		else if (hc.getParent(target).equals(1))
			return ACTIVES;
		else
			return null;
	}
class TreeSortDropHandler implements DropHandler {
...

			[color=#00AE0A]
Object itemId = container.addItem();
[/color]
			if (itemId != null) {
				container.getItem(itemId).getItemProperty(
						FilterManager.FILTER_NAME).setValue(value);
				if (targetItemId.equals(1))
					[color=#00AE0A]
container.setParent(itemId, targetItemId);
[/color]
				else if (container.getParent(targetItemId).equals(1))
					[color=#00AE0A]
container.setParent(itemId, container
							.getParent(targetItemId));
[/color]
				else
					return;
				container.setChildrenAllowed(itemId, false);
				[color=#00AE0A]
((FilterTree)tree).getActions(itemId, null);
				tree.requestRepaint();
[/color]
			}
		}
	}

11330.png
11331.war (3.41 MB)

After more fiddling with it, it just started working:

@Override
	public Action[] getActions(Object target, Object sender) {
		if(getParent(target) == null)
			return null;
		else if (getParent(target).equals(0))
			return PASSIVES;
		else if (getParent(target).equals(1))
			return ACTIVES;
		else
			return null;
	}

	@Override
	public void handleAction(Action action, Object sender, Object target) {
		if (action == PASSIVE_ADD) {			
			Object value = getItem(target).getItemProperty(
					FilterManager.FILTER_NAME).getValue();

			Collection ids = getChildren(1);
			if (ids != null)
				for (Object o : ids) {
					// if there's another like it ignore the add
					if (getItem(o).getItemProperty(FilterManager.FILTER_NAME)
							.getValue().equals(value))
						return;
				}
			Object itemId = addItem();
			if (itemId != null) {
				getItem(itemId).getItemProperty(FilterManager.FILTER_NAME)
						.setValue(value);
				setParent(itemId, 1);
				setChildrenAllowed(itemId, false);
			}
		}
		if (action == ACTIVE_REMOVE) {
			removeItem(target);