How to capture the value of a cell of a TableViewer where a contextual menu has been activated in eclipse e4?










1















In one of my eclipse e4 application JMSToolBox, some data is displayed in aTableViewer

A contextual menu is defined in the e4 model file (e4xmi) and linked to theTableViewer like this





menuService.registerContextMenu(tableViwere.getTable(), <name of the e4 part menu>);


Attached to the contextual menu in the e4 model, a "menu item" is linked to a"Dynamic Menu Contribution" class that dynamically add the menu items to the menu:



public class VisualizerShowPayloadAsMenu {
@Inject private EModelService modelService;
@AboutToShow
public void aboutToShow(EModelService modelService, List<MMenuElement> items)
// Not the real code..., illustrate adding a dynamic menu item to the contextual menu
MDirectMenuItem dynamicItem = modelService.createModelElement(MDirectMenuItem.class);
dynamicItem.setLabel(<name..>);
dynamicItem.setContributorURI(Constants.BASE_CORE_PLUGIN);// "platform:/plugin/org.titou10.jtb.core");
dynamicItem.setContributionURI(Constants.VISUALIZER_MENU_URI);// "bundleclass://org.titou10.jtb.core/org.titou10.jtb.visualizer.ui.VisualizerShowPayloadAsHandler");
items.add(dynamicItem);



Now, what I want to do is to capture the data in the underlying cell where the contextual menu has been activated, and get that value back in the method annotated by"@AboutToShow" in order
to addMDirectMenuItementries to the contextual menu with a label containing that value

Q: how to do that with eclipse rcp e4?



In the attached picture, the right click happened in the cell with content="ID:414d5120514d41414544202020202020ee4bb25612666920". I would like to get this value back in the @AboutToShowmethod and add menu items to the"Open Payload as..."menu based on that value
Thanks



enter image description here










share|improve this question
























  • @greg, you've deleted your anser. no problem with that but you also deleted my second comment. So, what I'm thinking about is to capture the right clicked event in a cell, get the text shown in the cell and store the value in the eclipse context. This could be injected later in the@AboutToShow method. The question is what listener wiil give access to the cell content? CellEditor? aFocusListenr? Something else? WDYT?

    – titou10
    Nov 8 '18 at 19:56











  • I don't think there is a straightforward way to determine which cell the mouse was on when the context menu was invoked - the cell generally won't have focus. EditingSupport is for allowing the current cell to be edited it isn't involved in context menu display.

    – greg-449
    Nov 9 '18 at 8:04















1















In one of my eclipse e4 application JMSToolBox, some data is displayed in aTableViewer

A contextual menu is defined in the e4 model file (e4xmi) and linked to theTableViewer like this





menuService.registerContextMenu(tableViwere.getTable(), <name of the e4 part menu>);


Attached to the contextual menu in the e4 model, a "menu item" is linked to a"Dynamic Menu Contribution" class that dynamically add the menu items to the menu:



public class VisualizerShowPayloadAsMenu {
@Inject private EModelService modelService;
@AboutToShow
public void aboutToShow(EModelService modelService, List<MMenuElement> items)
// Not the real code..., illustrate adding a dynamic menu item to the contextual menu
MDirectMenuItem dynamicItem = modelService.createModelElement(MDirectMenuItem.class);
dynamicItem.setLabel(<name..>);
dynamicItem.setContributorURI(Constants.BASE_CORE_PLUGIN);// "platform:/plugin/org.titou10.jtb.core");
dynamicItem.setContributionURI(Constants.VISUALIZER_MENU_URI);// "bundleclass://org.titou10.jtb.core/org.titou10.jtb.visualizer.ui.VisualizerShowPayloadAsHandler");
items.add(dynamicItem);



Now, what I want to do is to capture the data in the underlying cell where the contextual menu has been activated, and get that value back in the method annotated by"@AboutToShow" in order
to addMDirectMenuItementries to the contextual menu with a label containing that value

Q: how to do that with eclipse rcp e4?



In the attached picture, the right click happened in the cell with content="ID:414d5120514d41414544202020202020ee4bb25612666920". I would like to get this value back in the @AboutToShowmethod and add menu items to the"Open Payload as..."menu based on that value
Thanks



enter image description here










share|improve this question
























  • @greg, you've deleted your anser. no problem with that but you also deleted my second comment. So, what I'm thinking about is to capture the right clicked event in a cell, get the text shown in the cell and store the value in the eclipse context. This could be injected later in the@AboutToShow method. The question is what listener wiil give access to the cell content? CellEditor? aFocusListenr? Something else? WDYT?

    – titou10
    Nov 8 '18 at 19:56











  • I don't think there is a straightforward way to determine which cell the mouse was on when the context menu was invoked - the cell generally won't have focus. EditingSupport is for allowing the current cell to be edited it isn't involved in context menu display.

    – greg-449
    Nov 9 '18 at 8:04













1












1








1








In one of my eclipse e4 application JMSToolBox, some data is displayed in aTableViewer

A contextual menu is defined in the e4 model file (e4xmi) and linked to theTableViewer like this





menuService.registerContextMenu(tableViwere.getTable(), <name of the e4 part menu>);


Attached to the contextual menu in the e4 model, a "menu item" is linked to a"Dynamic Menu Contribution" class that dynamically add the menu items to the menu:



public class VisualizerShowPayloadAsMenu {
@Inject private EModelService modelService;
@AboutToShow
public void aboutToShow(EModelService modelService, List<MMenuElement> items)
// Not the real code..., illustrate adding a dynamic menu item to the contextual menu
MDirectMenuItem dynamicItem = modelService.createModelElement(MDirectMenuItem.class);
dynamicItem.setLabel(<name..>);
dynamicItem.setContributorURI(Constants.BASE_CORE_PLUGIN);// "platform:/plugin/org.titou10.jtb.core");
dynamicItem.setContributionURI(Constants.VISUALIZER_MENU_URI);// "bundleclass://org.titou10.jtb.core/org.titou10.jtb.visualizer.ui.VisualizerShowPayloadAsHandler");
items.add(dynamicItem);



Now, what I want to do is to capture the data in the underlying cell where the contextual menu has been activated, and get that value back in the method annotated by"@AboutToShow" in order
to addMDirectMenuItementries to the contextual menu with a label containing that value

Q: how to do that with eclipse rcp e4?



In the attached picture, the right click happened in the cell with content="ID:414d5120514d41414544202020202020ee4bb25612666920". I would like to get this value back in the @AboutToShowmethod and add menu items to the"Open Payload as..."menu based on that value
Thanks



enter image description here










share|improve this question
















In one of my eclipse e4 application JMSToolBox, some data is displayed in aTableViewer

A contextual menu is defined in the e4 model file (e4xmi) and linked to theTableViewer like this





menuService.registerContextMenu(tableViwere.getTable(), <name of the e4 part menu>);


Attached to the contextual menu in the e4 model, a "menu item" is linked to a"Dynamic Menu Contribution" class that dynamically add the menu items to the menu:



public class VisualizerShowPayloadAsMenu {
@Inject private EModelService modelService;
@AboutToShow
public void aboutToShow(EModelService modelService, List<MMenuElement> items)
// Not the real code..., illustrate adding a dynamic menu item to the contextual menu
MDirectMenuItem dynamicItem = modelService.createModelElement(MDirectMenuItem.class);
dynamicItem.setLabel(<name..>);
dynamicItem.setContributorURI(Constants.BASE_CORE_PLUGIN);// "platform:/plugin/org.titou10.jtb.core");
dynamicItem.setContributionURI(Constants.VISUALIZER_MENU_URI);// "bundleclass://org.titou10.jtb.core/org.titou10.jtb.visualizer.ui.VisualizerShowPayloadAsHandler");
items.add(dynamicItem);



Now, what I want to do is to capture the data in the underlying cell where the contextual menu has been activated, and get that value back in the method annotated by"@AboutToShow" in order
to addMDirectMenuItementries to the contextual menu with a label containing that value

Q: how to do that with eclipse rcp e4?



In the attached picture, the right click happened in the cell with content="ID:414d5120514d41414544202020202020ee4bb25612666920". I would like to get this value back in the @AboutToShowmethod and add menu items to the"Open Payload as..."menu based on that value
Thanks



enter image description here







swt eclipse-rcp e4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 '18 at 21:00









greg-449

88.9k166397




88.9k166397










asked Nov 7 '18 at 20:07









titou10titou10

1,1581825




1,1581825












  • @greg, you've deleted your anser. no problem with that but you also deleted my second comment. So, what I'm thinking about is to capture the right clicked event in a cell, get the text shown in the cell and store the value in the eclipse context. This could be injected later in the@AboutToShow method. The question is what listener wiil give access to the cell content? CellEditor? aFocusListenr? Something else? WDYT?

    – titou10
    Nov 8 '18 at 19:56











  • I don't think there is a straightforward way to determine which cell the mouse was on when the context menu was invoked - the cell generally won't have focus. EditingSupport is for allowing the current cell to be edited it isn't involved in context menu display.

    – greg-449
    Nov 9 '18 at 8:04

















  • @greg, you've deleted your anser. no problem with that but you also deleted my second comment. So, what I'm thinking about is to capture the right clicked event in a cell, get the text shown in the cell and store the value in the eclipse context. This could be injected later in the@AboutToShow method. The question is what listener wiil give access to the cell content? CellEditor? aFocusListenr? Something else? WDYT?

    – titou10
    Nov 8 '18 at 19:56











  • I don't think there is a straightforward way to determine which cell the mouse was on when the context menu was invoked - the cell generally won't have focus. EditingSupport is for allowing the current cell to be edited it isn't involved in context menu display.

    – greg-449
    Nov 9 '18 at 8:04
















@greg, you've deleted your anser. no problem with that but you also deleted my second comment. So, what I'm thinking about is to capture the right clicked event in a cell, get the text shown in the cell and store the value in the eclipse context. This could be injected later in the@AboutToShow method. The question is what listener wiil give access to the cell content? CellEditor? aFocusListenr? Something else? WDYT?

– titou10
Nov 8 '18 at 19:56





@greg, you've deleted your anser. no problem with that but you also deleted my second comment. So, what I'm thinking about is to capture the right clicked event in a cell, get the text shown in the cell and store the value in the eclipse context. This could be injected later in the@AboutToShow method. The question is what listener wiil give access to the cell content? CellEditor? aFocusListenr? Something else? WDYT?

– titou10
Nov 8 '18 at 19:56













I don't think there is a straightforward way to determine which cell the mouse was on when the context menu was invoked - the cell generally won't have focus. EditingSupport is for allowing the current cell to be edited it isn't involved in context menu display.

– greg-449
Nov 9 '18 at 8:04





I don't think there is a straightforward way to determine which cell the mouse was on when the context menu was invoked - the cell generally won't have focus. EditingSupport is for allowing the current cell to be edited it isn't involved in context menu display.

– greg-449
Nov 9 '18 at 8:04












1 Answer
1






active

oldest

votes


















0














I found a way to do it!

I'm not sure it is the best way, but at least it works and it is quite simple



The following code is here to illustrate the idea, it is not valid Java.
In the part that manage theTableViewer:



TableViewer tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
...
new TableViewerFocusCellManager(tableViewer, new JTBFocusCellHighlighter(tableViewer, windowContext));


JTBFocusCellHighlighterclass:



public class JTBFocusCellHighlighter extends FocusCellHighlighter 
private IEclipseContext windowContext;
private Table table;
public JTBFocusCellHighlighter(ColumnViewer viewer, IEclipseContext windowContext)
super(viewer);
this.windowContext = windowContext;
this.table = ((TableViewer) viewer).getTable();

@Override
protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell)
super.focusCellChanged(newCell, oldCell);
// Capture the content of the cell (or other info..) and store it in Eclipse Context
windowContext.set("key", newCell.getText());
TableColumn tableColumn = table.getColumn(newCell.getColumnIndex());




Real code implementation: JTBSessionContentViewPart , JTBFocusCellHighlighter and FilterMenu






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197054%2fhow-to-capture-the-value-of-a-cell-of-a-tableviewer-where-a-contextual-menu-has%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I found a way to do it!

    I'm not sure it is the best way, but at least it works and it is quite simple



    The following code is here to illustrate the idea, it is not valid Java.
    In the part that manage theTableViewer:



    TableViewer tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    ...
    new TableViewerFocusCellManager(tableViewer, new JTBFocusCellHighlighter(tableViewer, windowContext));


    JTBFocusCellHighlighterclass:



    public class JTBFocusCellHighlighter extends FocusCellHighlighter 
    private IEclipseContext windowContext;
    private Table table;
    public JTBFocusCellHighlighter(ColumnViewer viewer, IEclipseContext windowContext)
    super(viewer);
    this.windowContext = windowContext;
    this.table = ((TableViewer) viewer).getTable();

    @Override
    protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell)
    super.focusCellChanged(newCell, oldCell);
    // Capture the content of the cell (or other info..) and store it in Eclipse Context
    windowContext.set("key", newCell.getText());
    TableColumn tableColumn = table.getColumn(newCell.getColumnIndex());




    Real code implementation: JTBSessionContentViewPart , JTBFocusCellHighlighter and FilterMenu






    share|improve this answer



























      0














      I found a way to do it!

      I'm not sure it is the best way, but at least it works and it is quite simple



      The following code is here to illustrate the idea, it is not valid Java.
      In the part that manage theTableViewer:



      TableViewer tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
      ...
      new TableViewerFocusCellManager(tableViewer, new JTBFocusCellHighlighter(tableViewer, windowContext));


      JTBFocusCellHighlighterclass:



      public class JTBFocusCellHighlighter extends FocusCellHighlighter 
      private IEclipseContext windowContext;
      private Table table;
      public JTBFocusCellHighlighter(ColumnViewer viewer, IEclipseContext windowContext)
      super(viewer);
      this.windowContext = windowContext;
      this.table = ((TableViewer) viewer).getTable();

      @Override
      protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell)
      super.focusCellChanged(newCell, oldCell);
      // Capture the content of the cell (or other info..) and store it in Eclipse Context
      windowContext.set("key", newCell.getText());
      TableColumn tableColumn = table.getColumn(newCell.getColumnIndex());




      Real code implementation: JTBSessionContentViewPart , JTBFocusCellHighlighter and FilterMenu






      share|improve this answer

























        0












        0








        0







        I found a way to do it!

        I'm not sure it is the best way, but at least it works and it is quite simple



        The following code is here to illustrate the idea, it is not valid Java.
        In the part that manage theTableViewer:



        TableViewer tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
        ...
        new TableViewerFocusCellManager(tableViewer, new JTBFocusCellHighlighter(tableViewer, windowContext));


        JTBFocusCellHighlighterclass:



        public class JTBFocusCellHighlighter extends FocusCellHighlighter 
        private IEclipseContext windowContext;
        private Table table;
        public JTBFocusCellHighlighter(ColumnViewer viewer, IEclipseContext windowContext)
        super(viewer);
        this.windowContext = windowContext;
        this.table = ((TableViewer) viewer).getTable();

        @Override
        protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell)
        super.focusCellChanged(newCell, oldCell);
        // Capture the content of the cell (or other info..) and store it in Eclipse Context
        windowContext.set("key", newCell.getText());
        TableColumn tableColumn = table.getColumn(newCell.getColumnIndex());




        Real code implementation: JTBSessionContentViewPart , JTBFocusCellHighlighter and FilterMenu






        share|improve this answer













        I found a way to do it!

        I'm not sure it is the best way, but at least it works and it is quite simple



        The following code is here to illustrate the idea, it is not valid Java.
        In the part that manage theTableViewer:



        TableViewer tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
        ...
        new TableViewerFocusCellManager(tableViewer, new JTBFocusCellHighlighter(tableViewer, windowContext));


        JTBFocusCellHighlighterclass:



        public class JTBFocusCellHighlighter extends FocusCellHighlighter 
        private IEclipseContext windowContext;
        private Table table;
        public JTBFocusCellHighlighter(ColumnViewer viewer, IEclipseContext windowContext)
        super(viewer);
        this.windowContext = windowContext;
        this.table = ((TableViewer) viewer).getTable();

        @Override
        protected void focusCellChanged(ViewerCell newCell, ViewerCell oldCell)
        super.focusCellChanged(newCell, oldCell);
        // Capture the content of the cell (or other info..) and store it in Eclipse Context
        windowContext.set("key", newCell.getText());
        TableColumn tableColumn = table.getColumn(newCell.getColumnIndex());




        Real code implementation: JTBSessionContentViewPart , JTBFocusCellHighlighter and FilterMenu







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 21:58









        titou10titou10

        1,1581825




        1,1581825



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53197054%2fhow-to-capture-the-value-of-a-cell-of-a-tableviewer-where-a-contextual-menu-has%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Barbados

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3