KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-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 import java.util.Vector JavaDoc;
15 import org.eclipse.debug.internal.ui.DebugUIMessages;
16 import org.eclipse.debug.ui.IDebugUIConstants;
17 import org.eclipse.jface.dialogs.Dialog;
18 import org.eclipse.jface.dialogs.IDialogConstants;
19 import org.eclipse.swt.SWT;
20 import org.eclipse.swt.events.ModifyEvent;
21 import org.eclipse.swt.events.ModifyListener;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Combo;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Label;
28 import org.eclipse.swt.widgets.Shell;
29 import org.eclipse.ui.help.WorkbenchHelp;
30
31 /**
32  * @since 3.0
33  */

34
35 public class GoToAddressDialog extends Dialog implements ModifyListener{
36
37     private static Vector JavaDoc history = new Vector JavaDoc();
38     private Combo expressionInput;
39     private String JavaDoc expression;
40
41     
42     private static final String JavaDoc PREFIX = "GoToAddressDialog."; //$NON-NLS-1$
43
private static final String JavaDoc GO_TO_ADDRESS = PREFIX + "GoToAddress"; //$NON-NLS-1$
44
private static final String JavaDoc ADDRESS = PREFIX + "Address"; //$NON-NLS-1$
45

46
47     /**
48      * @param parentShell
49      */

50     public GoToAddressDialog(Shell parentShell) {
51         super(parentShell);
52         WorkbenchHelp.setHelp(parentShell, IDebugUIConstants.PLUGIN_ID + ".GoToAddressDialog_context"); //$NON-NLS-1$
53
}
54
55     /* (non-Javadoc)
56      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
57      */

58     protected Control createDialogArea(Composite parent) {
59     
60         parent.setLayout(new GridLayout());
61         GridData spec2= new GridData();
62         spec2.grabExcessVerticalSpace= true;
63         spec2.grabExcessHorizontalSpace= true;
64         spec2.horizontalAlignment= GridData.FILL;
65         spec2.verticalAlignment= GridData.CENTER;
66         parent.setLayoutData(spec2);
67
68         Label textLabel = new Label(parent, SWT.NONE);
69         textLabel.setText(DebugUIMessages.getString(ADDRESS));
70         GridData textLayout = new GridData();
71         textLayout.widthHint = 280;
72         textLabel.setLayoutData(textLayout);
73         
74         expressionInput = new Combo(parent, SWT.BORDER);
75         GridData spec= new GridData();
76         spec.grabExcessVerticalSpace= false;
77         spec.grabExcessHorizontalSpace= true;
78         spec.horizontalAlignment= GridData.FILL;
79         spec.verticalAlignment= GridData.BEGINNING;
80         spec.heightHint = 50;
81         expressionInput.setLayoutData(spec);
82         
83         // add history
84
String JavaDoc[] historyExpression = (String JavaDoc[])history.toArray(new String JavaDoc[history.size()]);
85         for (int i=0; i<historyExpression.length; i++)
86         {
87             expressionInput.add(historyExpression[i]);
88         }
89         
90         expressionInput.addModifyListener(this);
91         
92         return parent;
93     }
94     /* (non-Javadoc)
95      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
96      */

97     protected void configureShell(Shell newShell) {
98         super.configureShell(newShell);
99         
100         newShell.setText(DebugUIMessages.getString(GO_TO_ADDRESS));
101     }
102     
103     public String JavaDoc getExpression()
104     {
105         return expression;
106     }
107     
108     /* (non-Javadoc)
109      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
110      */

111     protected void okPressed() {
112
113         expression = expressionInput.getText();
114
115         // add to history list
116
if (!history.contains(expression))
117             history.insertElementAt(expression, 0);
118
119         super.okPressed();
120     }
121
122     /* (non-Javadoc)
123      * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
124      */

125     public void modifyText(ModifyEvent e) {
126
127         String JavaDoc input = expressionInput.getText();
128     
129         if (input == null || input.equals("")) //$NON-NLS-1$
130
{
131             getButton(IDialogConstants.OK_ID).setEnabled(false);
132         }
133         else
134         {
135             getButton(IDialogConstants.OK_ID).setEnabled(true);
136         }
137
138     }
139
140     /* (non-Javadoc)
141      * @see org.eclipse.jface.dialogs.Dialog#createButtonBar(org.eclipse.swt.widgets.Composite)
142      */

143     protected Control createButtonBar(Composite parent) {
144         
145         Control ret = super.createButtonBar(parent);
146         getButton(IDialogConstants.OK_ID).setEnabled(false);
147         
148         return ret;
149     }
150
151 }
152
Popular Tags