Skip to content

Instantly share code, notes, and snippets.

@EliJDonahue
Created November 3, 2016 23:11
Show Gist options
  • Save EliJDonahue/532ed82d4d86d9722ee1c2631ee8f330 to your computer and use it in GitHub Desktop.
Save EliJDonahue/532ed82d4d86d9722ee1c2631ee8f330 to your computer and use it in GitHub Desktop.
[ArasLabs/override-default-structure-browser] Adds the classification property to the items of the same type as the context item
XmlElement inItem = (XmlElement)this.dom.SelectSingleNode("//Item[@type='Method' and @action='GetItemsForStructureBrowser']/Item");
if (inItem != null)
{
XmlDocument resDOM = Aras.Server.Core.XmlProxy.CreateNewXMLDocument();
XmlElement result = Aras.Server.Core.XmlProxy.MakeBorders(resDOM);
//Comment out call to standard structure browser
//Aras.Server.Core.StructureBrowser sb = new Aras.Server.Core.StructureBrowser(ref CCO);
//Call for custom browser
CustomStructureBrowser sb = new CustomStructureBrowser(CCO);
//Add property for getting Class
sb.itemPropertiesToSelect.Add(inItem.GetAttribute("type"), new string[] {"classification" });
int levelsToSelect;
if (!Int32.TryParse(inItem.GetAttribute("levels"), out levelsToSelect))
levelsToSelect = 2;
result.InnerXml = sb.GetItemsForStructureBrowser(inItem.GetAttribute("type"),
inItem.GetAttribute("id"),
inItem.GetAttribute("compareToITName"),
inItem.GetAttribute("compareToId"),
levelsToSelect
);
Aras.IOM.Item resItem = this.newItem("");
resItem.loadAML(resDOM.OuterXml);
return resItem;
}
else
return null;
// StructureBrowser class can be overriden.
// Methods available for overriding: GetKeyedNameForItem, CompareItems.
}
class CustomStructureBrowser : Aras.Server.Core.StructureBrowser
{
public CustomStructureBrowser(Aras.Server.Core.CallContext CCO) : base(ref CCO){}
public override Aras.Server.Core.StructureItem GetNewStructureItem(string itemTypeName, Aras.Server.Core.InnovatorDataSet rs)
{
return new CustomStructureItem(rs); //Call to get our custom StructureItem
}
}
class CustomStructureItem : Aras.Server.Core.StructureItem
{
private string _classification;
public CustomStructureItem(Aras.Server.Core.InnovatorDataSet rs) : base(rs)
{
try
{
_classification = rs["classification", ""].ToString(); // property added by above
}
catch {} // property not returned for this ItemType
}
public override string KeyedName
{
get
{
string kn = base.KeyedName;
if (String.IsNullOrEmpty(this._classification))
{
// If property is empty - return KeyedName as is. (standard look)
return kn;
}
else
{
return kn + " Class: " + this._classification;
}
}
}
// NOTE: Do not close the last curly brace.
// This is taken care of in the template that runs C# server methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment