1
edit
Changes
no edit summary
}
</source>
<br/>
<br/>
'''RemoveCityHandler'''
For Commmand
<pre>
id: ecl.team2.lab3.rcpExample.RemoveCity
name: Add City
defaultHandler: ecl.team2.lab3.commands.RemoveCityHandler
</pre>
For Menu Command
<pre>
commandId: ecl.team2.lab3.rcpExample.RemoveCity
label: Remove City
tooltip: Removes a city or multiple cities based on selection
</pre>
For RemoveCityHandler.java<source lang=java>package ecl.team2.lab3.commands; import java.util.ArrayList;import java.util.Iterator; 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; import ecl.team2.lab3.rcpexample.WeatherView;import ecl.team2.lab3.weathermodel.*; public class RemoveCityHandler extends AbstractHandler implements IHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); IWorkbenchPage page = window.getActivePage(); WeatherView view = (WeatherView) page.findView(WeatherView.ID); ISelection select = view.getSite().getSelectionProvider().getSelection(); if(select!=null && select instanceof IStructuredSelection) { IStructuredSelection sel = (IStructuredSelection)select; for(Iterator<Weather> iter = sel.iterator(); iter.hasNext();) { Weather temp = iter.next(); SimpleWeatherSystem.INSTANCE.removeCity(temp.getCity()); } view.getViewer().refresh(); } return null; } }<br/source>
<br/>
===Views===