001: /* uDig - User Friendly Desktop Internet GIS client
002: * http://udig.refractions.net
003: * (C) 2004, Refractions Research Inc.
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation;
008: * version 2.1 of the License.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: */
015: package net.refractions.udig.project.ui;
016:
017: import java.util.ArrayList;
018:
019: import net.refractions.udig.project.internal.ProjectPlugin;
020: import net.refractions.udig.project.preferences.PreferenceConstants;
021: import net.refractions.udig.project.ui.internal.FeatureEditorLoader;
022: import net.refractions.udig.project.ui.internal.Messages;
023: import net.refractions.udig.project.ui.internal.ProjectUIPlugin;
024:
025: import org.eclipse.jface.preference.FieldEditor;
026: import org.eclipse.swt.SWT;
027: import org.eclipse.swt.layout.GridData;
028: import org.eclipse.swt.widgets.Combo;
029: import org.eclipse.swt.widgets.Composite;
030: import org.eclipse.swt.widgets.Label;
031:
032: /**
033: * Editor for modifying the default Feature Editor
034: *
035: * @author Jesse
036: * @since 1.1.0
037: */
038: public class FeatureEditorFieldEditor extends FieldEditor {
039: private Combo combo;
040: private GridData data;
041: private ArrayList<String> choices = new ArrayList<String>();
042: private ArrayList<String> ids = new ArrayList<String>();
043:
044: public FeatureEditorFieldEditor(Composite parent) {
045: setPreferenceStore(ProjectPlugin.getPlugin()
046: .getPreferenceStore());
047: FeatureEditorLoader[] loaders = ProjectUIPlugin.getDefault()
048: .getFeatureEditProcessor().getEditorLoaders();
049: for (FeatureEditorLoader loader : loaders) {
050: choices.add(loader.getName());
051: ids.add(loader.getId());
052: }
053: createControl(parent);
054: }
055:
056: @Override
057: protected void adjustForNumColumns(int numColumns) {
058: if (data != null)
059: data.horizontalSpan = numColumns - 1;
060: }
061:
062: @Override
063: protected void doFillIntoGrid(Composite parent, int numColumns) {
064: Label label = new Label(parent, SWT.NONE);
065: label.setText(Messages.FeatureEditorFieldEditor_label);
066: label
067: .setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
068: true));
069: combo = new Combo(parent, SWT.DEFAULT);
070: data = new GridData(SWT.FILL, SWT.TOP, true, true);
071: data.horizontalSpan = numColumns - 1;
072: combo.setLayoutData(data);
073: combo.setItems(choices.toArray(new String[0]));
074: }
075:
076: @Override
077: protected void doLoad() {
078: if (combo != null) {
079: int indexOf = ids.indexOf(getPreferenceStore().getString(
080: PreferenceConstants.P_DEFAULT_FEATURE_EDITOR));
081: if (indexOf == -1) {
082: doLoadDefault();
083: } else {
084: combo.select(indexOf);
085: }
086: }
087: }
088:
089: @Override
090: protected void doLoadDefault() {
091: int indexOf = ids.indexOf(getPreferenceStore()
092: .getDefaultString(
093: PreferenceConstants.P_DEFAULT_FEATURE_EDITOR));
094: if (indexOf == -1) {
095: combo.select(0);
096: } else {
097: combo.select(indexOf);
098: }
099: }
100:
101: @Override
102: protected void doStore() {
103: getPreferenceStore().setValue(
104: PreferenceConstants.P_DEFAULT_FEATURE_EDITOR,
105: this .ids.get(combo.getSelectionIndex()));
106: }
107:
108: @Override
109: public int getNumberOfControls() {
110: return 2;
111: }
112:
113: }
|