public static void SelectCompartmentItem(DiagramDocView docView, ModelElement compartmentOwner, string compartmentListName, ModelElement compartmentItem) { var shapeElement = DiagramUtil.GetModelElementFirstShape(compartmentOwner); ElementListCompartment compartment = null; foreach (ShapeElement shape in shapeElement.NestedChildShapes) { if (shape is ElementListCompartment) { if ((shape as ElementListCompartment).Name == compartmentListName) { compartment = (ElementListCompartment)shape; } } } if (compartment != null) { var listField = compartment.ListField; var child = listField.FindFirstChild(compartment, true); while (child != null && !child.RepresentedElements.OfType <ModelElement>().Any(element => element == compartmentItem)) { child = listField.FindNextChild(child, true); } var selectedShapesCollection = docView.CurrentDesigner.Selection; selectedShapesCollection.Clear(); selectedShapesCollection.Set(child); } }
private void ObjectModelBrowserOnDoubleClick(object sender, EventArgs eventArgs) { // Get the node selected in the model explorer tree ModelElementTreeNode node = (this.ObjectModelBrowser.SelectedNode as ModelElementTreeNode); if (node != null) { // Get the corresponding model element ModelElement element = node.ModelElement; if (element != null) { // Get the corresponding shape // If the model element is in a compartment the result will be null ShapeElement shape = DiagramUtil.GetModelElementFirstShape(element); if (shape == null) { // If the element is in a compartment, try to get the parent model element to select that ModelElement parentElement = GetCompartmentElementFirstParent(element); if (parentElement != null) { // Get the corresponding shape shape = DiagramUtil.GetModelElementFirstShape(parentElement); } } // Select the shape if (shape != null) { SelectShape(shape, this.ModelingDocData); } } } }