/// <summary> /// Creates a new policy for the policy document selected. /// </summary> /// <param name="sender">The mainTree control.</param> /// <param name="args">The arguements for the event.</param> private void CreatePolicyFromDocument( object sender, EventArgs args ) { PolicyDocument policyDocumentNode = (PolicyDocument)mainTree.SelectedNode; pol.PolicyDocumentReadWrite policyDocument = policyDocumentNode.PolicyDocumentDefinition; // Create a new policy pol.PolicyElementReadWrite newPolicy = new pol.PolicyElementReadWrite( "urn:newpolicy", "[TODO: add a description]", null, new pol.RuleReadWriteCollection(), RuleCombiningAlgorithms.FirstApplicable, new pol.ObligationReadWriteCollection(), string.Empty, null, null, null, XacmlVersion.Version11 ); //TODO: check version policyDocument.Policy = newPolicy ; // Create a new node Policy policyNode = new Policy( newPolicy ); // Add the tree node. policyDocumentNode.Nodes.Add( policyNode ); // Set the font so the user knows the item was changed policyNode.NodeFont = new Font( mainTree.Font, FontStyle.Bold ); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mainTree_BeforeSelect(object sender, TreeViewCancelEventArgs e) { // Check if the control have been modified if( mainPanel.Controls.Count != 0 ) { if( !(mainPanel.Controls[0] is XmlViewer) ) { BaseControl baseControl = mainPanel.Controls[0] as BaseControl; mainTree.SelectedNode.NodeFont = new Font( mainTree.Font, FontStyle.Regular ); NoBoldNode oNode = null; if( baseControl is CustomControls.PolicySet ) { oNode = new PolicySet(((CustomControls.PolicySet)baseControl).PolicySetElement); } else if( baseControl is CustomControls.PolicySet ) { oNode = new Policy(((CustomControls.Policy)baseControl).PolicyElement); } else if( baseControl is CustomControls.Rule ) { oNode = new Rule(((CustomControls.Rule)baseControl).RuleElement); } else if( baseControl is CustomControls.TargetItem ) { pol.TargetItemBaseReadWrite element = ((CustomControls.TargetItem)baseControl).TargetItemBaseElement; oNode = new TargetItem(element); } else if( baseControl is CustomControls.Obligations ) { oNode = new Obligations(((CustomControls.Obligations)baseControl).ObligationsElement); } else if( baseControl is ContextCustomControls.Attribute ) { oNode = new Attribute( ((ContextCustomControls.Attribute)baseControl).AttributeElement ); } else if( baseControl is ContextCustomControls.Resource ) { oNode = new Resource( ((ContextCustomControls.Resource)baseControl).ResourceElement ); } if( oNode != null ) { mainTree.SelectedNode = oNode; mainTree.SelectedNode.Text = oNode.Text; } } } }