1 11 package org.eclipse.debug.ui; 12 13 import java.util.List ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.debug.core.DebugPlugin; 17 import org.eclipse.debug.core.model.IExpression; 18 import org.eclipse.debug.internal.ui.DebugUIPlugin; 19 import org.eclipse.debug.internal.ui.SWTFactory; 20 import org.eclipse.debug.internal.ui.model.elements.ElementContentProvider; 21 import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate; 22 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 23 import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; 24 import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdateListener; 25 import org.eclipse.debug.internal.ui.viewers.model.provisional.PresentationContext; 26 import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; 27 import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages; 28 import org.eclipse.debug.internal.ui.views.variables.VariablesView; 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.jface.viewers.IStructuredSelection; 33 import org.eclipse.jface.viewers.StructuredViewer; 34 import org.eclipse.jface.viewers.ViewerFilter; 35 import org.eclipse.swt.SWT; 36 import org.eclipse.swt.custom.SashForm; 37 import org.eclipse.swt.events.SelectionEvent; 38 import org.eclipse.swt.events.SelectionListener; 39 import org.eclipse.swt.graphics.Point; 40 import org.eclipse.swt.layout.GridData; 41 import org.eclipse.swt.layout.GridLayout; 42 import org.eclipse.swt.widgets.Composite; 43 import org.eclipse.swt.widgets.Control; 44 import org.eclipse.swt.widgets.Shell; 45 import org.eclipse.swt.widgets.Tree; 46 import org.eclipse.ui.IViewPart; 47 import org.eclipse.ui.IWorkbenchPage; 48 import org.eclipse.ui.IWorkbenchPartSite; 49 import org.eclipse.ui.PartInitException; 50 51 59 public class InspectPopupDialog extends DebugPopup { 60 61 private static final String PREF_INSPECT_POPUP_SASH_WEIGHTS = DebugUIPlugin.getUniqueIdentifier() + "inspectPopupSashWeights"; 63 private static final int[] DEFAULT_SASH_WEIGHTS = new int[] { 90, 10 }; 64 private static final int MIN_WIDTH = 250; 65 private static final int MIN_HEIGHT = 200; 66 67 private TreeModelViewer fViewer; 68 private SashForm fSashForm; 69 private Composite fDetailPaneComposite; 70 private DetailPaneProxy fDetailPane; 71 private Tree fTree; 72 private IExpression fExpression; 73 74 84 public InspectPopupDialog(Shell shell, Point anchor, String commandId, IExpression expression) { 85 super(shell, anchor, commandId); 86 fExpression = expression; 87 } 88 89 92 protected Control createDialogArea(Composite parent) { 93 Composite composite = new Composite(parent, parent.getStyle()); 94 GridLayout layout = new GridLayout(); 95 composite.setLayout(layout); 96 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 97 98 fSashForm = new SashForm(composite, parent.getStyle()); 99 fSashForm.setOrientation(SWT.VERTICAL); 100 fSashForm.setLayoutData(new GridData(GridData.FILL_BOTH)); 101 102 VariablesView view = getViewToEmulate(); 103 IPresentationContext context; 104 if (view == null) { 105 context = new PresentationContext(IDebugUIConstants.ID_VARIABLE_VIEW); 106 } else { 107 context = ((TreeModelViewer)view.getViewer()).getPresentationContext(); 108 } 109 fViewer = new TreeModelViewer(fSashForm, SWT.NO_TRIM | SWT.MULTI | SWT.VIRTUAL, context); 110 111 fDetailPaneComposite = SWTFactory.createComposite(fSashForm, 1, 1, GridData.FILL_BOTH); 112 113 fDetailPane = new DetailPaneProxy(new DetailPaneContainer()); 114 fDetailPane.display(null); 116 fTree = fViewer.getTree(); 117 fTree.addSelectionListener(new SelectionListener() { 118 public void widgetSelected(SelectionEvent e) { 119 fDetailPane.display((IStructuredSelection)fViewer.getSelection()); 120 } 121 public void widgetDefaultSelected(SelectionEvent e) {} 122 }); 123 124 initSashWeights(); 125 126 fViewer.getContentProvider(); 127 if (view != null) { 128 StructuredViewer structuredViewer = (StructuredViewer) view.getViewer(); 129 if (structuredViewer != null) { 130 ViewerFilter[] filters = structuredViewer.getFilters(); 131 for (int i = 0; i < filters.length; i++) { 132 fViewer.addFilter(filters[i]); 133 } 134 } 135 } 136 137 TreeRoot treeRoot = new TreeRoot(); 138 fViewer.addViewerUpdateListener(new ViewerListener(fExpression)); 139 fViewer.setInput(treeRoot); 140 141 return fTree; 142 } 143 144 148 protected void initSashWeights(){ 149 String prefWeights = DebugUIPlugin.getDefault().getPreferenceStore().getString(PREF_INSPECT_POPUP_SASH_WEIGHTS); 150 if (prefWeights.length() > 0){ 151 String [] weights = prefWeights.split(":"); if (weights.length == 2){ 153 try{ 154 int[] intWeights = new int[2]; 155 intWeights[0] = Integer.parseInt(weights[0]); 156 intWeights[1] = Integer.parseInt(weights[1]); 157 fSashForm.setWeights(intWeights); 158 return; 159 } catch (NumberFormatException e){} 160 } 161 } 162 fSashForm.setWeights(DEFAULT_SASH_WEIGHTS); 163 } 164 165 168 protected void saveDialogBounds(Shell shell) { 169 super.saveDialogBounds(shell); 170 if (fSashForm != null && !fSashForm.isDisposed()){ 171 int[] weights = fSashForm.getWeights(); 172 if (weights.length == 2){ 173 String weightString = weights[0] + ":" + weights[1]; DebugUIPlugin.getDefault().getPluginPreferences().setValue(PREF_INSPECT_POPUP_SASH_WEIGHTS, weightString); 175 } 176 } 177 } 178 179 184 private class TreeRoot extends ElementContentProvider { 185 188 protected int getChildCount(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { 189 return 1; 190 } 191 194 protected Object [] getChildren(Object parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException { 195 return new Object [] { fExpression }; 196 } 197 198 201 protected boolean supportsContextId(String id) { 202 return true; 203 } 204 } 205 206 211 private VariablesView getViewToEmulate() { 212 IWorkbenchPage page = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage(); 213 VariablesView expressionsView = (VariablesView) page.findView(IDebugUIConstants.ID_EXPRESSION_VIEW); 214 if (expressionsView != null && expressionsView.isVisible()) { 215 return expressionsView; 216 } 217 VariablesView variablesView = (VariablesView) page.findView(IDebugUIConstants.ID_VARIABLE_VIEW); 218 if (variablesView != null && variablesView.isVisible()) { 219 return variablesView; 220 } 221 if (expressionsView != null) { 222 return expressionsView; 223 } 224 return variablesView; 225 } 226 227 230 public boolean close() { 231 if (!wasPersisted()) { 232 fExpression.dispose(); 233 } 234 fDetailPane.dispose(); 235 return super.close(); 236 } 237 238 241 protected String getActionText() { 242 return DebugUIViewsMessages.InspectPopupDialog_0; 243 } 244 245 248 protected void persist() { 249 super.persist(); 250 DebugPlugin.getDefault().getExpressionManager().addExpression(fExpression); 251 252 fExpression = null; 253 IWorkbenchPage page = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage(); 254 IViewPart part = page.findView(IDebugUIConstants.ID_EXPRESSION_VIEW); 255 if (part == null) { 256 try { 257 page.showView(IDebugUIConstants.ID_EXPRESSION_VIEW); 258 } catch (PartInitException e) { 259 } 260 } else { 261 page.bringToTop(part); 262 } 263 } 264 265 268 protected Point getInitialSize() { 269 Point initialSize = super.getInitialSize(); 270 initialSize.x = Math.max(initialSize.x, MIN_WIDTH); 271 initialSize.y = Math.max(initialSize.y, MIN_HEIGHT); 272 return initialSize; 273 } 274 275 278 protected List getBackgroundColorExclusions() { 279 List list = super.getBackgroundColorExclusions(); 280 list.add(fSashForm); 281 return list; 282 } 283 284 288 private class DetailPaneContainer implements IDetailPaneContainer{ 289 290 293 public String getCurrentPaneID() { 294 return fDetailPane.getCurrentPaneID(); 295 } 296 297 300 public IStructuredSelection getCurrentSelection() { 301 return (IStructuredSelection)fViewer.getSelection(); 302 } 303 304 307 public void refreshDetailPaneContents() { 308 fDetailPane.display(getCurrentSelection()); 309 } 310 311 314 public Composite getParentComposite() { 315 return fDetailPaneComposite; 316 } 317 318 321 public IWorkbenchPartSite getWorkbenchPartSite() { 322 return null; 323 } 324 325 328 public void paneChanged(String newPaneID) { 329 if (newPaneID.equals(DefaultDetailPane.ID)){ 330 applyBackgroundColor(getShell().getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND), fDetailPane.getCurrentControl()); 331 } 332 } 333 334 } 335 336 private class ViewerListener implements IViewerUpdateListener { 337 338 private Object rootElement; 339 340 ViewerListener(Object root) { 341 rootElement = root; 342 } 343 344 347 public void updateComplete(IViewerUpdate update) { 348 if (update instanceof IHasChildrenUpdate) { 349 IHasChildrenUpdate hcu = (IHasChildrenUpdate) update; 350 if (hcu.getElement().equals(rootElement)) { 351 fViewer.removeViewerUpdateListener(this); 352 fViewer.expandToLevel(update.getElementPath(), 1); 353 } 354 } 355 } 356 357 360 public void updateStarted(IViewerUpdate update) { 361 } 362 363 366 public void viewerUpdatesBegin() { 367 } 368 369 372 public void viewerUpdatesComplete() { 373 } 374 375 376 } 377 378 } 379 | Popular Tags |