Organized imports
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.monitor.ui / src / net / sourceforge / phpdt / monitor / ui / internal / MonitorPreferencePage.java
1 /**********************************************************************
2  * Copyright (c) 2003 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 - Initial API and implementation
10  **********************************************************************/
11 package net.sourceforge.phpdt.monitor.ui.internal;
12
13 import org.eclipse.jface.dialogs.Dialog;
14 import org.eclipse.jface.preference.PreferencePage;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.ui.IWorkbench;
23 import org.eclipse.ui.IWorkbenchPreferencePage;
24 import org.eclipse.ui.help.WorkbenchHelp;
25 /**
26  * The preference page that holds monitor properties.
27  */
28 public class MonitorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
29         protected Button displayButton;
30
31         /**
32          * MonitorPreferencePage constructor comment.
33          */
34         public MonitorPreferencePage() {
35                 super();
36                 noDefaultAndApplyButton();
37         }
38
39         /**
40          * Create the preference options.
41          *
42          * @param parent org.eclipse.swt.widgets.Composite
43          * @return org.eclipse.swt.widgets.Control
44          */
45         protected Control createContents(Composite parent) {
46                 initializeDialogUnits(parent);
47                 
48                 Composite composite = new Composite(parent, SWT.NONE);
49                 GridLayout layout = new GridLayout();
50                 layout.numColumns = 1;
51                 layout.horizontalSpacing = convertHorizontalDLUsToPixels(4);
52                 layout.verticalSpacing = convertVerticalDLUsToPixels(4);
53                 layout.marginWidth = 0;
54                 layout.marginHeight = 0;
55                 composite.setLayout(layout);
56                 GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
57                 composite.setLayoutData(data);
58                 WorkbenchHelp.setHelp(composite, ContextIds.PREF);
59                 
60                 Label label = new Label(composite, SWT.WRAP);
61                 label.setText(MonitorUIPlugin.getResource("%preferenceDescription"));
62                 data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
63                 label.setLayoutData(data);
64         
65                 displayButton = new Button(composite, SWT.CHECK);
66                 displayButton.setText(MonitorUIPlugin.getResource("%prefShowView"));
67                 displayButton.setSelection(MonitorUIPlugin.getShowOnActivityPreference());
68                 WorkbenchHelp.setHelp(displayButton, ContextIds.PREF_SHOW);
69                 
70                 label = new Label(composite, SWT.NONE);
71                 label.setText("");
72         
73                 MonitorComposite monitorComp = new MonitorComposite(composite, SWT.NONE);
74                 data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
75                 monitorComp.setLayoutData(data);
76                 
77                 Dialog.applyDialogFont(composite);
78         
79                 return composite;
80         }
81
82         /**
83          * Initializes this preference page using the passed desktop.
84          *
85          * @param desktop the current desktop
86          */
87         public void init(IWorkbench workbench) {
88         }
89
90         /**
91          * Performs special processing when this page's Defaults button has been pressed.
92          * <p>
93          * This is a framework hook method for sublcasses to do special things when
94          * the Defaults button has been pressed.
95          * Subclasses may override, but should call <code>super.performDefaults</code>.
96          * </p>
97          */
98         protected void performDefaults() {
99                 displayButton.setSelection(MonitorUIPlugin.getDefaultShowOnActivityPreference());
100                 super.performDefaults();
101         }
102
103         /** 
104          * Method declared on IPreferencePage.
105          * Subclasses should override
106          */
107         public boolean performOk() {
108                 MonitorUIPlugin.setShowOnActivityPreference(displayButton.getSelection());
109                 MonitorUIPlugin.getInstance().savePluginPreferences();
110                 return true;
111         }
112 }