KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > actions > PopupDisplayAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 package org.eclipse.jdt.internal.debug.ui.actions;
12
13 import org.eclipse.debug.ui.DebugPopup;
14 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
15 import org.eclipse.jdt.internal.debug.ui.display.DisplayView;
16 import org.eclipse.jdt.internal.debug.ui.display.IDataDisplay;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.custom.StyledText;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Display;
23 import org.eclipse.swt.widgets.Shell;
24 import org.eclipse.ui.IWorkbenchPart;
25
26 public class PopupDisplayAction extends DisplayAction {
27
28     public static final String JavaDoc ACTION_DEFINITION_ID = "org.eclipse.jdt.debug.ui.commands.Display"; //$NON-NLS-1$
29

30     private String JavaDoc snippet;
31
32     private String JavaDoc resultString;
33
34     public PopupDisplayAction() {
35         super();
36     }
37
38     private void showPopup(StyledText textWidget) {
39         DebugPopup displayPopup = new DisplayPopup(getShell(), textWidget);
40         displayPopup.open();
41     }
42
43     private class DisplayPopup extends DebugPopup {
44         public DisplayPopup(Shell shell, StyledText textWidget) {
45             super(shell, getPopupAnchor(textWidget), ACTION_DEFINITION_ID);
46         }
47
48         protected String JavaDoc getActionText() {
49             return ActionMessages.PopupDisplayAction_2;
50         }
51
52         protected void persist() {
53             IDataDisplay directDisplay = getDirectDataDisplay();
54             Display display = JDIDebugUIPlugin.getStandardDisplay();
55
56             if (!display.isDisposed()) {
57                 IDataDisplay dataDisplay = getDataDisplay();
58                 if (dataDisplay != null) {
59                     if (directDisplay == null) {
60                         dataDisplay.displayExpression(snippet);
61                     }
62                     dataDisplay.displayExpressionValue(resultString);
63                 }
64             }
65         }
66
67         protected Control createDialogArea(Composite parent) {
68             GridData gd = new GridData(GridData.FILL_BOTH);
69             StyledText text = new StyledText(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL);
70             text.setLayoutData(gd);
71
72             text.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
73             text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
74
75             text.setText(resultString);
76             return text;
77         }
78     }
79
80     protected void displayStringResult(String JavaDoc currentSnippet, String JavaDoc currentResultString) {
81         IWorkbenchPart part = getTargetPart();
82
83         if (part instanceof DisplayView) {
84             super.displayStringResult(currentSnippet, currentResultString);
85             return;
86         }
87         
88         final StyledText textWidget = EvaluateAction.getStyledText(part);
89         if (textWidget == null) {
90             super.displayStringResult(currentSnippet, currentResultString);
91         } else {
92             snippet = currentSnippet;
93             resultString = currentResultString;
94             Display.getDefault().asyncExec(new Runnable JavaDoc() {
95                 public void run() {
96                     showPopup(textWidget);
97                 }
98             });
99             evaluationCleanup();
100         }
101     }
102
103 }
104
Popular Tags