KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > handlers > OpenCheatSheetURLHandler


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.cheatsheets.handlers;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
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 /**
22  * Opens a cheatsheet given an id, name and a URL to a cheat sheet content file.
23  *
24  * @since 3.2
25  */

26 public class OpenCheatSheetURLHandler extends AbstractHandler {
27
28     private static final String JavaDoc PARAM_ID_CHEAT_SHEET_ID = "cheatSheetId"; //$NON-NLS-1$
29

30     private static final String JavaDoc PARAM_ID_NAME = "name"; //$NON-NLS-1$
31

32     private static final String JavaDoc PARAM_ID_URL = "url"; //$NON-NLS-1$
33

34     public Object JavaDoc execute(ExecutionEvent event) throws ExecutionException {
35
36         String JavaDoc cheatSheetId = event.getParameter(PARAM_ID_CHEAT_SHEET_ID);
37         if (cheatSheetId == null) {
38             throw new ExecutionException("missing cheatSheetId parameter"); //$NON-NLS-1$
39
}
40
41         String JavaDoc name = event.getParameter(PARAM_ID_NAME);
42         if (name == null) {
43             throw new ExecutionException("missing name parameter"); //$NON-NLS-1$
44
}
45
46         String JavaDoc urlText = event.getParameter(PARAM_ID_URL);
47         if (urlText == null) {
48             throw new ExecutionException("missing url parameter"); //$NON-NLS-1$
49
}
50
51         URL JavaDoc url;
52         try {
53             url = new URL JavaDoc(urlText);
54         } catch (MalformedURLException JavaDoc ex) {
55             throw new ExecutionException("malformed url: " + urlText, ex); //$NON-NLS-1$
56
}
57
58         OpenCheatSheetAction action = new OpenCheatSheetAction(cheatSheetId,
59                 name, url);
60         action.run();
61
62         return null;
63     }
64
65 }
66
Popular Tags