1 11 package org.eclipse.ui.internal.cheatsheets.handlers; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 16 import org.eclipse.core.commands.AbstractHandler; 17 import org.eclipse.core.commands.ExecutionEvent; 18 import org.eclipse.core.commands.ExecutionException; 19 import org.eclipse.ui.cheatsheets.OpenCheatSheetAction; 20 21 26 public class OpenCheatSheetURLHandler extends AbstractHandler { 27 28 private static final String PARAM_ID_CHEAT_SHEET_ID = "cheatSheetId"; 30 private static final String PARAM_ID_NAME = "name"; 32 private static final String PARAM_ID_URL = "url"; 34 public Object execute(ExecutionEvent event) throws ExecutionException { 35 36 String cheatSheetId = event.getParameter(PARAM_ID_CHEAT_SHEET_ID); 37 if (cheatSheetId == null) { 38 throw new ExecutionException("missing cheatSheetId parameter"); } 40 41 String name = event.getParameter(PARAM_ID_NAME); 42 if (name == null) { 43 throw new ExecutionException("missing name parameter"); } 45 46 String urlText = event.getParameter(PARAM_ID_URL); 47 if (urlText == null) { 48 throw new ExecutionException("missing url parameter"); } 50 51 URL url; 52 try { 53 url = new URL (urlText); 54 } catch (MalformedURLException ex) { 55 throw new ExecutionException("malformed url: " + urlText, ex); } 57 58 OpenCheatSheetAction action = new OpenCheatSheetAction(cheatSheetId, 59 name, url); 60 action.run(); 61 62 return null; 63 } 64 65 } 66 | Popular Tags |