KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.debug.internal.ui.views.memory;
13
14 import org.eclipse.debug.internal.ui.DebugUIMessages;
15 import org.eclipse.debug.internal.ui.DebugUIPlugin;
16 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants;
17 import org.eclipse.debug.ui.IDebugUIConstants;
18 import org.eclipse.jface.dialogs.Dialog;
19 import org.eclipse.jface.preference.IPreferenceStore;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Combo;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.Shell;
28 import org.eclipse.ui.help.WorkbenchHelp;
29
30 /**
31  * Dialog for setting default column size in Memory View
32  */

33 public class DefaultColumnSizeDialog extends Dialog {
34
35     private static final String JavaDoc PREFIX = "DefaultColumnSizeDialog."; //$NON-NLS-1$
36
private static final String JavaDoc DEFAULT_COLUMN_SIZE = PREFIX + "DefaultColumnSize"; //$NON-NLS-1$
37
private static final String JavaDoc COLUMN_SIZE = PREFIX + "ColumnSize"; //$NON-NLS-1$
38

39     IPreferenceStore fPrefStore;
40     Combo fColumnSize;
41     
42     private int[] fColumnSizes = new int[] {1, 2, 4, 8, 16};
43     
44     /**
45      * @param parentShell
46      */

47     protected DefaultColumnSizeDialog(Shell parentShell) {
48         super(parentShell);
49         fPrefStore = DebugUIPlugin.getDefault().getPreferenceStore();
50     }
51     
52     /* (non-Javadoc)
53      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
54      */

55     protected Control createDialogArea(Composite parent) {
56         WorkbenchHelp.setHelp(parent, IDebugUIConstants.PLUGIN_ID + ".DefaultColumnSizeDialog_context"); //$NON-NLS-1$
57

58         getShell().setText(DebugUIMessages.getString(DEFAULT_COLUMN_SIZE));
59         
60         Composite content = new Composite(parent, SWT.NONE);
61         GridLayout layout = new GridLayout();
62         layout.numColumns = 2;
63         content.setLayout(layout);
64         
65         Label textLabel = new Label(content, SWT.NONE);
66         textLabel.setText(DebugUIMessages.getString(COLUMN_SIZE));
67         
68         GridData textLayout = new GridData();
69         textLabel.setLayoutData(textLayout);
70         
71         fColumnSize = new Combo(content, SWT.BORDER|SWT.READ_ONLY);
72
73         GridData columnLayout= new GridData();
74         fColumnSize.setLayoutData(columnLayout);
75         
76         for (int i=0; i<fColumnSizes.length; i++)
77         {
78             fColumnSize.add(String.valueOf(fColumnSizes[i]));
79         }
80         
81         int colSize = fPrefStore.getInt(IDebugPreferenceConstants.PREF_COLUMN_SIZE);
82         int idx = 0;
83         
84         for (int i=0; i<fColumnSizes.length; i++)
85         {
86             if (fColumnSizes[i] == colSize)
87             {
88                 idx = i;
89                 break;
90             }
91         }
92         
93         fColumnSize.select(idx);
94         
95         return content;
96     }
97     
98     /* (non-Javadoc)
99      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
100      */

101     protected void okPressed() {
102         int idx = fColumnSize.getSelectionIndex();
103         int colSize = fColumnSizes[idx];
104         
105         fPrefStore.setValue(IDebugPreferenceConstants.PREF_COLUMN_SIZE, colSize);
106         
107         super.okPressed();
108     }
109 }
110
Popular Tags