KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > ide > dialogs > EncodingFieldEditor


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 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.ui.ide.dialogs;
12
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Group;
15 import org.eclipse.ui.ide.IDEEncoding;
16
17 /**
18  * The EncodingFieldEditor is a field editor that allows the
19  * user to set an encoding on a preference in a preference
20  * store.
21  * <p>
22  * This class may be instantiated; it is not intended to be subclassed.
23  * </p>
24  *
25  * @since 3.1
26  */

27 public final class EncodingFieldEditor extends AbstractEncodingFieldEditor {
28
29     
30     /**
31      * Creates a new encoding field editor with the given preference name, label
32      * and parent.
33      *
34      * @param name
35      * the name of the preference this field editor works on
36      * @param labelText
37      * the label text of the field editor
38      * @param groupTitle
39      * the title for the field editor's control. If groupTitle is
40      * <code>null</code> the control will be unlabelled
41      * (by default a {@link Composite} instead of a {@link Group}.
42      * @param parent
43      * the parent of the field editor's control
44      * @see AbstractEncodingFieldEditor#setGroupTitle(String)
45      * @since 3.3
46      */

47     public EncodingFieldEditor(String JavaDoc name, String JavaDoc labelText,
48             String JavaDoc groupTitle, Composite parent) {
49         super(name, labelText, groupTitle, parent);
50     }
51     /**
52      * Create a new instance of the receiver on the preference called name
53      * with a label of labelText.
54      * @param name
55      * @param labelText
56      * @param parent
57      */

58     public EncodingFieldEditor(String JavaDoc name, String JavaDoc labelText, Composite parent) {
59         super(name, labelText, parent);
60     }
61     /* (non-Javadoc)
62      * @see org.eclipse.ui.internal.ide.dialogs.AbstractEncodingFieldEditor#getStoredValue()
63      */

64     protected String JavaDoc getStoredValue() {
65         return getPreferenceStore().getString(getPreferenceName());
66     }
67     
68     /* (non-Javadoc)
69      * @see org.eclipse.jface.preference.FieldEditor#doStore()
70      */

71     protected void doStore() {
72         String JavaDoc encoding = getSelectedEncoding();
73         
74         if(hasSameEncoding(encoding)) {
75             return;
76         }
77         
78         IDEEncoding.addIDEEncoding(encoding);
79         
80         if (encoding.equals(getDefaultEnc())) {
81             getPreferenceStore().setToDefault(getPreferenceName());
82         } else {
83             getPreferenceStore().setValue(getPreferenceName(), encoding);
84         }
85     }
86
87 }
88
Popular Tags