How do I select a DSL shape via API
- Hi All
I want select particular Shape programmatically...
public void SelectShape(ModelElement modelElement){
ShapeElement modelElementShape = PresentationViewsSubject .GetPresentation(modelElement).FirstOrDefault() as ShapeElement ;
Diagram diagram = modelElement.Store.ElementDirectory.AllElements.OfType<Diagram >().FirstOrDefault();
DiagramItem diagramItem = new DiagramItem (modelElementShape);
diagram.ActiveDiagramView.Selection.Set(diagramItem);
}
but diagram.ActiveDiagramView value is null ..
what is wrong with my code?
Thank You
Atul Katare
_____________________________
Build Relationship Dynamically
Respuestas
- Hello, DslTools generate a CommandSet class in your DslPackage that you can extend with your own commands. I suppose you want to select the shape responding to some command action. So there, in YourLanguageCommandSet, you can get Store by this.CurrentDocData.Store. Regards!!
RubenBrenes- Marcado como respuestaRong-Chun ZhangMSFT, Moderadormartes, 07 de julio de 2009 9:52
Todas las respuestas
- Hi Atul,
could you please provide some additional information, especially with respect to the context you are invoking this method from and your general porpuse? I tried to reproduce the issue and diagram.ActiveDiagramView returned the correct object.
Kind regards
Sebastian - Hi Sebastian
I will get Model Element using
Store store = new Store(typeof(CoreDomainModel), typeof(CoreDesignSurfaceDomainModel),
typeof(ExampleDomainModel));
using (Transaction txtTransaction = store.TransactionManager.BeginTransaction("Root Transaction"))
{
ExampleModel ExampleRoot = ExampleSerializationHelper.Instance.LoadModelAndDiagram
(store, FilePath, FilePath + ".diagram", null, null);
ModelElement modelElement= ExampleRoot .ExampleElement.First();
// then I will call SelectShape Method
Selectshape(modelElement);
txtTransaction .Commit();
}
public void SelectShape(ModelElement modelElement){
ShapeElement modelElementShape = PresentationViewsSubject .GetPresentation(modelElement).FirstOrDefault() as ShapeElement ;
Diagram diagram = modelElement.Store.ElementDirectory.AllElements.OfType<Diagram >().FirstOrDefault();
DiagramItem diagramItem = new DiagramItem (modelElementShape);
diagram.ActiveDiagramView.Selection.Set(diagramItem);
}
Thank You
AtulKatare
_________________________________
Build Relationship Dynamically - Hello, you are opening a model into a new Store, so this Store doesn't have the current active diagram view. I think if you take from the commandset the current opened store and then you get the active diagram view from the diagram, this object wouldn't be null. Regards!!
RubenBrenes- Propuesto como respuestaRubenJMarrufo jueves, 02 de julio de 2009 15:34
- Hi Ruben
How to get Store from CommandSet class?
CommandSet class constructor require IServiceProvider, how to pass value?
Thank You.. - Hello, DslTools generate a CommandSet class in your DslPackage that you can extend with your own commands. I suppose you want to select the shape responding to some command action. So there, in YourLanguageCommandSet, you can get Store by this.CurrentDocData.Store. Regards!!
RubenBrenes- Marcado como respuestaRong-Chun ZhangMSFT, Moderadormartes, 07 de julio de 2009 9:52
- Dude, you should not create a new store for this requirement.
Instead, here you go!
1. Go to your DSL Package
2. Create a partial class for your CommandSet
3. Write a new method, let the name to be what ever you want
4. Write your logic based on this.
I'll give you a sample piece of code for select all command which will work directly for you.
Try this; You have everything selected on Select All (Ctl + A)namespace YourNameSpace { /// <summary> /// Partial implementation provides the status and command /// handlers for Select All Menu /// </summary> internal partial class YourCommandSet { /// <summary> /// Handler for select all /// </summary> /// <param name="sender">the object that invokes the method as object</param> /// <param name="e">event arguments as EventArgs</param> protected override void ProcessOnMenuSelectAllCommand() { base.ProcessOnMenuSelectAllCommand(); List<ShapeElement> lstSelectableElements = this.GetSelectableElements() ?? new List<ShapeElement>(); foreach (ShapeElement oShape in lstSelectableElements) { if (oShape.ModelElement != null) { DiagramItem diagramItem = new DiagramItem(oShape); if (this.CurrentYourModelDocView!= null && this.CurrentYourModelDocView.Diagram != null && this.CurrentYourModelDocView.Diagram.ActiveDiagramView != null && this.CurrentYourModelDocView.Diagram.ActiveDiagramView.DiagramClientView != null) { this.CurrentYourModelDocView.Diagram.ActiveDiagramView.DiagramClientView.Selection.Add(diagramItem); } } } this.CurrentDocView.SetSelectedComponents(lstSelectableElements); } /// <summary> /// Status handler for select all /// </summary> /// <param name="command">command invokes the method</param> protected override void ProcessOnStatusSelectAllCommand(MenuCommand command) { base.ProcessOnStatusSelectAllCommand(command); List<ShapeElement> lstSelectableElements = this.GetSelectableElements() ?? new List<ShapeElement>(); command.Enabled = lstSelectableElements.Count > 0; } /// <summary> /// Gets the list of the selectable elements /// </summary> /// <returns>gets the list of the selectable shape elements as generic collection of shape element</returns> private List<ShapeElement> GetSelectableElements() { ReadOnlyCollection<ShapeElement> lstShapeElements = null; List<ShapeElement> lstSelectableElements = null; Store oStore = null; oStore = this.CurrentYourModelDocView.Diagram.Store; lstShapeElements = oStore.ElementDirectory.FindElements<ShapeElement>(true); lstShapeElements = lstShapeElements ?? new ReadOnlyCollection<ShapeElement>(new List<ShapeElement>()); lstSelectableElements = (from shape in lstShapeElements where shape is NodeShape select shape).ToList(); return lstSelectableElements; } } }
--Kiran Chand Palakkattiri--
kiran.chand@live.in- Propuesto como respuestaKiran Chand Palakkattiri miércoles, 08 de julio de 2009 13:41

