Browse Source

DbConnection tree now updates down to table->column level

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2956 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Dickon Field 18 years ago
parent
commit
f08371fa8b
  1. 102
      src/AddIns/Misc/ServerTools/ColumnNode.cs
  2. 54
      src/AddIns/Misc/ServerTools/DbControlController.cs
  3. 35
      src/AddIns/Misc/ServerTools/FieldNode.cs
  4. 4
      src/AddIns/Misc/ServerTools/ICSharpCode.ServerTools.csproj
  5. 59
      src/AddIns/Misc/ServerTools/ItemCollectionExtender.cs
  6. 72
      src/AddIns/Misc/ServerTools/TreeViewItemExtender.cs

102
src/AddIns/Misc/ServerTools/ColumnNode.cs

@ -0,0 +1,102 @@ @@ -0,0 +1,102 @@
/*
* Created by SharpDevelop.
* User: dickon
* Date: 07/02/2008
* Time: 15:58
*
*
*/
using System;
using System.ComponentModel;
using System.Windows.Controls;
namespace ICSharpCode.ServerTools
{
/// <summary>
/// Description of ColumnNode.
/// </summary>
public class ColumnNode: TreeViewItem
{
private string _name;
private string _type;
private string _length;
private string _nullable;
private string _precision;
private string _scale;
public ColumnNode() {
}
public ColumnNode(string name,
string type,
string length,
string nullable,
string precision,
string scale)
{
_name = name;
_type = type;
_length = length;
_nullable = nullable;
_precision = precision;
_scale = scale;
}
[Browsable(true)]
public string FieldName {
get {
return this._name;
}
set {
this._name = value;
}
}
public string Type {
get {
return this._type;
}
set {
this._type = value;
}
}
public string Length {
get {
return this._type;
}
set {
this._type = value;
}
}
public string Nullable {
get {
return this._nullable;
}
set {
this._nullable = value;
}
}
public string Precision {
get {
return this._precision;
}
set {
this._precision = value;
}
}
public string Scale {
get {
return this._scale;
}
set {
this._scale = value;
}
}
}
}

54
src/AddIns/Misc/ServerTools/DbControlController.cs

@ -12,6 +12,7 @@ using System.Windows.Controls; @@ -12,6 +12,7 @@ using System.Windows.Controls;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Configuration;
using System.Windows.Threading;
using MyMeta;
@ -35,7 +36,7 @@ namespace ICSharpCode.ServerTools @@ -35,7 +36,7 @@ namespace ICSharpCode.ServerTools
/// Creates or refreshes the tree of database objects below the DbConnectionNode
/// </summary>
/// <param name="dbNode"></param>
public void UpdateDbConnectionNode(DbConnectionNode dbNode, ConnectionStringSettings s)
private void UpdateDbConnectionNode(DbConnectionNode dbNode, ConnectionStringSettings s)
{
// update the TablesNode
@ -45,7 +46,7 @@ namespace ICSharpCode.ServerTools @@ -45,7 +46,7 @@ namespace ICSharpCode.ServerTools
}
public void UpdateTablesNode(TablesNode tablesNode, ConnectionStringSettings s)
private void UpdateTablesNode(TablesNode tablesNode, ConnectionStringSettings s)
{
// get a list of table names for the current connection to work with
@ -66,18 +67,43 @@ namespace ICSharpCode.ServerTools @@ -66,18 +67,43 @@ namespace ICSharpCode.ServerTools
dbName = (String)o;
IDatabase db = dbs[dbName];
ITables tables = db.Tables;
List<string> tableNames = new List<string>();
foreach (ITable t in tables) {
// yes, much TODO: this does not update, it just adds
TableNode tableNode = new TableNode();
tableNode.Header = t.Alias;
tablesNode.Items.Add(tableNode);
}
tableNames.Add(t.Alias);
TableNode tableNode = (TableNode)tablesNode.GetItemWithHeader(t.Alias);
if (tableNode == null) {
tableNode = new TableNode();
tableNode.Header = t.Alias;
tablesNode.Items.Add(tableNode);
}
this.UpdateTableNode(tableNode, t);
}
tablesNode.RemoveItemsWithHeaderNotIn(tableNames);
}
}
public void UpdateTableNode(DbConnectionNode dbNode, string connectionName)
private void UpdateTableNode(TableNode tableNode, ITable table)
{
IColumns columns = table.Columns;
List<string> columnNames = new List<string>();
foreach (IColumn column in columns) {
string columnName = column.Alias;
columnNames.Add(columnName);
ColumnNode columnNode = (ColumnNode)tableNode.GetItemWithHeader(columnName);
if (columnNode == null) {
columnNode = new ColumnNode();
columnNode.Header = columnName;
tableNode.Items.Add(columnNode);
}
}
}
private void UpdateColumnNode(ColumnNode columnNode, IColumn column)
{
columnNode.Type = column.DataTypeName;
columnNode.FieldName = column.Alias;
// TODO: assign other properties
}
/// <summary>
@ -91,6 +117,11 @@ namespace ICSharpCode.ServerTools @@ -91,6 +117,11 @@ namespace ICSharpCode.ServerTools
public void UpdateDbConnectionsNode()
{
log.Debug("updating connections node");
if(!_dbConnectionsNode.Dispatcher.CheckAccess()) {
_dbConnectionsNode.Dispatcher.Invoke(DispatcherPriority.Normal,
new UpdateDbConnectionsNodeDelegate(UpdateDbConnectionsNode));
}
ConnectionStringSettingsCollection c
= OleDbConnectionService.GetConnectionSettingsCollection();
@ -99,10 +130,13 @@ namespace ICSharpCode.ServerTools @@ -99,10 +130,13 @@ namespace ICSharpCode.ServerTools
foreach (ConnectionStringSettings s in c)
{
string settingsName = s.Name;
log.Debug("got ConnectionStringSettings with name: " + settingsName);
headers.Add(settingsName);
DbConnectionNode dbNode = (DbConnectionNode)_dbConnectionsNode.GetItemWithHeader(settingsName);
log.Debug("got DbConnectionNode with name: " + (dbNode == null? null:dbNode.Header));
if (dbNode == null) {
// initial state for a new connection is always closed I think
log.Debug("creating new DbConnectionNode for settings with name: " + settingsName);
dbNode = new DbConnectionNode(settingsName);
_dbConnectionsNode.Items.Add(dbNode);
}
@ -111,6 +145,8 @@ namespace ICSharpCode.ServerTools @@ -111,6 +145,8 @@ namespace ICSharpCode.ServerTools
_dbConnectionsNode.RemoveItemsWithHeaderNotIn(headers);
}
public delegate void UpdateDbConnectionsNodeDelegate();
/// <summary>
/// Uses the DataLink dialog to define a new Oledb connection string,
/// test it, and adds it to config.

35
src/AddIns/Misc/ServerTools/FieldNode.cs

@ -1,35 +0,0 @@ @@ -1,35 +0,0 @@
/*
* Created by SharpDevelop.
* User: dickon
* Date: 07/02/2008
* Time: 15:58
*
*
*/
using System;
using System.Windows.Controls;
namespace ICSharpCode.ServerTools
{
/// <summary>
/// Description of FieldNode.
/// </summary>
public class FieldNode: TreeViewItem
{
private string _name;
private string _type;
public FieldNode(string name, string type)
{
_name = name;
_type = type;
}
public string FieldName {
get {
return this._name;
}
}
}
}

4
src/AddIns/Misc/ServerTools/ICSharpCode.ServerTools.csproj

@ -112,10 +112,10 @@ @@ -112,10 +112,10 @@
<Compile Include="DbConnectionNode.cs" />
<Compile Include="DbConnectionsNode.cs" />
<Compile Include="DbControlController.cs" />
<Compile Include="FieldNode.cs" />
<Compile Include="ColumnNode.cs" />
<Compile Include="FunctionNode.cs" />
<Compile Include="FunctionsNode.cs" />
<Compile Include="ItemCollectionExtender.cs" />
<Compile Include="TreeViewItemExtender.cs" />
<Compile Include="Properties\DbConnectionsNode.cs" />
<Compile Include="ServerControl.xaml.cs">
<DependentUpon>ServerControl.xaml</DependentUpon>

59
src/AddIns/Misc/ServerTools/ItemCollectionExtender.cs

@ -1,59 +0,0 @@ @@ -1,59 +0,0 @@
/*
* Created by SharpDevelop.
* User: dickon
* Date: 07/02/2008
* Time: 16:30
*
*
*/
using System;
using System.Windows.Controls;
using System.Collections.Generic;
namespace ICSharpCode.ServerTools
{
/// <summary>
/// Description of HeaderIndexedTreeViewItem.
/// </summary>
public static class ItemCollectionExtender
{
public static Object GetItemWithHeader(this TreeViewItem t, string header)
{
foreach(Object o in t.Items) {
HeaderedContentControl h = o as HeaderedContentControl;
if (h != null) {
if (h.Header.Equals(header)) {
return h;
}
}
}
return null;
}
public static void RemoveItemWithHeader(this TreeViewItem t, string header)
{
foreach(Object o in t.Items) {
HeaderedContentControl h = o as HeaderedContentControl;
if (h != null) {
if (h.Header.Equals(header)) {
t.Items.Remove(h);
}
}
}
}
public static void RemoveItemsWithHeaderNotIn(this TreeViewItem t, IList<string> headers)
{
foreach(Object o in t.Items) {
HeaderedContentControl h = o as HeaderedContentControl;
if (h != null) {
string header = h.Header as string;
if (!(headers.Contains(header))) {
t.Items.Remove(h);
}
}
}
}
}
}

72
src/AddIns/Misc/ServerTools/TreeViewItemExtender.cs

@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
/*
* Created by SharpDevelop.
* User: dickon
* Date: 07/02/2008
* Time: 16:30
*
*
*/
using System;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Collections.Generic;
using log=ICSharpCode.Core.LoggingService;
namespace ICSharpCode.ServerTools
{
/// <summary>
/// Description of HeaderIndexedTreeViewItem.
/// </summary>
public static class TreeViewItemExtender
{
public static TreeViewItem GetItemWithHeader(this TreeViewItem t, string header)
{
log.Debug("looking for item with name: " + header);
foreach(Object o in t.Items) {
TreeViewItem item = o as TreeViewItem;
if (item != null) {
string h = (string)item.Header;
log.Debug("looking at item with name: " + h);
if (h.Equals(header)) {
log.Debug("found item with name: " + header);
return item;
}
} else {
MessageBox.Show("While navigating the db connection tree an object not of type TreeViewItem was found",
"Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
log.Error("found and item in the DbConnectionsNode tree that is not a TreeViewItem");
}
}
log.Debug("could not find item with name: " + header);
return null;
}
public static void RemoveItemWithHeader(this TreeViewItem t, string header)
{
foreach(Object o in t.Items) {
HeaderedContentControl h = o as HeaderedContentControl;
if (h != null) {
if (h.Header.Equals(header)) {
log.Debug("removing item with name: " + header);
t.Items.Remove(h);
}
}
}
}
public static void RemoveItemsWithHeaderNotIn(this TreeViewItem t, IList<string> headers)
{
foreach(Object o in t.Items) {
HeaderedContentControl h = o as HeaderedContentControl;
if (h != null) {
string header = h.Header as string;
if (!(headers.Contains(header))) {
log.Debug("item with name: " + header + " was not in the keep-list, so removing it");
t.Items.Remove(h);
}
}
}
}
}
}
Loading…
Cancel
Save