HomeActive Query Builder - HowTos and TroubleshootingUser Interface CustomizationHow add an object to the query building area by dragging from external list?

1.6. How add an object to the query building area by dragging from external list?

Delphi (VCL Edition):

procedure TfMain.acQueryBuilder1DragDrop(Sender, Source: TObject; 
    X, Y: Integer);
    var selectedNodeName: string;
begin
    Assert((Source = CustomMetadataTree) and (CustomMetadataTree.Selected <> nil));
    selectedNodeName := CustomMetadataTree.Selected.Text;
    acQueryBuilder1.ActiveSubQuery.ActiveUnionSubquery.AddObjectWithFKAt(
        selectedNodeName,
        Point(X, Y)
    );
end;

procedure TfMain.acQueryBuilder1DragOver(Sender, Source: TObject;
    X, Y: Integer; State: TDragState; var Accept: Boolean);
begin
    Accept := (Source = CustomMetadataTree) and (CustomMetadataTree.Selected <> nil);
end;

C# (.NET Edition):

private void queryBuilder1_DragOver(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Copy;
}


private void queryBuilder1_DragDrop(object sender, DragEventArgs e)
{
    if (e.Data != null && e.Data.GetDataPresent(typeof(String)))
    {
        String objectName = (String) e.Data.GetData(typeof(String));
        queryBuilder1.ActiveSubQuery.ActiveUnionSubquery.AddObjectWithFKAt(objectName, new Point(e.X, e.Y), "");
    }
}

Java:

queryBuilder1.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 objectName = (String) transferable.getTransferData(DataFlavor.stringFlavor);
                queryBuilder1.getActiveSubquery().getActiveUnionSubquery().addObjectWithFKAt(objectName, event.getLocation(), "");
            }
            catch (UnsupportedFlavorException ex)
            {
                // handle exception
            }
            catch (IOException ex)
            {
                // handle exception
            }
        }
    }
}));

This page was: Helpful | Not Helpful