KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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
13 package org.eclipse.debug.internal.ui.views.memory;
14
15 import java.io.UnsupportedEncodingException JavaDoc;
16
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.debug.internal.ui.DebugUIMessages;
19 import org.eclipse.debug.internal.ui.DebugUIPlugin;
20 import org.eclipse.debug.ui.DebugUITools;
21 import org.eclipse.debug.ui.IDebugUIConstants;
22 import org.eclipse.jface.dialogs.ErrorDialog;
23 import org.eclipse.jface.preference.FieldEditorPreferencePage;
24 import org.eclipse.jface.preference.StringFieldEditor;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Shell;
28 import org.eclipse.ui.PlatformUI;
29
30 public class CodePagesPreferencePage extends FieldEditorPreferencePage {
31
32     private StringFieldEditor fEbcdicCodePage;
33     private StringFieldEditor fAsciiCodePage;
34
35     protected CodePagesPreferencePage() {
36         super(FieldEditorPreferencePage.GRID);
37         setPreferenceStore(DebugUITools.getPreferenceStore());
38         setTitle(DebugUIMessages.CodePagesPrefDialog_1);
39     }
40
41     protected void createFieldEditors() {
42         fAsciiCodePage = new StringFieldEditor(IDebugUIConstants.PREF_DEFAULT_ASCII_CODE_PAGE, DebugUIMessages.CodePagesPrefDialog_2, getFieldEditorParent());
43         fAsciiCodePage.setEmptyStringAllowed(false);
44         addField(fAsciiCodePage);
45         
46         fEbcdicCodePage = new StringFieldEditor(IDebugUIConstants.PREF_DEFAULT_EBCDIC_CODE_PAGE, DebugUIMessages.CodePagesPrefDialog_4, getFieldEditorParent());
47         fEbcdicCodePage.setEmptyStringAllowed(false);
48         addField(fEbcdicCodePage);
49     }
50
51     public boolean performOk() {
52         
53         if (fAsciiCodePage == null || fEbcdicCodePage == null)
54             return super.performOk();
55         
56         // check that the codepages are supported
57
String JavaDoc asciiCodePage = fAsciiCodePage.getStringValue();
58         asciiCodePage = asciiCodePage.trim();
59         try {
60             new String JavaDoc(new byte[]{1}, asciiCodePage);
61         } catch (UnsupportedEncodingException JavaDoc e) {
62             Shell shell = DebugUIPlugin.getShell();
63             if (shell != null)
64             {
65                 IStatus status = DebugUIPlugin.newErrorStatus(DebugUIMessages.CodePagesPrefDialog_0, e);
66                 ErrorDialog.openError(shell, DebugUIMessages.CodePagesPrefDialog_6, DebugUIMessages.CodePagesPrefDialog_7, status); //
67
}
68             return false;
69         }
70         
71         String JavaDoc ebcdicCodePage = fEbcdicCodePage.getStringValue();
72         ebcdicCodePage = ebcdicCodePage.trim();
73         try {
74             new String JavaDoc(new byte[]{1}, ebcdicCodePage);
75         } catch (UnsupportedEncodingException JavaDoc e) {
76             Shell shell = DebugUIPlugin.getShell();
77             if (shell != null)
78             {
79                 IStatus status = DebugUIPlugin.newErrorStatus(DebugUIMessages.CodePagesPrefDialog_0, e);
80                 ErrorDialog.openError(shell, DebugUIMessages.CodePagesPrefDialog_8, DebugUIMessages.CodePagesPrefDialog_9, status); //
81
}
82             return false;
83         }
84         return super.performOk();
85     }
86
87     protected Control createContents(Composite parent) {
88         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, DebugUIPlugin.getUniqueIdentifier() + ".CodePagesPrefDialog_context"); //$NON-NLS-1$
89
return super.createContents(parent);
90     }
91
92 }
93
Popular Tags