Eclipse plugin: How to find from which View the user opened a Dialog?












0














I know how to find out whether a View like the "Project Explorer" is open in Eclipse. But how can I determine if the user opened a dialog from the "z/OS Projects" View or from the "Project Explorer" View?



On base of the result, I need to locate a file in the current active View.
This part I got covered already.










share|improve this question






















  • I don't think you can. It is normal to use use the current selection rather than trying to find a view. This is straightforward in a handler.
    – greg-449
    Nov 23 '18 at 11:11












  • Thanks Greg, can you follow up on this by giving an example? :-)
    – Peter DK
    Nov 23 '18 at 11:54










  • Not until you give more information. Is this a dialog you are opening from and command handler (something extending AbstractHandler)? If not what are you doing?
    – greg-449
    Nov 23 '18 at 12:13










  • Sure. I am opening a LocateMemberHandler: public class LocateMemberHandler extends AbstractHandler{ It is used to quickly locate files accross the workbench. A Locate button on the dialog will locate the selected file in z/OS Projects or Project Explorer (expanding all folders) without opening the source code.
    – Peter DK
    Nov 23 '18 at 12:18


















0














I know how to find out whether a View like the "Project Explorer" is open in Eclipse. But how can I determine if the user opened a dialog from the "z/OS Projects" View or from the "Project Explorer" View?



On base of the result, I need to locate a file in the current active View.
This part I got covered already.










share|improve this question






















  • I don't think you can. It is normal to use use the current selection rather than trying to find a view. This is straightforward in a handler.
    – greg-449
    Nov 23 '18 at 11:11












  • Thanks Greg, can you follow up on this by giving an example? :-)
    – Peter DK
    Nov 23 '18 at 11:54










  • Not until you give more information. Is this a dialog you are opening from and command handler (something extending AbstractHandler)? If not what are you doing?
    – greg-449
    Nov 23 '18 at 12:13










  • Sure. I am opening a LocateMemberHandler: public class LocateMemberHandler extends AbstractHandler{ It is used to quickly locate files accross the workbench. A Locate button on the dialog will locate the selected file in z/OS Projects or Project Explorer (expanding all folders) without opening the source code.
    – Peter DK
    Nov 23 '18 at 12:18
















0












0








0







I know how to find out whether a View like the "Project Explorer" is open in Eclipse. But how can I determine if the user opened a dialog from the "z/OS Projects" View or from the "Project Explorer" View?



On base of the result, I need to locate a file in the current active View.
This part I got covered already.










share|improve this question













I know how to find out whether a View like the "Project Explorer" is open in Eclipse. But how can I determine if the user opened a dialog from the "z/OS Projects" View or from the "Project Explorer" View?



On base of the result, I need to locate a file in the current active View.
This part I got covered already.







java eclipse eclipse-plugin






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 11:07









Peter DK

112




112












  • I don't think you can. It is normal to use use the current selection rather than trying to find a view. This is straightforward in a handler.
    – greg-449
    Nov 23 '18 at 11:11












  • Thanks Greg, can you follow up on this by giving an example? :-)
    – Peter DK
    Nov 23 '18 at 11:54










  • Not until you give more information. Is this a dialog you are opening from and command handler (something extending AbstractHandler)? If not what are you doing?
    – greg-449
    Nov 23 '18 at 12:13










  • Sure. I am opening a LocateMemberHandler: public class LocateMemberHandler extends AbstractHandler{ It is used to quickly locate files accross the workbench. A Locate button on the dialog will locate the selected file in z/OS Projects or Project Explorer (expanding all folders) without opening the source code.
    – Peter DK
    Nov 23 '18 at 12:18




















  • I don't think you can. It is normal to use use the current selection rather than trying to find a view. This is straightforward in a handler.
    – greg-449
    Nov 23 '18 at 11:11












  • Thanks Greg, can you follow up on this by giving an example? :-)
    – Peter DK
    Nov 23 '18 at 11:54










  • Not until you give more information. Is this a dialog you are opening from and command handler (something extending AbstractHandler)? If not what are you doing?
    – greg-449
    Nov 23 '18 at 12:13










  • Sure. I am opening a LocateMemberHandler: public class LocateMemberHandler extends AbstractHandler{ It is used to quickly locate files accross the workbench. A Locate button on the dialog will locate the selected file in z/OS Projects or Project Explorer (expanding all folders) without opening the source code.
    – Peter DK
    Nov 23 '18 at 12:18


















I don't think you can. It is normal to use use the current selection rather than trying to find a view. This is straightforward in a handler.
– greg-449
Nov 23 '18 at 11:11






I don't think you can. It is normal to use use the current selection rather than trying to find a view. This is straightforward in a handler.
– greg-449
Nov 23 '18 at 11:11














Thanks Greg, can you follow up on this by giving an example? :-)
– Peter DK
Nov 23 '18 at 11:54




Thanks Greg, can you follow up on this by giving an example? :-)
– Peter DK
Nov 23 '18 at 11:54












Not until you give more information. Is this a dialog you are opening from and command handler (something extending AbstractHandler)? If not what are you doing?
– greg-449
Nov 23 '18 at 12:13




Not until you give more information. Is this a dialog you are opening from and command handler (something extending AbstractHandler)? If not what are you doing?
– greg-449
Nov 23 '18 at 12:13












Sure. I am opening a LocateMemberHandler: public class LocateMemberHandler extends AbstractHandler{ It is used to quickly locate files accross the workbench. A Locate button on the dialog will locate the selected file in z/OS Projects or Project Explorer (expanding all folders) without opening the source code.
– Peter DK
Nov 23 '18 at 12:18






Sure. I am opening a LocateMemberHandler: public class LocateMemberHandler extends AbstractHandler{ It is used to quickly locate files accross the workbench. A Locate button on the dialog will locate the selected file in z/OS Projects or Project Explorer (expanding all folders) without opening the source code.
– Peter DK
Nov 23 '18 at 12:18














1 Answer
1






active

oldest

votes


















0














In a handler class extending AbstractHandler you can use the HandlerUtil method to get various information from the execution event.



For the current selection you can use:



IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event);


where event is the ExecutionEvent passed to the handler.



To get any resource (such as an IFile) contained in the selection use:



IResource resource = Adapters.adapt(sel.getFirstElement(), IResource.class);


(you may also be able to adapt directly to IFile).



Note: both getCurrentStructuredSelection and Adapters are only in fairly recent versions of Eclipse. For older versions the code is a little more complex.






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%2f53445558%2feclipse-plugin-how-to-find-from-which-view-the-user-opened-a-dialog%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














    In a handler class extending AbstractHandler you can use the HandlerUtil method to get various information from the execution event.



    For the current selection you can use:



    IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event);


    where event is the ExecutionEvent passed to the handler.



    To get any resource (such as an IFile) contained in the selection use:



    IResource resource = Adapters.adapt(sel.getFirstElement(), IResource.class);


    (you may also be able to adapt directly to IFile).



    Note: both getCurrentStructuredSelection and Adapters are only in fairly recent versions of Eclipse. For older versions the code is a little more complex.






    share|improve this answer


























      0














      In a handler class extending AbstractHandler you can use the HandlerUtil method to get various information from the execution event.



      For the current selection you can use:



      IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event);


      where event is the ExecutionEvent passed to the handler.



      To get any resource (such as an IFile) contained in the selection use:



      IResource resource = Adapters.adapt(sel.getFirstElement(), IResource.class);


      (you may also be able to adapt directly to IFile).



      Note: both getCurrentStructuredSelection and Adapters are only in fairly recent versions of Eclipse. For older versions the code is a little more complex.






      share|improve this answer
























        0












        0








        0






        In a handler class extending AbstractHandler you can use the HandlerUtil method to get various information from the execution event.



        For the current selection you can use:



        IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event);


        where event is the ExecutionEvent passed to the handler.



        To get any resource (such as an IFile) contained in the selection use:



        IResource resource = Adapters.adapt(sel.getFirstElement(), IResource.class);


        (you may also be able to adapt directly to IFile).



        Note: both getCurrentStructuredSelection and Adapters are only in fairly recent versions of Eclipse. For older versions the code is a little more complex.






        share|improve this answer












        In a handler class extending AbstractHandler you can use the HandlerUtil method to get various information from the execution event.



        For the current selection you can use:



        IStructuredSelection sel = HandlerUtil.getCurrentStructuredSelection(event);


        where event is the ExecutionEvent passed to the handler.



        To get any resource (such as an IFile) contained in the selection use:



        IResource resource = Adapters.adapt(sel.getFirstElement(), IResource.class);


        (you may also be able to adapt directly to IFile).



        Note: both getCurrentStructuredSelection and Adapters are only in fairly recent versions of Eclipse. For older versions the code is a little more complex.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 14:10









        greg-449

        88.1k166296




        88.1k166296






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53445558%2feclipse-plugin-how-to-find-from-which-view-the-user-opened-a-dialog%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







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks