2012-01-24 03:01:53 +04:00
|
|
|
|
//
|
|
|
|
|
// TreeStoreBackend.cs
|
|
|
|
|
//
|
|
|
|
|
// Author:
|
|
|
|
|
// Luís Reis <luiscubal@gmail.com>
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2011 Luís Reis
|
|
|
|
|
//
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
//
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
//
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
using System;
|
2012-02-10 05:57:45 +04:00
|
|
|
|
using System.Collections.Generic;
|
2012-01-24 03:01:53 +04:00
|
|
|
|
using Xwt.Backends;
|
2012-03-25 22:13:46 +04:00
|
|
|
|
using Xwt.WPFBackend.Utilities;
|
|
|
|
|
using SWC=System.Windows.Controls;
|
2012-01-24 03:01:53 +04:00
|
|
|
|
|
|
|
|
|
namespace Xwt.WPFBackend
|
|
|
|
|
{
|
2012-02-10 05:57:45 +04:00
|
|
|
|
class TreeNode : TreePosition
|
|
|
|
|
{
|
2012-03-25 22:13:46 +04:00
|
|
|
|
public IList<Tuple<TreeViewBackend, SWC.ItemsControl>> TreeViewData = new List<Tuple<TreeViewBackend, SWC.ItemsControl>> ();
|
2012-02-10 05:57:45 +04:00
|
|
|
|
public object[] Values;
|
|
|
|
|
public IList<TreeNode> Children = new List<TreeNode>();
|
|
|
|
|
public TreeNode Previous;
|
|
|
|
|
public TreeNode Next;
|
|
|
|
|
public TreeNode Parent;
|
|
|
|
|
|
|
|
|
|
public TreeNode LastChild
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Children.Count == 0 ? null : Children[Children.Count - 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-24 03:01:53 +04:00
|
|
|
|
public class TreeStoreBackend: ITreeStoreBackend
|
|
|
|
|
{
|
|
|
|
|
public event EventHandler<TreeNodeEventArgs> NodeInserted;
|
|
|
|
|
public event EventHandler<TreeNodeChildEventArgs> NodeDeleted;
|
|
|
|
|
public event EventHandler<TreeNodeEventArgs> NodeChanged;
|
|
|
|
|
public event EventHandler<TreeNodeOrderEventArgs> NodesReordered;
|
|
|
|
|
|
2012-02-10 05:57:45 +04:00
|
|
|
|
private Type[] columnTypes;
|
|
|
|
|
private TreeNode rootNode = new TreeNode ();
|
|
|
|
|
|
2012-01-24 03:01:53 +04:00
|
|
|
|
public void Initialize (Type[] columnTypes)
|
|
|
|
|
{
|
2012-02-10 05:57:45 +04:00
|
|
|
|
this.columnTypes = new Type [columnTypes.Length];
|
|
|
|
|
for (int n = 0; n < columnTypes.Length; n++)
|
|
|
|
|
{
|
|
|
|
|
this.columnTypes[n] = columnTypes[n];
|
|
|
|
|
}
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
2012-04-04 12:18:34 +04:00
|
|
|
|
public void InitializeBackend (object frontend)
|
2012-01-24 03:01:53 +04:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear ()
|
|
|
|
|
{
|
2012-02-10 05:57:45 +04:00
|
|
|
|
rootNode.Children.Clear ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal TreeNode RootNode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return rootNode;
|
|
|
|
|
}
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TreePosition AddChild (TreePosition pos)
|
|
|
|
|
{
|
2012-02-10 05:57:45 +04:00
|
|
|
|
TreeNode parent = pos as TreeNode ?? rootNode;
|
|
|
|
|
TreeNode node = new TreeNode();
|
|
|
|
|
node.Previous = parent.LastChild;
|
|
|
|
|
node.Values = new object[columnTypes.Length];
|
|
|
|
|
node.Parent = parent;
|
|
|
|
|
if (parent.LastChild != null)
|
|
|
|
|
parent.LastChild.Next = node;
|
|
|
|
|
parent.Children.Add (node);
|
2012-03-25 22:13:46 +04:00
|
|
|
|
|
|
|
|
|
foreach (Tuple<TreeViewBackend, SWC.ItemsControl> parentData in parent.TreeViewData)
|
|
|
|
|
{
|
|
|
|
|
MultiColumnTreeViewItem childItem = parentData.Item1.GenerateTreeViewItem (node);
|
|
|
|
|
node.TreeViewData.Add (Tuple.Create<TreeViewBackend, SWC.ItemsControl>(parentData.Item1, childItem));
|
|
|
|
|
parentData.Item2.Items.Add (childItem);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-10 05:57:45 +04:00
|
|
|
|
return node;
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TreePosition GetPrevious (TreePosition pos)
|
|
|
|
|
{
|
2012-02-10 05:57:45 +04:00
|
|
|
|
TreeNode node = pos as TreeNode;
|
|
|
|
|
return node.Previous;
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TreePosition GetNext (TreePosition pos)
|
|
|
|
|
{
|
2012-02-10 05:57:45 +04:00
|
|
|
|
TreeNode node = pos as TreeNode;
|
|
|
|
|
return node.Next;
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetValue (TreePosition pos, int column, object value)
|
|
|
|
|
{
|
2012-02-10 05:57:45 +04:00
|
|
|
|
TreeNode node = pos as TreeNode;
|
2012-03-25 22:13:46 +04:00
|
|
|
|
|
|
|
|
|
if (node == rootNode)
|
|
|
|
|
throw new InvalidOperationException("Root node can not have data");
|
|
|
|
|
|
2012-02-10 05:57:45 +04:00
|
|
|
|
node.Values[column] = value;
|
2012-03-25 22:13:46 +04:00
|
|
|
|
|
|
|
|
|
foreach (var treeViewData in node.TreeViewData)
|
|
|
|
|
{
|
|
|
|
|
//We can perform this cast since Item2 is always a MultiColumnTreeViewItem for any non-root node.
|
|
|
|
|
MultiColumnTreeViewItem treeViewItem = (MultiColumnTreeViewItem)treeViewData.Item2;
|
|
|
|
|
treeViewItem.UpdateColumn (column, value);
|
|
|
|
|
}
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public object GetValue (TreePosition pos, int column)
|
|
|
|
|
{
|
2012-02-10 05:57:45 +04:00
|
|
|
|
TreeNode node = pos as TreeNode;
|
|
|
|
|
return node.Values[column];
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TreePosition GetParent (TreePosition pos)
|
|
|
|
|
{
|
2012-02-10 05:57:45 +04:00
|
|
|
|
TreeNode node = pos as TreeNode;
|
|
|
|
|
TreeNode parent = node.Parent;
|
|
|
|
|
if (parent == rootNode)
|
|
|
|
|
return null;
|
|
|
|
|
return parent;
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GetChildrenCount (TreePosition pos)
|
|
|
|
|
{
|
2012-02-10 05:57:45 +04:00
|
|
|
|
TreeNode node = pos as TreeNode;
|
|
|
|
|
return node.Children.Count;
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TreePosition GetChild (TreePosition pos, int index)
|
|
|
|
|
{
|
2012-03-31 02:12:58 +04:00
|
|
|
|
if (pos == null)
|
|
|
|
|
return RootNode.Children [index];
|
|
|
|
|
|
2012-02-10 05:57:45 +04:00
|
|
|
|
TreeNode node = pos as TreeNode;
|
|
|
|
|
return node.Children[index];
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Remove (TreePosition pos)
|
|
|
|
|
{
|
2012-03-25 22:13:46 +04:00
|
|
|
|
TreeNode node = pos as TreeNode;
|
|
|
|
|
|
|
|
|
|
if (node == rootNode)
|
|
|
|
|
throw new InvalidOperationException ("Can not remove root node");
|
|
|
|
|
|
|
|
|
|
node.Parent.Children.Remove (node);
|
|
|
|
|
|
|
|
|
|
foreach (var treeViewData in node.TreeViewData)
|
|
|
|
|
{
|
|
|
|
|
var item = treeViewData.Item2;
|
|
|
|
|
var parent = item.Parent;
|
|
|
|
|
((SWC.ItemsControl)parent).Items.Remove (item);
|
|
|
|
|
}
|
2012-01-24 03:01:53 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TreePosition InsertBefore (TreePosition pos)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TreePosition InsertAfter (TreePosition pos)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Type[] ColumnTypes
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EnableEvent (object eventId)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisableEvent (object eventId)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|