private void MoveSelection(int direction)
{
TreeNode tn = this.treeView.SelectedNode;
TreeNode tnParent = tn.Parent;
int treeindex = tnParent.Nodes.IndexOf(tn);
if (tn.Tag is DocTerm)
{
DocTerm docUsage = (DocTerm)tn.Tag;
if (tn.Parent.Tag is DocTerm)
{
DocTerm docEntity = (DocTerm)tnParent.Tag;
int index = docEntity.Terms.IndexOf(docUsage);
index += direction;
treeindex += direction;
docEntity.Terms.Remove(docUsage);
docEntity.Terms.Insert(index, docUsage);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
else
{
// top-level
int index = this.m_project.Terms.IndexOf(docUsage);
index += direction;
treeindex += direction;
this.m_project.Terms.Remove(docUsage);
this.m_project.Terms.Insert(index, docUsage);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
}
else if(tn.Tag is DocConceptRoot)
{
DocModelView dmv = (DocModelView)tn.Parent.Tag;
DocConceptRoot dcr = (DocConceptRoot)tn.Tag;
int index = dmv.ConceptRoots.IndexOf(dcr);
index += direction;
treeindex += direction;
dmv.ConceptRoots.Remove(dcr);
dmv.ConceptRoots.Insert(index, dcr);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
else if (tn.Tag is DocTemplateUsage)
{
DocTemplateUsage docUsage = (DocTemplateUsage)tn.Tag;
if (tnParent.Tag is DocConceptRoot)
{
DocConceptRoot docRoot = (DocConceptRoot)tnParent.Tag;
int index = docRoot.Concepts.IndexOf(docUsage);
index += direction;
treeindex += direction;
docRoot.Concepts.Remove(docUsage);
docRoot.Concepts.Insert(index, docUsage);
}
else if (tnParent.Tag is DocTemplateUsage)
{
DocTemplateUsage docRoot = (DocTemplateUsage)tnParent.Tag;
int index = docRoot.Concepts.IndexOf(docUsage);
index += direction;
treeindex += direction;
docRoot.Concepts.Remove(docUsage);
docRoot.Concepts.Insert(index, docUsage);
}
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
else if (tn.Tag is DocTemplateDefinition)
{
DocTemplateDefinition docUsage = (DocTemplateDefinition)tn.Tag;
if (tn.Parent.Tag is DocTemplateDefinition)
{
DocTemplateDefinition docEntity = (DocTemplateDefinition)tnParent.Tag;
int index = docEntity.Templates.IndexOf(docUsage);
index += direction;
treeindex += direction;
docEntity.Templates.Remove(docUsage);
docEntity.Templates.Insert(index, docUsage);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
else
{
// top-level
int index = this.m_project.Templates.IndexOf(docUsage);
index += direction;
treeindex += direction;
this.m_project.Templates.Remove(docUsage);
this.m_project.Templates.Insert(index, docUsage);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
}
else if (tn.Tag is DocModelView)
{
DocModelView docUsage = (DocModelView)tn.Tag;
int index = this.m_project.ModelViews.IndexOf(docUsage);
index += direction;
treeindex += direction;
this.m_project.ModelViews.Remove(docUsage);
this.m_project.ModelViews.Insert(index, docUsage);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
else if (tn.Tag is DocExchangeDefinition)
{
DocExchangeDefinition docUsage = (DocExchangeDefinition)tn.Tag;
if (tn.Parent.Tag is DocModelView)
{
DocModelView docEntity = (DocModelView)tnParent.Tag;
int index = docEntity.Exchanges.IndexOf(docUsage);
index += direction;
treeindex += direction;
docEntity.Exchanges.Remove(docUsage);
docEntity.Exchanges.Insert(index, docUsage);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
}
else if(tn.Tag is DocAttribute)
{
DocEntity docEnt = (DocEntity)tn.Parent.Tag;
DocAttribute docAttr = (DocAttribute)tn.Tag;
int index = docEnt.Attributes.IndexOf(docAttr);
index += direction;
treeindex += direction;
docEnt.Attributes.Remove(docAttr);
docEnt.Attributes.Insert(index, docAttr);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
else if (tn.Tag is DocWhereRule)
{
DocEntity docEnt = (DocEntity)tn.Parent.Tag;
DocWhereRule docAttr = (DocWhereRule)tn.Tag;
int index = docEnt.WhereRules.IndexOf(docAttr);
index += direction;
treeindex += direction;
docEnt.WhereRules.Remove(docAttr);
docEnt.WhereRules.Insert(index, docAttr);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
else if (tn.Tag is DocPropertySet)
{
DocPropertySet docProp = (DocPropertySet)tn.Tag;
if (tn.Parent.Parent.Tag is DocSchema)
{
DocSchema docSchema = (DocSchema)tnParent.Parent.Tag;
int index = docSchema.PropertySets.IndexOf(docProp);
index += direction;
treeindex += direction;
docSchema.PropertySets.Remove(docProp);
docSchema.PropertySets.Insert(index, docProp);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
}
else if (tn.Tag is DocProperty)
{
DocProperty docProp = (DocProperty)tn.Tag;
if (tn.Parent.Tag is DocPropertySet)
{
DocPropertySet docSchema = (DocPropertySet)tnParent.Tag;
int index = docSchema.Properties.IndexOf(docProp);
index += direction;
treeindex += direction;
docSchema.Properties.Remove(docProp);
docSchema.Properties.Insert(index, docProp);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
}
else if (tn.Tag is DocQuantitySet)
{
DocQuantitySet docProp = (DocQuantitySet)tn.Tag;
if (tn.Parent.Parent.Tag is DocSchema)
{
DocSchema docSchema = (DocSchema)tnParent.Parent.Tag;
int index = docSchema.QuantitySets.IndexOf(docProp);
index += direction;
treeindex += direction;
docSchema.QuantitySets.Remove(docProp);
docSchema.QuantitySets.Insert(index, docProp);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
}
else if (tn.Tag is DocPropertyConstant)
{
DocPropertyConstant docConst = (DocPropertyConstant)tn.Tag;
DocPropertyEnumeration docEnum = (DocPropertyEnumeration)tnParent.Tag;
int index = docEnum.Constants.IndexOf(docConst);
index += direction;
treeindex += direction;
docEnum.Constants.Remove(docConst);
docEnum.Constants.Insert(index, docConst);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
else if (tn.Tag is DocConstant)
{
DocConstant docConst = (DocConstant)tn.Tag;
DocEnumeration docEnum = (DocEnumeration)tnParent.Tag;
int index = docEnum.Constants.IndexOf(docConst);
index += direction;
treeindex += direction;
docEnum.Constants.Remove(docConst);
docEnum.Constants.Insert(index, docConst);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
else if (tn.Tag is DocQuantity)
{
DocQuantity docProp = (DocQuantity)tn.Tag;
if (tn.Parent.Tag is DocQuantitySet)
{
DocQuantitySet docSchema = (DocQuantitySet)tnParent.Tag;
int index = docSchema.Quantities.IndexOf(docProp);
index += direction;
treeindex += direction;
docSchema.Quantities.Remove(docProp);
docSchema.Quantities.Insert(index, docProp);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
}
else if (tn.Tag is DocExample)
{
DocExample docUsage = (DocExample)tn.Tag;
if (tn.Parent.Tag is DocExample)
{
DocExample docEntity = (DocExample)tnParent.Tag;
int index = docEntity.Examples.IndexOf(docUsage);
index += direction;
treeindex += direction;
docEntity.Examples.Remove(docUsage);
docEntity.Examples.Insert(index, docUsage);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
else
{
// top-level
int index = this.m_project.Examples.IndexOf(docUsage);
index += direction;
treeindex += direction;
this.m_project.Examples.Remove(docUsage);
this.m_project.Examples.Insert(index, docUsage);
tnParent.Nodes.Remove(tn);
tnParent.Nodes.Insert(treeindex, tn);
}
}
this.treeView.SelectedNode = tn;
}