DZone
Java Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > Keyboard Accessibility Through Command Framework

Keyboard Accessibility Through Command Framework

Prakash  user avatar by
Prakash
·
Jun. 26, 09 · Java Zone · Interview
Like (0)
Save
Tweet
3.57K Views

Join the DZone community and get the full member experience.

Join For Free

Keyboard shortcuts is usually much speedier than reaching out your mouse, moving it, pointing it to something and clicking. But there are some things which cannot be done that easily by keyboard shortcuts. For me, one of them is finding out a closed project and open it. Unfortunately, I've quite a large set of projects in my workspace and try to keep most them closed, when not used. In addition to that in the Package Explorer, I've the 'Closed Projects' filter on. So if I need to open a project, I've use the pull down menu, uncheck 'Closed Projects' navigate thru the working sets to find the right project and double click it. To enable keyboard access to this regular task, I decided to make use of Commands Framework.

The solution is to add a parameterized command, and in the values, I compute the projects which are closed. So when I press the awesome shortcut (Ctrl+3) it would display me the list of closed projects. With few keys, I can navigate to the project I want and open it. Lets see how to do it. First step is the command with the parameter:

<extension point="org.eclipse.ui.commands">
<command
defaultHandler="com.eclipse_tips.handlers.OpenProjectHandler"
id="com.eclipse-tips.openProject.command"
name="Open Project">
<commandParameter
id="com.eclipse-tips.openProject.projectNameParameter"
name="Name"
optional="false"
values="com.eclipse_tips.handlers.ProjectNameParameterValues">
</commandParameter>
</command>
</extension>

And the handler:

public Object execute(ExecutionEvent event) throws ExecutionException {
String projectName = event.getParameter("com.eclipse-tips.openProject.projectNameParameter");
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(projectName);
try {
project.open(null);
} catch (CoreException e) {
throw new ExecutionException("Error occured while open project", e);
}
return null;
}

For the parameter values, I look for closed projects and return them:

public Map<String, String> getParameterValues() {

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = root.getProjects();
Map<String, String> paramValues = new HashMap<String, String>();
for (IProject project : projects) {
if (project.exists() && !project.isOpen()) {
paramValues.put(project.getName(), project.getName());
}

}
return paramValues;
}

So finally, When I press Ctrl+3 and type OPN, I get the list:

 

This idea can be extended to provide keyboard accessibility to many functionalities. Say in an RCP mail application, you can add a command like 'Go To Mail' with parameter as the Subject/Sender:


Hmmm, if only the 'Built On Eclipse' mail app that I *have* to use, knows the existence of threads other than the UI thread :-(

From http://blog.eclipse-tips.com

 

Command (computing) Framework

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • JIT Compilation of SQL in NoSQL
  • Introduction to JWT (Also JWS, JWE, JWA, JWK)
  • Is NoOps the End of DevOps?
  • SSH Tutorial: Nice and Easy [Video]

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo