1 11 package org.eclipse.debug.internal.ui.views.memory; 12 13 import java.io.UnsupportedEncodingException ; 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 42 public class CodePagesPrefDialog extends Dialog { 43 44 private Text fAsciiCodePage; 45 private Text fEbcdicCodePage; 46 47 50 public CodePagesPrefDialog(Shell parentShell) { 51 super(parentShell); 52 setShellStyle(getShellStyle() | SWT.RESIZE); 53 PlatformUI.getWorkbench().getHelpSystem().setHelp(parentShell, DebugUIPlugin.getUniqueIdentifier() + ".CodePagesPrefDialog_context"); } 55 56 59 protected Control createDialogArea(Composite parent) { 60 61 getShell().setText(DebugUIMessages.CodePagesPrefDialog_1); 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); 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 codepage = DebugUITools.getPreferenceStore().getString(IDebugUIConstants.PREF_DEFAULT_ASCII_CODE_PAGE); 90 if (codepage == null || codepage.length() == 0) 91 codepage = IDebugPreferenceConstants.DEFAULT_ASCII_CP; fAsciiCodePage.setText(codepage); 93 94 Label ebcdicLabel = new Label(canvas, SWT.WRAP); 95 ebcdicLabel.setText(DebugUIMessages.CodePagesPrefDialog_4); 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; 117 return canvas; 118 } 119 protected void okPressed() { 120 121 String asciiCodePage = fAsciiCodePage.getText(); 123 asciiCodePage = asciiCodePage.trim(); 124 try { 125 new String (new byte[]{1}, asciiCodePage); 126 } catch (UnsupportedEncodingException e) { 127 Shell shell = DebugUIPlugin.getShell(); 128 if (shell != null) 129 { 130 IStatus status = DebugUIPlugin.newErrorStatus(DebugUIMessages.CodePagesPrefDialog_0, e); ErrorDialog.openError(shell, DebugUIMessages.CodePagesPrefDialog_6, DebugUIMessages.CodePagesPrefDialog_7, status); } 133 return; 134 } 135 136 String ebcdicCodePage = fEbcdicCodePage.getText(); 137 ebcdicCodePage = ebcdicCodePage.trim(); 138 try { 139 new String (new byte[]{1}, ebcdicCodePage); 140 } catch (UnsupportedEncodingException e) { 141 Shell shell = DebugUIPlugin.getShell(); 142 if (shell != null) 143 { 144 IStatus status = DebugUIPlugin.newErrorStatus(DebugUIMessages.CodePagesPrefDialog_0, e); ErrorDialog.openError(shell, DebugUIMessages.CodePagesPrefDialog_8, DebugUIMessages.CodePagesPrefDialog_9, status); } 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 160 161 protected void createButtonsForButtonBar(Composite parent) { 162 Button defaultButton = createButton(parent, 3, DebugUIMessages.CodePagesPrefDialog_13, false); defaultButton.addSelectionListener(new SelectionAdapter() { 164 165 public void widgetSelected(SelectionEvent e) { 166 String defaultASCII = IDebugPreferenceConstants.DEFAULT_ASCII_CP; 167 fAsciiCodePage.setText(defaultASCII); 168 String defaulgEBCDIC = IDebugPreferenceConstants.DEFAULT_EBCDIC_CP; 169 fEbcdicCodePage.setText(defaulgEBCDIC); 170 }}); 171 super.createButtonsForButtonBar(parent); 172 } 173 } 174 | Popular Tags |