KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > CodeTemplatePreferencePage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.internal.ui.preferences;
12
13 import java.util.Map JavaDoc;
14
15 import org.eclipse.core.runtime.IStatus;
16
17 import org.eclipse.core.resources.IProject;
18
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21
22 import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData;
23
24 import org.eclipse.ui.PlatformUI;
25
26 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
27 import org.eclipse.jdt.internal.ui.JavaPlugin;
28 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
29
30 /*
31  * The page to configure the code templates.
32  */

33 public class CodeTemplatePreferencePage extends PropertyAndPreferencePage {
34
35     public static final String JavaDoc PREF_ID= "org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage"; //$NON-NLS-1$
36
public static final String JavaDoc PROP_ID= "org.eclipse.jdt.ui.propertyPages.CodeTemplatePreferencePage"; //$NON-NLS-1$
37

38     public static final String JavaDoc DATA_SELECT_TEMPLATE= "CodeTemplatePreferencePage.select_template"; //$NON-NLS-1$
39

40     private CodeTemplateBlock fCodeTemplateConfigurationBlock;
41
42     public CodeTemplatePreferencePage() {
43         setPreferenceStore(JavaPlugin.getDefault().getPreferenceStore());
44         //setDescription(PreferencesMessages.getString("CodeTemplatesPreferencePage.description")); //$NON-NLS-1$
45

46         // only used when page is shown programatically
47
setTitle(PreferencesMessages.CodeTemplatesPreferencePage_title);
48     }
49
50     /*
51      * @see PreferencePage#createControl(Composite)
52      */

53     public void createControl(Composite parent) {
54         fCodeTemplateConfigurationBlock= new CodeTemplateBlock(getProject());
55         
56         super.createControl(parent);
57         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.CODE_TEMPLATES_PREFERENCE_PAGE);
58     }
59
60     /* (non-Javadoc)
61      * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#createPreferenceContent(org.eclipse.swt.widgets.Composite)
62      */

63     protected Control createPreferenceContent(Composite composite) {
64         return fCodeTemplateConfigurationBlock.createContents(composite);
65     }
66     
67     /*
68      * @see IPreferencePage#performOk()
69      */

70     public boolean performOk() {
71         if (fCodeTemplateConfigurationBlock != null) {
72             return fCodeTemplateConfigurationBlock.performOk(useProjectSettings());
73         }
74         return true;
75     }
76     
77     /*
78      * @see PreferencePage#performDefaults()
79      */

80     protected void performDefaults() {
81         super.performDefaults();
82         if (fCodeTemplateConfigurationBlock != null) {
83             fCodeTemplateConfigurationBlock.performDefaults();
84         }
85     }
86     
87     /* (non-Javadoc)
88      * @see org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener#statusChanged(org.eclipse.core.runtime.IStatus)
89      */

90     public void statusChanged(IStatus status) {
91         setValid(!status.matches(IStatus.ERROR));
92         StatusUtil.applyToStatusLine(this, status);
93     }
94
95     /* (non-Javadoc)
96      * @see org.eclipse.jface.preference.IPreferencePage#performCancel()
97      */

98     public boolean performCancel() {
99         if (fCodeTemplateConfigurationBlock != null) {
100             fCodeTemplateConfigurationBlock.performCancel();
101         }
102         return super.performCancel();
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#hasProjectSpecificOptions(org.eclipse.core.resources.IProject)
107      */

108     protected boolean hasProjectSpecificOptions(IProject project) {
109         return fCodeTemplateConfigurationBlock.hasProjectSpecificOptions(project);
110     }
111
112     /* (non-Javadoc)
113      * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#getPreferencePageID()
114      */

115     protected String JavaDoc getPreferencePageID() {
116         return PREF_ID;
117     }
118     
119     /* (non-Javadoc)
120      * @see org.eclipse.jdt.internal.ui.preferences.PropertyAndPreferencePage#getPropertyPageID()
121      */

122     protected String JavaDoc getPropertyPageID() {
123         return PROP_ID;
124     }
125
126     /*
127      * @see org.eclipse.jface.preference.PreferencePage#applyData(java.lang.Object)
128      */

129     public void applyData(Object JavaDoc data) {
130         if (data instanceof Map JavaDoc) {
131             Object JavaDoc id= ((Map JavaDoc) data).get(DATA_SELECT_TEMPLATE);
132             if (id instanceof String JavaDoc) {
133                 final TemplatePersistenceData[] templates= fCodeTemplateConfigurationBlock.fTemplateStore.getTemplateData();
134                 TemplatePersistenceData template= null;
135                 for (int index= 0; index < templates.length; index++) {
136                     template= templates[index];
137                     if (template.getId().equals(id)) {
138                         fCodeTemplateConfigurationBlock.postSetSelection(template);
139                         break;
140                     }
141                 }
142             }
143         }
144         super.applyData(data);
145     }
146 }
147
Popular Tags