1 11 12 13 package org.eclipse.debug.internal.ui.views.memory; 14 15 import java.io.UnsupportedEncodingException ; 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 String asciiCodePage = fAsciiCodePage.getStringValue(); 58 asciiCodePage = asciiCodePage.trim(); 59 try { 60 new String (new byte[]{1}, asciiCodePage); 61 } catch (UnsupportedEncodingException 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); } 68 return false; 69 } 70 71 String ebcdicCodePage = fEbcdicCodePage.getStringValue(); 72 ebcdicCodePage = ebcdicCodePage.trim(); 73 try { 74 new String (new byte[]{1}, ebcdicCodePage); 75 } catch (UnsupportedEncodingException 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); } 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"); return super.createContents(parent); 90 } 91 92 } 93 | Popular Tags |