HomeActive Query Builder - HowTos and TroubleshootingUser Interface CustomizationHow to drag an object from the metadata tree outside the component?

1.5. How to drag an object from the metadata tree outside the component?

Delphi (VCL Edition):

procedure TForm2.Memo1DragDrop(Sender, Source: TObject; X, Y: Integer);
var n:TacTreeNode;
        mo:TacMetadataObject;
begin
    Assert(Source=qb.MetadataTree);
    Assert(qb.MetadataTree.Selected<>nil);

    n:=qb.MetadataTree.Selected;
    mo:=TacMetadataObject(n.Data);
    Memo1.Lines.Add(mo.FullNameStr);
end;


procedure TForm2.Memo1DragOver(Sender, Source: TObject; X, Y: Integer;
    State: TDragState; var Accept: Boolean);
begin
    Accept:=false;
    if (Source=qb.MetadataTree)and
        (qb.MetadataTree.Selected<>nil)
    then Accept:=true;
end;

C# (.NET Edition):

private void listBox1_DragOver(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(typeof(DataSourceFieldList)))
    {
        e.Effect = DragDropEffects.Link;
    }
}

private void listBox1_DragDrop(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(typeof(DataSourceFieldList)))
    {
        e.Effect = DragDropEffects.Link;

	DataSourceFieldList fieldListControl = (DataSourceFieldList) e.Data.GetData(typeof(DataSourceFieldList));

        if (fieldListControl.SelectedItem != null)
        {
            if (((TextAndObject) fieldListControl.SelectedItem).obj != null)
            {
                MetadataField field = (MetadataField) ((TextAndObject) fieldListControl.SelectedItem).obj;

                int x = listBox1.Items.Add(field.NameStr + " [" + field.FieldTypeName + "]");

                listBox1.SelectedIndex = x;
            }
        }
    }
}

Java:

jTextArea1.setDropTarget(new DropTarget(this, new DropTargetAdapter()
{
    @Override
    public void dragOver(DropTargetDragEvent event)
    {
        if (!event.getTransferable().isDataFlavorSupported(DataFlavor.stringFlavor))
        {
            event.rejectDrag();
        }
    }

    @Override
    public void drop(DropTargetDropEvent event)
    {
        event.acceptDrop(DnDConstants.ACTION_LINK);

        Transferable transferable = event.getTransferable();

        if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor))
        {
            try
            {
                String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
                jTextArea1.setText(data);
            }
            catch (UnsupportedFlavorException ex)
            {
                // handle exception
            }
            catch (IOException ex)
            {
                // handle exception
            }
        }
    }
}));

This page was: Helpful | Not Helpful