1 11 package org.eclipse.debug.ui; 12 13 import com.ibm.icu.text.MessageFormat; 14 15 import org.eclipse.core.commands.AbstractHandler; 16 import org.eclipse.core.commands.ExecutionEvent; 17 import org.eclipse.core.commands.ExecutionException; 18 import org.eclipse.core.commands.IHandler; 19 import org.eclipse.debug.internal.ui.DebugUIPlugin; 20 import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages; 21 import org.eclipse.jface.dialogs.IDialogSettings; 22 import org.eclipse.jface.dialogs.PopupDialog; 23 import org.eclipse.swt.graphics.Point; 24 import org.eclipse.swt.graphics.Rectangle; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Control; 27 import org.eclipse.swt.widgets.Shell; 28 import org.eclipse.ui.IWorkbench; 29 import org.eclipse.ui.PlatformUI; 30 import org.eclipse.ui.handlers.IHandlerActivation; 31 import org.eclipse.ui.handlers.IHandlerService; 32 import org.eclipse.ui.keys.IBindingService; 33 34 44 public abstract class DebugPopup extends PopupDialog { 45 46 private Point fAnchor; 47 48 private IHandlerActivation fActivation; 49 50 private IHandlerService fHandlerService; 51 52 private String fCommandId; 53 54 private boolean fPersisted = false; 55 56 64 public DebugPopup(Shell parent, Point anchor, String commandId) { 65 super(parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, true, true, false, null, null); 66 fAnchor = anchor; 67 fCommandId = commandId; 68 } 69 70 80 protected String getInfoText() { 81 if (getCommandId() != null && getActionText() != null) { 82 IWorkbench workbench = PlatformUI.getWorkbench(); 83 IBindingService bindingService = (IBindingService) workbench.getAdapter(IBindingService.class); 84 String formattedBinding = bindingService.getBestActiveBindingFormattedFor(getCommandId()); 85 86 String infoText = null; 87 if (formattedBinding != null) { 88 infoText = MessageFormat.format(DebugUIViewsMessages.InspectPopupDialog_1, new String [] { formattedBinding, getActionText()}); 89 } 90 return infoText; 91 } 92 return null; 93 } 94 95 104 protected String getActionText() { 105 return null; 106 } 107 108 116 protected String getCommandId() { 117 return fCommandId; 118 } 119 120 124 protected void persist() { 125 fPersisted = true; 126 } 127 128 133 protected boolean wasPersisted() { 134 return fPersisted; 135 } 136 137 141 protected abstract Control createDialogArea(Composite parent); 142 143 144 155 protected Point getInitialLocation(Point initialSize) { 156 if (fAnchor == null) { 157 return super.getInitialLocation(initialSize); 158 } 159 Point point = fAnchor; 160 Rectangle monitor = getShell().getMonitor().getClientArea(); 161 if (monitor.width < point.x + initialSize.x) { 162 point.x = Math.max(0, point.x - initialSize.x); 163 } 164 if (monitor.height < point.y + initialSize.y) { 165 point.y = Math.max(0, point.y - initialSize.y); 166 } 167 return point; 168 } 169 170 174 protected IDialogSettings getDialogSettings() { 175 IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings(); 176 return settings; 177 } 178 179 180 183 public int open() { 184 IWorkbench workbench = PlatformUI.getWorkbench(); 185 String commandId = getCommandId(); 186 if (commandId != null) { 187 IHandler fCloseHandler = new AbstractHandler() { 188 public Object execute(ExecutionEvent event) throws ExecutionException { 189 persist(); 190 close(); 191 return null; 192 } 193 }; 194 195 fHandlerService = (IHandlerService) workbench.getAdapter(IHandlerService.class); 196 fActivation = fHandlerService.activateHandler(commandId, fCloseHandler); 197 } 198 199 String infoText = getInfoText(); 200 if (infoText != null) 201 setInfoText(infoText); 202 203 return super.open(); 204 } 205 206 209 public boolean close() { 210 if (fActivation != null) 211 fHandlerService.deactivateHandler(fActivation); 212 213 return super.close(); 214 } 215 } 216 | Popular Tags |