KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > MonitorMemoryBlockDialog


1 /*******************************************************************************
2  * Copyright (c) 2004, 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
12 package org.eclipse.debug.internal.ui.views.memory;
13
14
15 import org.eclipse.debug.core.model.IMemoryBlockRetrieval;
16 import org.eclipse.debug.core.model.IMemoryBlockRetrievalExtension;
17 import org.eclipse.debug.internal.ui.DebugUIMessages;
18 import org.eclipse.debug.internal.ui.SWTFactory;
19 import org.eclipse.debug.ui.IDebugUIConstants;
20 import org.eclipse.jface.dialogs.IDialogConstants;
21 import org.eclipse.jface.dialogs.TrayDialog;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.ModifyEvent;
24 import org.eclipse.swt.events.ModifyListener;
25 import org.eclipse.swt.widgets.Combo;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Control;
28 import org.eclipse.swt.widgets.Shell;
29 import org.eclipse.swt.widgets.Text;
30 import org.eclipse.ui.PlatformUI;
31
32 /**
33  * @since 3.0
34  */

35 public class MonitorMemoryBlockDialog extends TrayDialog implements ModifyListener{
36
37     private Combo expressionInput;
38     private Text lengthInput;
39     private String JavaDoc expression;
40     private String JavaDoc length;
41     private boolean needLength = true;
42     private String JavaDoc fPrefillExp = null;
43     private String JavaDoc fPrefillLength = null;
44     
45     /**
46      * the predefined width of the wrapping label for the expression to enter combo
47      * @since 3.3
48      */

49     private static final int LABEL_WIDTH = 210;
50     
51     /**
52      * @param parentShell
53      */

54     public MonitorMemoryBlockDialog(Shell parentShell, IMemoryBlockRetrieval memRetrieval, String JavaDoc prefillExp, String JavaDoc prefillLength) {
55         super(parentShell);
56         
57         if (memRetrieval instanceof IMemoryBlockRetrievalExtension)
58             needLength = false;
59         
60         fPrefillExp = prefillExp;
61         fPrefillLength = prefillLength;
62         setShellStyle(getShellStyle() | SWT.RESIZE);
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
67      */

68     protected Control createDialogArea(Composite parent) {
69         Composite comp = (Composite) super.createDialogArea(parent);
70         SWTFactory.createWrapLabel(comp, DebugUIMessages.MonitorMemoryBlockDialog_EnterExpressionToMonitor, 1, LABEL_WIDTH);
71         expressionInput = SWTFactory.createCombo(comp, SWT.BORDER, 1, MemoryViewUtil.getHistory());
72         if (fPrefillExp != null) {
73             expressionInput.setText(fPrefillExp);
74         }
75         expressionInput.addModifyListener(this);
76         
77         if (needLength) {
78             SWTFactory.createLabel(comp, DebugUIMessages.MonitorMemoryBlockDialog_NumberOfBytes, 1);
79             lengthInput = SWTFactory.createSingleText(comp, 1);
80             if (fPrefillLength != null) {
81                 lengthInput.setText(fPrefillLength);
82             }
83             lengthInput.addModifyListener(this);
84         }
85         PlatformUI.getWorkbench().getHelpSystem().setHelp(comp, IDebugUIConstants.PLUGIN_ID + ".MonitorMemoryBlockDialog_context"); //$NON-NLS-1$
86
return comp;
87     }
88     /* (non-Javadoc)
89      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
90      */

91     protected void configureShell(Shell newShell) {
92         super.configureShell(newShell);
93         
94         newShell.setText(DebugUIMessages.MonitorMemoryBlockDialog_MonitorMemory);
95     }
96     
97     /**
98      * @return the entered expression
99      */

100     public String JavaDoc getExpression() {
101         return expression;
102     }
103     
104     /**
105      * @return the entered length
106      */

107     public String JavaDoc getLength() {
108         return length;
109     }
110     
111     /* (non-Javadoc)
112      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
113      */

114     protected void okPressed() {
115
116         expression = expressionInput.getText();
117
118         // add to HISTORY list
119
MemoryViewUtil.addHistory(expression);
120
121         if (needLength)
122             length = lengthInput.getText();
123
124         super.okPressed();
125     }
126
127     /* (non-Javadoc)
128      * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
129      */

130     public void modifyText(ModifyEvent e) {
131         updateOKButtonState();
132     }
133
134     private void updateOKButtonState() {
135         if (needLength)
136         {
137             String JavaDoc lengthText = lengthInput.getText();
138             String JavaDoc input = expressionInput.getText();
139             
140             if (input == null || input.equals("") || lengthText == null || lengthText.equals("")) //$NON-NLS-1$ //$NON-NLS-2$
141
{
142                 getButton(IDialogConstants.OK_ID).setEnabled(false);
143             }
144             else
145             {
146                 getButton(IDialogConstants.OK_ID).setEnabled(true);
147             }
148         }
149     }
150
151     /* (non-Javadoc)
152      * @see org.eclipse.jface.dialogs.Dialog#createButtonBar(org.eclipse.swt.widgets.Composite)
153      */

154     protected Control createButtonBar(Composite parent) {
155         
156         Control ret = super.createButtonBar(parent);
157         
158         if (needLength)
159             updateOKButtonState();
160         else
161             // always enable the OK button if we only need the expression
162
getButton(IDialogConstants.OK_ID).setEnabled(true);
163         
164         return ret;
165     }
166 }
167
Popular Tags