001: /*******************************************************************************
002: * Copyright (c) 2005, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.views.markers.internal;
011:
012: import org.eclipse.jface.dialogs.IDialogConstants;
013: import org.eclipse.jface.preference.IntegerFieldEditor;
014: import org.eclipse.swt.SWT;
015: import org.eclipse.swt.events.SelectionAdapter;
016: import org.eclipse.swt.events.SelectionEvent;
017: import org.eclipse.swt.layout.GridData;
018: import org.eclipse.swt.layout.GridLayout;
019: import org.eclipse.swt.widgets.Button;
020: import org.eclipse.swt.widgets.Composite;
021: import org.eclipse.swt.widgets.Control;
022: import org.eclipse.swt.widgets.Shell;
023: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
024: import org.eclipse.ui.preferences.ViewSettingsDialog;
025:
026: /**
027: * The MarkerViewPreferenceDialog is the dialog that is used for preference
028: * settings in a markers view.
029: *
030: * @since 3.1
031: *
032: */
033: public class MarkerViewPreferenceDialog extends ViewSettingsDialog {
034:
035: String enablementKey;
036:
037: String limitKey;
038:
039: String dialogTitle;
040:
041: private IntegerFieldEditor limitEditor;
042:
043: private Button enablementButton;
044:
045: private Composite editArea;
046:
047: /**
048: * Create a new instance of the receiver.
049: *
050: * @param parentShell
051: * @param enablementPreference
052: * The key for the enablement preference.
053: * @param limitPreference
054: * The key for the limit preference.
055: * @param title
056: * The title for the dialog.
057: */
058: public MarkerViewPreferenceDialog(Shell parentShell,
059: String enablementPreference, String limitPreference,
060: String title) {
061: super (parentShell);
062: enablementKey = enablementPreference;
063: limitKey = limitPreference;
064: dialogTitle = title;
065:
066: }
067:
068: /*
069: * (non-Javadoc)
070: *
071: * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
072: */
073: protected void configureShell(Shell newShell) {
074: super .configureShell(newShell);
075: newShell.setText(dialogTitle);
076: }
077:
078: /*
079: * (non-Javadoc)
080: *
081: * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
082: */
083: protected Control createDialogArea(Composite parent) {
084: Composite topComposite = (Composite) super
085: .createDialogArea(parent);
086:
087: boolean checked = IDEWorkbenchPlugin.getDefault()
088: .getPreferenceStore().getBoolean(enablementKey);
089: enablementButton = new Button(topComposite, SWT.CHECK);
090: enablementButton
091: .setText(MarkerMessages.MarkerPreferences_MarkerLimits);
092: enablementButton.setSelection(checked);
093:
094: editArea = new Composite(topComposite, SWT.NONE);
095: editArea.setLayout(new GridLayout());
096: GridData editData = new GridData(GridData.FILL_BOTH
097: | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
098: editData.horizontalIndent = 10;
099: editArea.setLayoutData(editData);
100:
101: limitEditor = new IntegerFieldEditor(
102: "limit", MarkerMessages.MarkerPreferences_VisibleItems, editArea) { //$NON-NLS-1$
103: /* (non-Javadoc)
104: * @see org.eclipse.jface.preference.IntegerFieldEditor#checkState()
105: */
106: protected boolean checkState() {
107: boolean state = super .checkState();
108: Button okButton = getButton(IDialogConstants.OK_ID);
109: if (okButton != null) {
110: okButton.setEnabled(state);
111: }
112: return state;
113: }
114: };
115: limitEditor.setPreferenceStore(IDEWorkbenchPlugin.getDefault()
116: .getPreferenceStore());
117: limitEditor.setPreferenceName(limitKey);
118: limitEditor.load();
119:
120: GridData checkedData = new GridData(SWT.FILL, SWT.NONE, true,
121: false);
122: checkedData.horizontalSpan = limitEditor.getNumberOfControls();
123: enablementButton.setLayoutData(checkedData);
124:
125: enablementButton.addSelectionListener(new SelectionAdapter() {
126: public void widgetSelected(SelectionEvent e) {
127: setLimitEditorEnablement(editArea, enablementButton
128: .getSelection());
129: }
130: });
131:
132: setLimitEditorEnablement(editArea, checked);
133:
134: return topComposite;
135: }
136:
137: /**
138: * Enable the limitEditor based on checked.
139: *
140: * @param control
141: * The parent of the editor
142: * @param checked
143: */
144: private void setLimitEditorEnablement(Composite control,
145: boolean checked) {
146: limitEditor.setEnabled(checked, control);
147: }
148:
149: /*
150: * (non-Javadoc)
151: *
152: * @see org.eclipse.jface.dialogs.Dialog#okPressed()
153: */
154: protected void okPressed() {
155: limitEditor.store();
156: IDEWorkbenchPlugin.getDefault().getPreferenceStore().setValue(
157: enablementKey, enablementButton.getSelection());
158: IDEWorkbenchPlugin.getDefault().savePluginPreferences();
159: super .okPressed();
160: }
161:
162: /*
163: * (non-Javadoc)
164: *
165: * @see org.eclipse.ui.preferences.ViewSettingsDialog#performDefaults()
166: */
167: protected void performDefaults() {
168: super .performDefaults();
169: limitEditor.loadDefault();
170: boolean checked = IDEWorkbenchPlugin.getDefault()
171: .getPreferenceStore().getDefaultBoolean(enablementKey);
172: enablementButton.setSelection(checked);
173: setLimitEditorEnablement(editArea, checked);
174: }
175:
176: }
|