Disable Drag & Drop in Tree for some nodes
It is very easy to enable Drag and Drop on Tree controls. How
do I disable some Nodes from being dragged? I do not need all nodes
to be draggable.
The trick is not to use the tree drag* properties of the
control and instead use the DragManager to do custom drag and drop.
This allows to listen to mouse down events and evaluate
whether to useDragManager.doDrag() to initiate a drag.
Similar Messages
-
Hide disclosure icon for some nodes
Hi,
For some nodes with children, I would like hide the
disclosure icon; for some not.
How can I do that?
I tried disclosure._visible = false in the function
setValue(node, state) of my custom TreeRow Renderer extended from
mx.controls.treeclasses.TreeRow. It did not work though.
For other embedded moviclip in a tree, it seems I can
control, i.e. nodeIcon, cell.
Thx,
GuangmingThanks, a case of missing the obvious
Extending HierarchicalData and overriding canHaveChildren and hasChildren worked. -
Drag & Drop kills Tree Change event
I have a tree that I am dragging from to a HorizontalList.
Anyway, I have the actual drag and drop working fine. However, my
tree has a handler for it's change event so that when the selected
item changes, a web service lookup is initiated. After the drag and
drop the tree appears to have a different item selected, however
the change event does not fire. Also if I manually click on the
same row that already appears selected, the event fires and my
lookup is kicked off.
It's like after the drag drop the tree's selected item
appears selected VISUALLY but the tree does not know it is the
selected item.
HELP PLEASE.
P.S. - I am using Flex 2.01 by the way.The trick is not to use the tree drag* properties of the
control and instead use the DragManager to do custom drag and drop.
This allows to listen to mouse down events and evaluate
whether to useDragManager.doDrag() to initiate a drag. -
How to disable disclosureClosedIcon on a tree for a particular node ?
How can I selectively disable the disclosureClosedIcon in front of a particular tree node and leave the other tree nodes unaffected. If I do myTree.setStyle("disclosureClosedIcon",null);
Then the whole tree is affected. Please look at the code below.
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.events.ListEvent;
import mx.controls.Alert;
import mx.events.TreeEvent;[
Bindable]
public var selectedNode:XML;
public function myTreeOpening(event:TreeEvent):void {
//How to do the following selectively just for one node. For example if I want to just disable
//further opening of "Marketing" node and leave the other two
Alert.show(
"Trying to disable the disclosureClosedIcon just for the Marketing node");
//myTree.setStyle("disclosureClosedIcon",null);
]]>
</mx:Script>
<mx:XML
id="treeData">
<node label="Mail Box">
<node label="Inbox">
<node label="Marketing">
<node label="Professional"/>
<node label="Individual"/>
<node label="team"/>
</node>
<node label="Product Management">
<node label="Professional"/>
<node label="Individual"/>
<node label="team"/>
</node>
<node label="Sales">
<node label="Professional"/>
<node label="Individual"/>
<node label="team"/>
</node>
</node>
</node>
</mx:XML>
<mx:Panel
title="Tree Control Example" height="75%" width="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
<mx:Label width="100%" color="blue" text="Select a node in the Tree control."/>
<mx:Tree id="myTree" width="50%" height="100%" labelField="@label" showRoot="
false" dataProvider="{treeData}" itemOpening="myTreeOpening(event)"/>
</mx:Panel>
</mx:Application>Thank you
but I don't want to modify the underlying xml data by adding isBranch on the node. I just want to modify the display of the data on Tree. The reason is that the xml data is retrieved from database and I can not modify the XML. -
About to use my tree for some firewood :o(
I was wondering if someone could maybe clue me into a problem that I am having with my DefaultMutableTree. See, I call a recursive method to get the file system of the computer, which is what is added to the tree. So the user is looking at a tree structure of the file system of their computer. My problem is that when I compile and run my program the tree shows up fine, with no hitches. I have given my code to other friends, and for some of them it does not show up, and throws a null pointer exception at the internal interface of this recursive method. I was wondering what might be causing this? My friends that have problems with the code are running either WIN XP, or Mac OS 10.1.4. Here is the code for the initialization of the tree (This will look ugly on the post, so I would hope that you would take the time to copy and paste this into your editor :D)
//code start.
import java.io.*;
import java.io.File;
import java.lang.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.beans.*;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.event.TreeSelectionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreeSelectionModel;
public class File_Encryptor extends JFrame {
private JFrame thisFrame = this;
private JTree tree;
private JMenuBar jMenuBar1 = new JMenuBar();
private JMenuItem menuOpen = new JMenuItem("Open");
private JMenuItem menuSave = new JMenuItem("Save");
private JMenuItem menuClose = new JMenuItem("Close");
private JMenuItem menuQuit = new JMenuItem("Quit");
private JMenuItem menuAbout = new JMenuItem("About this software...");
private JMenuItem menuAdd = new JMenuItem("Add key and user");
private JMenuItem menuChange = new JMenuItem("Change buddy key");
private JMenuItem menuSend = new JMenuItem("Send your buddy key");
private JMenuItem menuDelete = new JMenuItem("Delete selected buddy key");
private JMenuItem menuReset = new JMenuItem("Reset your key");
private JMenuItem menuChangeLogin = new JMenuItem("Change Login");
private JMenuItem menuHelp = new JMenuItem("Help...");
private JButton openDir = new JButton("Open path");
private JTextField jTextField1 = new JTextField();
private JScrollPane treeView;
private JScrollPane imageView;
private JScrollPane textView;
private String ROOT;
private File root;
private DefaultMutableTreeNode top;
final private DefaultMutableTreeNode FILLER = new DefaultMutableTreeNode(new FileInfo ("about:blank", "about:blank"));
public File_Encryptor() throws FileNotFoundException, InterruptedException, IOException, ClassNotFoundException {
super("FILE ENCRYPTOR 1.0");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
ROOT = getRoot(System.getProperty("user.home"));
root = new File(ROOT);
try{
//Create the nodes.
top = unfold(root);
top.setUserObject(new FileInfo(ROOT,ROOT));
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode
(TreeSelectionModel.SINGLE_TREE_SELECTION);
Object nodage = top.getNextNode().getUserObject();
FileInfo leaf = (FileInfo) nodage;
tree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if (node == null) return;
try{
Object nodeInfo = node.getUserObject();
FileInfo temp = (FileInfo) nodeInfo;
if((node.isLeaf()) && (!(node.isRoot())))
System.out.println(temp.Path());
//figure out how to place file in editor pane.
else
return;
catch(Exception fubar)
fubar.printStackTrace();
treeView = new JScrollPane(tree);
treeView.setSize(150,450);
jTextField1.setMaximumSize(new Dimension(50, 100));
jTextField1.setText("PATH");
this.getContentPane().add(jTextField1, BorderLayout.EAST);
this.getContentPane().add(treeView, BorderLayout.WEST);
catch(Exception e) {
e.printStackTrace();
jMenuBar1.setBorder(BorderFactory.createEtchedBorder());
JMenu menu = new JMenu("File");
JMenu about = new JMenu("Help");
JMenu keys = new JMenu("Keys");
JMenu change = new JMenu("Login");
menuQuit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.META_MASK));
menuQuit.setEnabled(true);
menuQuit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
menu.add(menuQuit);
jMenuBar1.add(menu);
jMenuBar1.add(keys);
jMenuBar1.add(change);
jMenuBar1.add(about);
this.setJMenuBar(jMenuBar1);
public class FileInfo {
private String path = "";
private String name = "";
public FileInfo(String p , String n){
path = p;
name = n;
public String toString(){
return name;
public String Path(){
return path;
public static String getFileEx(String po){
String ext = "";
int i = po.lastIndexOf('.');
if(i > 0)
ext = po.substring(i-1);
else
ext = null;
return ext;
private DefaultMutableTreeNode unfold(File path) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode("");
Vector Files = new Vector();
Vector Direc = new Vector();
if((path.isDirectory()) && (path.list().length != 0))
node = new DefaultMutableTreeNode(new FileInfo(path.getPath(),path.getName()));
File [] childs = path.listFiles();
for(int j = 0; j < childs.length; j++)
if(childs[j].isDirectory())
Direc.addElement(childs[j]);
else
Files.addElement(childs[j]);
for(int g = 0; g < Files.size(); g++)
Direc.addElement((File)Files.elementAt(g));
for(int i = 0; i < Direc.size(); i++)
node.add(unfold((File)Direc.elementAt(i)));
else if(!(path.isDirectory()))
node = new DefaultMutableTreeNode(new FileInfo(path.getPath(),path.getName()));
else
node = new DefaultMutableTreeNode(new FileInfo(path.getPath(),path.getName()));
node.add(new DefaultMutableTreeNode(new FileInfo(null,"<EMPTY FOLDER>")));
return node;
public static String getRoot(String path)
int find = path.indexOf(System.getProperty("file.separator"));
String root = path.substring(0,find + 1);
return root;
public static void main( String [ ] args )throws FileNotFoundException, InterruptedException, IOException, ClassNotFoundException {
File_Encryptor show = new File_Encryptor();
show.setSize(700, 500);
show.setResizable(false);
//show.setLocation(100,100);
show.setVisible(true);
//code end.
//well there it is. Hope someone can help me with my problem.
//I know this code is ugly, but I was trying a bunch of different
//things hoping something would work. but ehh no such luck.
//I am running windows 98, yea that's prolly my problem.
//thank you for your time.I ran this on XP and got the null pointer exception...
it's likely that it's running into a file or directory that it can't list (in my case it was a mount on a different directory ntfs is kinda cool)... SO... to handle that problem I just put the whole method in a try / catch block
it was just the method unfold ... the fix returns a blank treenode... it should probably return null and the caller should see that as a sign to not add it to the tree...
private DefaultMutableTreeNode unfold(File path) {
DefaultMutableTreeNode node = new DefaultMutableTreeNode("");
try
Vector Files = new Vector();
Vector Direc = new Vector();
if(path==null)
return(node);
if((path.isDirectory()) && (path.list().length != 0))
node = new DefaultMutableTreeNode(new FileInfo(path.getPath(),path.getName()));
File [] childs = path.listFiles();
for(int j = 0; j < childs.length; j++)
if(childs[j].isDirectory())
Direc.addElement(childs[j]);
else
Files.addElement(childs[j]);
for(int g = 0; g < Files.size(); g++)
Direc.addElement((File)Files.elementAt(g));
for(int i = 0; i < Direc.size(); i++)
node.add(unfold((File)Direc.elementAt(i)));
else if(!(path.isDirectory()))
node = new DefaultMutableTreeNode(new FileInfo(path.getPath(),path.getName()));
else
node = new DefaultMutableTreeNode(new FileInfo(path.getPath(),path.getName()));
node.add(new DefaultMutableTreeNode(new FileInfo(null,"<EMPTY FOLDER>")));
catch (Exception e)
return node;
} -
Disable drag & drop in cs2 bridge
Can I disable cs2 bridge drag & drop?
Hi,
See this discussion javascript - Disable Drag and Drop on HTML elements? - Stack Overflow and try accordingly.
also accordion has events such as detachSectionsReorder check if it is useful for your requirement.
Regards,
Chandra -
Drill Down Reports and Drag & Drop capability Tool for Developer2000
I am currently doing my development in Developer2000 rel. 2.0.
I have seen many tools for VB which provide the facility for Drill Down reporting and drag & drop option in reporting, but unable to find any tool for developer2000. I wonder if anyone can guide me about any tool for developer2000 which can provide these facilities in reporting and forms.......
Qamar Bilalyou can use the mouse triggers to do drag and drop.
you have mouse-move and mouse-enter etc...
what do you mean by drill down?
you can do drill down reporting in reports by using srw.run_report built in and you can also use oracle discoverer. -
Adding skin to SkinnableContainer disables drag/drop ability.
Hi all,
I'm having a bit of a problem with a SkinnableContainer. The code defining the SkinnableContainer looks like:
<s:SkinnableContainer
id="actionContainer1" width="100" height="100"
dragEnter="dragEnterHandler(event, 'actionGroup1')" dragDrop="dragDropHandler(event, 'actionGroup1')">
<s:HGroup id="actionGroup1" height="100%" width="100%">
</s:HGroup>
</s:SkinnableContainer>
and I have a skin defined as:
<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" height="100" width="100">
<!-- host component -->
<fx:Metadata>
[HostComponent("spark.components.SkinnableContainer")]
</fx:Metadata>
<!-- states -->
<s:states>
<s:State name="disabled" />
<s:State name="normal" />
</s:states>
<!-- SkinParts
name=contentGroup, type=spark.components.Group, required=false
-->
<s:Rect left="0" right="0" top="0" bottom="0" radiusX="5" radiusY="5" >
<s:stroke>
<s:SolidColorStroke color="#ff00ff" weight="4" />
</s:stroke>
</s:Rect>
<s:Group id="contentGroup" left="0" right="0" top="0" bottom="0">
<s:layout>
<s:BasicLayout />
</s:layout>
</s:Group>
</s:Skin>
If I add styleName="DropboxSkin" to the skinnablecontainer (actionContainer1), then it appears that my dragEnterHandler refuses to accept the drag source. Is there any reason this might be occurring? Removing it returns the functionality back to how it was and the drag source is accepted.
Thanks very much,
AlastairWith Pages you can add text and then drag and drop photos from iPhoto to wherever you want and resize just by clicking on the photo and dragging a corner:
The text wrap is automatic so you just move the photo to get the wrap effect you want.
You can save the document as a PDF file for printing. -
Acrobat 8 disables "Save to PDF" only for some PDFs?
Hi there,
I have a tax for for this year that I downloaded from the Colorado Dept of Revenue. The form lets me "fill in the blanks" and prints, but won't let me "Save As" (like the Fed forms will).
So I thought I'd try to "Print" and select "Save as PDF", but somehow, Acrobat has disabled this function completely, and a dialog comes back and says "Use File -> Save As" in Acrobat. But that functionality is disabled.
How can Adobe disable a system function like Print to PDF???? That seems "bad" to me... Can anybody tell me how to save the form that I've filled in? I don't need to edit it again, but it would be nice to be able to do this.
I can print it, then rescan the printed copy to PDF again, but that seems like an extraordinarily stupid and manual workaround....
Thanks in advance....
Steve
PS: If anybody wants to try it, the link to the form I'm working with is
http://www.revenue.state.co.us/PDF/06106fill.pdfYou need to moan at the original creator, who has
apparently given the file the wrong attributes due to
lack of forethought. Acrobat is only behaving as
it's supposed to.
It's that Acrobat has apparently modified a system function (print to PDF) that I'm complaining about. I understand them disabling the "Save as PDF" function, but I totally disagree with them modifying my print driver's ability to perform a function that every other Macintosh application can perform.
I will be opening this as an issue with both Apple and Adobe. I don't believe they should be allowed to do this. They can make their own program do whatever they want, just don't modify the way the printer driver works.
I'll also open this issue with the State of Colorado to make their forms "saveable".
Thanks for the feedback.
Steve -
Able to drag drop items of combobox but want to disable 1st item
Hello Sir,
I am able to drag drop elements of the combobox.
Here is my code...
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:local="*" xmlns:utils="adobe.utils.*" xmlns:controls="qs.controls.*" initialize="init()">
<mx:Script>
<![CDATA[
import mx.events.DragEvent;
import mx.events.ListEvent;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.ComboBox;
import mx.controls.Alert;
[Bindable]
public var str:String = "";
public var comboLength:int;
public function init():void
var xml:XML = <test>
<col>
<col1>one</col1>
</col>
<col>
<col1>two</col1>
</col>
<col>
<col1>three</col1>
</col>
<col>
<col1>four</col1>
</col>
<col>
<col1>five</col1>
</col>
<col>
<col1>six</col1>
</col>
<col>
<col1>seven</col1>
</col>
</test>;
cb1.dataProvider = xml;
comboLength = xml.col.length();
cb1.rowCount = comboLength;
str = (xml.col[0].col1.toString());
cb1.prompt = str;
public function closeHandler(event:Event):void
if(MouseEvent.DOUBLE_CLICK)
// Alert.show("Click Event");
public function changeHandler(event:ListEvent):void
// Alert.show("Single Click Event");
public function doubleClickEvent(event:MouseEvent):void
Alert.show(event.currentTarget.toString());
Alert.show(event.target.toString(),"Double Click");
public function dragEnterFunction(event:DragEvent):void
Alert.show(event.target.parent.toString());
]]>
</mx:Script>
<mx:ComboBox id="cb1" prompt="prashant" doubleClickEnabled="true" doubleClick="doubleClickEvent(event)"
close="closeHandler(event)" dragEnter="dragEnterFunction(event)" >
<mx:itemRenderer>
<mx:Component>
<mx:DataGrid itemClick="outerDocument.cb1.text = this.selectedItem.col1.toString();itemSelected(event)"
dragEnabled="true" dropEnabled="true" dragDrop="draDropHandler(event)" dragMoveEnabled="true" headerHeight="0" showHeaders="false"
creationComplete="init()" click="clickable()"
itemDoubleClick="doubleClickEvent(event)">
<mx:columns>
<mx:DataGridColumn dataField="col1" headerText="" id="da" disabledColor="white" />
</mx:columns>
<mx:Script>
<![CDATA[
import mx.controls.DataGrid;
import mx.events.DropdownEvent;
import mx.events.ListEvent;
import mx.events.DragEvent;
import mx.controls.Label;
import mx.controls.Alert;
public function clickable():void
//Alert.show("clickable");
public function itemSelected(event:ListEvent):void
Alert.show(event.itemRenderer.data.col1,"Single Click");
public function draDropHandler(event:Event):void
Alert.show(event.target.parent.toString());
public function dragEnterFunction(event:DragEvent):void
Alert.show(event.target.parent);
override public function set data( value:Object ) : void
this.dataProvider = value.col;
//outerDocument.cb1.text = this.selectedItem.col1.toString()
//myList.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, onItemDoubleClick,
public function doubleClickEvent(event:ListEvent):void
Alert.show(event.itemRenderer.data.col1,"Double Click");
]]>
</mx:Script>
</mx:DataGrid>
</mx:Component>
</mx:itemRenderer>
</mx:ComboBox>
</mx:Application>
But now i want to disable drag drop of the 1st item and the last item.
And also add double click of each item.
Can someone please help me out.
Awaiting your reply.
Thanks in advance.Hello Sir,
Thanks a lot for your reply.
I have implemented some thing can you please help me out with this?
In this can you help me out with the double click event????
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
xmlns:local="" xmlns:utils="adobe.utils." xmlns:controls="qs.controls.*"
initialize="init()">
<mx:Script>
<![CDATA[
import mx.events.DragEvent;
import mx.events.ListEvent;
import mx.controls.dataGridClasses.DataGridColumn;
import mx.controls.ComboBox;
import mx.controls.Alert;
import mx.controls.listClasses.ListBase;
import mx.core.UIComponent;
public var str:String = "";
public var comboLength:int;
public function init():void
var xml:XML =
</mx:Application -
Strange UI sticking issue with drag/drop and JList
Hi all,
I have implemented drag/drop between a jtree and jlist. The jtree can accept drops from the jtree (nodes to other parent nodes) and from the jlist. The jlist can accept nodes of the tree being dropped on it.
Let me say this much, it all works. Works fine and great. BUT, the purpose of my post is I am seeing a very strange and not easily reproducible problem.
I should first say that after a successful drop, the list removes the selected items. I do support drag/drop for multiple items.
When I drag items from the list to the tree, reasonbly normal (not too fast), everything seems to work every time. But if I drag an item quickly from the list to the tree, for some reason after the items are removed from the list, another item is selected, sometimes NOT in the place of where the item(s) were selected. Infact, when I drag quickly, I notice the selection changes in the list itself. I only accept tree objects being dropped in the list, so there is no ability to drag/drop list items onto itself, and thus if I drag a list item around the list normally, nothing changes..the item I am dragging stays selected and the cursor shows the drag arrow.
So this problem seems seems odd. I can reproduce it fairly easily, but only when I click and drag quickly.
Anyone have ideas? I don't see where in my list code that as I drag, when drop is done, etc that I select anything in the list. I have tried JDK 1.4.1 and 1.4.2 and it does it in both. I don't see a bug in the bug database for it, and I am not sure its a bug in the JVM or my own code!
Any help is appreciated. Can't really post code as its a large set of code and it is dependent on our company project, so it would take some time to take the code out into its own app to test it again.Hi,
+" Please note that dropSite==null is a legal value for collection components. dropSite=null and DropOrientation==ON indicates that the drop has happened outside the data portion of the collection component and should be treated as a drop on the entire component Also note that dropSite==null and DropOrientation==AFTER indicates that the drop has happened on an empty collection component and the user intends to append the data."+
http://download.oracle.com/docs/cd/E17904_01/apirefs.1111/e10684/oracle/adf/view/rich/event/DropEvent.html#getDropSite__
List dropRowKey = (List) dropEvent.getDropSite();
//if no dropsite then drop area was not a data area
if(dropRowKey == null){
return DnDAction.NONE;
}Frank
Edited by: Frank Nimphius on Feb 18, 2011 11:18 PM -
JTree how to use different font's color for different node
Hi all
This is the first time I am using JTree in my application and I have got some problems with it that I can't work out after reading the Java tutorial. Please help!
1. For some nodes, the font color need to be different.
2. One node need to use more than one font type for example "This is a sample " some words need to be bolded.
Kind regards
EdmondDid you read the section on [url http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display]Customizing a Tree's Display?
And did you follow the link on renderers? -
I have been backing up iMovie 08 files to my external drive, but for some reason I can't open these files in iMovie. I used drag and drop to copy them.
You really should be doing backups with an actual backup application, especially one that will work automatically, and, if your external HD is large enough, back up your entire system. These can automatically back up only what's changed since the previous backup, and some will keep "archive" copies of things you've changed or deleted, also.
Too many things can go wrong, such as your internal HD failing, and you'll have a major project to reinstall everything.
You already have Time Machine, built-in to OSX. You might want to review the Time Machine Tutorial, and perhaps browse Time Machine - Frequently Asked Questions.
#27 in the second link mentions some alternatives, too. -
How to disable drag and drop feature for a document library?
Hi
How can I disable drag and drop feature for a document library? Do I have an option to disable it from the SharePoint's feature set?
Or can I disable it using a script? If so, how?
Regards
ParuHi,
According to your post, my understanding is that you want to disable drag and drop feature for a document library.
Drag and drop in SharePoint 2013 is a feature that depends on HTML5, which requires version of browser, SharePoint by default doesn’t has feature to disable or enable this.
You can try disabling the drag and drop feature by disabling an add-on in Internet Explorer, or
using Internet Explorer 9 or lower.
Here is a similar thread for your reference:
https://social.msdn.microsoft.com/Forums/office/en-US/8961ff07-039d-47b0-ae7d-8e24af96234a/2013-doc-library-settings-turn-off-drag-and-drop-and-findsearchfilter-on-metadata-columns?forum=sharepointcustomization
http://community.office365.com/en-us/f/154/t/228079.aspx
More information:
The Solution to SharePoint 2013 Drop and Drag Not Working
SharePoint 2013 Drag and Drop Upload Not Working
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
Manual Drag and Drop from Tree to Tree with XML dataProvider
Been struggling with Drag-n-Drop between Tree controls. As far as I can tell, it doesn't work very well.
I have boiled it down to a minimal project below and would be ever so grateful if someone can tell me what I am doing wrong.
The complete MXML application file is below. Flex 3.5.
Two trees side-by-side. One has XML that I want to drag over to the drop tree.
On the DragOver() event, I select the node which is given to me by the calculateDropIndex() function.
After startup; first open the L1 branch on the left and drag L11 over and drop it on the right Tree.
Looks good, root node is selected/highlighted and dropFeedback is correct and dropping the node drops it as a child of "Start Here".
Open the Start Here root node to see it.
Now proceded to #1 below.
Here are the problems:
1) Drag "L12" from the left tree over to the middle of the right tree (below "L11" just dropped). "L11" will not be selected. The Selected node (with dropIndex=4) will be the entire new nested XML "<L><L11/></L>"; and therefore only "Start Here" node will be highlighted. Drop "L12" anyway. So, it is acting like selectedIndex = <anynumber> will only select the root node. How do I get the new L11 to show as a drop target?
2) Now drag "L21" from the left tree onto the right tree; again starting below all nodes on the right tree. Selected node will not change until you drag it above #2 out of 3. Then, you can drag it anywhere, and correctly highlight/select any node as the target, and get that node in code. This is a problem. Go ahead and drop it anywhere. Now if you drag, for example, L22 from the left it will correctly highlight/select any node without having to first drag above #2 in the list.
3) Now, grab and drag L11 a second time and drop it at the bottom on the right. Drag L23 over. No matter which L11 you hover over, it highlights the one at the bottom. How can this be right?
Those are the bugs I would like to figure out. If I am doing it wrong, I sure would like to know what I am doing wrong. The code below is distilled down to one simple mxml application module.
Thanks,
Jeff
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" minWidth="955" minHeight="600">
<mx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.core.IUIComponent;
import mx.events.DragEvent;
import mx.managers.DragManager;
Bindable]
private var dragXML:XML =
<Tree label="root"><L1 label="L1">
<L11 label="L11"/>
<L12 label="L12"/>
</L1>
<L2 label="L2">
<L21 label="L21"/>
<L22 label="L22"/>
<L23 label="L23"/>
</L2>
</Tree> ;
Bindable]
private var dragXMLListCollection:XMLListCollection = new XMLListCollection(dragXML.*);
Bindable]
private var dropXML:XML =
<Tree label="root"><L label="Start Here"/>
</Tree> ;
Bindable]
private var dropXMLListCollection:XMLListCollection = new XMLListCollection(dropXML.*);
// ************* Drag Drop Events ********************
private function dragEnter(evt:DragEvent):void
if (evt.dragSource.hasFormat("treeItems")) DragManager.acceptDragDrop(IUIComponent(evt.target));}
private function dragOver(evt:DragEvent):void
// Calculate dropindex and set selected item
var dropIndex:int = dropTree.calculateDropIndex(evt);dropTree.selectedIndex = dropIndex;
// setting the selected item based on calculateDropIndex()
var selNode:XML = dropTree.selectedItem as XML; // Getting XML for selected node in Tree
var selNodeName:String = (selNode != null ? selNode.localName() : "");
// Get dragged XML
var dragNode:XML = XML(evt.dragSource.dataForFormat("treeItems")[0]);
var dragNodeName:String = dragNode.localName();
trace(evt, "\n", dropIndex, "\n", (selNode ? selNode.toXMLString() : "null"), "\n", dragNode.toXMLString());
// you cannot drop a shorter name on a longer name
if ((dragNodeName.length >= selNodeName.length) && (selNode != null)) DragManager.showFeedback(DragManager.COPY);
else DragManager.showFeedback(DragManager.NONE);}
private function dragDrop(evt:DragEvent):void
// get selected node in drop tree
var selNode:XML = dropTree.selectedItem as XML; //selected in dragOver() event
// Get dragged XML
var dragNode:XML = XML(evt.dragSource.dataForFormat("treeItems")[0]);
// Drop logic
// Compare dragNode.localName().length to dropNode.localName().length
// if drag longer; drop as child
// if drag is equal; drop as sibling
// Drag can never be shorter in this example.
var isChild:Boolean = String(dragNode.localName()).length > String(selNode.localName()).length;
if (isChild){
selNode.insertChildAfter(
null, dragNode);}
else
selNode.parent().insertChildAfter(selNode, dragNode);
]]>
</mx:Script>
<mx:Tree id="dragTree" width="30%" showRoot="true" height="100%" labelField="@label"dataProvider="
{dragXMLListCollection}"dragEnabled="
true" dragMoveEnabled="false" dropEnabled="false" />
<mx:Tree id="dropTree" width="30%" showRoot="true" height="100%" labelField="@label"dataProvider="
{dropXMLListCollection}"dragEnter="dragEnter(event);" dragDrop="dragDrop(event);" dragOver="dragOver(event);"
/>
</mx:Application>I just found out that by setting the dataProvider for each tree to the XML variable instead of the XMLListCollection variable, problems #1 and #2 went away!
But the documentation says to use an XMLListCollection if you will be dynamically changing the tree contents.
And, I just found out that #1 returns if I specify showRoot="false". But with it set to "true" that problem goes away. Is there some sort of minimum XML required to make drag-n-drop work on these Tree controls?
Hmmmm. It appears that (for #3) the calculateDropIndex() will always return the last matching XML node - by name - in the tree.
Maybe you are looking for
-
Colors not displaying when viewing PDF files
Recently I've discovered that when viewing PDF files I'm not seeing all of the colors in the charts. This is happening with PDF files that I made as recently as last year (when everything looked fine). It's also happening with files that other people
-
Business Information Management - Quickbase, Basecamp, etc.
I work with international trade with dozens of customers and factories, hundreds of contacts, and at any moment in time there may be dozens if not hundreds of projects I need to manage, from quotes to production to shipments and deliveries. Recently
-
BT Line product not allowing broadband
Hi, Im trying to order broadband from a company that isnt BT, but when I put my BT phone number into their internet ordering page it says my phone line has a product or service that is making my phone line incompatible. Any idea what this might be? A
-
Tx1000 laptop lid not staying upright?
Recently, the lid hasn't been staying up properly and was falling down sometimes when i moved the laptop, but suddenly it won't stay upright by itself at all. It may be the hinge or something, but i don't really know. Any ideas or advice, and is it f
-
Why is there so much room on either side of the webpages?
The content of webpages does not fill the entire space. There is emptiness on either side. I don't have this on Internet Explorer.