Formular una preguntaFormular una pregunta
 

RespondidaHow do I select a DSL shape via API

  • miércoles, 01 de julio de 2009 13:53AtulKatare Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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

  • jueves, 02 de julio de 2009 15:33RubenJMarrufo Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    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

Todas las respuestas

  • miércoles, 01 de julio de 2009 22:26Sebastian Dyck Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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
  • jueves, 02 de julio de 2009 5:10AtulKatare Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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
  • jueves, 02 de julio de 2009 12:19RubenJMarrufo Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respuesta propuesta
    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
    •  
  • jueves, 02 de julio de 2009 14:11AtulKatare Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Hi Ruben

    How to get Store from CommandSet class?
    CommandSet class constructor require IServiceProvider, how to pass value?

    Thank You..
  • jueves, 02 de julio de 2009 15:33RubenJMarrufo Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    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
  • miércoles, 08 de julio de 2009 13:41Kiran Chand Palakkattiri Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respuesta propuestaTiene código
    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.


    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;
            }
        }
    }
    
    Try this; You have everything selected on Select All (Ctl + A)
    --Kiran Chand Palakkattiri--
    kiran.chand@live.in