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