KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005 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.debug.internal.ui.views.memory;
12
13 import java.io.UnsupportedEncodingException JavaDoc;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.debug.internal.ui.DebugUIMessages;
17 import org.eclipse.debug.internal.ui.DebugUIPlugin;
18 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
19 import org.eclipse.debug.ui.DebugUITools;
20 import org.eclipse.debug.ui.IDebugUIConstants;
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.jface.dialogs.ErrorDialog;
23 import org.eclipse.jface.preference.IPreferenceStore;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.events.SelectionAdapter;
26 import org.eclipse.swt.events.SelectionEvent;
27 import org.eclipse.swt.layout.GridData;
28 import org.eclipse.swt.layout.GridLayout;
29 import org.eclipse.swt.widgets.Button;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.swt.widgets.Shell;
34 import org.eclipse.swt.widgets.Text;
35 import org.eclipse.ui.PlatformUI;
36
37
38 /**
39  * Dialog to allow user to change code page preference
40  * @since 3.1
41  */

42 public class CodePagesPrefDialog extends Dialog {
43
44     private Text fAsciiCodePage;
45     private Text fEbcdicCodePage;
46     
47     /**
48      * @param parentShell
49      */

50     public CodePagesPrefDialog(Shell parentShell) {
51         super(parentShell);
52         setShellStyle(getShellStyle() | SWT.RESIZE);
53         PlatformUI.getWorkbench().getHelpSystem().setHelp(parentShell, DebugUIPlugin.getUniqueIdentifier() + ".CodePagesPrefDialog_context"); //$NON-NLS-1$
54
}
55
56     /* (non-Javadoc)
57      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
58      */

59     protected Control createDialogArea(Composite parent) {
60     
61         getShell().setText(DebugUIMessages.CodePagesPrefDialog_1); //$NON-NLS-1$
62
setShellStyle(SWT.RESIZE);
63         
64         Composite canvas = new Composite(parent, SWT.NONE);
65         canvas.setLayout(new GridLayout(2, false));
66         GridData spec2= new GridData();
67         spec2.grabExcessVerticalSpace= true;
68         spec2.grabExcessHorizontalSpace= true;
69         spec2.horizontalAlignment= GridData.FILL;
70         spec2.verticalAlignment= GridData.CENTER;
71         canvas.setLayoutData(spec2);
72
73         Label textLabel = new Label(canvas, SWT.WRAP);
74         textLabel.setText(DebugUIMessages.CodePagesPrefDialog_2); //$NON-NLS-1$
75
GridData textLayout = new GridData();
76         textLayout.widthHint = 280;
77         textLayout.horizontalSpan = 2;
78         textLabel.setLayoutData(textLayout);
79         
80         fAsciiCodePage = new Text(canvas, SWT.BORDER);
81         GridData asciispec= new GridData();
82         asciispec.grabExcessVerticalSpace= false;
83         asciispec.grabExcessHorizontalSpace= true;
84         asciispec.horizontalAlignment= GridData.FILL;
85         asciispec.verticalAlignment= GridData.BEGINNING;
86         asciispec.horizontalSpan = 1;
87         fAsciiCodePage.setLayoutData(asciispec);
88         
89         String JavaDoc codepage = DebugUITools.getPreferenceStore().getString(IDebugUIConstants.PREF_DEFAULT_ASCII_CODE_PAGE);
90         if (codepage == null || codepage.length() == 0)
91             codepage = IDebugPreferenceConstants.DEFAULT_ASCII_CP; //$NON-NLS-1$
92
fAsciiCodePage.setText(codepage);
93         
94         Label ebcdicLabel = new Label(canvas, SWT.WRAP);
95         ebcdicLabel.setText(DebugUIMessages.CodePagesPrefDialog_4); //$NON-NLS-1$
96
GridData ebcdicLayout = new GridData();
97         ebcdicLayout.widthHint = 280;
98         ebcdicLayout.horizontalSpan = 2;
99         ebcdicLabel.setLayoutData(ebcdicLayout);
100         
101         fEbcdicCodePage = new Text(canvas, SWT.BORDER);
102         GridData ebcdicspec= new GridData();
103         ebcdicspec.grabExcessVerticalSpace= false;
104         ebcdicspec.grabExcessHorizontalSpace= true;
105         ebcdicspec.horizontalAlignment= GridData.FILL;
106         ebcdicspec.verticalAlignment= GridData.BEGINNING;
107         ebcdicspec.horizontalSpan = 1;
108         fAsciiCodePage.setLayoutData(ebcdicspec);
109         fEbcdicCodePage.setLayoutData(asciispec);
110
111         codepage = DebugUITools.getPreferenceStore().getString(IDebugUIConstants.PREF_DEFAULT_EBCDIC_CODE_PAGE);
112         fEbcdicCodePage.setText(codepage);
113         
114         if (codepage == null || codepage.length() == 0)
115             codepage = IDebugPreferenceConstants.DEFAULT_EBCDIC_CP; //$NON-NLS-1$
116

117         return canvas;
118     }
119     protected void okPressed() {
120
121         // check that the codepages are supported
122
String JavaDoc asciiCodePage = fAsciiCodePage.getText();
123         asciiCodePage = asciiCodePage.trim();
124         try {
125             new String JavaDoc(new byte[]{1}, asciiCodePage);
126         } catch (UnsupportedEncodingException JavaDoc e) {
127             Shell shell = DebugUIPlugin.getShell();
128             if (shell != null)
129             {
130                 IStatus status = DebugUIPlugin.newErrorStatus(DebugUIMessages.CodePagesPrefDialog_0, e); //$NON-NLS-1$
131
ErrorDialog.openError(shell, DebugUIMessages.CodePagesPrefDialog_6, DebugUIMessages.CodePagesPrefDialog_7, status); //$NON-NLS-1$ //$NON-NLS-2$
132
}
133             return;
134         }
135         
136         String JavaDoc ebcdicCodePage = fEbcdicCodePage.getText();
137         ebcdicCodePage = ebcdicCodePage.trim();
138         try {
139             new String JavaDoc(new byte[]{1}, ebcdicCodePage);
140         } catch (UnsupportedEncodingException JavaDoc e) {
141             Shell shell = DebugUIPlugin.getShell();
142             if (shell != null)
143             {
144                 IStatus status = DebugUIPlugin.newErrorStatus(DebugUIMessages.CodePagesPrefDialog_0, e); //$NON-NLS-1$
145
ErrorDialog.openError(shell, DebugUIMessages.CodePagesPrefDialog_8, DebugUIMessages.CodePagesPrefDialog_9, status); //$NON-NLS-1$ //$NON-NLS-2$
146
}
147             return;
148         }
149         
150         IPreferenceStore store = DebugUITools.getPreferenceStore();
151         store.setValue(IDebugUIConstants.PREF_DEFAULT_ASCII_CODE_PAGE, asciiCodePage);
152         store.setValue(IDebugUIConstants.PREF_DEFAULT_EBCDIC_CODE_PAGE, ebcdicCodePage);
153         
154         super.okPressed();
155     }
156     
157     /**
158      * @param shell
159      */

160     
161     protected void createButtonsForButtonBar(Composite parent) {
162         Button defaultButton = createButton(parent, 3, DebugUIMessages.CodePagesPrefDialog_13, false); //$NON-NLS-1$
163
defaultButton.addSelectionListener(new SelectionAdapter() {
164
165             public void widgetSelected(SelectionEvent e) {
166                 String JavaDoc defaultASCII = IDebugPreferenceConstants.DEFAULT_ASCII_CP;
167                 fAsciiCodePage.setText(defaultASCII);
168                 String JavaDoc defaulgEBCDIC = IDebugPreferenceConstants.DEFAULT_EBCDIC_CP;
169                 fEbcdicCodePage.setText(defaulgEBCDIC);
170             }});
171         super.createButtonsForButtonBar(parent);
172     }
173 }
174
Popular Tags