|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2005, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2005, 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 86-101
Link Here
|
| 86 |
|
86 |
|
| 87 |
private static boolean dialogHelpAvailable; |
87 |
private static boolean dialogHelpAvailable; |
| 88 |
|
88 |
|
| 89 |
/* |
89 |
/** |
| 90 |
* The dialog's tray (null if none). |
90 |
* The dialog's tray (null if none). |
| 91 |
*/ |
91 |
*/ |
| 92 |
private DialogTray tray; |
92 |
private DialogTray tray; |
| 93 |
|
93 |
|
| 94 |
/* |
94 |
/** |
| 95 |
* The tray's control. |
95 |
* The tray's control (null if none). |
| 96 |
*/ |
96 |
*/ |
| 97 |
private Control trayControl; |
97 |
private Control trayControl; |
| 98 |
|
98 |
|
|
|
99 |
/** |
| 100 |
* The control that had focus before the tray was opened (null if none). |
| 101 |
*/ |
| 102 |
private Control nonTrayFocusControl; |
| 103 |
|
| 99 |
/* |
104 |
/* |
| 100 |
* The separator to the left of the sash. |
105 |
* The separator to the left of the sash. |
| 101 |
*/ |
106 |
*/ |
|
Lines 121-126
Link Here
|
| 121 |
private ControlAdapter resizeListener; |
126 |
private ControlAdapter resizeListener; |
| 122 |
|
127 |
|
| 123 |
/** |
128 |
/** |
|
|
129 |
* The help button (null if none). |
| 130 |
*/ |
| 131 |
private ToolItem fHelpButton; |
| 132 |
|
| 133 |
/** |
| 124 |
* Creates a tray dialog instance. Note that the window will have no visual |
134 |
* Creates a tray dialog instance. Note that the window will have no visual |
| 125 |
* representation (no widgets) until it is told to open. |
135 |
* representation (no widgets) until it is told to open. |
| 126 |
* |
136 |
* |
|
Lines 149-154
Link Here
|
| 149 |
throw new IllegalStateException("Tray was not open"); //$NON-NLS-1$ |
159 |
throw new IllegalStateException("Tray was not open"); //$NON-NLS-1$ |
| 150 |
} |
160 |
} |
| 151 |
Shell shell = getShell(); |
161 |
Shell shell = getShell(); |
|
|
162 |
Control focusControl = shell.getDisplay().getFocusControl(); |
| 163 |
if (isContained(trayControl, focusControl) && nonTrayFocusControl!= null && !nonTrayFocusControl.isDisposed()) { |
| 164 |
nonTrayFocusControl.setFocus(); |
| 165 |
} |
| 166 |
nonTrayFocusControl= null; |
| 152 |
shell.removeControlListener (resizeListener); |
167 |
shell.removeControlListener (resizeListener); |
| 153 |
resizeListener = null; |
168 |
resizeListener = null; |
| 154 |
int trayWidth = trayControl.getSize().x + leftSeparator.getSize().x + sash.getSize().x + rightSeparator.getSize().x; |
169 |
int trayWidth = trayControl.getSize().x + leftSeparator.getSize().x + sash.getSize().x + rightSeparator.getSize().x; |
|
Lines 163-170
Link Here
|
| 163 |
sash = null; |
178 |
sash = null; |
| 164 |
Rectangle bounds = shell.getBounds(); |
179 |
Rectangle bounds = shell.getBounds(); |
| 165 |
shell.setBounds(bounds.x + ((getDefaultOrientation() == SWT.RIGHT_TO_LEFT) ? trayWidth : 0), bounds.y, bounds.width - trayWidth, bounds.height); |
180 |
shell.setBounds(bounds.x + ((getDefaultOrientation() == SWT.RIGHT_TO_LEFT) ? trayWidth : 0), bounds.y, bounds.width - trayWidth, bounds.height); |
|
|
181 |
if (fHelpButton != null) { |
| 182 |
fHelpButton.setSelection(false); |
| 183 |
} |
| 166 |
} |
184 |
} |
| 167 |
|
185 |
|
|
|
186 |
/** |
| 187 |
* Returns true if the given Control is a direct or indirect child of |
| 188 |
* container. |
| 189 |
* |
| 190 |
* @param container |
| 191 |
* the potential parent |
| 192 |
* @param control |
| 193 |
* @return boolean <code>true</code> if control is a child of container |
| 194 |
*/ |
| 195 |
private boolean isContained(Control container, Control control) { |
| 196 |
Composite parent; |
| 197 |
while ((parent = control.getParent()) != null) { |
| 198 |
if (parent == container) { |
| 199 |
return true; |
| 200 |
} |
| 201 |
control = parent; |
| 202 |
} |
| 203 |
return false; |
| 204 |
} |
| 205 |
|
| 168 |
/* (non-Javadoc) |
206 |
/* (non-Javadoc) |
| 169 |
* @see org.eclipse.jface.dialogs.Dialog#close() |
207 |
* @see org.eclipse.jface.dialogs.Dialog#close() |
| 170 |
*/ |
208 |
*/ |
|
Lines 238-247
Link Here
|
| 238 |
cursor.dispose(); |
276 |
cursor.dispose(); |
| 239 |
} |
277 |
} |
| 240 |
}); |
278 |
}); |
| 241 |
ToolItem item = new ToolItem(toolBar, SWT.NONE); |
279 |
fHelpButton = new ToolItem(toolBar, SWT.CHECK); |
| 242 |
item.setImage(image); |
280 |
fHelpButton.setImage(image); |
| 243 |
item.setToolTipText(JFaceResources.getString("helpToolTip")); //$NON-NLS-1$ |
281 |
fHelpButton.setToolTipText(JFaceResources.getString("helpToolTip")); //$NON-NLS-1$ |
| 244 |
item.addSelectionListener(new SelectionAdapter() { |
282 |
fHelpButton.addSelectionListener(new SelectionAdapter() { |
| 245 |
public void widgetSelected(SelectionEvent e) { |
283 |
public void widgetSelected(SelectionEvent e) { |
| 246 |
helpPressed(); |
284 |
helpPressed(); |
| 247 |
} |
285 |
} |
|
Lines 326-348
Link Here
|
| 326 |
* context help behavior (e.g. F1 on Windows). It traverses the widget |
364 |
* context help behavior (e.g. F1 on Windows). It traverses the widget |
| 327 |
* tree upward until it finds a widget that has a help listener on it, |
365 |
* tree upward until it finds a widget that has a help listener on it, |
| 328 |
* then invokes a help event on that widget. |
366 |
* then invokes a help event on that widget. |
|
|
367 |
* If the help tray is already open, it closes it and doesn't invoke |
| 368 |
* any help listener. |
| 329 |
*/ |
369 |
*/ |
| 330 |
private void helpPressed() { |
370 |
private void helpPressed() { |
| 331 |
if (getShell() != null) { |
371 |
if (getTray() == null) { |
| 332 |
Control c = getShell().getDisplay().getFocusControl(); |
372 |
if (getShell() != null) { |
| 333 |
while (c != null) { |
373 |
Control c = getShell().getDisplay().getFocusControl(); |
| 334 |
if (c.isListening(SWT.Help)) { |
374 |
while (c != null) { |
| 335 |
c.notifyListeners(SWT.Help, new Event()); |
375 |
if (c.isListening(SWT.Help)) { |
| 336 |
break; |
376 |
c.notifyListeners(SWT.Help, new Event()); |
| 337 |
} |
377 |
break; |
| 338 |
c = c.getParent(); |
378 |
} |
| 339 |
} |
379 |
c = c.getParent(); |
| 340 |
} |
380 |
} |
|
|
381 |
} |
| 382 |
|
| 383 |
} else { |
| 384 |
closeTray(); |
| 385 |
} |
| 341 |
} |
386 |
} |
| 342 |
|
387 |
|
| 343 |
/** |
388 |
/** |
| 344 |
* Constructs the tray's widgets and displays the tray in this dialog. The |
389 |
* Constructs the tray's widgets and displays the tray in this dialog. The |
| 345 |
* dialog's size will be adjusted to accomodate the tray. |
390 |
* dialog's size will be adjusted to accommodate the tray. |
| 346 |
* |
391 |
* |
| 347 |
* @param tray the tray to show in this dialog |
392 |
* @param tray the tray to show in this dialog |
| 348 |
* @throws IllegalStateException if the dialog already has a tray open |
393 |
* @throws IllegalStateException if the dialog already has a tray open |
|
Lines 360-365
Link Here
|
| 360 |
throw new UnsupportedOperationException("Trays not supported with custom layouts"); //$NON-NLS-1$ |
405 |
throw new UnsupportedOperationException("Trays not supported with custom layouts"); //$NON-NLS-1$ |
| 361 |
} |
406 |
} |
| 362 |
final Shell shell = getShell(); |
407 |
final Shell shell = getShell(); |
|
|
408 |
Control focusControl = shell.getDisplay().getFocusControl(); |
| 409 |
if (isContained(shell, focusControl)) { |
| 410 |
nonTrayFocusControl = focusControl; |
| 411 |
} |
| 363 |
leftSeparator = new Label(shell, SWT.SEPARATOR | SWT.VERTICAL); |
412 |
leftSeparator = new Label(shell, SWT.SEPARATOR | SWT.VERTICAL); |
| 364 |
leftSeparator.setLayoutData(new GridData(GridData.FILL_VERTICAL)); |
413 |
leftSeparator.setLayoutData(new GridData(GridData.FILL_VERTICAL)); |
| 365 |
sash = new Sash(shell, SWT.VERTICAL); |
414 |
sash = new Sash(shell, SWT.VERTICAL); |
|
Lines 392-397
Link Here
|
| 392 |
shell.addControlListener (resizeListener); |
441 |
shell.addControlListener (resizeListener); |
| 393 |
|
442 |
|
| 394 |
this.tray = tray; |
443 |
this.tray = tray; |
|
|
444 |
if (fHelpButton != null) { |
| 445 |
fHelpButton.setSelection(true); |
| 446 |
} |
| 395 |
} |
447 |
} |
| 396 |
|
448 |
|
| 397 |
/** |
449 |
/** |