Skip to content

Instantly share code, notes, and snippets.

@EliJDonahue
Created November 3, 2016 23:41
Show Gist options
  • Save EliJDonahue/806a47b8ce19bd6fc35ef302c5927bb8 to your computer and use it in GitHub Desktop.
Save EliJDonahue/806a47b8ce19bd6fc35ef302c5927bb8 to your computer and use it in GitHub Desktop.
[ArasLabs/override-default-structure-browser] Display the classification property for Part, Document, and CAD
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);
// HashSet defined below, add properties for ItemTypes specified.
foreach (string specifiedType in SpecifiedItemTypes)
{
sb.itemPropertiesToSelect.Add(specifiedType, 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.
}
public HashSet<string> SpecifiedItemTypes = new HashSet<string>
{
"Part",
"Document",
"CAD"
};
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)
{
// Call to get our custom StructureItem
return new CustomStructureItem(rs);
}
}
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