KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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.renderings;
13
14 import java.util.Vector JavaDoc;
15
16 import org.eclipse.debug.internal.ui.DebugUIMessages;
17 import org.eclipse.debug.ui.IDebugUIConstants;
18 import org.eclipse.jface.dialogs.IDialogConstants;
19 import org.eclipse.jface.dialogs.TrayDialog;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.ModifyEvent;
22 import org.eclipse.swt.events.ModifyListener;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
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.Label;
29 import org.eclipse.swt.widgets.Shell;
30 import org.eclipse.ui.PlatformUI;
31
32 /**
33  * @since 3.0
34  */

35
36 public class GoToAddressDialog extends TrayDialog implements ModifyListener{
37
38     private static Vector JavaDoc history = new Vector JavaDoc();
39     private Combo expressionInput;
40     private String JavaDoc expression;
41
42     /**
43      * @param parentShell
44      */

45     public GoToAddressDialog(Shell parentShell) {
46         super(parentShell);
47         setShellStyle(getShellStyle() | SWT.RESIZE);
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
52      */

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

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

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

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

139     protected Control createButtonBar(Composite parent) {
140         
141         Control ret = super.createButtonBar(parent);
142         getButton(IDialogConstants.OK_ID).setEnabled(false);
143         
144         return ret;
145     }
146
147 }
148
Popular Tags