View Javadoc

1   /* ====================================================================
2    *   Copyright 2003-2004 Fabrizio Giustina.
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   * ====================================================================
16   */
17  package net.sf.commonclipse.preferences;
18  
19  import net.sf.commonclipse.CCMessages;
20  import net.sf.commonclipse.CCPlugin;
21  
22  import org.eclipse.jface.preference.BooleanFieldEditor;
23  import org.eclipse.jface.preference.RadioGroupFieldEditor;
24  import org.eclipse.ui.IWorkbench;
25  import org.eclipse.ui.IWorkbenchPreferencePage;
26  
27  
28  /***
29   * This class represents a preference page that is contributed to the Preferences dialog. By subclassing <code>
30   * FieldEditorPreferencePage</code>,
31   * we can use the field support built into JFace that allows us to create a page that is small and knows how to save,
32   * restore and apply itself.
33   * <p>
34   * This page is used to modify preferences only. They are stored in the preference store that belongs to the main
35   * plug-in class. That way, preferences can be accessed directly via the preference store.
36   * @author fgiust
37   * @version $Revision: 1.8 $ ($Author: fgiust $)
38   */
39  
40  public class CCPreferencePage extends TabbedFieldEditorPreferencePage implements IWorkbenchPreferencePage
41  {
42  
43      /***
44       * init preference page.
45       */
46      public CCPreferencePage()
47      {
48          super(GRID);
49          setPreferenceStore(CCPlugin.getDefault().getPreferenceStore());
50      }
51  
52      /***
53       * Creates the field editors. Field editors are abstractions of the common GUI blocks needed to manipulate various
54       * types of preferences. Each field editor knows how to save and restore itself.
55       */
56      public void createFieldEditors()
57      {
58  
59          addTab(CCMessages.getString("preference.tab.tostring")); //$NON-NLS-1$
60  
61          addField(new RadioGroupFieldEditor(
62              CCPlugin.P_TOSTRING_BEAN,
63              CCMessages.getString("preference.tostringtype"), 1, new String[][]{ //$NON-NLS-1$
64              {CCMessages.getString("preference.tostringtype.bean"), CCPlugin.TOSTRINGSTYLE_BEAN}, //$NON-NLS-1$
65                  {CCMessages.getString("preference.tostringtype.fieds"), //$NON-NLS-1$
66                      CCPlugin.TOSTRINGSTYLE_FIELDS}},
67              getFieldEditorParent(),
68              true));
69  
70          addField(new SpacerFieldEditor(getFieldEditorParent()));
71  
72          ClassConstantFieldEditor selectEditor = new ClassConstantFieldEditor(CCPlugin.P_TOSTRING_STYLE, CCMessages
73              .getString("preference.customtostringtype"), //$NON-NLS-1$
74              getFieldEditorParent());
75  
76          String[] styles = new String[]{"org.apache.commons.lang.builder.ToStringStyle.DEFAULT_STYLE", //$NON-NLS-1$
77              "org.apache.commons.lang.builder.ToStringStyle.MULTI_LINE_STYLE", //$NON-NLS-1$
78              "org.apache.commons.lang.builder.ToStringStyle.NO_FIELD_NAMES_STYLE", //$NON-NLS-1$
79              "org.apache.commons.lang.builder.ToStringStyle.SIMPLE_STYLE"}; //$NON-NLS-1$
80  
81          selectEditor.setPredefinedValues(styles);
82  
83          selectEditor.setErrorMessage(CCMessages.getString("preference.customtostring.error")); //$NON-NLS-1$
84  
85          addField(selectEditor);
86  
87          addField(new SpacerFieldEditor(getFieldEditorParent()));
88  
89          addTab(CCMessages.getString("preference.tab.general")); //$NON-NLS-1$
90  
91          addField(new BooleanFieldEditor(CCPlugin.P_TOSTRING_SUPER, CCMessages
92              .getString("preference.appendsuper.tostring"), getFieldEditorParent())); //$NON-NLS-1$
93          addField(new BooleanFieldEditor(CCPlugin.P_HASHCODE_SUPER, CCMessages
94              .getString("preference.appendsuper.hashcode"), getFieldEditorParent())); //$NON-NLS-1$
95          addField(new BooleanFieldEditor(
96              CCPlugin.P_EQUALS_SUPER,
97              CCMessages.getString("preference.appendsuper.equals"), getFieldEditorParent())); //$NON-NLS-1$
98          addField(new BooleanFieldEditor(CCPlugin.P_COMPARETO_SUPER, CCMessages
99              .getString("preference.appendsuper.compareto"), //$NON-NLS-1$
100             getFieldEditorParent()));
101 
102         addField(new SpacerFieldEditor(getFieldEditorParent()));
103 
104         addField(new BooleanFieldEditor(CCPlugin.P_FINALPARAMETERS, //
105             CCMessages.getString("preference.finalparameters"), //$NON-NLS-1$
106             getFieldEditorParent()));
107 
108         addField(new BooleanFieldEditor(CCPlugin.P_EQUALS_INSTANCECHECK, CCMessages
109             .getString("preference.equals.equalitycheck"), //$NON-NLS-1$
110             getFieldEditorParent()));
111 
112         addField(new SpacerFieldEditor(getFieldEditorParent()));
113 
114         addField(new BooleanFieldEditor(CCPlugin.P_DONTASKONOVERWRITE, CCMessages
115             .getString("preference.overwriteconfirmation"), //$NON-NLS-1$
116             getFieldEditorParent()));
117 
118         addField(new SpacerFieldEditor(getFieldEditorParent()));
119 
120         addTab(CCMessages.getString("preference.tab.exclude")); //$NON-NLS-1$
121 
122         AddRemoveListFieldEditor excludedEditor = new AddRemoveListFieldEditor(CCPlugin.P_EXCLUDE, CCMessages
123             .getString("preference.excluded"), //$NON-NLS-1$
124             getFieldEditorParent());
125 
126         addField(excludedEditor);
127 
128     }
129 
130     /***
131      * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
132      */
133     public void init(IWorkbench workbench)
134     {
135     }
136 }