using umbraco.controls.Tree;
using umbraco.editorControls.MultiNodeTreePicker;
namespace Orc.example.plugin.dialogs.TreeExample
{
public class ExampleContentTree : FilteredContentTree
{
public ExampleContentTree(string app) : base(app) { }
public override int StartNodeID
{
get { return 1077; }
}
}
public class ExampleContentTreeControl : CustomTreeControl
{
public ExampleContentTreeControl()
{
ShowContextMenu = false;
Height = 300;
TreeType = typeof (ExampleContentTree).Name;
FunctionToCall = "onNodeSelected";
}
}
}
using System.Linq;
using Umbraco.Core;
using Umbraco.Web;
using umbraco.cms.presentation.Trees;
namespace Orc.example.plugin.dialogs.TreeExample
{
public class CustomTreeExampleInitializer : IApplicationEventHandler
{
public void OnApplicationInitialized(UmbracoApplication app, ApplicationContext ctx)
{
// get a handle on the main content tree
var contentTree = TreeDefinitionCollection.Instance.Single(x => x.Tree.Alias.ToUpper() == "CONTENT");
// create our tree type
var filteredTreeType = typeof (ExampleContentTree);
// make the definition
var filteredContentTreeDefinition = new TreeDefinition(filteredTreeType,
new umbraco.BusinessLogic.ApplicationTree(true, false, 0, contentTree.Tree.ApplicationAlias, filteredTreeType.Name, null, null, null, null, null, null),
contentTree.App);
// add it to the collection
TreeDefinitionCollection.Instance.Add(filteredContentTreeDefinition);
}
public void OnApplicationStarting(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
}
public void OnApplicationStarted(UmbracoApplication httpApplication, ApplicationContext applicationContext)
{
}
}
}
using System;
using Orc.example.plugin.dialogs.TreeExample;
namespace Orc.example.plugin.dialogs
{
public partial class CustomTreeExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TreeContainer.Controls.Add(new ExampleContentTreeControl());
}
}
// once the user has selected their node, they click ok and this method is fired
protected void DisplaySelectedNodeId(object sender, EventArgs e)
{
// here we'll just output the selected node id as text;
var selectedNodeId = SelectedNode.Value;
// ... do stuff with selected node id ...
// for our example, update the UI and show the selected node id
TreeAndButtons.Visible = false;
Results.Visible = true;
resultsText.Text = selectedNodeId;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomTreeExample.aspx.cs"
Inherits="Orc.example.plugin.dialogs.CustomTreeExample" MasterPageFile="/umbraco/masterpages/umbracoDialog.Master" %>
<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %>
<%@ Register TagPrefix="treepicker" Namespace="umbraco.uicontrols.TreePicker" Assembly="controls" %>
<%@ Register TagPrefix="umbraco" TagName="TreeControl" Src="~/umbraco/controls/Tree/TreeControl.ascx" %>
<asp:Content ContentPlaceHolderID="body" runat="server">
<script type="text/javascript">
function onNodeSelected(id)
{
document.getElementById("<%= SelectedNode.ClientID %>").value = id;
}
</script>
<% // here we add a hidden field to store the nodeID in during postback %>
<asp:HiddenField ID="SelectedNode" runat="server" />
<% // here we create a very simple ui container %>
<asp:Panel runat="server" ID="TreeAndButtons">
<% // we create a pane to hold the tree %>
<cc1:Pane runat="server" Visible="true">
<% // add our usual umbraco ui classes %>
<div style="padding-top: 10px;" class="guiDialogNormal">
<% // here we actually want to render the tree (the tree is injected into the PropertyPanel as a Child Control) %>
<cc1:PropertyPanel ID="TreeContainer" runat="server" Style="overflow: auto; height: 220px;position: relative;">
</cc1:PropertyPanel>
</div>
</cc1:Pane>
<% // now lets help our users with some basic ui commands%>
<p> Pick a node and click ok!
<% // user will select their node, and then click ok %>
<asp:Button ID="OkButton" runat="server" Text="ok" OnClick="DisplaySelectedNodeId" />
<em>or</em>
<% // create a cancel button %>
<a href="#" onclick="UmbClientMgr.closeModalWindow()">Cancel</a>
</p>
</asp:Panel>
<asp:Panel runat="server" ID="Results" Visible="False">
Do stuff with node : <asp:Literal runat="server" ID="resultsText"></asp:Literal>
</asp:Panel>
</asp:Content>