1 11 package org.eclipse.ui.internal.cheatsheets.handlers; 12 13 import org.eclipse.core.commands.AbstractHandler; 14 import org.eclipse.core.commands.ExecutionEvent; 15 import org.eclipse.core.commands.ExecutionException; 16 import org.eclipse.jface.dialogs.InputDialog; 17 import org.eclipse.jface.window.Window; 18 import org.eclipse.swt.widgets.Shell; 19 import org.eclipse.ui.IWorkbenchWindow; 20 import org.eclipse.ui.PlatformUI; 21 22 28 public class OpenInputDialogHandler extends AbstractHandler { 29 30 private static final String PARAM_ID_TITLE = "title"; 32 private static final String PARAM_ID_MESSAGE = "message"; 34 private static final String PARAM_ID_INITIAL_VALUE = "initialValue"; 36 private static final String PARAM_ID_CANCEL_RETURNS = "cancelReturns"; 38 public Object execute(ExecutionEvent event) throws ExecutionException { 39 40 String title = event.getParameter(PARAM_ID_TITLE); 41 String message = event.getParameter(PARAM_ID_MESSAGE); 42 String initialValue = event.getParameter(PARAM_ID_INITIAL_VALUE); 43 44 IWorkbenchWindow activeWindow = PlatformUI.getWorkbench() 45 .getActiveWorkbenchWindow(); 46 Shell shell = (activeWindow != null) ? activeWindow.getShell() : null; 47 48 InputDialog dialog = new InputDialog(shell, title, message, 49 initialValue, null); 50 int returnCode = dialog.open(); 51 52 if (returnCode == Window.CANCEL) { 53 String cancelReturns = event.getParameter(PARAM_ID_CANCEL_RETURNS); 54 if (cancelReturns != null) 55 return cancelReturns; 56 else 57 throw new ExecutionException("dialog canceled"); } 59 60 return dialog.getValue(); 61 } 62 63 } 64 | Popular Tags |