Tree Drag and Drop Functionality - apache-flex

label1
|
|*label2
|*label3
|___label4
|___label5
I want a tree in this structure, having line between the nodes, also, instead of Open and Close Folders, I have added my own graphic there with label. I did by extending TreeItemRenderer Class. Now, I if iam dragging and dropping a child node ex:label5, and try i drop it above label1 here, it is getting dropped there. i.e.,it is becoming like
label5 ----------> This should not happen.Child should be restricted from being added
label1 above parent.
|
|_label2
|_*label3
|___label4
I need to restrict the same. Kindly help me regarding the same.

You can implement custom dragging and dropping and apply any logic to this.
See here.

Related

Prevent drag outside QTreeWidget

In a QTreeWidget I want to be able to reorder items using InternalMove AND receive drops from another tree in my application.
If I set dragDropMode to InternalMove I cannot drop items inside it. However, if I set it to DragDrop it lets the user drag items out of the my QTreeWidget.
Is there a way of preventing this? Is there another way around the problem?
If you are not worried about drags outside of your application, maybe setting the DragDropMode of the other QTreeWidget in your application (or anything that derives from QAbstractItemView for that matter) to:
treeWidget->setDragDropMode(QAbstractItemView::DragOnly);
is enough to get the desired behavior. This does not prevent the items of the QTreeWidget in question from being dragged, but they cannot be dropped in the other tree, while you can still drop them (and the items from the DragOnly tree) into the tree that accepts drops. Does this help? (Admittedly not the most intricate way to attack the problem but performing some local tests it seemed to work)

JavaFX nodes - How to make them resizable by the end user?

I am developing a JavaFX application where a class I have developed (extended from javafx.scene.Parent) is created on-the-fly based on what entry the user has clicked in a ListView control.
Just to be clear about this node, it is not created using a layout tool like SceneBuilder, it is created at runtime based on the user's actions.
The constructor for my custom node class creates a VBox and a Label and uses passed coordinates (X,Y) in the constructor method to set its own Layout coords. I then use a custom utility class to make the node draggable. This new node is then added to the main application Pane.
However, I have failed to find out how I can make these nodes resizable by the user. That is, allow the user to mouse over the corner of the node, hold and drag to resize. An operation that all users are used to, no matter what the OS.
Has anyone done anything like this in JavaFX? (My searches on the subject only seem to pull up subjects on the automatic resizing that a parent node does with its child nodes.)
Many thanks,
Ian.
As you can see on the documentation of VBox you can only define minimum, prefered and maximum range, there's not really a way to make it manually resizable.
The only proper solution to solve your problem is to develop your own class to do it, because what you want seems very specific, with your problem description, I don't think use some layouts or panels will do what you exactly want.
I found something that you can use : Dragging to resize a JavaFX Region
This allows you to resize a region, all you have to do after is to put you VBox in this region, but notice in this article that :
Only height resizing is currently implemented.
This code won't work in JavaFX8, you'll have to check the comment to see how it worls in JavaFX8
Hope this helps.

Remove item from QListWidget by dropping it outside the widget?

I have searched the web for possibilities to realize this but haven't found a solution. Is there a simple way of removing an item from the list that is dropped on a non-receiving area or even outside the application's window?
So far I accept the delete key for removing items by means of a shortcut:
QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_Delete), myList);
shortcut->setContext(Qt::WidgetShortcut);
connect(shortcut, SIGNAL(activated()), this, SLOT(deleteSelection()));
But since I add items to the list via drag and drop, I would like to be able to remove them in the same way, too. The items in the list can also be ordered via drag and drop.
Any hints or links are appreciated.
This seems to work for me:
The drag-and-drop action should be Qt::MoveAction
Ensure the parent of the QListWidget (e.g., QDialog) has the following:
dragEnterEvent() implemented
dropEvent() implemented (ignore the mime data here)
setAcceptDrops(true);
Ignoring the mime data in dropEvent() in a Qt::MoveAction should be equivalent to a item remove operation.
Good luck!

flex expand and collapse icon in Tree control

I am having some trouble with the flex Tree control.
I have a control in my system and of course it is data driven.
I have a group which shows a folder icon and that's fine but it also shows an expand icon when the item has no children.
I don't what it to show the expand icon when the group has no children but I do want to show the folder icon, because it is different entities in my system.
here's an example of what I'm talking about. I still want to show the folder icon, the expand Icon should be hidden in this case only for the child icon.
It's easy to get this problem if you're trying to use a non-XML data provider (e.g. setting the dataProvider property of the Tree to a structure of nested ArrayCollections). In that case, the trick is to give each node a children() function that returns null (as opposed to an empty set) if there are no children.
However, assuming you're using a plain old XMLListCollection, what are you doing to make it display a folder icon at all? If you're giving the node an empty set of children, then once again, the expand icon will be displayed. The list of child nodes must be null. Alternatively, if you set the isBranch property of the node to true, it will display 'incorrectly' as you have it above.
The easiest way to display a folder icon without the expand icons is to just replace all the (really rather ugly) default icons with your own, which gives you complete control of how they appear. What you would do is set three properties: defaultLeafIcon, folderClosedIcon, and folderOpenIcon (good example at Flex Examples):
[Embed(source="folder.png")]
public var iconFolder:Class;
[Embed(source="folder.png")]
public var iconFolderOpen:Class;
<mx:Tree dataProvider="{yourData}"
defaultLeafIcon="{iconFolder}"
folderClosedIcon="{iconFolder}"
folderOpenIcon="{iconFolderOpen}" />
I see you're already using the Silk icon set, which has a rather nice closed folder icon. For some reason it doesn't contain an open folder icon though, but you can just use a closed one or anything else.
You could also just use an iconFunction (Flex Examples again), though I think the approach above is easier for what you're trying to achieve.
If it's none of those problems, give us a bit more detail on the content of your data provider and existing tree properties and see if we can't figure it out then. Hope that helps a bit anyway.

Can I add a node to a tree without adding it to the dataProvider?

I've got a couple trees that I allow a user to drag and drop from one to another, works great except one apparent limitation. I'm picking up where they drop it in the list and adding it to the dataProvider manually. The user can drop it everywhere except after the last child of any particular node it seems, since it reads that position as being between the node and it's next sibling.
It seems the best way to deal with this is to add something like a dummy leaf so the user has something to drop the item in front of. I don't want this leaf in the dataProvider, so is it possible to add a leaf (or a folder) to the tree without adding it to the dataProvider? if so how?
Unfortunately, that is not possible.
Thanks Gabriel, I worked around the issue by adding the item when a node is opened, removing it when the node is closed, also loop through and remove it all before data is committed to the DB.

Resources