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 :-(


Hi, I am so glad I've discovered such a useful site! Thank you!
ReplyDelete