Browse Source

Added drag n drop behaviour to Database Explorer. Selecting a database node and dragging it to a drop target results in the connection string for that database connection being copied to the target.

Bugs exist, most importantly in some cases a retrieval of database metadata results in a class cast exception. It is however possible to create a logical database connection, create and test its connection string, without retrieving metadata.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2424 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Dickon Field 19 years ago
parent
commit
3739cf2778
  1. 1
      src/AddIns/Misc/SharpServerTools/ServerBrowserTool/ServerBrowserTool.csproj
  2. 23
      src/AddIns/Misc/SharpServerTools/ServerBrowserTool/Src/Forms/ISupportsDragDrop.cs
  3. 15
      src/AddIns/Misc/SharpServerTools/ServerBrowserTool/Src/Forms/ServerToolTreeView.cs
  4. 28
      src/AddIns/Misc/SharpServerTools/SharpDbTools/Src/Forms/DatabaseExplorerTreeNode.cs

1
src/AddIns/Misc/SharpServerTools/ServerBrowserTool/ServerBrowserTool.csproj

@ -40,6 +40,7 @@ @@ -40,6 +40,7 @@
<Reference Include="System.Drawing" />
</ItemGroup>
<ItemGroup>
<Compile Include="Src\Forms\ISupportsDragDrop.cs" />
<Compile Include="Src\Forms\ServerToolTreeView.cs" />
<Compile Include="Src\Forms\IInitializable.cs" />
<Compile Include="Src\Forms\NodeAwareContextMenuStrip.cs" />

23
src/AddIns/Misc/SharpServerTools/ServerBrowserTool/Src/Forms/ISupportsDragDrop.cs

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
/*
* Created by SharpDevelop.
* User: dickon
* Date: 04/03/2007
* Time: 09:14
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Windows.Forms;
namespace SharpServerTools.Forms
{
/// <summary>
/// This interface is implemented by any plugin to ServerExplorer that supports drag and drop
/// of some of its data
/// </summary>
public interface ISupportsDragDrop
{
void HandleMouseDownEvent(object sender, MouseEventArgs e);
}
}

15
src/AddIns/Misc/SharpServerTools/ServerBrowserTool/Src/Forms/ServerToolTreeView.cs

@ -34,14 +34,25 @@ namespace SharpServerTools.Forms @@ -34,14 +34,25 @@ namespace SharpServerTools.Forms
// create an instance of the relevant ServerTool TreeNode
string id = codon.Id;
TreeNode treeNode = (TreeNode)node.BuildChildItem(id, null, null);
IRequiresRebuildSource s = treeNode as IRequiresRebuildSource;
// a ServerTool plugin can register to be refreshed by the ServerToolTreeView
// control by implementing the IRequiresRebuildSource interface
IRequiresRebuildSource s = treeNode as IRequiresRebuildSource;
if (s != null) {
s.RebuildRequiredEvent += new RebuildRequiredEventHandler(RebuildRequiredNotify);
}
// a ServerTool plugin can also register to handle drag-n-drop if it implements
// the required interface
ISupportsDragDrop d = treeNode as ISupportsDragDrop;
if (d != null) {
this.MouseDown += new MouseEventHandler(d.HandleMouseDownEvent);
}
this.Nodes.Add(treeNode);
}
@ -91,7 +102,7 @@ namespace SharpServerTools.Forms @@ -91,7 +102,7 @@ namespace SharpServerTools.Forms
}
}
}
public delegate void RebuildChildrenDelegate(IEnumerable children);
}

28
src/AddIns/Misc/SharpServerTools/SharpDbTools/Src/Forms/DatabaseExplorerTreeNode.cs

@ -22,7 +22,7 @@ namespace SharpDbTools.Forms @@ -22,7 +22,7 @@ namespace SharpDbTools.Forms
/// Description of DatabaseExplorerNode.
/// Hold minimal state - access state through the DbModelInfoService
/// </summary>
public class DatabaseExplorerTreeNode: TreeNode, IRebuildable, IRequiresRebuildSource
public class DatabaseExplorerTreeNode: TreeNode, IRebuildable, IRequiresRebuildSource, ISupportsDragDrop
{
public DatabaseExplorerTreeNode(): base("Database Explorer")
{
@ -143,5 +143,31 @@ namespace SharpDbTools.Forms @@ -143,5 +143,31 @@ namespace SharpDbTools.Forms
}
}
}
/// <summary>
/// If a DbModelInfoTreeNode is selected then the desired drag and drop behaviour
/// is to pass the ConnectionString to drop target.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void HandleMouseDownEvent(object sender, MouseEventArgs e)
{
LoggingService.Debug(this.GetType().Name + " handling MouseDownEvent");
TreeView parent = this.TreeView;
TreeNode currentlySelected = parent.SelectedNode;
// If the user has selected a TreeNode for a specific connection, and has the right
// mouse button down, then initiate a drag drop operation
DbModelInfoTreeNode infoNode = currentlySelected as DbModelInfoTreeNode;
if (infoNode != null) {
string logicalConnectionName = infoNode.LogicalConnectionName;
DbModelInfo info = DbModelInfoService.GetDbModelInfo(logicalConnectionName);
string connectionString = info.ConnectionString;
LoggingService.Debug("drag drop operation initiated for ConnectionString: " + connectionString);
if (connectionString != null) {
parent.DoDragDrop(connectionString, DragDropEffects.Copy);
}
}
}
}
}

Loading…
Cancel
Save