Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7402957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:55:33+00:00 2026-05-29T04:55:33+00:00

I have two separate views that both show multiple lists of values. Both views

  • 0

I have two separate views that both show multiple lists of values. Both views are open at the same time.

I have a generic command AddNewItemInList that I want to add to the Toolbar of both views. The command should add a new item to the list that currently has focus. The command should be disabled if the user has not yet selected a list.

I currently have used the following to execute the command.

public class MyViewPart extends ViewPart {
    [...]
    public Object getAdapter(Class clazz) {
       if(clazz.equals(List.class))
           return getListInFocus(); // can be null if no list in focus
       return null;
    }
}

public class AddNewItemInList extends AbstractHandler {
    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        MyList list = HandlerUtil.getActivePart(event).getAdapter(MyList.class);
        list.add(new Item());
        return null;
    }
}

So far so good, but I have no clue how to enable or disable the Handler accordingly. I have read about the Eclipse Core Commands framework. I am very lost.

Answered questions:
How can I create an expression to see if the getAdapter() method of the view does not return null? -> Answered below

How do I get the view for which this command was configured (and not the currently active view) ? -> I can add the viewId as a command parameter

Remaining questions:
Should I configure two separate Handler instances in my plugin.xml (one for each view) ? -> The enabledWhen condition can only use the current evaluation context. It seems I cannot use any parameters provided by the command. This means a handler is either enabled or disabled depending on the state of the full workbench.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:55:34+00:00Added an answer on May 29, 2026 at 4:55 am

    How can I create an expression to see if the getAdapter() method of the view does not return null?

    You can use custom property testers. It needs a lot of boilerplate and looks ugly, but it works.

    EDIT: Actually, it’s a lot simpler:

    <with variable="activePart">
      <adapt type="com.foo.MyList"/>
    </with>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two divs and two separate links that triggers slideDown and slideUp for
I have an odd need to open two separate instances of excel and having
I have two columns in a location model that should both associate with the
I have an iPhone app, it has two separate MKMapView components in different views,
I have a view table which is a union of two separate tables (say
We have two separate web-apps, say 'retailUI' and 'bulkUI'. These two are basically two
We have two databases, in two separate locations. One of the databases resides in
Say I have two separate classes, A and B. I also have Repository class
I have two essentially separate applications for configuring two pieces of hardware sold by
I have two physically-separate MySQL databases on which I have to run a single

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.