activation of actions in the TOCContext in 2.4

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

activation of actions in the TOCContext in 2.4

Andrea Antonello
Hi, I am right now testing the jgrasstools extensions in gvSIG 2.4 and
am facing a strange issue.

I have a few actions that should be enabled in the TOCContext, but
only if a raster layer is selected.
I used to do this check in the method of the Extension:

org.jgrasstools.gvsig.spatialtoolbox.RasterStyleExtension.isVisible()

and there activate the action if a raster was indeed selected.

This now doesn't work for some of the actions.

Is there a best practice on how to handle such an activation.

Thanks,
Andrea

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: activation of actions in the TOCContext in 2.4

Francisco Puga-2
Usually, I don't check for the visibility / enability of external plugins to check this kind of things. It can happen that the user does not have that plugin installed.

At iCarto we use this helper class to check if a FLyVect is active, visible, ... It can be easily adapted for being used for raster layers. Here there is a work in progress of how to generalise that class to work with any FLayer child.

The code is GPL so, reuse it in your own project if it's of any help to you. If you like the approach, and you have any issue probably I can take some time to make it work with raster layers.

2017-07-21 12:10 GMT+02:00 andrea antonello <[hidden email]>:
Hi, I am right now testing the jgrasstools extensions in gvSIG 2.4 and
am facing a strange issue.

I have a few actions that should be enabled in the TOCContext, but
only if a raster layer is selected.
I used to do this check in the method of the Extension:

org.jgrasstools.gvsig.spatialtoolbox.RasterStyleExtension.isVisible()

and there activate the action if a raster was indeed selected.

This now doesn't work for some of the actions.

Is there a best practice on how to handle such an activation.

Thanks,
Andrea

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel



--
Francisco Puga
iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.

c/ Rafael Alberti nº 13 – 1º D
15008 A Coruña
Galicia (Spain)
+34 881927808

Este correo electrónico contiene información estrictamente confidencial y es de uso exclusivo del destinatario, quedando prohibida a cualquier otra persona su revelación, copia, distribución, o el ejercicio de cualquier acción relativa a su contenido. Si ha recibido este mensaje por error, por favor conteste a su remitente mediante correo electrónico y proceda a borrarlo de su sistema.

Sus datos personales serán tratados de forma confidencial y no serán cedidos a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer los derecho de oposición, acceso, rectificación y cancelación de acuerdo con lo establecido en la Ley Orgánica 15/99, de 13 de diciembre, de Protección de Datos de Carácter Personal dirigiéndose a Innovación, Cooperación, Cartografía e Territorio, SL. (ICARTO) en la dirección postal a C/ Rafael Alberti, nº 13, 1ºD, 15.008 – (A Coruña).

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: activation of actions in the TOCContext in 2.4

Andrea Antonello
Hi Francisco,

> Usually, I don't check for the visibility / enability of external plugins to
> check this kind of things. It can happen that the user does not have that
> plugin installed.

I am not sure I understand.

Let me lay it down in a workflow:

* I have a plugin that wants to add an entry to the TOCContext.
* the same plugin contains the action that needs to be executed
* the action should be visible in the right click TOCContext menu only
if the right click occurs over a selected raster map
* to do so, I need to make the action object's setActive method true
or false. These action only makes sense for raster maps
* so I need to listen to selection/change of map-view and things the
like, in order to enable/disable and use the proper mapcontext and
layers
* the isVisible method was the one that had been suggested to me
during a code sprint, so I went for that one

> At iCarto we use this helper class to check if a FLyVect is active, visible,
> ... It can be easily adapted for being used for raster layers. Here there is
> a work in progress of how to generalise that class to work with any FLayer
> child.
>
> The code is GPL so, reuse it in your own project if it's of any help to you.
> If you like the approach, and you have any issue probably I can take some
> time to make it work with raster layers.

Thanks for the link, I like the class and also like the plugin. i will
sure have a look at it to better learn how to do certain things.

But if I understood it correctly, it is not what I need, right? Do you agree?

Ciao,
Andrea


>
> 2017-07-21 12:10 GMT+02:00 andrea antonello <[hidden email]>:
>>
>> Hi, I am right now testing the jgrasstools extensions in gvSIG 2.4 and
>> am facing a strange issue.
>>
>> I have a few actions that should be enabled in the TOCContext, but
>> only if a raster layer is selected.
>> I used to do this check in the method of the Extension:
>>
>> org.jgrasstools.gvsig.spatialtoolbox.RasterStyleExtension.isVisible()
>>
>> and there activate the action if a raster was indeed selected.
>>
>> This now doesn't work for some of the actions.
>>
>> Is there a best practice on how to handle such an activation.
>>
>> Thanks,
>> Andrea
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>
>
>
>
> --
> Francisco Puga
> iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
> http://www.icarto.es/
>
> c/ Rafael Alberti nº 13 – 1º D
> 15008 A Coruña
> Galicia (Spain)
> +34 881927808
>
> Este correo electrónico contiene información estrictamente confidencial y es
> de uso exclusivo del destinatario, quedando prohibida a cualquier otra
> persona su revelación, copia, distribución, o el ejercicio de cualquier
> acción relativa a su contenido. Si ha recibido este mensaje por error, por
> favor conteste a su remitente mediante correo electrónico y proceda a
> borrarlo de su sistema.
>
> Sus datos personales serán tratados de forma confidencial y no serán cedidos
> a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer los derecho de
> oposición, acceso, rectificación y cancelación de acuerdo con lo establecido
> en la Ley Orgánica 15/99, de 13 de diciembre, de Protección de Datos de
> Carácter Personal dirigiéndose a Innovación, Cooperación, Cartografía e
> Territorio, SL. (ICARTO) en la dirección postal a C/ Rafael Alberti, nº 13,
> 1ºD, 15.008 – (A Coruña).
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: activation of actions in the TOCContext in 2.4

Joaquin Jose del Cerro Murciano

Hello Andrea.
I do not quite understand where the problem is. I tell you how to add an entry to the contextual menu of the view and then you already ask me what is not understood.

The recommended way would be to define an "action" in the "config.xml", for example something like:

  <extension class-name="org.gvsig.myfunctionality.MyRasterExtension"
             description=""
             active="true"
             priority="1">
      <action
          name="myraster-action"
          label="_myraster_action"
          position="909000000" 
          tooltip="_myraster_action"
          action-command="myraster-action"
          icon="myraster-action"
          accelerator=""
      />   

      <menu
          name="myraster-action"
          text="tools/myfunctionality/myraster-action"
      />             
  </extension>   

The entry in the menus is optional, but is recomended that al actions in context menu are in the application menus.

With the action already created in the "config.xml", we would create an "Extension" that we will associate with that "action" and register it in the contextual menu of the view.

Un saludo
Joaquin

public class MyRasterExtension extends Extension {

    private static final String MYRASTER_ACTION = "myraster-action";
   
    @Override
    public void initialize() {
        IconThemeHelper.registerIcon("action", MYRASTER_ACTION, this);
    }

    @Override
    public void postInitialize() {
        super.postInitialize();

        // Add to the TOC Context menu of view the action
        ProjectManager projectManager = ApplicationLocator.getProjectManager();
        ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME);
        viewManager.addTOCContextAction(MYRASTER_ACTION);

    }

    @Override
    public void execute(String actionCommand) {
        this.execute(actionCommand, null);
    }

    @Override
    public void execute(String command, Object[] args) {
        if( MYRASTER_ACTION.equalsIgnoreCase(command) ) {
            do_the_requested_action();
        }
    }

    @Override
    public boolean isEnabled() {
        ApplicationManager application = ApplicationLocator.getManager();
        ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
        if ( view != null ) {
            FLayer[] actives = view.getMapContext().getLayers().getActives();
            // Check if a raster layer is active
            for (FLayer active : actives) {
                if (active instanceof FLyrRaster) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public boolean isVisible() {
        ApplicationManager application = ApplicationLocator.getManager();
        ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
        return view != null;
    }
   
}





2017-07-24 12:46 GMT+02:00 andrea antonello <[hidden email]>:
Hi Francisco,

> Usually, I don't check for the visibility / enability of external plugins to
> check this kind of things. It can happen that the user does not have that
> plugin installed.

I am not sure I understand.

Let me lay it down in a workflow:

* I have a plugin that wants to add an entry to the TOCContext.
* the same plugin contains the action that needs to be executed
* the action should be visible in the right click TOCContext menu only
if the right click occurs over a selected raster map
* to do so, I need to make the action object's setActive method true
or false. These action only makes sense for raster maps
* so I need to listen to selection/change of map-view and things the
like, in order to enable/disable and use the proper mapcontext and
layers
* the isVisible method was the one that had been suggested to me
during a code sprint, so I went for that one

> At iCarto we use this helper class to check if a FLyVect is active, visible,
> ... It can be easily adapted for being used for raster layers. Here there is
> a work in progress of how to generalise that class to work with any FLayer
> child.
>
> The code is GPL so, reuse it in your own project if it's of any help to you.
> If you like the approach, and you have any issue probably I can take some
> time to make it work with raster layers.

Thanks for the link, I like the class and also like the plugin. i will
sure have a look at it to better learn how to do certain things.

But if I understood it correctly, it is not what I need, right? Do you agree?

Ciao,
Andrea


>
> 2017-07-21 12:10 GMT+02:00 andrea antonello <[hidden email]>:
>>
>> Hi, I am right now testing the jgrasstools extensions in gvSIG 2.4 and
>> am facing a strange issue.
>>
>> I have a few actions that should be enabled in the TOCContext, but
>> only if a raster layer is selected.
>> I used to do this check in the method of the Extension:
>>
>> org.jgrasstools.gvsig.spatialtoolbox.RasterStyleExtension.isVisible()
>>
>> and there activate the action if a raster was indeed selected.
>>
>> This now doesn't work for some of the actions.
>>
>> Is there a best practice on how to handle such an activation.
>>
>> Thanks,
>> Andrea
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>
>
>
>
> --
> Francisco Puga
> iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
> http://www.icarto.es/
>
> c/ Rafael Alberti nº 13 – 1º D
> 15008 A Coruña
> Galicia (Spain)
> <a href="tel:%2B34%20881927808" value="+34881927808">+34 881927808
>
> Este correo electrónico contiene información estrictamente confidencial y es
> de uso exclusivo del destinatario, quedando prohibida a cualquier otra
> persona su revelación, copia, distribución, o el ejercicio de cualquier
> acción relativa a su contenido. Si ha recibido este mensaje por error, por
> favor conteste a su remitente mediante correo electrónico y proceda a
> borrarlo de su sistema.
>
> Sus datos personales serán tratados de forma confidencial y no serán cedidos
> a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer los derecho de
> oposición, acceso, rectificación y cancelación de acuerdo con lo establecido
> en la Ley Orgánica 15/99, de 13 de diciembre, de Protección de Datos de
> Carácter Personal dirigiéndose a Innovación, Cooperación, Cartografía e
> Territorio, SL. (ICARTO) en la dirección postal a C/ Rafael Alberti, nº 13,
> 1ºD, 15.008 – (A Coruña).
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel



--
--------------------------------------
Joaquin Jose del Cerro Murciano
Development and software arquitecture manager at gvSIG Team
[hidden email]
[hidden email]
gvSIG Association
www.gvsig.com
www.gvsig.org

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: activation of actions in the TOCContext in 2.4

Andrea Antonello
Hi Joaquin,

> I do not quite understand where the problem is. I tell you how to add an
> entry to the contextual menu of the view and then you already ask me what is
> not understood.
>
> The recommended way would be to define an "action" in the "config.xml", for
> example something like:
>
>   <extension class-name="org.gvsig.myfunctionality.MyRasterExtension"
>              description=""
>              active="true"
>              priority="1">
>       <action
>           name="myraster-action"
>           label="_myraster_action"
>           position="909000000"
>           tooltip="_myraster_action"
>           action-command="myraster-action"
>           icon="myraster-action"
>           accelerator=""
>       />
>
>       <menu
>           name="myraster-action"
>           text="tools/myfunctionality/myraster-action"
>       />
>   </extension>
>
> The entry in the menus is optional, but is recomended that al actions in
> context menu are in the application menus.
>
> With the action already created in the "config.xml", we would create an
> "Extension" that we will associate with that "action" and register it in the
> contextual menu of the view.

I have this already and it used to work all until 2.3.1. Now with the
2.4 my actions are not visible any more.
Maybe I changed something, but I can't understand what that might be.

The isVisible/isEnabled methods are called at gvSIG startup, but then
not when the layers are selected (vector or raster, which should
change enablement) or views are changed.

Ciao,
Andrea



>
> Un saludo
> Joaquin
>
> public class MyRasterExtension extends Extension {
>
>     private static final String MYRASTER_ACTION = "myraster-action";
>
>     @Override
>     public void initialize() {
>         IconThemeHelper.registerIcon("action", MYRASTER_ACTION, this);
>     }
>
>     @Override
>     public void postInitialize() {
>         super.postInitialize();
>
>         // Add to the TOC Context menu of view the action
>         ProjectManager projectManager =
> ApplicationLocator.getProjectManager();
>         ViewManager viewManager = (ViewManager)
> projectManager.getDocumentManager(ViewManager.TYPENAME);
>         viewManager.addTOCContextAction(MYRASTER_ACTION);
>
>     }
>
>     @Override
>     public void execute(String actionCommand) {
>         this.execute(actionCommand, null);
>     }
>
>     @Override
>     public void execute(String command, Object[] args) {
>         if( MYRASTER_ACTION.equalsIgnoreCase(command) ) {
>             do_the_requested_action();
>         }
>     }
>
>     @Override
>     public boolean isEnabled() {
>         ApplicationManager application = ApplicationLocator.getManager();
>         ViewDocument view = (ViewDocument)
> application.getActiveDocument(ViewManager.TYPENAME);
>         if ( view != null ) {
>             FLayer[] actives =
> view.getMapContext().getLayers().getActives();
>             // Check if a raster layer is active
>             for (FLayer active : actives) {
>                 if (active instanceof FLyrRaster) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
>
>     @Override
>     public boolean isVisible() {
>         ApplicationManager application = ApplicationLocator.getManager();
>         ViewDocument view = (ViewDocument)
> application.getActiveDocument(ViewManager.TYPENAME);
>         return view != null;
>     }
>
> }
>
>
>
>
>
> 2017-07-24 12:46 GMT+02:00 andrea antonello <[hidden email]>:
>>
>> Hi Francisco,
>>
>> > Usually, I don't check for the visibility / enability of external
>> > plugins to
>> > check this kind of things. It can happen that the user does not have
>> > that
>> > plugin installed.
>>
>> I am not sure I understand.
>>
>> Let me lay it down in a workflow:
>>
>> * I have a plugin that wants to add an entry to the TOCContext.
>> * the same plugin contains the action that needs to be executed
>> * the action should be visible in the right click TOCContext menu only
>> if the right click occurs over a selected raster map
>> * to do so, I need to make the action object's setActive method true
>> or false. These action only makes sense for raster maps
>> * so I need to listen to selection/change of map-view and things the
>> like, in order to enable/disable and use the proper mapcontext and
>> layers
>> * the isVisible method was the one that had been suggested to me
>> during a code sprint, so I went for that one
>>
>> > At iCarto we use this helper class to check if a FLyVect is active,
>> > visible,
>> > ... It can be easily adapted for being used for raster layers. Here
>> > there is
>> > a work in progress of how to generalise that class to work with any
>> > FLayer
>> > child.
>> >
>> > The code is GPL so, reuse it in your own project if it's of any help to
>> > you.
>> > If you like the approach, and you have any issue probably I can take
>> > some
>> > time to make it work with raster layers.
>>
>> Thanks for the link, I like the class and also like the plugin. i will
>> sure have a look at it to better learn how to do certain things.
>>
>> But if I understood it correctly, it is not what I need, right? Do you
>> agree?
>>
>> Ciao,
>> Andrea
>>
>>
>> >
>> > 2017-07-21 12:10 GMT+02:00 andrea antonello
>> > <[hidden email]>:
>> >>
>> >> Hi, I am right now testing the jgrasstools extensions in gvSIG 2.4 and
>> >> am facing a strange issue.
>> >>
>> >> I have a few actions that should be enabled in the TOCContext, but
>> >> only if a raster layer is selected.
>> >> I used to do this check in the method of the Extension:
>> >>
>> >> org.jgrasstools.gvsig.spatialtoolbox.RasterStyleExtension.isVisible()
>> >>
>> >> and there activate the action if a raster was indeed selected.
>> >>
>> >> This now doesn't work for some of the actions.
>> >>
>> >> Is there a best practice on how to handle such an activation.
>> >>
>> >> Thanks,
>> >> Andrea
>> >>
>> >> _______________________________________________
>> >> gvSIG-desktop-devel mailing list
>> >> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>> >
>> >
>> >
>> >
>> > --
>> > Francisco Puga
>> > iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
>> > http://www.icarto.es/
>> >
>> > c/ Rafael Alberti nº 13 – 1º D
>> > 15008 A Coruña
>> > Galicia (Spain)
>> > +34 881927808
>> >
>> > Este correo electrónico contiene información estrictamente confidencial
>> > y es
>> > de uso exclusivo del destinatario, quedando prohibida a cualquier otra
>> > persona su revelación, copia, distribución, o el ejercicio de cualquier
>> > acción relativa a su contenido. Si ha recibido este mensaje por error,
>> > por
>> > favor conteste a su remitente mediante correo electrónico y proceda a
>> > borrarlo de su sistema.
>> >
>> > Sus datos personales serán tratados de forma confidencial y no serán
>> > cedidos
>> > a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer los derecho
>> > de
>> > oposición, acceso, rectificación y cancelación de acuerdo con lo
>> > establecido
>> > en la Ley Orgánica 15/99, de 13 de diciembre, de Protección de Datos de
>> > Carácter Personal dirigiéndose a Innovación, Cooperación, Cartografía e
>> > Territorio, SL. (ICARTO) en la dirección postal a C/ Rafael Alberti, nº
>> > 13,
>> > 1ºD, 15.008 – (A Coruña).
>> >
>> > _______________________________________________
>> > gvSIG-desktop-devel mailing list
>> > http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>
>
>
>
> --
> --------------------------------------
> Joaquin Jose del Cerro Murciano
> Development and software arquitecture manager at gvSIG Team
> [hidden email]
> [hidden email]
> gvSIG Association
> www.gvsig.com
> www.gvsig.org
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: activation of actions in the TOCContext in 2.4

Francisco Puga-2
I did not understand you the first time. The code I provided will not work for you. Follow Joaquin instructions is the way to go. 

I just link you, an example code, adapted from gvSIG 1.x that more or less should work with gvSIG 2. I think that this code is deprecated but maybe it works for you.

 
It registers an action to the contextual menu of the TOC from an extension. The action will checkout that one and only one raster layer is active to be shown. Hope this will help you.



2017-07-24 14:32 GMT+02:00 andrea antonello <[hidden email]>:
Hi Joaquin,

> I do not quite understand where the problem is. I tell you how to add an
> entry to the contextual menu of the view and then you already ask me what is
> not understood.
>
> The recommended way would be to define an "action" in the "config.xml", for
> example something like:
>
>   <extension class-name="org.gvsig.myfunctionality.MyRasterExtension"
>              description=""
>              active="true"
>              priority="1">
>       <action
>           name="myraster-action"
>           label="_myraster_action"
>           position="909000000"
>           tooltip="_myraster_action"
>           action-command="myraster-action"
>           icon="myraster-action"
>           accelerator=""
>       />
>
>       <menu
>           name="myraster-action"
>           text="tools/myfunctionality/myraster-action"
>       />
>   </extension>
>
> The entry in the menus is optional, but is recomended that al actions in
> context menu are in the application menus.
>
> With the action already created in the "config.xml", we would create an
> "Extension" that we will associate with that "action" and register it in the
> contextual menu of the view.

I have this already and it used to work all until 2.3.1. Now with the
2.4 my actions are not visible any more.
Maybe I changed something, but I can't understand what that might be.

The isVisible/isEnabled methods are called at gvSIG startup, but then
not when the layers are selected (vector or raster, which should
change enablement) or views are changed.

Ciao,
Andrea



>
> Un saludo
> Joaquin
>
> public class MyRasterExtension extends Extension {
>
>     private static final String MYRASTER_ACTION = "myraster-action";
>
>     @Override
>     public void initialize() {
>         IconThemeHelper.registerIcon("action", MYRASTER_ACTION, this);
>     }
>
>     @Override
>     public void postInitialize() {
>         super.postInitialize();
>
>         // Add to the TOC Context menu of view the action
>         ProjectManager projectManager =
> ApplicationLocator.getProjectManager();
>         ViewManager viewManager = (ViewManager)
> projectManager.getDocumentManager(ViewManager.TYPENAME);
>         viewManager.addTOCContextAction(MYRASTER_ACTION);
>
>     }
>
>     @Override
>     public void execute(String actionCommand) {
>         this.execute(actionCommand, null);
>     }
>
>     @Override
>     public void execute(String command, Object[] args) {
>         if( MYRASTER_ACTION.equalsIgnoreCase(command) ) {
>             do_the_requested_action();
>         }
>     }
>
>     @Override
>     public boolean isEnabled() {
>         ApplicationManager application = ApplicationLocator.getManager();
>         ViewDocument view = (ViewDocument)
> application.getActiveDocument(ViewManager.TYPENAME);
>         if ( view != null ) {
>             FLayer[] actives =
> view.getMapContext().getLayers().getActives();
>             // Check if a raster layer is active
>             for (FLayer active : actives) {
>                 if (active instanceof FLyrRaster) {
>                     return true;
>                 }
>             }
>         }
>         return false;
>     }
>
>     @Override
>     public boolean isVisible() {
>         ApplicationManager application = ApplicationLocator.getManager();
>         ViewDocument view = (ViewDocument)
> application.getActiveDocument(ViewManager.TYPENAME);
>         return view != null;
>     }
>
> }
>
>
>
>
>
> 2017-07-24 12:46 GMT+02:00 andrea antonello <[hidden email]>:
>>
>> Hi Francisco,
>>
>> > Usually, I don't check for the visibility / enability of external
>> > plugins to
>> > check this kind of things. It can happen that the user does not have
>> > that
>> > plugin installed.
>>
>> I am not sure I understand.
>>
>> Let me lay it down in a workflow:
>>
>> * I have a plugin that wants to add an entry to the TOCContext.
>> * the same plugin contains the action that needs to be executed
>> * the action should be visible in the right click TOCContext menu only
>> if the right click occurs over a selected raster map
>> * to do so, I need to make the action object's setActive method true
>> or false. These action only makes sense for raster maps
>> * so I need to listen to selection/change of map-view and things the
>> like, in order to enable/disable and use the proper mapcontext and
>> layers
>> * the isVisible method was the one that had been suggested to me
>> during a code sprint, so I went for that one
>>
>> > At iCarto we use this helper class to check if a FLyVect is active,
>> > visible,
>> > ... It can be easily adapted for being used for raster layers. Here
>> > there is
>> > a work in progress of how to generalise that class to work with any
>> > FLayer
>> > child.
>> >
>> > The code is GPL so, reuse it in your own project if it's of any help to
>> > you.
>> > If you like the approach, and you have any issue probably I can take
>> > some
>> > time to make it work with raster layers.
>>
>> Thanks for the link, I like the class and also like the plugin. i will
>> sure have a look at it to better learn how to do certain things.
>>
>> But if I understood it correctly, it is not what I need, right? Do you
>> agree?
>>
>> Ciao,
>> Andrea
>>
>>
>> >
>> > 2017-07-21 12:10 GMT+02:00 andrea antonello
>> > <[hidden email]>:
>> >>
>> >> Hi, I am right now testing the jgrasstools extensions in gvSIG 2.4 and
>> >> am facing a strange issue.
>> >>
>> >> I have a few actions that should be enabled in the TOCContext, but
>> >> only if a raster layer is selected.
>> >> I used to do this check in the method of the Extension:
>> >>
>> >> org.jgrasstools.gvsig.spatialtoolbox.RasterStyleExtension.isVisible()
>> >>
>> >> and there activate the action if a raster was indeed selected.
>> >>
>> >> This now doesn't work for some of the actions.
>> >>
>> >> Is there a best practice on how to handle such an activation.
>> >>
>> >> Thanks,
>> >> Andrea
>> >>
>> >> _______________________________________________
>> >> gvSIG-desktop-devel mailing list
>> >> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>> >
>> >
>> >
>> >
>> > --
>> > Francisco Puga
>> > iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
>> > http://www.icarto.es/
>> >
>> > c/ Rafael Alberti nº 13 – 1º D
>> > 15008 A Coruña
>> > Galicia (Spain)
>> > <a href="tel:%2B34%20881927808" value="+34881927808">+34 881927808
>> >
>> > Este correo electrónico contiene información estrictamente confidencial
>> > y es
>> > de uso exclusivo del destinatario, quedando prohibida a cualquier otra
>> > persona su revelación, copia, distribución, o el ejercicio de cualquier
>> > acción relativa a su contenido. Si ha recibido este mensaje por error,
>> > por
>> > favor conteste a su remitente mediante correo electrónico y proceda a
>> > borrarlo de su sistema.
>> >
>> > Sus datos personales serán tratados de forma confidencial y no serán
>> > cedidos
>> > a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer los derecho
>> > de
>> > oposición, acceso, rectificación y cancelación de acuerdo con lo
>> > establecido
>> > en la Ley Orgánica 15/99, de 13 de diciembre, de Protección de Datos de
>> > Carácter Personal dirigiéndose a Innovación, Cooperación, Cartografía e
>> > Territorio, SL. (ICARTO) en la dirección postal a C/ Rafael Alberti, nº
>> > 13,
>> > 1ºD, 15.008 – (A Coruña).
>> >
>> > _______________________________________________
>> > gvSIG-desktop-devel mailing list
>> > http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>
>
>
>
> --
> --------------------------------------
> Joaquin Jose del Cerro Murciano
> Development and software arquitecture manager at gvSIG Team
> [hidden email]
> [hidden email]
> gvSIG Association
> www.gvsig.com
> www.gvsig.org
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel



--
Francisco Puga
iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.

c/ Rafael Alberti nº 13 – 1º D
15008 A Coruña
Galicia (Spain)
+34 881927808

Este correo electrónico contiene información estrictamente confidencial y es de uso exclusivo del destinatario, quedando prohibida a cualquier otra persona su revelación, copia, distribución, o el ejercicio de cualquier acción relativa a su contenido. Si ha recibido este mensaje por error, por favor conteste a su remitente mediante correo electrónico y proceda a borrarlo de su sistema.

Sus datos personales serán tratados de forma confidencial y no serán cedidos a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer los derecho de oposición, acceso, rectificación y cancelación de acuerdo con lo establecido en la Ley Orgánica 15/99, de 13 de diciembre, de Protección de Datos de Carácter Personal dirigiéndose a Innovación, Cooperación, Cartografía e Territorio, SL. (ICARTO) en la dirección postal a C/ Rafael Alberti, nº 13, 1ºD, 15.008 – (A Coruña).

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: activation of actions in the TOCContext in 2.4

Andrea Antonello
In reply to this post by Andrea Antonello
Just to add some info on what might happen:

I have 3 actions that are registered. Once I add a dtm_all raster and
right click, I see only 2 of the actions. After unselecting and trying
again, no action is visible any more.

The log shows:

 INFO 76812 [AWT-EventQueue-0]
(FilesystemExplorerWizardPanel.java:243) - addLayer('dtm_all.asc',...)
 INFO 76899 [Thread-12] (DefaultActionInfo.java:326) -
org.gvsig.app.mainplugin:org.gvsig.app.extension.ViewControls.execute('view-change-scale',
Object[] args)
 INFO 78697 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action style-singleband-raster not active
 INFO 78699 [AWT-EventQueue-0] (Messages.java:753) -
[org.gvsig.i18n.Messages] Cannot find translation for key 'Raster
Values Copy'.
 INFO 78700 [AWT-EventQueue-0] (Messages.java:753) -
[org.gvsig.i18n.Messages] Cannot find translation for key 'Raster
Graphics View'.
 INFO 86887 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action style-singleband-raster not active
 INFO 89602 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action quick-raster-graphics not active
 INFO 89602 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action copy-raster-values not active
 INFO 89602 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action style-singleband-raster not active
 INFO 91845 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action quick-raster-graphics not active
 INFO 91845 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action copy-raster-values not active
 INFO 91845 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action style-singleband-raster not active
 INFO 94438 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action quick-raster-graphics not active
 INFO 94439 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action copy-raster-values not active
 INFO 94440 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action style-singleband-raster not active


INFO 78697 shows the first missing action, and after  INFO 86887 no
action is here anymore. But the debug breakpoints in the isVisible and
isEnabled do not react anymore, so I have no idea why this happens.


Thanks for any hint.

Andrea





On Mon, Jul 24, 2017 at 2:32 PM, andrea antonello
<[hidden email]> wrote:

> Hi Joaquin,
>
>> I do not quite understand where the problem is. I tell you how to add an
>> entry to the contextual menu of the view and then you already ask me what is
>> not understood.
>>
>> The recommended way would be to define an "action" in the "config.xml", for
>> example something like:
>>
>>   <extension class-name="org.gvsig.myfunctionality.MyRasterExtension"
>>              description=""
>>              active="true"
>>              priority="1">
>>       <action
>>           name="myraster-action"
>>           label="_myraster_action"
>>           position="909000000"
>>           tooltip="_myraster_action"
>>           action-command="myraster-action"
>>           icon="myraster-action"
>>           accelerator=""
>>       />
>>
>>       <menu
>>           name="myraster-action"
>>           text="tools/myfunctionality/myraster-action"
>>       />
>>   </extension>
>>
>> The entry in the menus is optional, but is recomended that al actions in
>> context menu are in the application menus.
>>
>> With the action already created in the "config.xml", we would create an
>> "Extension" that we will associate with that "action" and register it in the
>> contextual menu of the view.
>
> I have this already and it used to work all until 2.3.1. Now with the
> 2.4 my actions are not visible any more.
> Maybe I changed something, but I can't understand what that might be.
>
> The isVisible/isEnabled methods are called at gvSIG startup, but then
> not when the layers are selected (vector or raster, which should
> change enablement) or views are changed.
>
> Ciao,
> Andrea
>
>
>
>>
>> Un saludo
>> Joaquin
>>
>> public class MyRasterExtension extends Extension {
>>
>>     private static final String MYRASTER_ACTION = "myraster-action";
>>
>>     @Override
>>     public void initialize() {
>>         IconThemeHelper.registerIcon("action", MYRASTER_ACTION, this);
>>     }
>>
>>     @Override
>>     public void postInitialize() {
>>         super.postInitialize();
>>
>>         // Add to the TOC Context menu of view the action
>>         ProjectManager projectManager =
>> ApplicationLocator.getProjectManager();
>>         ViewManager viewManager = (ViewManager)
>> projectManager.getDocumentManager(ViewManager.TYPENAME);
>>         viewManager.addTOCContextAction(MYRASTER_ACTION);
>>
>>     }
>>
>>     @Override
>>     public void execute(String actionCommand) {
>>         this.execute(actionCommand, null);
>>     }
>>
>>     @Override
>>     public void execute(String command, Object[] args) {
>>         if( MYRASTER_ACTION.equalsIgnoreCase(command) ) {
>>             do_the_requested_action();
>>         }
>>     }
>>
>>     @Override
>>     public boolean isEnabled() {
>>         ApplicationManager application = ApplicationLocator.getManager();
>>         ViewDocument view = (ViewDocument)
>> application.getActiveDocument(ViewManager.TYPENAME);
>>         if ( view != null ) {
>>             FLayer[] actives =
>> view.getMapContext().getLayers().getActives();
>>             // Check if a raster layer is active
>>             for (FLayer active : actives) {
>>                 if (active instanceof FLyrRaster) {
>>                     return true;
>>                 }
>>             }
>>         }
>>         return false;
>>     }
>>
>>     @Override
>>     public boolean isVisible() {
>>         ApplicationManager application = ApplicationLocator.getManager();
>>         ViewDocument view = (ViewDocument)
>> application.getActiveDocument(ViewManager.TYPENAME);
>>         return view != null;
>>     }
>>
>> }
>>
>>
>>
>>
>>
>> 2017-07-24 12:46 GMT+02:00 andrea antonello <[hidden email]>:
>>>
>>> Hi Francisco,
>>>
>>> > Usually, I don't check for the visibility / enability of external
>>> > plugins to
>>> > check this kind of things. It can happen that the user does not have
>>> > that
>>> > plugin installed.
>>>
>>> I am not sure I understand.
>>>
>>> Let me lay it down in a workflow:
>>>
>>> * I have a plugin that wants to add an entry to the TOCContext.
>>> * the same plugin contains the action that needs to be executed
>>> * the action should be visible in the right click TOCContext menu only
>>> if the right click occurs over a selected raster map
>>> * to do so, I need to make the action object's setActive method true
>>> or false. These action only makes sense for raster maps
>>> * so I need to listen to selection/change of map-view and things the
>>> like, in order to enable/disable and use the proper mapcontext and
>>> layers
>>> * the isVisible method was the one that had been suggested to me
>>> during a code sprint, so I went for that one
>>>
>>> > At iCarto we use this helper class to check if a FLyVect is active,
>>> > visible,
>>> > ... It can be easily adapted for being used for raster layers. Here
>>> > there is
>>> > a work in progress of how to generalise that class to work with any
>>> > FLayer
>>> > child.
>>> >
>>> > The code is GPL so, reuse it in your own project if it's of any help to
>>> > you.
>>> > If you like the approach, and you have any issue probably I can take
>>> > some
>>> > time to make it work with raster layers.
>>>
>>> Thanks for the link, I like the class and also like the plugin. i will
>>> sure have a look at it to better learn how to do certain things.
>>>
>>> But if I understood it correctly, it is not what I need, right? Do you
>>> agree?
>>>
>>> Ciao,
>>> Andrea
>>>
>>>
>>> >
>>> > 2017-07-21 12:10 GMT+02:00 andrea antonello
>>> > <[hidden email]>:
>>> >>
>>> >> Hi, I am right now testing the jgrasstools extensions in gvSIG 2.4 and
>>> >> am facing a strange issue.
>>> >>
>>> >> I have a few actions that should be enabled in the TOCContext, but
>>> >> only if a raster layer is selected.
>>> >> I used to do this check in the method of the Extension:
>>> >>
>>> >> org.jgrasstools.gvsig.spatialtoolbox.RasterStyleExtension.isVisible()
>>> >>
>>> >> and there activate the action if a raster was indeed selected.
>>> >>
>>> >> This now doesn't work for some of the actions.
>>> >>
>>> >> Is there a best practice on how to handle such an activation.
>>> >>
>>> >> Thanks,
>>> >> Andrea
>>> >>
>>> >> _______________________________________________
>>> >> gvSIG-desktop-devel mailing list
>>> >> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > Francisco Puga
>>> > iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
>>> > http://www.icarto.es/
>>> >
>>> > c/ Rafael Alberti nº 13 – 1º D
>>> > 15008 A Coruña
>>> > Galicia (Spain)
>>> > +34 881927808
>>> >
>>> > Este correo electrónico contiene información estrictamente confidencial
>>> > y es
>>> > de uso exclusivo del destinatario, quedando prohibida a cualquier otra
>>> > persona su revelación, copia, distribución, o el ejercicio de cualquier
>>> > acción relativa a su contenido. Si ha recibido este mensaje por error,
>>> > por
>>> > favor conteste a su remitente mediante correo electrónico y proceda a
>>> > borrarlo de su sistema.
>>> >
>>> > Sus datos personales serán tratados de forma confidencial y no serán
>>> > cedidos
>>> > a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer los derecho
>>> > de
>>> > oposición, acceso, rectificación y cancelación de acuerdo con lo
>>> > establecido
>>> > en la Ley Orgánica 15/99, de 13 de diciembre, de Protección de Datos de
>>> > Carácter Personal dirigiéndose a Innovación, Cooperación, Cartografía e
>>> > Territorio, SL. (ICARTO) en la dirección postal a C/ Rafael Alberti, nº
>>> > 13,
>>> > 1ºD, 15.008 – (A Coruña).
>>> >
>>> > _______________________________________________
>>> > gvSIG-desktop-devel mailing list
>>> > http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>>
>>> _______________________________________________
>>> gvSIG-desktop-devel mailing list
>>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>
>>
>>
>>
>> --
>> --------------------------------------
>> Joaquin Jose del Cerro Murciano
>> Development and software arquitecture manager at gvSIG Team
>> [hidden email]
>> [hidden email]
>> gvSIG Association
>> www.gvsig.com
>> www.gvsig.org
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: activation of actions in the TOCContext in 2.4

Andrea Antonello
In reply to this post by Francisco Puga-2
> I did not understand you the first time. The code I provided will not work
> for you. Follow Joaquin instructions is the way to go.
>
> I just link you, an example code, adapted from gvSIG 1.x that more or less
> should work with gvSIG 2. I think that this code is deprecated but maybe it
> works for you.
>
> https://pastebin.com/JHau532Y
>
> It registers an action to the contextual menu of the TOC from an extension.
> The action will checkout that one and only one raster layer is active to be
> shown. Hope this will help you.

Your code does exactly what I was hoping for, thanks you. But it is
quite different from what Joaquin proposes. Still you say to follow
Joaquin's way.
Since I didn't find any deprecation in the code, I am wondering what
the right way to go is :-D

Thanks,
Andrea

>
>
>
> 2017-07-24 14:32 GMT+02:00 andrea antonello <[hidden email]>:
>>
>> Hi Joaquin,
>>
>> > I do not quite understand where the problem is. I tell you how to add an
>> > entry to the contextual menu of the view and then you already ask me
>> > what is
>> > not understood.
>> >
>> > The recommended way would be to define an "action" in the "config.xml",
>> > for
>> > example something like:
>> >
>> >   <extension class-name="org.gvsig.myfunctionality.MyRasterExtension"
>> >              description=""
>> >              active="true"
>> >              priority="1">
>> >       <action
>> >           name="myraster-action"
>> >           label="_myraster_action"
>> >           position="909000000"
>> >           tooltip="_myraster_action"
>> >           action-command="myraster-action"
>> >           icon="myraster-action"
>> >           accelerator=""
>> >       />
>> >
>> >       <menu
>> >           name="myraster-action"
>> >           text="tools/myfunctionality/myraster-action"
>> >       />
>> >   </extension>
>> >
>> > The entry in the menus is optional, but is recomended that al actions in
>> > context menu are in the application menus.
>> >
>> > With the action already created in the "config.xml", we would create an
>> > "Extension" that we will associate with that "action" and register it in
>> > the
>> > contextual menu of the view.
>>
>> I have this already and it used to work all until 2.3.1. Now with the
>> 2.4 my actions are not visible any more.
>> Maybe I changed something, but I can't understand what that might be.
>>
>> The isVisible/isEnabled methods are called at gvSIG startup, but then
>> not when the layers are selected (vector or raster, which should
>> change enablement) or views are changed.
>>
>> Ciao,
>> Andrea
>>
>>
>>
>> >
>> > Un saludo
>> > Joaquin
>> >
>> > public class MyRasterExtension extends Extension {
>> >
>> >     private static final String MYRASTER_ACTION = "myraster-action";
>> >
>> >     @Override
>> >     public void initialize() {
>> >         IconThemeHelper.registerIcon("action", MYRASTER_ACTION, this);
>> >     }
>> >
>> >     @Override
>> >     public void postInitialize() {
>> >         super.postInitialize();
>> >
>> >         // Add to the TOC Context menu of view the action
>> >         ProjectManager projectManager =
>> > ApplicationLocator.getProjectManager();
>> >         ViewManager viewManager = (ViewManager)
>> > projectManager.getDocumentManager(ViewManager.TYPENAME);
>> >         viewManager.addTOCContextAction(MYRASTER_ACTION);
>> >
>> >     }
>> >
>> >     @Override
>> >     public void execute(String actionCommand) {
>> >         this.execute(actionCommand, null);
>> >     }
>> >
>> >     @Override
>> >     public void execute(String command, Object[] args) {
>> >         if( MYRASTER_ACTION.equalsIgnoreCase(command) ) {
>> >             do_the_requested_action();
>> >         }
>> >     }
>> >
>> >     @Override
>> >     public boolean isEnabled() {
>> >         ApplicationManager application =
>> > ApplicationLocator.getManager();
>> >         ViewDocument view = (ViewDocument)
>> > application.getActiveDocument(ViewManager.TYPENAME);
>> >         if ( view != null ) {
>> >             FLayer[] actives =
>> > view.getMapContext().getLayers().getActives();
>> >             // Check if a raster layer is active
>> >             for (FLayer active : actives) {
>> >                 if (active instanceof FLyrRaster) {
>> >                     return true;
>> >                 }
>> >             }
>> >         }
>> >         return false;
>> >     }
>> >
>> >     @Override
>> >     public boolean isVisible() {
>> >         ApplicationManager application =
>> > ApplicationLocator.getManager();
>> >         ViewDocument view = (ViewDocument)
>> > application.getActiveDocument(ViewManager.TYPENAME);
>> >         return view != null;
>> >     }
>> >
>> > }
>> >
>> >
>> >
>> >
>> >
>> > 2017-07-24 12:46 GMT+02:00 andrea antonello
>> > <[hidden email]>:
>> >>
>> >> Hi Francisco,
>> >>
>> >> > Usually, I don't check for the visibility / enability of external
>> >> > plugins to
>> >> > check this kind of things. It can happen that the user does not have
>> >> > that
>> >> > plugin installed.
>> >>
>> >> I am not sure I understand.
>> >>
>> >> Let me lay it down in a workflow:
>> >>
>> >> * I have a plugin that wants to add an entry to the TOCContext.
>> >> * the same plugin contains the action that needs to be executed
>> >> * the action should be visible in the right click TOCContext menu only
>> >> if the right click occurs over a selected raster map
>> >> * to do so, I need to make the action object's setActive method true
>> >> or false. These action only makes sense for raster maps
>> >> * so I need to listen to selection/change of map-view and things the
>> >> like, in order to enable/disable and use the proper mapcontext and
>> >> layers
>> >> * the isVisible method was the one that had been suggested to me
>> >> during a code sprint, so I went for that one
>> >>
>> >> > At iCarto we use this helper class to check if a FLyVect is active,
>> >> > visible,
>> >> > ... It can be easily adapted for being used for raster layers. Here
>> >> > there is
>> >> > a work in progress of how to generalise that class to work with any
>> >> > FLayer
>> >> > child.
>> >> >
>> >> > The code is GPL so, reuse it in your own project if it's of any help
>> >> > to
>> >> > you.
>> >> > If you like the approach, and you have any issue probably I can take
>> >> > some
>> >> > time to make it work with raster layers.
>> >>
>> >> Thanks for the link, I like the class and also like the plugin. i will
>> >> sure have a look at it to better learn how to do certain things.
>> >>
>> >> But if I understood it correctly, it is not what I need, right? Do you
>> >> agree?
>> >>
>> >> Ciao,
>> >> Andrea
>> >>
>> >>
>> >> >
>> >> > 2017-07-21 12:10 GMT+02:00 andrea antonello
>> >> > <[hidden email]>:
>> >> >>
>> >> >> Hi, I am right now testing the jgrasstools extensions in gvSIG 2.4
>> >> >> and
>> >> >> am facing a strange issue.
>> >> >>
>> >> >> I have a few actions that should be enabled in the TOCContext, but
>> >> >> only if a raster layer is selected.
>> >> >> I used to do this check in the method of the Extension:
>> >> >>
>> >> >>
>> >> >> org.jgrasstools.gvsig.spatialtoolbox.RasterStyleExtension.isVisible()
>> >> >>
>> >> >> and there activate the action if a raster was indeed selected.
>> >> >>
>> >> >> This now doesn't work for some of the actions.
>> >> >>
>> >> >> Is there a best practice on how to handle such an activation.
>> >> >>
>> >> >> Thanks,
>> >> >> Andrea
>> >> >>
>> >> >> _______________________________________________
>> >> >> gvSIG-desktop-devel mailing list
>> >> >> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Francisco Puga
>> >> > iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
>> >> > http://www.icarto.es/
>> >> >
>> >> > c/ Rafael Alberti nº 13 – 1º D
>> >> > 15008 A Coruña
>> >> > Galicia (Spain)
>> >> > +34 881927808
>> >> >
>> >> > Este correo electrónico contiene información estrictamente
>> >> > confidencial
>> >> > y es
>> >> > de uso exclusivo del destinatario, quedando prohibida a cualquier
>> >> > otra
>> >> > persona su revelación, copia, distribución, o el ejercicio de
>> >> > cualquier
>> >> > acción relativa a su contenido. Si ha recibido este mensaje por
>> >> > error,
>> >> > por
>> >> > favor conteste a su remitente mediante correo electrónico y proceda a
>> >> > borrarlo de su sistema.
>> >> >
>> >> > Sus datos personales serán tratados de forma confidencial y no serán
>> >> > cedidos
>> >> > a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer los
>> >> > derecho
>> >> > de
>> >> > oposición, acceso, rectificación y cancelación de acuerdo con lo
>> >> > establecido
>> >> > en la Ley Orgánica 15/99, de 13 de diciembre, de Protección de Datos
>> >> > de
>> >> > Carácter Personal dirigiéndose a Innovación, Cooperación, Cartografía
>> >> > e
>> >> > Territorio, SL. (ICARTO) en la dirección postal a C/ Rafael Alberti,
>> >> > nº
>> >> > 13,
>> >> > 1ºD, 15.008 – (A Coruña).
>> >> >
>> >> > _______________________________________________
>> >> > gvSIG-desktop-devel mailing list
>> >> > http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>> >>
>> >> _______________________________________________
>> >> gvSIG-desktop-devel mailing list
>> >> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>> >
>> >
>> >
>> >
>> > --
>> > --------------------------------------
>> > Joaquin Jose del Cerro Murciano
>> > Development and software arquitecture manager at gvSIG Team
>> > [hidden email]
>> > [hidden email]
>> > gvSIG Association
>> > www.gvsig.com
>> > www.gvsig.org
>> >
>> > _______________________________________________
>> > gvSIG-desktop-devel mailing list
>> > http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>
>
>
>
> --
> Francisco Puga
> iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
> http://www.icarto.es/
>
> c/ Rafael Alberti nº 13 – 1º D
> 15008 A Coruña
> Galicia (Spain)
> +34 881927808
>
> Este correo electrónico contiene información estrictamente confidencial y es
> de uso exclusivo del destinatario, quedando prohibida a cualquier otra
> persona su revelación, copia, distribución, o el ejercicio de cualquier
> acción relativa a su contenido. Si ha recibido este mensaje por error, por
> favor conteste a su remitente mediante correo electrónico y proceda a
> borrarlo de su sistema.
>
> Sus datos personales serán tratados de forma confidencial y no serán cedidos
> a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer los derecho de
> oposición, acceso, rectificación y cancelación de acuerdo con lo establecido
> en la Ley Orgánica 15/99, de 13 de diciembre, de Protección de Datos de
> Carácter Personal dirigiéndose a Innovación, Cooperación, Cartografía e
> Territorio, SL. (ICARTO) en la dirección postal a C/ Rafael Alberti, nº 13,
> 1ºD, 15.008 – (A Coruña).
>
> _______________________________________________
> gvSIG-desktop-devel mailing list
> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: activation of actions in the TOCContext in 2.4

Joaquin Jose del Cerro Murciano
In reply to this post by Andrea Antonello


2017-07-24 14:55 GMT+02:00 andrea antonello <[hidden email]>:
Just to add some info on what might happen:

I have 3 actions that are registered. Once I add a dtm_all raster and
right click, I see only 2 of the actions. After unselecting and trying
again, no action is visible any more.

The log shows:

 INFO 76812 [AWT-EventQueue-0]
(FilesystemExplorerWizardPanel.java:243) - addLayer('dtm_all.asc',...)
 INFO 76899 [Thread-12] (DefaultActionInfo.java:326) -
org.gvsig.app.mainplugin:org.gvsig.app.extension.ViewControls.execute('view-change-scale',
Object[] args)
 INFO 78697 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action style-singleband-raster not active
 INFO 78699 [AWT-EventQueue-0] (Messages.java:753) -
[org.gvsig.i18n.Messages] Cannot find translation for key 'Raster
Values Copy'.
 INFO 78700 [AWT-EventQueue-0] (Messages.java:753) -
[org.gvsig.i18n.Messages] Cannot find translation for key 'Raster
Graphics View'.
 INFO 86887 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action style-singleband-raster not active
 INFO 89602 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action quick-raster-graphics not active
 INFO 89602 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action copy-raster-values not active
 INFO 89602 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action style-singleband-raster not active
 INFO 91845 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action quick-raster-graphics not active
 INFO 91845 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action copy-raster-values not active
 INFO 91845 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action style-singleband-raster not active
 INFO 94438 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action quick-raster-graphics not active
 INFO 94439 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action copy-raster-values not active
 INFO 94440 [AWT-EventQueue-0] (DefaultActionInfo.java:231) -
isVisible(), action style-singleband-raster not active


INFO 78697 shows the first missing action, and after  INFO 86887 no
action is here anymore. But the debug breakpoints in the isVisible and
isEnabled do not react anymore, so I have no idea why this happens.

In gvSIG 2.4 you have added a new functionality that allows the user to activate and deactivate actions.
You can use the "actionConfigurator" script to activate and deactivate the actions.

From what is shown in the trace, it seems that those actions are deactivate.
Can you check if the file "HOME/gvsig/actions-states.properties" exists?
If it exists you can delete it to activate all the actions again.

 

Thanks for any hint.

Andrea





On Mon, Jul 24, 2017 at 2:32 PM, andrea antonello
<[hidden email]> wrote:
> Hi Joaquin,
>
>> I do not quite understand where the problem is. I tell you how to add an
>> entry to the contextual menu of the view and then you already ask me what is
>> not understood.
>>
>> The recommended way would be to define an "action" in the "config.xml", for
>> example something like:
>>
>>   <extension class-name="org.gvsig.myfunctionality.MyRasterExtension"
>>              description=""
>>              active="true"
>>              priority="1">
>>       <action
>>           name="myraster-action"
>>           label="_myraster_action"
>>           position="909000000"
>>           tooltip="_myraster_action"
>>           action-command="myraster-action"
>>           icon="myraster-action"
>>           accelerator=""
>>       />
>>
>>       <menu
>>           name="myraster-action"
>>           text="tools/myfunctionality/myraster-action"
>>       />
>>   </extension>
>>
>> The entry in the menus is optional, but is recomended that al actions in
>> context menu are in the application menus.
>>
>> With the action already created in the "config.xml", we would create an
>> "Extension" that we will associate with that "action" and register it in the
>> contextual menu of the view.
>
> I have this already and it used to work all until 2.3.1. Now with the
> 2.4 my actions are not visible any more.
> Maybe I changed something, but I can't understand what that might be.
>
> The isVisible/isEnabled methods are called at gvSIG startup, but then
> not when the layers are selected (vector or raster, which should
> change enablement) or views are changed.
>
> Ciao,
> Andrea
>
>
>
>>
>> Un saludo
>> Joaquin
>>
>> public class MyRasterExtension extends Extension {
>>
>>     private static final String MYRASTER_ACTION = "myraster-action";
>>
>>     @Override
>>     public void initialize() {
>>         IconThemeHelper.registerIcon("action", MYRASTER_ACTION, this);
>>     }
>>
>>     @Override
>>     public void postInitialize() {
>>         super.postInitialize();
>>
>>         // Add to the TOC Context menu of view the action
>>         ProjectManager projectManager =
>> ApplicationLocator.getProjectManager();
>>         ViewManager viewManager = (ViewManager)
>> projectManager.getDocumentManager(ViewManager.TYPENAME);
>>         viewManager.addTOCContextAction(MYRASTER_ACTION);
>>
>>     }
>>
>>     @Override
>>     public void execute(String actionCommand) {
>>         this.execute(actionCommand, null);
>>     }
>>
>>     @Override
>>     public void execute(String command, Object[] args) {
>>         if( MYRASTER_ACTION.equalsIgnoreCase(command) ) {
>>             do_the_requested_action();
>>         }
>>     }
>>
>>     @Override
>>     public boolean isEnabled() {
>>         ApplicationManager application = ApplicationLocator.getManager();
>>         ViewDocument view = (ViewDocument)
>> application.getActiveDocument(ViewManager.TYPENAME);
>>         if ( view != null ) {
>>             FLayer[] actives =
>> view.getMapContext().getLayers().getActives();
>>             // Check if a raster layer is active
>>             for (FLayer active : actives) {
>>                 if (active instanceof FLyrRaster) {
>>                     return true;
>>                 }
>>             }
>>         }
>>         return false;
>>     }
>>
>>     @Override
>>     public boolean isVisible() {
>>         ApplicationManager application = ApplicationLocator.getManager();
>>         ViewDocument view = (ViewDocument)
>> application.getActiveDocument(ViewManager.TYPENAME);
>>         return view != null;
>>     }
>>
>> }
>>
>>
>>
>>
>>
>> 2017-07-24 12:46 GMT+02:00 andrea antonello <[hidden email]>:
>>>
>>> Hi Francisco,
>>>
>>> > Usually, I don't check for the visibility / enability of external
>>> > plugins to
>>> > check this kind of things. It can happen that the user does not have
>>> > that
>>> > plugin installed.
>>>
>>> I am not sure I understand.
>>>
>>> Let me lay it down in a workflow:
>>>
>>> * I have a plugin that wants to add an entry to the TOCContext.
>>> * the same plugin contains the action that needs to be executed
>>> * the action should be visible in the right click TOCContext menu only
>>> if the right click occurs over a selected raster map
>>> * to do so, I need to make the action object's setActive method true
>>> or false. These action only makes sense for raster maps
>>> * so I need to listen to selection/change of map-view and things the
>>> like, in order to enable/disable and use the proper mapcontext and
>>> layers
>>> * the isVisible method was the one that had been suggested to me
>>> during a code sprint, so I went for that one
>>>
>>> > At iCarto we use this helper class to check if a FLyVect is active,
>>> > visible,
>>> > ... It can be easily adapted for being used for raster layers. Here
>>> > there is
>>> > a work in progress of how to generalise that class to work with any
>>> > FLayer
>>> > child.
>>> >
>>> > The code is GPL so, reuse it in your own project if it's of any help to
>>> > you.
>>> > If you like the approach, and you have any issue probably I can take
>>> > some
>>> > time to make it work with raster layers.
>>>
>>> Thanks for the link, I like the class and also like the plugin. i will
>>> sure have a look at it to better learn how to do certain things.
>>>
>>> But if I understood it correctly, it is not what I need, right? Do you
>>> agree?
>>>
>>> Ciao,
>>> Andrea
>>>
>>>
>>> >
>>> > 2017-07-21 12:10 GMT+02:00 andrea antonello
>>> > <[hidden email]>:
>>> >>
>>> >> Hi, I am right now testing the jgrasstools extensions in gvSIG 2.4 and
>>> >> am facing a strange issue.
>>> >>
>>> >> I have a few actions that should be enabled in the TOCContext, but
>>> >> only if a raster layer is selected.
>>> >> I used to do this check in the method of the Extension:
>>> >>
>>> >> org.jgrasstools.gvsig.spatialtoolbox.RasterStyleExtension.isVisible()
>>> >>
>>> >> and there activate the action if a raster was indeed selected.
>>> >>
>>> >> This now doesn't work for some of the actions.
>>> >>
>>> >> Is there a best practice on how to handle such an activation.
>>> >>
>>> >> Thanks,
>>> >> Andrea
>>> >>
>>> >> _______________________________________________
>>> >> gvSIG-desktop-devel mailing list
>>> >> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > Francisco Puga
>>> > iCarto | Innovación, Cooperación, Cartografía y Territorio S.L.
>>> > http://www.icarto.es/
>>> >
>>> > c/ Rafael Alberti nº 13 – 1º D
>>> > 15008 A Coruña
>>> > Galicia (Spain)
>>> > <a href="tel:%2B34%20881927808" value="+34881927808">+34 881927808
>>> >
>>> > Este correo electrónico contiene información estrictamente confidencial
>>> > y es
>>> > de uso exclusivo del destinatario, quedando prohibida a cualquier otra
>>> > persona su revelación, copia, distribución, o el ejercicio de cualquier
>>> > acción relativa a su contenido. Si ha recibido este mensaje por error,
>>> > por
>>> > favor conteste a su remitente mediante correo electrónico y proceda a
>>> > borrarlo de su sistema.
>>> >
>>> > Sus datos personales serán tratados de forma confidencial y no serán
>>> > cedidos
>>> > a terceros ajenos a ICARTO. En cualquier caso, podrá ejercer los derecho
>>> > de
>>> > oposición, acceso, rectificación y cancelación de acuerdo con lo
>>> > establecido
>>> > en la Ley Orgánica 15/99, de 13 de diciembre, de Protección de Datos de
>>> > Carácter Personal dirigiéndose a Innovación, Cooperación, Cartografía e
>>> > Territorio, SL. (ICARTO) en la dirección postal a C/ Rafael Alberti, nº
>>> > 13,
>>> > 1ºD, 15.008 – (A Coruña).
>>> >
>>> > _______________________________________________
>>> > gvSIG-desktop-devel mailing list
>>> > http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>>
>>> _______________________________________________
>>> gvSIG-desktop-devel mailing list
>>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
>>
>>
>>
>>
>> --
>> --------------------------------------
>> Joaquin Jose del Cerro Murciano
>> Development and software arquitecture manager at gvSIG Team
>> [hidden email]
>> [hidden email]
>> gvSIG Association
>> www.gvsig.com
>> www.gvsig.org
>>
>> _______________________________________________
>> gvSIG-desktop-devel mailing list
>> http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel



--
--------------------------------------
Joaquin Jose del Cerro Murciano
Development and software arquitecture manager at gvSIG Team
[hidden email]
[hidden email]
gvSIG Association
www.gvsig.com
www.gvsig.org

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: activation of actions in the TOCContext in 2.4

Andrea Antonello
[...]

>> INFO 78697 shows the first missing action, and after  INFO 86887 no
>> action is here anymore. But the debug breakpoints in the isVisible and
>> isEnabled do not react anymore, so I have no idea why this happens.
>>
> In gvSIG 2.4 you have added a new functionality that allows the user to
> activate and deactivate actions.
> You can use the "actionConfigurator" script to activate and deactivate the
> actions.
>
> From what is shown in the trace, it seems that those actions are deactivate.
> Can you check if the file "HOME/gvsig/actions-states.properties" exists?
> If it exists you can delete it to activate all the actions again.

This is a very interesting feature.
But no, I don't have that file, so it has to be something else.

Cheers,
Andrea

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel
Reply | Threaded
Open this post in threaded view
|

Re: activation of actions in the TOCContext in 2.4

Joaquin Jose del Cerro Murciano


2017-07-25 8:54 GMT+02:00 andrea antonello <[hidden email]>:
[...]
>> INFO 78697 shows the first missing action, and after  INFO 86887 no
>> action is here anymore. But the debug breakpoints in the isVisible and
>> isEnabled do not react anymore, so I have no idea why this happens.
>>
> In gvSIG 2.4 you have added a new functionality that allows the user to
> activate and deactivate actions.
> You can use the "actionConfigurator" script to activate and deactivate the
> actions.
>
> From what is shown in the trace, it seems that those actions are deactivate.
> Can you check if the file "HOME/gvsig/actions-states.properties" exists?
> If it exists you can delete it to activate all the actions again.

This is a very interesting feature.
But no, I don't have that file, so it has to be something else.

Well, the only thing I can think of is to see if you can put a breakpoint in the setActive method of the DefaultActionInfo class (by line 500) to see who can be set to false.
 
Cheers,
Andrea

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel



--
--------------------------------------
Joaquin Jose del Cerro Murciano
Development and software arquitecture manager at gvSIG Team
[hidden email]
[hidden email]
gvSIG Association
www.gvsig.com
www.gvsig.org

_______________________________________________
gvSIG-desktop-devel mailing list
http://joinup.ec.europa.eu/mailman/listinfo/gvsig-desktop-devel