|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2011 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 |
|
| 12 |
package org.eclipse.e4.ui.bindings.internal; |
| 13 |
|
| 14 |
import java.util.ArrayList; |
| 15 |
import java.util.Collection; |
| 16 |
import java.util.Comparator; |
| 17 |
import java.util.Iterator; |
| 18 |
import java.util.List; |
| 19 |
import java.util.TreeSet; |
| 20 |
import org.eclipse.core.commands.ParameterizedCommand; |
| 21 |
import org.eclipse.core.commands.common.CommandException; |
| 22 |
import org.eclipse.core.commands.common.NotDefinedException; |
| 23 |
import org.eclipse.e4.core.contexts.IEclipseContext; |
| 24 |
import org.eclipse.e4.ui.bindings.EBindingService; |
| 25 |
import org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher; |
| 26 |
import org.eclipse.jface.bindings.Binding; |
| 27 |
import org.eclipse.jface.bindings.keys.KeySequence; |
| 28 |
import org.eclipse.jface.dialogs.Dialog; |
| 29 |
import org.eclipse.jface.dialogs.PopupDialog; |
| 30 |
import org.eclipse.jface.window.Window; |
| 31 |
import org.eclipse.swt.SWT; |
| 32 |
import org.eclipse.swt.graphics.Point; |
| 33 |
import org.eclipse.swt.graphics.Rectangle; |
| 34 |
import org.eclipse.swt.layout.GridData; |
| 35 |
import org.eclipse.swt.layout.GridLayout; |
| 36 |
import org.eclipse.swt.widgets.Composite; |
| 37 |
import org.eclipse.swt.widgets.Control; |
| 38 |
import org.eclipse.swt.widgets.Event; |
| 39 |
import org.eclipse.swt.widgets.Label; |
| 40 |
import org.eclipse.swt.widgets.Listener; |
| 41 |
import org.eclipse.swt.widgets.Shell; |
| 42 |
import org.eclipse.swt.widgets.Table; |
| 43 |
import org.eclipse.swt.widgets.TableColumn; |
| 44 |
import org.eclipse.swt.widgets.TableItem; |
| 45 |
|
| 46 |
/** |
| 47 |
* <p> |
| 48 |
* A dialog displaying a list of key bindings. The dialog will execute a command if it is selected. |
| 49 |
* </p> |
| 50 |
* <p> |
| 51 |
* The methods on this class are not thread-safe and must be run from the UI thread. |
| 52 |
* </p> |
| 53 |
* |
| 54 |
* @since 3.1 |
| 55 |
*/ |
| 56 |
public final class KeyAssistDialog extends PopupDialog { |
| 57 |
|
| 58 |
public static final String WINDOW_SHOW_KEY_ASSIST = "org.eclipse.ui.window.showKeyAssist"; //$NON-NLS-1$ |
| 59 |
|
| 60 |
/** |
| 61 |
* The data key for the binding stored on an SWT widget. The key is a fully-qualified name, but |
| 62 |
* in reverse order. This is so that the equals method will detect misses faster. |
| 63 |
*/ |
| 64 |
private static final String BINDING_KEY = "Binding.bindings.jface.eclipse.org"; //$NON-NLS-1$ |
| 65 |
|
| 66 |
/** |
| 67 |
* The value of <code>previousWidth</code> to set if there is no remembered width. |
| 68 |
*/ |
| 69 |
private static final int NO_REMEMBERED_WIDTH = -1; |
| 70 |
|
| 71 |
/** |
| 72 |
* The ordered list of command identifiers corresponding to the table. |
| 73 |
*/ |
| 74 |
private final List<Binding> bindings = new ArrayList<Binding>(); |
| 75 |
|
| 76 |
/** |
| 77 |
* The table containing of the possible completions. This value is <code>null</code> until the |
| 78 |
* dialog is created. |
| 79 |
*/ |
| 80 |
private Table completionsTable = null; |
| 81 |
|
| 82 |
/** |
| 83 |
* The width of the shell when it was previously open. This is only remembered until |
| 84 |
* <code>clearRememberedState()</code> is called. |
| 85 |
*/ |
| 86 |
private int previousWidth = NO_REMEMBERED_WIDTH; |
| 87 |
|
| 88 |
/** |
| 89 |
* The key binding listener for the associated workbench. |
| 90 |
*/ |
| 91 |
private final KeyBindingDispatcher workbenchKeyboard; |
| 92 |
|
| 93 |
/** |
| 94 |
* A sorted map of conflicts or partial matches to be used when the dialog pops up. |
| 95 |
* |
| 96 |
* @since 3.3 |
| 97 |
*/ |
| 98 |
private Collection<Binding> matches; |
| 99 |
|
| 100 |
private IEclipseContext context; |
| 101 |
|
| 102 |
/** |
| 103 |
* Constructs a new instance of <code>KeyAssistDialog</code>. When the dialog is first |
| 104 |
* constructed, it contains no widgets. The dialog is first created with no parent. If a parent |
| 105 |
* is required, call <code>setParentShell()</code>. Also, between uses, it might be necessary to |
| 106 |
* call <code>setParentShell()</code> as well. |
| 107 |
* |
| 108 |
* @param context |
| 109 |
* The context in which this dialog is created; must not be <code>null</code>. |
| 110 |
* @param associatedKeyboard |
| 111 |
* The key binding listener for the workbench; must not be <code>null</code>. |
| 112 |
* @param associatedState |
| 113 |
* The key binding state associated with the workbench; must not be <code>null</code> |
| 114 |
* . |
| 115 |
*/ |
| 116 |
public KeyAssistDialog(final IEclipseContext context, |
| 117 |
final KeyBindingDispatcher associatedKeyboard, final KeySequence associatedState) { |
| 118 |
super((Shell) null, PopupDialog.INFOPOPUP_SHELLSTYLE, true, false, false, false, null, null); |
| 119 |
//super(null, PopupDialog.INFOPOPUP_SHELLSTYLE, true, false, false, false, false, DIALOG_TITLE, getKeySequenceString()); //$NON-NLS-1$ |
| 120 |
|
| 121 |
this.context = context; |
| 122 |
this.workbenchKeyboard = associatedKeyboard; |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Clears out the remembered state of the key assist dialog. This includes its width, as well as |
| 127 |
* the selected binding. |
| 128 |
*/ |
| 129 |
public final void clearRememberedState() { |
| 130 |
previousWidth = NO_REMEMBERED_WIDTH; |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Closes this shell, but first remembers some state of the dialog. This way it will have a |
| 135 |
* response if asked to open the dialog again or if asked to open the keys preference page. This |
| 136 |
* does not remember the internal state. |
| 137 |
* |
| 138 |
* @return Whether the shell was already closed. |
| 139 |
*/ |
| 140 |
public final boolean close() { |
| 141 |
return close(false); |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Closes this shell, but first remembers some state of the dialog. This way it will have a |
| 146 |
* response if asked to open the dialog again or if asked to open the keys preference page. |
| 147 |
* |
| 148 |
* @param rememberState |
| 149 |
* Whether the internal state should be remembered. |
| 150 |
* @return Whether the shell was already closed. |
| 151 |
*/ |
| 152 |
public final boolean close(final boolean rememberState) { |
| 153 |
return close(rememberState, true); |
| 154 |
} |
| 155 |
|
| 156 |
/** |
| 157 |
* Closes this shell, but first remembers some state of the dialog. This way it will have a |
| 158 |
* response if asked to open the dialog again or if asked to open the keys preference page. |
| 159 |
* |
| 160 |
* @param rememberState |
| 161 |
* Whether the internal state should be remembered. |
| 162 |
* @param resetState |
| 163 |
* Whether the state should be reset. |
| 164 |
* @return Whether the shell was already closed. |
| 165 |
*/ |
| 166 |
private final boolean close(final boolean rememberState, final boolean resetState) { |
| 167 |
final Shell shell = getShell(); |
| 168 |
if (rememberState) { |
| 169 |
|
| 170 |
// Remember the previous width. |
| 171 |
final int widthToRemember; |
| 172 |
if ((shell != null) && (!shell.isDisposed())) { |
| 173 |
widthToRemember = getShell().getSize().x; |
| 174 |
} else { |
| 175 |
widthToRemember = NO_REMEMBERED_WIDTH; |
| 176 |
} |
| 177 |
|
| 178 |
// Remember the selected command name and key sequence. |
| 179 |
final Binding bindingToRemember; |
| 180 |
if ((completionsTable != null) && (!completionsTable.isDisposed())) { |
| 181 |
final int selectedIndex = completionsTable.getSelectionIndex(); |
| 182 |
if (selectedIndex != -1) { |
| 183 |
final TableItem selectedItem = completionsTable.getItem(selectedIndex); |
| 184 |
bindingToRemember = (Binding) selectedItem.getData(BINDING_KEY); |
| 185 |
} else { |
| 186 |
bindingToRemember = null; |
| 187 |
} |
| 188 |
} else { |
| 189 |
bindingToRemember = null; |
| 190 |
} |
| 191 |
|
| 192 |
rememberState(widthToRemember, bindingToRemember); |
| 193 |
completionsTable = null; |
| 194 |
} |
| 195 |
matches = null; |
| 196 |
return super.close(); |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* Sets the position for the dialog based on the position of the workbench window. The dialog is |
| 201 |
* flush with the bottom right corner of the workbench window. However, the dialog will not |
| 202 |
* appear outside of the display's client area. |
| 203 |
* |
| 204 |
* @param size |
| 205 |
* The final size of the dialog; must not be <code>null</code>. |
| 206 |
*/ |
| 207 |
private final void configureLocation(final Point size) { |
| 208 |
final Shell shell = getShell(); |
| 209 |
|
| 210 |
final Shell workbenchWindowShell = (Shell) shell.getParent(); |
| 211 |
final int xCoord; |
| 212 |
final int yCoord; |
| 213 |
if (workbenchWindowShell != null) { |
| 214 |
/* |
| 215 |
* Position the shell at the bottom right corner of the workbench window |
| 216 |
*/ |
| 217 |
final Rectangle workbenchWindowBounds = workbenchWindowShell.getBounds(); |
| 218 |
xCoord = workbenchWindowBounds.x + workbenchWindowBounds.width - size.x - 10; |
| 219 |
yCoord = workbenchWindowBounds.y + workbenchWindowBounds.height - size.y - 10; |
| 220 |
|
| 221 |
} else { |
| 222 |
xCoord = 0; |
| 223 |
yCoord = 0; |
| 224 |
|
| 225 |
} |
| 226 |
final Rectangle bounds = new Rectangle(xCoord, yCoord, size.x, size.y); |
| 227 |
shell.setBounds(getConstrainedShellBounds(bounds)); |
| 228 |
} |
| 229 |
|
| 230 |
/** |
| 231 |
* Sets the size for the dialog based on its previous size. The width of the dialog is its |
| 232 |
* previous width, if it exists. Otherwise, it is simply the packed width of the dialog. The |
| 233 |
* maximum width is 40% of the workbench window's width. The dialog's height is the packed |
| 234 |
* height of the dialog to a maximum of half the height of the workbench window. |
| 235 |
* |
| 236 |
* @return The size of the dialog |
| 237 |
*/ |
| 238 |
private final Point configureSize() { |
| 239 |
final Shell shell = getShell(); |
| 240 |
|
| 241 |
// Get the packed size of the shell. |
| 242 |
shell.pack(); |
| 243 |
final Point size = shell.getSize(); |
| 244 |
|
| 245 |
// Use the previous width if appropriate. |
| 246 |
if ((previousWidth != NO_REMEMBERED_WIDTH) && (previousWidth > size.x)) { |
| 247 |
size.x = previousWidth; |
| 248 |
} |
| 249 |
|
| 250 |
// Enforce maximum sizing. |
| 251 |
final Shell workbenchWindowShell = (Shell) shell.getParent(); |
| 252 |
if (workbenchWindowShell != null) { |
| 253 |
final Point workbenchWindowSize = workbenchWindowShell.getSize(); |
| 254 |
final int maxWidth = workbenchWindowSize.x * 2 / 5; |
| 255 |
final int maxHeight = workbenchWindowSize.y / 2; |
| 256 |
if (size.x > maxWidth) { |
| 257 |
size.x = maxWidth; |
| 258 |
} |
| 259 |
if (size.y > maxHeight) { |
| 260 |
size.y = maxHeight; |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
// Set the size for the shell. |
| 265 |
shell.setSize(size); |
| 266 |
return size; |
| 267 |
} |
| 268 |
|
| 269 |
/** |
| 270 |
* Creates the content area for the key assistant. This creates a table and places it inside the |
| 271 |
* composite. The composite will contain a list of all the key bindings. |
| 272 |
* |
| 273 |
* @param parent |
| 274 |
* The parent composite to contain the dialog area; must not be <code>null</code>. |
| 275 |
*/ |
| 276 |
protected final Control createDialogArea(final Composite parent) { |
| 277 |
|
| 278 |
// Create a composite for the dialog area. |
| 279 |
final Composite composite = new Composite(parent, SWT.NONE); |
| 280 |
final GridLayout compositeLayout = new GridLayout(); |
| 281 |
compositeLayout.marginHeight = 0; |
| 282 |
compositeLayout.marginWidth = 0; |
| 283 |
composite.setLayout(compositeLayout); |
| 284 |
composite.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 285 |
composite.setBackground(parent.getBackground()); |
| 286 |
|
| 287 |
// Layout the partial matches. |
| 288 |
final Collection<Binding> bindings; |
| 289 |
// if we're going to display a list of conflicts or partial matches... |
| 290 |
if (matches != null) { |
| 291 |
bindings = matches; |
| 292 |
} |
| 293 |
// else just grab the entire list of active bindings |
| 294 |
else { |
| 295 |
bindings = getActiveBindings(); |
| 296 |
} |
| 297 |
|
| 298 |
if (bindings == null || bindings.isEmpty()) { |
| 299 |
createEmptyDialogArea(composite); |
| 300 |
} else { |
| 301 |
createTableDialogArea(composite, bindings); |
| 302 |
} |
| 303 |
return composite; |
| 304 |
} |
| 305 |
|
| 306 |
/** |
| 307 |
* Creates an empty dialog area with a simple message saying there were no matches. This is used |
| 308 |
* if no partial matches could be found. This should not really ever happen, but might be |
| 309 |
* possible if the commands are changing while waiting for this dialog to open. |
| 310 |
* |
| 311 |
* @param parent |
| 312 |
* The parent composite for the dialog area; must not be <code>null</code>. |
| 313 |
*/ |
| 314 |
private final void createEmptyDialogArea(final Composite parent) { |
| 315 |
final Label noMatchesLabel = new Label(parent, SWT.NULL); |
| 316 |
noMatchesLabel.setText("No matches"); //$NON-NLS-1$ |
| 317 |
noMatchesLabel.setLayoutData(new GridData(GridData.FILL_BOTH)); |
| 318 |
noMatchesLabel.setBackground(parent.getBackground()); |
| 319 |
} |
| 320 |
|
| 321 |
/** |
| 322 |
* Creates a dialog area with a table of the partial matches for the current key binding state. |
| 323 |
* The table will be either the minimum width, or <code>previousWidth</code> if it is not |
| 324 |
* <code>NO_REMEMBERED_WIDTH</code>. |
| 325 |
* |
| 326 |
* @param parent |
| 327 |
* The parent composite for the dialog area; must not be <code>null</code>. |
| 328 |
* @param partialMatches |
| 329 |
* The lexicographically sorted map of partial matches for the current state; must |
| 330 |
* not be <code>null</code> or empty. |
| 331 |
*/ |
| 332 |
private final void createTableDialogArea(final Composite parent, |
| 333 |
final Collection<Binding> partialMatches) { |
| 334 |
// Layout the table. |
| 335 |
completionsTable = new Table(parent, SWT.FULL_SELECTION | SWT.SINGLE); |
| 336 |
final GridData gridData = new GridData(GridData.FILL_BOTH); |
| 337 |
completionsTable.setLayoutData(gridData); |
| 338 |
completionsTable.setBackground(parent.getBackground()); |
| 339 |
completionsTable.setLinesVisible(true); |
| 340 |
|
| 341 |
// Initialize the columns and rows. |
| 342 |
bindings.clear(); |
| 343 |
final TableColumn columnCommandName = new TableColumn(completionsTable, SWT.LEFT, 0); |
| 344 |
final TableColumn columnKeySequence = new TableColumn(completionsTable, SWT.LEFT, 1); |
| 345 |
final Iterator<Binding> itemsItr = partialMatches.iterator(); |
| 346 |
while (itemsItr.hasNext()) { |
| 347 |
final Binding binding = itemsItr.next(); |
| 348 |
final String sequence = binding.getTriggerSequence().format(); |
| 349 |
final ParameterizedCommand command = binding.getParameterizedCommand(); |
| 350 |
try { |
| 351 |
final String[] text = { command.getName(), sequence }; |
| 352 |
final TableItem item = new TableItem(completionsTable, SWT.NULL); |
| 353 |
item.setText(text); |
| 354 |
item.setData(BINDING_KEY, binding); |
| 355 |
bindings.add(binding); |
| 356 |
} catch (NotDefinedException e) { |
| 357 |
// Not much to do, but this shouldn't really happen. |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
Dialog.applyDialogFont(parent); |
| 362 |
columnKeySequence.pack(); |
| 363 |
if (previousWidth != NO_REMEMBERED_WIDTH) { |
| 364 |
columnKeySequence.setWidth(previousWidth); |
| 365 |
} |
| 366 |
columnCommandName.pack(); |
| 367 |
if (completionsTable.getItems().length > 0) { |
| 368 |
completionsTable.setSelection(0); |
| 369 |
} |
| 370 |
|
| 371 |
/* |
| 372 |
* If you double-click on the table, it should execute the selected command. |
| 373 |
*/ |
| 374 |
completionsTable.addListener(SWT.DefaultSelection, new Listener() { |
| 375 |
public final void handleEvent(final Event event) { |
| 376 |
executeKeyBinding(event); |
| 377 |
} |
| 378 |
}); |
| 379 |
} |
| 380 |
|
| 381 |
/** |
| 382 |
* Handles the default selection event on the table of possible completions. This attempts to |
| 383 |
* execute the given command. |
| 384 |
*/ |
| 385 |
private final void executeKeyBinding(final Event trigger) { |
| 386 |
final int selectionIndex = completionsTable.getSelectionIndex(); |
| 387 |
// Try to execute the corresponding command. |
| 388 |
if (selectionIndex >= 0) { |
| 389 |
final Binding binding = bindings.get(selectionIndex); |
| 390 |
try { |
| 391 |
// workbenchKeyboard.updateShellKludge(null); |
| 392 |
workbenchKeyboard.executeCommand(binding.getParameterizedCommand(), trigger); |
| 393 |
} catch (final CommandException e) { |
| 394 |
// WorkbenchPlugin.log(binding.getParameterizedCommand().toString(), e); |
| 395 |
// TODO we probably need to log something here. |
| 396 |
System.err.println(binding.getParameterizedCommand().toString() + " : " + e); //$NON-NLS-1$ |
| 397 |
} |
| 398 |
} |
| 399 |
} |
| 400 |
|
| 401 |
private final Collection<Binding> getActiveBindings() { |
| 402 |
|
| 403 |
EBindingService bindingService = context.getActiveLeaf().get(EBindingService.class); |
| 404 |
|
| 405 |
Iterator<Binding> iter, matchesIter; |
| 406 |
Binding binding, bindingToAdd; |
| 407 |
Collection<Binding> matchesForCommand; |
| 408 |
Collection<Binding> activeBindings = bindingService.getActiveBindings(); |
| 409 |
Collection<Binding> conflictBindings = bindingService.getAllConflicts(); |
| 410 |
Collection<Binding> sortedMatches = new TreeSet<Binding>(new Comparator<Binding>() { |
| 411 |
public int compare(Binding binding1, Binding binding2) { |
| 412 |
final ParameterizedCommand cmdA = binding1.getParameterizedCommand(); |
| 413 |
final ParameterizedCommand cmdB = binding2.getParameterizedCommand(); |
| 414 |
int result = 0; |
| 415 |
try { |
| 416 |
result = cmdA.getName().compareTo(cmdB.getName()); |
| 417 |
} catch (NotDefinedException e) { |
| 418 |
// whaaa? |
| 419 |
} |
| 420 |
return result; |
| 421 |
} |
| 422 |
}); |
| 423 |
|
| 424 |
// if the active scheme is not the default scheme then we should clean up the active |
| 425 |
// bindings list... if we find multiple bindings for the same command and they are for |
| 426 |
// different schemes, then we need to handle which one should be displayed in the dialog |
| 427 |
if (activeBindings != null) { |
| 428 |
iter = activeBindings.iterator(); |
| 429 |
while (iter.hasNext()) { |
| 430 |
binding = iter.next(); |
| 431 |
matchesForCommand = bindingService |
| 432 |
.getBindingsFor(binding.getParameterizedCommand()); |
| 433 |
// if there is more than one match, then look for a binding that does not belong to |
| 434 |
// the default scheme. If they all belong to the default scheme or they all do NOT |
| 435 |
// belong to the default scheme, then arbitrarily choose one |
| 436 |
if (matchesForCommand != null && matchesForCommand.size() > 1) { |
| 437 |
bindingToAdd = null; |
| 438 |
|
| 439 |
matchesIter = matchesForCommand.iterator(); |
| 440 |
while (matchesIter.hasNext()) { |
| 441 |
bindingToAdd = matchesIter.next(); |
| 442 |
if (!bindingToAdd.getSchemeId().equals(EBindingService.DEFAULT_SCHEME_ID)) { |
| 443 |
sortedMatches.add(bindingToAdd); |
| 444 |
break; |
| 445 |
} |
| 446 |
} |
| 447 |
// if they're all the same, arbitrarily choose one |
| 448 |
if (bindingToAdd != null) { |
| 449 |
sortedMatches.add(bindingToAdd); |
| 450 |
} |
| 451 |
} |
| 452 |
// if there is only one match, then just add it |
| 453 |
else if (matchesForCommand != null && matchesForCommand.size() == 1) { |
| 454 |
sortedMatches.addAll(matchesForCommand); |
| 455 |
} |
| 456 |
} |
| 457 |
} |
| 458 |
if (conflictBindings != null) { |
| 459 |
iter = conflictBindings.iterator(); |
| 460 |
while (iter.hasNext()) { |
| 461 |
binding = iter.next(); |
| 462 |
sortedMatches.add(binding); |
| 463 |
} |
| 464 |
} |
| 465 |
return sortedMatches; |
| 466 |
} |
| 467 |
|
| 468 |
/** |
| 469 |
* Opens this dialog. This method can be called multiple times on the same dialog. This only |
| 470 |
* opens the dialog if there is no remembered state; if there is remembered state, then it tries |
| 471 |
* to open the preference page instead. |
| 472 |
* |
| 473 |
* @return The return code from this dialog. |
| 474 |
*/ |
| 475 |
public final int open() { |
| 476 |
// If the dialog is already open, dispose the shell and recreate it. |
| 477 |
final Shell shell = getShell(); |
| 478 |
if (shell != null) { |
| 479 |
close(false, false); |
| 480 |
return Window.OK; |
| 481 |
} |
| 482 |
create(); |
| 483 |
|
| 484 |
// Configure the size and location. |
| 485 |
final Point size = configureSize(); |
| 486 |
configureLocation(size); |
| 487 |
|
| 488 |
// Call the super method. |
| 489 |
return super.open(); |
| 490 |
} |
| 491 |
|
| 492 |
/** |
| 493 |
* Opens this dialog with the list of bindings for the user to select from. |
| 494 |
* |
| 495 |
* @return The return code from this dialog. |
| 496 |
* @since 3.3 |
| 497 |
*/ |
| 498 |
public final int open(Collection<Binding> bindings) { |
| 499 |
matches = new TreeSet<Binding>(new Comparator<Binding>() { |
| 500 |
public final int compare(final Binding a, final Binding b) { |
| 501 |
final Binding bindingA = a; |
| 502 |
final Binding bindingB = b; |
| 503 |
final ParameterizedCommand commandA = bindingA.getParameterizedCommand(); |
| 504 |
final ParameterizedCommand commandB = bindingB.getParameterizedCommand(); |
| 505 |
try { |
| 506 |
return commandA.getName().compareTo(commandB.getName()); |
| 507 |
} catch (final NotDefinedException e) { |
| 508 |
// should not happen |
| 509 |
return 0; |
| 510 |
} |
| 511 |
} |
| 512 |
}); |
| 513 |
matches.addAll(bindings); |
| 514 |
|
| 515 |
// If the dialog is already open, dispose the shell and recreate it. |
| 516 |
final Shell shell = getShell(); |
| 517 |
if (shell != null) { |
| 518 |
close(false, false); |
| 519 |
return Window.OK; |
| 520 |
} |
| 521 |
create(); |
| 522 |
|
| 523 |
// Configure the size and location. |
| 524 |
final Point size = configureSize(); |
| 525 |
configureLocation(size); |
| 526 |
|
| 527 |
// Call the super method. |
| 528 |
return super.open(); |
| 529 |
} |
| 530 |
|
| 531 |
/** |
| 532 |
* Remembers the current state of this dialog. |
| 533 |
* |
| 534 |
* @param previousWidth |
| 535 |
* The previous width of the dialog. |
| 536 |
* @param binding |
| 537 |
* The binding to remember, may be <code>null</code> if none. |
| 538 |
*/ |
| 539 |
private final void rememberState(final int previousWidth, final Binding binding) { |
| 540 |
this.previousWidth = previousWidth; |
| 541 |
} |
| 542 |
|
| 543 |
/** |
| 544 |
* Exposing this within the keys package. |
| 545 |
* |
| 546 |
* @param newParentShell |
| 547 |
* The new parent shell; this value may be <code>null</code> if there is to be no |
| 548 |
* parent. |
| 549 |
*/ |
| 550 |
public final void setParentShell(final Shell newParentShell) { |
| 551 |
super.setParentShell(newParentShell); |
| 552 |
} |
| 553 |
} |