unification of bug fixes 1198893, 1404228
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / preferences / CodeTemplatePreferencePage.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package net.sourceforge.phpdt.internal.ui.preferences;
12
13 import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds;
14 import net.sourceforge.phpdt.internal.ui.dialogs.StatusUtil;
15 import net.sourceforge.phpdt.internal.ui.wizards.IStatusChangeListener;
16 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
17
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.jface.dialogs.Dialog;
20 import org.eclipse.jface.preference.PreferencePage;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.ui.IWorkbench;
24 import org.eclipse.ui.IWorkbenchPreferencePage;
25 import org.eclipse.ui.help.WorkbenchHelp;
26
27 /*
28  * The page to configure the code formatter options.
29  */
30 public class CodeTemplatePreferencePage extends PreferencePage implements IWorkbenchPreferencePage, IStatusChangeListener {
31
32         private CodeTemplateBlock fCodeTemplateConfigurationBlock;
33
34         public CodeTemplatePreferencePage() {
35                 setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore());
36                 //setDescription(PreferencesMessages.getString("CodeTemplatesPreferencePage.description")); //$NON-NLS-1$
37                 
38                 // only used when page is shown programatically
39                 setTitle(PreferencesMessages.getString("CodeTemplatesPreferencePage.title"));            //$NON-NLS-1$
40                 
41                 fCodeTemplateConfigurationBlock= new CodeTemplateBlock();
42         }
43
44         /*
45          * @see IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
46          */     
47         public void init(IWorkbench workbench) {
48         }
49
50         /*
51          * @see PreferencePage#createControl(Composite)
52          */
53         public void createControl(Composite parent) {
54                 super.createControl(parent);
55                 WorkbenchHelp.setHelp(getControl(), IJavaHelpContextIds.CODE_MANIPULATION_PREFERENCE_PAGE);
56         }       
57
58         /*
59          * @see PreferencePage#createContents(Composite)
60          */
61         protected Control createContents(Composite parent) {
62                 Control composite= fCodeTemplateConfigurationBlock.createContents(parent);
63                 Dialog.applyDialogFont(composite);
64                 return composite;
65         }
66
67         /*
68          * @see IPreferencePage#performOk()
69          */
70         public boolean performOk() {
71                 if (!fCodeTemplateConfigurationBlock.performOk(true)) {
72                         return false;
73                 }                       
74                 return super.performOk();
75         }
76         
77         /*
78          * @see PreferencePage#performDefaults()
79          */
80         protected void performDefaults() {
81                 fCodeTemplateConfigurationBlock.performDefaults();
82                 super.performDefaults();
83         }
84         
85         /* (non-Javadoc)
86          * @see net.sourceforge.phpdt.internal.ui.wizards.IStatusChangeListener#statusChanged(org.eclipse.core.runtime.IStatus)
87          */
88         public void statusChanged(IStatus status) {
89                 setValid(!status.matches(IStatus.ERROR));
90                 StatusUtil.applyToStatusLine(this, status);             
91         }
92
93         /* (non-Javadoc)
94          * @see org.eclipse.jface.preference.IPreferencePage#performCancel()
95          */
96         public boolean performCancel() {
97                 fCodeTemplateConfigurationBlock.performCancel();
98                 
99                 return super.performCancel();
100         }
101
102 }
103
104
105