|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2009 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 |
* Wind River Systems - adapted for DSF |
| 11 |
*******************************************************************************/ |
| 12 |
package org.eclipse.cdt.dsf.debug.ui; |
| 13 |
|
| 14 |
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext; |
| 15 |
import org.eclipse.cdt.dsf.internal.ui.DsfUIPlugin; |
| 16 |
import org.eclipse.core.runtime.CoreException; |
| 17 |
import org.eclipse.debug.core.model.IVariable; |
| 18 |
import org.eclipse.debug.internal.ui.SWTFactory; |
| 19 |
import org.eclipse.debug.internal.ui.model.elements.ElementContentProvider; |
| 20 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate; |
| 21 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; |
| 22 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputRequestor; |
| 23 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerInputUpdate; |
| 24 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; |
| 25 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdateListener; |
| 26 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.PresentationContext; |
| 27 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; |
| 28 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.ViewerInputService; |
| 29 |
import org.eclipse.debug.internal.ui.views.variables.details.DefaultDetailPane; |
| 30 |
import org.eclipse.debug.internal.ui.views.variables.details.DetailPaneProxy; |
| 31 |
import org.eclipse.debug.internal.ui.views.variables.details.IDetailPaneContainer; |
| 32 |
import org.eclipse.debug.ui.AbstractDebugView; |
| 33 |
import org.eclipse.debug.ui.IDebugUIConstants; |
| 34 |
import org.eclipse.jface.dialogs.IDialogSettings; |
| 35 |
import org.eclipse.jface.text.AbstractInformationControl; |
| 36 |
import org.eclipse.jface.text.IInformationControl; |
| 37 |
import org.eclipse.jface.text.IInformationControlCreator; |
| 38 |
import org.eclipse.jface.text.IInformationControlExtension2; |
| 39 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 40 |
import org.eclipse.jface.viewers.StructuredViewer; |
| 41 |
import org.eclipse.jface.viewers.TreeSelection; |
| 42 |
import org.eclipse.jface.viewers.ViewerFilter; |
| 43 |
import org.eclipse.swt.SWT; |
| 44 |
import org.eclipse.swt.custom.SashForm; |
| 45 |
import org.eclipse.swt.events.SelectionEvent; |
| 46 |
import org.eclipse.swt.events.SelectionListener; |
| 47 |
import org.eclipse.swt.graphics.Color; |
| 48 |
import org.eclipse.swt.graphics.Point; |
| 49 |
import org.eclipse.swt.layout.GridData; |
| 50 |
import org.eclipse.swt.layout.GridLayout; |
| 51 |
import org.eclipse.swt.widgets.Composite; |
| 52 |
import org.eclipse.swt.widgets.Layout; |
| 53 |
import org.eclipse.swt.widgets.Shell; |
| 54 |
import org.eclipse.swt.widgets.Tree; |
| 55 |
import org.eclipse.ui.IWorkbenchPage; |
| 56 |
import org.eclipse.ui.IWorkbenchPartSite; |
| 57 |
|
| 58 |
/** |
| 59 |
* Creates an information control to display an expression in a hover control. |
| 60 |
* |
| 61 |
* @noextend This class is not intended to be subclassed by clients. |
| 62 |
* |
| 63 |
* @since 2.1 |
| 64 |
*/ |
| 65 |
public class ExpressionInformationControlCreator implements IInformationControlCreator { |
| 66 |
|
| 67 |
class ExpressionInformationControl extends AbstractInformationControl implements IInformationControlExtension2, IViewerInputRequestor { |
| 68 |
|
| 69 |
/** |
| 70 |
* Dialog setting key for height |
| 71 |
*/ |
| 72 |
private static final String HEIGHT = "HEIGHT"; //$NON-NLS-1$ |
| 73 |
|
| 74 |
/** |
| 75 |
* Dialog setting key for width. |
| 76 |
*/ |
| 77 |
private static final String WIDTH = "WIDTH"; //$NON-NLS-1$ |
| 78 |
|
| 79 |
/** |
| 80 |
* Dialog setting key for tree sash weight |
| 81 |
*/ |
| 82 |
private static final String SASH_WEIGHT_TREE = "SashWeightTree"; //$NON-NLS-1$ |
| 83 |
|
| 84 |
/** |
| 85 |
* Dialog setting key for details sash weight |
| 86 |
*/ |
| 87 |
private static final String SASH_WEIGHT_DETAILS = "SashWeightDetails"; //$NON-NLS-1$ |
| 88 |
|
| 89 |
/** |
| 90 |
* Variable to display. |
| 91 |
*/ |
| 92 |
private Object fVariable; |
| 93 |
|
| 94 |
private TreeModelViewer fViewer; |
| 95 |
private SashForm fSashForm; |
| 96 |
private Composite fDetailPaneComposite; |
| 97 |
private DetailPaneProxy fDetailPane; |
| 98 |
private Tree fTree; |
| 99 |
|
| 100 |
private ViewerInputService fInputService; |
| 101 |
|
| 102 |
/** |
| 103 |
* Creates the content for the root element of the tree viewer in the hover |
| 104 |
*/ |
| 105 |
private class TreeRoot extends ElementContentProvider { |
| 106 |
@Override |
| 107 |
protected int getChildCount(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { |
| 108 |
return 1; |
| 109 |
} |
| 110 |
@Override |
| 111 |
protected Object[] getChildren(Object parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException { |
| 112 |
return new Object[] { fVariable }; |
| 113 |
} |
| 114 |
@Override |
| 115 |
protected boolean supportsContextId(String id) { |
| 116 |
return true; |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Inner class implementing IDetailPaneContainer methods. Handles changes to detail |
| 122 |
* pane and provides limited access to the detail pane proxy. |
| 123 |
*/ |
| 124 |
private class DetailPaneContainer implements IDetailPaneContainer { |
| 125 |
|
| 126 |
/* |
| 127 |
* @see org.eclipse.debug.internal.ui.views.variables.details.IDetailPaneContainer#getCurrentPaneID() |
| 128 |
*/ |
| 129 |
public String getCurrentPaneID() { |
| 130 |
return fDetailPane.getCurrentPaneID(); |
| 131 |
} |
| 132 |
|
| 133 |
/* |
| 134 |
* @see org.eclipse.debug.internal.ui.views.variables.details.IDetailPaneContainer#getCurrentSelection() |
| 135 |
*/ |
| 136 |
public IStructuredSelection getCurrentSelection() { |
| 137 |
return (IStructuredSelection)fViewer.getSelection(); |
| 138 |
} |
| 139 |
|
| 140 |
/* |
| 141 |
* @see org.eclipse.debug.internal.ui.views.variables.details.IDetailPaneContainer#refreshDetailPaneContents() |
| 142 |
*/ |
| 143 |
public void refreshDetailPaneContents() { |
| 144 |
fDetailPane.display(getCurrentSelection()); |
| 145 |
} |
| 146 |
|
| 147 |
/* |
| 148 |
* @see org.eclipse.debug.internal.ui.views.variables.details.IDetailPaneContainer#getParentComposite() |
| 149 |
*/ |
| 150 |
public Composite getParentComposite() { |
| 151 |
return fDetailPaneComposite; |
| 152 |
} |
| 153 |
|
| 154 |
/* |
| 155 |
* @see org.eclipse.debug.internal.ui.views.variables.details.IDetailPaneContainer#getWorkbenchPartSite() |
| 156 |
*/ |
| 157 |
public IWorkbenchPartSite getWorkbenchPartSite() { |
| 158 |
return null; |
| 159 |
} |
| 160 |
|
| 161 |
/* |
| 162 |
* @see org.eclipse.debug.internal.ui.views.variables.details.IDetailPaneContainer#paneChanged(java.lang.String) |
| 163 |
*/ |
| 164 |
public void paneChanged(String newPaneID) { |
| 165 |
if (DefaultDetailPane.ID.equals(newPaneID)){ |
| 166 |
fDetailPane.getCurrentControl().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* Constructs a new control in the given shell. |
| 174 |
* |
| 175 |
* @param parentShell shell |
| 176 |
* @param resize whether resize is supported |
| 177 |
*/ |
| 178 |
ExpressionInformationControl(Shell parentShell, boolean resize) { |
| 179 |
super(parentShell, resize); |
| 180 |
create(); |
| 181 |
} |
| 182 |
|
| 183 |
@Override |
| 184 |
public Point computeSizeHint() { |
| 185 |
IDialogSettings settings = getDialogSettings(false); |
| 186 |
if (settings != null) { |
| 187 |
int x = getIntSetting(settings, WIDTH); |
| 188 |
if (x > 0) { |
| 189 |
int y = getIntSetting(settings, HEIGHT); |
| 190 |
if (y > 0) { |
| 191 |
final Point size= new Point(x,y); |
| 192 |
return size; |
| 193 |
} |
| 194 |
} |
| 195 |
} |
| 196 |
return super.computeSizeHint(); |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* Returns the dialog settings for this hover or <code>null</code> if none |
| 201 |
* |
| 202 |
* @param create whether to create the settings |
| 203 |
*/ |
| 204 |
private IDialogSettings getDialogSettings(boolean create) { |
| 205 |
IDialogSettings settings = DsfUIPlugin.getDefault().getDialogSettings(); |
| 206 |
IDialogSettings section = settings.getSection(this.getClass().getName()); |
| 207 |
if (section == null & create) { |
| 208 |
section = settings.addNewSection(this.getClass().getName()); |
| 209 |
} |
| 210 |
return section; |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* Returns an integer value in the given dialog settings or -1 if none. |
| 215 |
* |
| 216 |
* @param settings dialog settings |
| 217 |
* @param key key |
| 218 |
* @return value or -1 if not present |
| 219 |
*/ |
| 220 |
private int getIntSetting(IDialogSettings settings, String key) { |
| 221 |
try { |
| 222 |
return settings.getInt(key); |
| 223 |
} catch (NumberFormatException e) { |
| 224 |
return -1; |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
@Override |
| 229 |
public void dispose() { |
| 230 |
persistSettings(getShell()); |
| 231 |
super.dispose(); |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* Persists dialog settings. |
| 236 |
* |
| 237 |
* @param shell |
| 238 |
*/ |
| 239 |
private void persistSettings(Shell shell) { |
| 240 |
if (shell != null && !shell.isDisposed()) { |
| 241 |
if (isResizable()) { |
| 242 |
IDialogSettings settings = getDialogSettings(true); |
| 243 |
Point size = shell.getSize(); |
| 244 |
System.out.println("ExpressionInformationControlCreator.ExpressionInformationControl.persistSettings() " + size); |
| 245 |
settings.put(WIDTH, size.x); |
| 246 |
settings.put(HEIGHT, size.y); |
| 247 |
int[] weights = fSashForm.getWeights(); |
| 248 |
settings.put(SASH_WEIGHT_TREE, weights[0]); |
| 249 |
settings.put(SASH_WEIGHT_DETAILS, weights[1]); |
| 250 |
} |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
@Override |
| 255 |
public void setVisible(boolean visible) { |
| 256 |
if (!visible) { |
| 257 |
persistSettings(getShell()); |
| 258 |
} |
| 259 |
super.setVisible(visible); |
| 260 |
} |
| 261 |
|
| 262 |
@Override |
| 263 |
protected void createContent(Composite parent) { |
| 264 |
|
| 265 |
fSashForm = new SashForm(parent, parent.getStyle()); |
| 266 |
fSashForm.setOrientation(SWT.VERTICAL); |
| 267 |
|
| 268 |
// update presentation context |
| 269 |
AbstractDebugView view = getViewToEmulate(); |
| 270 |
IPresentationContext context = new PresentationContext(IDsfDebugUIConstants.ID_EXPRESSION_HOVER); |
| 271 |
if (view != null) { |
| 272 |
// copy over properties |
| 273 |
IPresentationContext copy = ((TreeModelViewer)view.getViewer()).getPresentationContext(); |
| 274 |
try { |
| 275 |
String[] properties = copy.getProperties(); |
| 276 |
for (int i = 0; i < properties.length; i++) { |
| 277 |
String key = properties[i]; |
| 278 |
context.setProperty(key, copy.getProperty(key)); |
| 279 |
} |
| 280 |
} catch (NoSuchMethodError e) { |
| 281 |
// ignore |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
fViewer = new TreeModelViewer(fSashForm, SWT.NO_TRIM | SWT.MULTI | SWT.VIRTUAL, context); |
| 286 |
fViewer.setAutoExpandLevel(1); |
| 287 |
|
| 288 |
if (view != null) { |
| 289 |
// copy over filters |
| 290 |
StructuredViewer structuredViewer = (StructuredViewer) view.getViewer(); |
| 291 |
if (structuredViewer != null) { |
| 292 |
ViewerFilter[] filters = structuredViewer.getFilters(); |
| 293 |
for (int i = 0; i < filters.length; i++) { |
| 294 |
fViewer.addFilter(filters[i]); |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
fInputService = new ViewerInputService(fViewer, this); |
| 299 |
|
| 300 |
fDetailPaneComposite = SWTFactory.createComposite(fSashForm, 1, 1, GridData.FILL_BOTH); |
| 301 |
Layout layout = fDetailPaneComposite.getLayout(); |
| 302 |
if (layout instanceof GridLayout) { |
| 303 |
GridLayout gl = (GridLayout) layout; |
| 304 |
gl.marginHeight = 0; |
| 305 |
gl.marginWidth = 0; |
| 306 |
} |
| 307 |
|
| 308 |
fDetailPane = new DetailPaneProxy(new DetailPaneContainer()); |
| 309 |
fDetailPane.display(null); // Bring up the default pane so the user doesn't see an empty composite |
| 310 |
|
| 311 |
fTree = fViewer.getTree(); |
| 312 |
fTree.addSelectionListener(new SelectionListener() { |
| 313 |
public void widgetSelected(SelectionEvent e) { |
| 314 |
fDetailPane.display((IStructuredSelection)fViewer.getSelection()); |
| 315 |
} |
| 316 |
public void widgetDefaultSelected(SelectionEvent e) {} |
| 317 |
}); |
| 318 |
|
| 319 |
initSashWeights(); |
| 320 |
|
| 321 |
// add update listener to auto-select and display details of root expression |
| 322 |
fViewer.addViewerUpdateListener(new IViewerUpdateListener() { |
| 323 |
public void viewerUpdatesComplete() { |
| 324 |
} |
| 325 |
public void viewerUpdatesBegin() { |
| 326 |
} |
| 327 |
public void updateStarted(IViewerUpdate update) { |
| 328 |
} |
| 329 |
public void updateComplete(IViewerUpdate update) { |
| 330 |
if (update instanceof IChildrenUpdate) { |
| 331 |
fViewer.removeViewerUpdateListener(this); |
| 332 |
fViewer.getDisplay().timerExec(100, new Runnable() { |
| 333 |
public void run() { |
| 334 |
TreeSelection selection = new TreeSelection(fViewer.getTopElementPath()); |
| 335 |
fViewer.setSelection(selection); |
| 336 |
fDetailPane.display(selection); |
| 337 |
}}); |
| 338 |
} |
| 339 |
} |
| 340 |
}); |
| 341 |
|
| 342 |
setBackgroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
/** |
| 347 |
* Attempts to find an appropriate view to emulate, this will either be the |
| 348 |
* variables view or the expressions view. |
| 349 |
* @return a view to emulate or <code>null</code> |
| 350 |
*/ |
| 351 |
private AbstractDebugView getViewToEmulate() { |
| 352 |
IWorkbenchPage page = DsfUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
| 353 |
AbstractDebugView expressionsView = (AbstractDebugView) page.findView(IDebugUIConstants.ID_EXPRESSION_VIEW); |
| 354 |
if (expressionsView != null && expressionsView.isVisible()) { |
| 355 |
return expressionsView; |
| 356 |
} |
| 357 |
AbstractDebugView variablesView = (AbstractDebugView) page.findView(IDebugUIConstants.ID_VARIABLE_VIEW); |
| 358 |
if (variablesView != null && variablesView.isVisible()) { |
| 359 |
return variablesView; |
| 360 |
} |
| 361 |
if (expressionsView != null) { |
| 362 |
return expressionsView; |
| 363 |
} |
| 364 |
return variablesView; |
| 365 |
} |
| 366 |
|
| 367 |
/** |
| 368 |
* Initializes the sash form weights from the preference store (using default values if |
| 369 |
* no sash weights were stored previously). |
| 370 |
*/ |
| 371 |
protected void initSashWeights(){ |
| 372 |
IDialogSettings settings = getDialogSettings(false); |
| 373 |
if (settings != null) { |
| 374 |
int tree = getIntSetting(settings, SASH_WEIGHT_TREE); |
| 375 |
if (tree > 0) { |
| 376 |
int details = getIntSetting(settings, SASH_WEIGHT_DETAILS); |
| 377 |
if (details > 0) { |
| 378 |
fSashForm.setWeights(new int[]{tree, details}); |
| 379 |
} |
| 380 |
} |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
/* (non-Javadoc) |
| 385 |
* @see org.eclipse.jface.text.AbstractInformationControl#setBackgroundColor(org.eclipse.swt.graphics.Color) |
| 386 |
*/ |
| 387 |
@Override |
| 388 |
public void setBackgroundColor(Color background) { |
| 389 |
super.setBackgroundColor(background); |
| 390 |
fDetailPaneComposite.setBackground(background); |
| 391 |
fTree.setBackground(background); |
| 392 |
} |
| 393 |
|
| 394 |
/* (non-Javadoc) |
| 395 |
* @see org.eclipse.jface.text.AbstractInformationControl#setFocus() |
| 396 |
*/ |
| 397 |
@Override |
| 398 |
public void setFocus() { |
| 399 |
super.setFocus(); |
| 400 |
fTree.setFocus(); |
| 401 |
} |
| 402 |
|
| 403 |
/* (non-Javadoc) |
| 404 |
* @see org.eclipse.jface.text.IInformationControlExtension#hasContents() |
| 405 |
*/ |
| 406 |
public boolean hasContents() { |
| 407 |
return fVariable != null; |
| 408 |
} |
| 409 |
|
| 410 |
/* (non-Javadoc) |
| 411 |
* @see org.eclipse.jface.text.IInformationControlExtension2#setInput(java.lang.Object) |
| 412 |
*/ |
| 413 |
public void setInput(Object input) { |
| 414 |
if (input instanceof IExpressionDMContext) { |
| 415 |
fVariable = input; |
| 416 |
fInputService.resolveViewerInput(input); |
| 417 |
} else if (input instanceof IVariable) { |
| 418 |
fVariable = input; |
| 419 |
fViewer.setInput(new TreeRoot()); |
| 420 |
} |
| 421 |
} |
| 422 |
|
| 423 |
@Override |
| 424 |
public IInformationControlCreator getInformationPresenterControlCreator() { |
| 425 |
return new ExpressionInformationControlCreator() { |
| 426 |
@Override |
| 427 |
public IInformationControl createInformationControl(Shell shell) { |
| 428 |
return new ExpressionInformationControl(shell, true); |
| 429 |
} |
| 430 |
}; |
| 431 |
} |
| 432 |
|
| 433 |
public void viewerInputComplete(IViewerInputUpdate update) { |
| 434 |
fViewer.setInput(fVariable = update.getInputElement()); |
| 435 |
} |
| 436 |
|
| 437 |
} |
| 438 |
|
| 439 |
/* |
| 440 |
* @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell) |
| 441 |
*/ |
| 442 |
public IInformationControl createInformationControl(Shell parent) { |
| 443 |
return new ExpressionInformationControl(parent, false); |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
} |