Changes

Jump to: navigation, search

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

1,831 bytes added, 23:55, 8 March 2011
"Delete Student" Command
[[Image: RCPCommand18.jpg | 700px]]<br/>
<br/>
Here is the code for the execute method of the DeleteStudent class. It finds the student(s) that user has selected on the table viewer to delete from the ModelProvider and then refreshes the viewer.<br/> <code>DeleteStudent.java </code><source lang=java> package cs.ecl.rcp.simplercp.commands; import java.util.Iterator;import java.util.List; import cs.ecl.rcp.simplercp.StudentsView;import cs.ecl.rcp.simplercp.model.*; 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.jface.viewers.ISelection;import org.eclipse.jface.viewers.IStructuredSelection;import org.eclipse.ui.IWorkbenchPage;import org.eclipse.ui.IWorkbenchWindow;import org.eclipse.ui.handlers.HandlerUtil; public class DeleteStudent extends AbstractHandler implements IHandler { @SuppressWarnings("unchecked") @Override public Object execute(ExecutionEvent event) throws ExecutionException { // TODO Auto-generated method stub IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); StudentsView studentsView = (StudentsView) page.findView(StudentsView.ID); ISelection selection = studentsView.getSite().getSelectionProvider().getSelection(); if(selection!=null && selection instanceof IStructuredSelection){ List<Student> students = ModelProvider.INSTANCE.getStudents(); IStructuredSelection sel = (IStructuredSelection)selection; // go through all selections if multiple selection is made for(Iterator<Student> iterator =sel.iterator();iterator.hasNext(); ){ Student student = iterator.next() ; students.remove(student); } studentsView.getViewer().refresh(); } return null; } } </source>
==== "Add Student" Command ====
1
edit

Navigation menu