KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > MarkerViewPreferenceDialog


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.ui.views.markers.internal;
12
13 import org.eclipse.jface.preference.IntegerFieldEditor;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.SelectionAdapter;
16 import org.eclipse.swt.events.SelectionEvent;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
24 import org.eclipse.ui.preferences.ViewSettingsDialog;
25
26 /**
27  * The MarkerViewPreferenceDialog is the dialog that is used for preference
28  * settings in a markers view.
29  *
30  * @since 3.1
31  *
32  */

33 public class MarkerViewPreferenceDialog extends ViewSettingsDialog {
34
35     String JavaDoc enablementKey;
36
37     String JavaDoc limitKey;
38
39     String JavaDoc dialogTitle;
40
41     private IntegerFieldEditor limitEditor;
42
43     private Button enablementButton;
44
45     private Composite editArea;
46
47     /**
48      * Create a new instance of the receiver.
49      *
50      * @param parentShell
51      * @param enablementPreference
52      * The key for the enablement preference.
53      * @param limitPreference
54      * The key for the limit preference.
55      * @param title
56      * The title for the dialog.
57      */

58     public MarkerViewPreferenceDialog(Shell parentShell,
59             String JavaDoc enablementPreference, String JavaDoc limitPreference, String JavaDoc title) {
60         super(parentShell);
61         enablementKey = enablementPreference;
62         limitKey = limitPreference;
63         dialogTitle = title;
64
65     }
66
67     /*
68      * (non-Javadoc)
69      *
70      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
71      */

72     protected void configureShell(Shell newShell) {
73         super.configureShell(newShell);
74         newShell.setText(dialogTitle);
75     }
76
77     /*
78      * (non-Javadoc)
79      *
80      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
81      */

82     protected Control createDialogArea(Composite parent) {
83         Composite topComposite = (Composite) super.createDialogArea(parent);
84
85         boolean checked = IDEWorkbenchPlugin.getDefault().getPreferenceStore()
86                 .getBoolean(enablementKey);
87         enablementButton = new Button(topComposite, SWT.CHECK);
88         enablementButton.setText(MarkerMessages.MarkerPreferences_MarkerLimits);
89         enablementButton.setSelection(checked);
90
91         editArea = new Composite(topComposite, SWT.NONE);
92         editArea.setLayout(new GridLayout());
93         GridData editData = new GridData(GridData.FILL_BOTH
94                 | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
95         editData.horizontalIndent = 10;
96         editArea.setLayoutData(editData);
97
98         limitEditor = new IntegerFieldEditor(
99                 "limit", MarkerMessages.MarkerPreferences_VisibleItems, editArea);//$NON-NLS-1$
100
limitEditor.setPreferenceStore(IDEWorkbenchPlugin.getDefault()
101                 .getPreferenceStore());
102         limitEditor.setPreferenceName(limitKey);
103         limitEditor.load();
104
105         GridData checkedData = new GridData(SWT.FILL, SWT.NONE, true, false);
106         checkedData.horizontalSpan = limitEditor.getNumberOfControls();
107         enablementButton.setLayoutData(checkedData);
108
109         enablementButton.addSelectionListener(new SelectionAdapter() {
110             public void widgetSelected(SelectionEvent e) {
111                 setLimitEditorEnablement(editArea, enablementButton
112                         .getSelection());
113             }
114         });
115
116         setLimitEditorEnablement(editArea, checked);
117
118         return topComposite;
119     }
120
121     /**
122      * Enable the limitEditor based on checked.
123      *
124      * @param control
125      * The parent of the editor
126      * @param checked
127      */

128     private void setLimitEditorEnablement(Composite control, boolean checked) {
129         limitEditor.setEnabled(checked, control);
130     }
131
132     /*
133      * (non-Javadoc)
134      *
135      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
136      */

137     protected void okPressed() {
138         limitEditor.store();
139         IDEWorkbenchPlugin.getDefault().getPreferenceStore().setValue(
140                 enablementKey, enablementButton.getSelection());
141         IDEWorkbenchPlugin.getDefault().savePluginPreferences();
142         super.okPressed();
143     }
144
145     /*
146      * (non-Javadoc)
147      *
148      * @see org.eclipse.ui.preferences.ViewSettingsDialog#performDefaults()
149      */

150     protected void performDefaults() {
151         super.performDefaults();
152         limitEditor.loadDefault();
153         boolean checked = IDEWorkbenchPlugin.getDefault().getPreferenceStore()
154                 .getDefaultBoolean(enablementKey);
155         enablementButton.setSelection(checked);
156         setLimitEditorEnablement(editArea, checked);
157     }
158
159 }
160
Popular Tags