5 Replies Latest reply on May 12, 2020 7:01 PM by Philipp Salvisberg

    Adding a context menu item to a table grid (e.g. for GeoRaptor)

    Philipp Salvisberg

      Dear SQL Developer Team,

       

      Simon Greener and his team tried to migrate an ESDK v1 extension called GeoRaptor to ESDK v2. See also his blog post on https://www.spdba.com.au/spatially-extending-database-management-and-development-tools-georaptor-dbeaver-pgadmin-and-ssms/

       

      They wanted to add a context menu to the data table (probably oracle.dbtools.raptor.controls.display.DisplayEditableResultTable). I guess that there is no option to do it via extension.xml (adding an action, controller and context-menu-hook). Looks like the hook is missing.

       

      Is it possible to do that with ESDK v2? If yes, any hint how? If no, any chance to provide this hook in a coming version of SQLDev?

       

      I know It is always possible to create an own view/editor and do whatever you want there. But providing an own context menu item in the data table would be much more flexible and the better solution from a usability point of view. It would work also in Reports and in ad hoc queries.

       

      Thank you very much.

      Philipp

        • 1. Re: Adding a context menu item to a table grid (e.g. for GeoRaptor)
          Simon Greener

          Thank you for this Philipp,

           

          I am the maintainer of the GeoRaptor extension. A number of people have tried to implement the grid hook that was a fundamental part of the extension. We have all failed and now it appears that in the API change the hook is no longer available.

           

          I second Philipp's request and request consideration be given to making some sort of hook available.

           

          regards

          Simon

          • 2. Re: Adding a context menu item to a table grid (e.g. for GeoRaptor)
            Brian Jeffries-Oracle

            Hi guys -

             

            Can one of you point me at / send me the prior hook registration and the menu handler? From the image in the post, it looks like you want to target a grid cell with sdo_geometry data -- or is it a grid with sdo_geometery columns? Basically need to know what context should the menu appear in and what information you need for the extension.

             

            -Brian.

             

            P.S.: Here's your hint:

            Looks like you want a context-menu-listeners declaration. So Action & Controller declared as usual (if you wish) then after trigger-hooks,

            ``` xml

              <hooks>

                <jdeveloper-hook>

                  <context-menu-listners>

                    <site idref="editor">

                      <listener-class>my.package.MyContextMenuListener</listener-class>

                    </site>

                </jdeveloper-hook>

              </hooks>

            ```

            Then in menuWillShow(ContextMenu menu)

            EventObject event = contextMenu.getContext().getEvent();

            Object source = null == event ? null : event.getSource();

            if (source instanceof RaptorGridTable) { //ResultSetTable/EditableResultSetTable

                // add your menu items either defining actions/controllers here, or from declarations in extension.xml

                // note that in your controller, the target cell is based on mouse position for mouse events, table focused cell for keyboard

            }

            -Brian

            • 3. Re: Adding a context menu item to a table grid (e.g. for GeoRaptor)
              Philipp Salvisberg

              Hi Brian,

               

              Thank you for the hint.

               

              I created a small sample project on GitHub. I'm able to load the extension via another action. But the context menu listener is not invoked on the result table. Any idea what I'm doing wrong in the extension.xml ?  As soon as the class is registered correctly I should be able to deal with the rest.

               

              Thanks,

              Philipp

              • 4. Re: Adding a context menu item to a table grid (e.g. for GeoRaptor)
                Brian Jeffries-Oracle

                Hi Philipp -

                 

                I'll grab your repo & take a look later today / tomorrow. The menuWillShow *should* be being called any time a context menu on any 'editor' is requested. What result table are you using to test?

                 

                Another option (assuming your extension has an Addin) is to do it the old fashioned way by calling EditorManager.getEditorManager().getContextMenu().addContextMenuListener(new MyContextMenuListener()) during initialize().

                 

                Ah, grid has it's own context menu with its own menu listener class. It will have to be done programmatically (e.g., in Addin.initialize()), but you can add your own.

                GridContextMenuItem menuListener = new GridContextMenuItem() {
                    /**
                     * PRECONDITION: _table will NOT be null
                     * @param contextMenu the context menu being built
                     * @return true if createAndShowAction should be called
                     */
                     @override
                     protected boolean canShow(ContextMenu contextMenu) {
                         // and any other preconditions besides 'just' RaptorGridTable _table != null   
                         return true;
                    }
                  
                    /**
                     * PRECONDITION: _table will NOT be null and canShow has returned true
                     * @param contextMenu the context menu being built
                     * Add your menuItem(s) to the context menu
                     */
                     @override
                     protected abstract void createAndShowMenu(ContextMenu contextMenu) {   
                         // add your stuff
                     }
                };
                RaptorGridTable.addGridContextMenu(menuListener);

                -Brian.

                2 people found this helpful
                • 5. Re: Adding a context menu item to a table grid (e.g. for GeoRaptor)
                  Philipp Salvisberg

                  Hi Brian,

                   

                  Thanks a lot. Works. I had to add the namespace for jdeveloper-hook. Creating the GridContextMenuItem in the addin did the trick. Wow. I would never have found this solution myself. Thanks again.

                   

                  grid.png

                  I've updated the example in GitHub. Needs some cleaning up and some exploration of the context. But this should be easy now.

                   

                  Cheers,

                  Philipp