Changes

Jump to: navigation, search

Teams Winter 2011/team1/RCP/Define and use commands

1,370 bytes added, 12:24, 9 March 2011
"Add Student" Command
Please do this part, after the view, Jface viewer and Editor view is added and working properly.<br/>
1. Implementing the execute method of the command handler class:<br/>
This code will get access to the page and creates an empty editor input (sending it the id of string "0" indicating that it belongs to no student), then tries to open the editor with that input id.
<code>AddStudent.java </code>
<source lang=java>
package cs.ecl.rcp.simplercp.commands;
 
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.handlers.HandlerUtil;
 
import cs.ecl.rcp.simplercp.editor.MyStudentEditor;
import cs.ecl.rcp.simplercp.editor.MyStudentEditorInput;
 
 
public class AddStudent extends AbstractHandler implements IHandler {
 
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
MyStudentEditorInput input = new MyStudentEditorInput("0");
try {
page.openEditor(input, MyStudentEditor.ID);
 
} catch (PartInitException e) {
throw new RuntimeException(e);
}
 
return null;
}
 
}
 
<source>
==== "Delete Student" Command ====
1
edit

Navigation menu