01: /*******************************************************************************
02: * Copyright (c) 2004, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.ide.dialogs;
11:
12: import org.eclipse.swt.widgets.Composite;
13: import org.eclipse.swt.widgets.Group;
14: import org.eclipse.ui.ide.IDEEncoding;
15:
16: /**
17: * The EncodingFieldEditor is a field editor that allows the
18: * user to set an encoding on a preference in a preference
19: * store.
20: * <p>
21: * This class may be instantiated; it is not intended to be subclassed.
22: * </p>
23: *
24: * @since 3.1
25: */
26: public final class EncodingFieldEditor extends
27: AbstractEncodingFieldEditor {
28:
29: /**
30: * Creates a new encoding field editor with the given preference name, label
31: * and parent.
32: *
33: * @param name
34: * the name of the preference this field editor works on
35: * @param labelText
36: * the label text of the field editor
37: * @param groupTitle
38: * the title for the field editor's control. If groupTitle is
39: * <code>null</code> the control will be unlabelled
40: * (by default a {@link Composite} instead of a {@link Group}.
41: * @param parent
42: * the parent of the field editor's control
43: * @see AbstractEncodingFieldEditor#setGroupTitle(String)
44: * @since 3.3
45: */
46: public EncodingFieldEditor(String name, String labelText,
47: String groupTitle, Composite parent) {
48: super (name, labelText, groupTitle, parent);
49: }
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 name, String labelText,
59: Composite parent) {
60: super (name, labelText, parent);
61: }
62:
63: /* (non-Javadoc)
64: * @see org.eclipse.ui.internal.ide.dialogs.AbstractEncodingFieldEditor#getStoredValue()
65: */
66: protected String getStoredValue() {
67: return getPreferenceStore().getString(getPreferenceName());
68: }
69:
70: /* (non-Javadoc)
71: * @see org.eclipse.jface.preference.FieldEditor#doStore()
72: */
73: protected void doStore() {
74: String encoding = getSelectedEncoding();
75:
76: if (hasSameEncoding(encoding)) {
77: return;
78: }
79:
80: IDEEncoding.addIDEEncoding(encoding);
81:
82: if (encoding.equals(getDefaultEnc())) {
83: getPreferenceStore().setToDefault(getPreferenceName());
84: } else {
85: getPreferenceStore()
86: .setValue(getPreferenceName(), encoding);
87: }
88: }
89:
90: }
|