001: package net.refractions.udig.render.wms.basic.preferences;
002:
003: import net.refractions.udig.render.wms.basic.WMSPlugin;
004: import net.refractions.udig.render.wms.basic.internal.Messages;
005:
006: import org.eclipse.jface.preference.BooleanFieldEditor;
007: import org.eclipse.jface.preference.FieldEditorPreferencePage;
008: import org.eclipse.jface.preference.ListEditor;
009: import org.eclipse.jface.util.PropertyChangeEvent;
010: import org.eclipse.swt.widgets.Composite;
011: import org.eclipse.ui.IWorkbench;
012: import org.eclipse.ui.IWorkbenchPreferencePage;
013:
014: /**
015: * This class represents a preference page that
016: * is contributed to the Preferences dialog. By
017: * subclassing <samp>FieldEditorPreferencePage</samp>, we
018: * can use the field support built into JFace that allows
019: * us to create a page that is small and knows how to
020: * save, restore and apply itself.
021: * <p>
022: * This page is used to modify preferences only. They
023: * are stored in the preference store that belongs to
024: * the main plug-in class. That way, preferences can
025: * be accessed directly via the preference store.
026: */
027:
028: public class BasicWMSRendererPreferencePage extends
029: FieldEditorPreferencePage implements IWorkbenchPreferencePage {
030:
031: private ImageTypeListEditor editor;
032: private BooleanFieldEditor checkbox;
033:
034: /**
035: *
036: */
037: public BasicWMSRendererPreferencePage() {
038: super (GRID);
039: setPreferenceStore(WMSPlugin.getDefault().getPreferenceStore());
040: setDescription(Messages.BasicWMSRendererPreferencePage_warning);
041: }
042:
043: /**
044: * Creates the field editors. Field editors are abstractions of
045: * the common GUI blocks needed to manipulate various types
046: * of preferences. Each field editor knows how to save and
047: * restore itself.
048: */
049: @Override
050: public void createFieldEditors() {
051: checkbox = new BooleanFieldEditor(
052: PreferenceConstants.P_USE_DEFAULT_ORDER,
053: Messages.BasicWMSRendererPreferencePage_useDefaults,
054: getFieldEditorParent());
055: // checkbox.setPropertyChangeListener(this);
056: addField(checkbox);
057: editor = new ImageTypeListEditor(
058: PreferenceConstants.P_IMAGE_TYPE_ORDER,
059: Messages.BasicWMSRendererPreferencePage_setOrder,
060: getFieldEditorParent());
061: editor.setEnabled(!getPreferenceStore().getBoolean(
062: PreferenceConstants.P_USE_DEFAULT_ORDER),
063: getFieldEditorParent());
064: addField(editor);
065: }
066:
067: /* (non-Javadoc)
068: * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
069: */
070: public void init(IWorkbench workbench) {
071: // nothing to do here
072: }
073:
074: @Override
075: public void propertyChange(PropertyChangeEvent event) {
076: super .propertyChange(event);
077: if (event.getSource().equals(checkbox)) {
078: boolean useDefault = ((Boolean) event.getNewValue())
079: .booleanValue();
080: editor.setEnabled(!useDefault, getFieldEditorParent());
081: }
082: }
083:
084: protected class ImageTypeListEditor extends ListEditor {
085: protected ImageTypeListEditor(String name, String labelText,
086: Composite parent) {
087: super (name, labelText, parent);
088: }
089:
090: @Override
091: protected String createList(String[] items) {
092: StringBuilder stringList = new StringBuilder();
093: for (String str : items) {
094: if (stringList.length() > 0) {
095: stringList.append(',');
096: }
097: stringList.append(str);
098:
099: }
100: return stringList.toString();
101: }
102:
103: @Override
104: protected String getNewInputObject() {
105: // String str = new String("image/");
106: // InputDialog dialog = new InputDialog(
107: // Display.getCurrent().getActiveShell(),
108: // "New Image Type",
109: // "Enter the image type",
110: // str,
111: // null
112: // );
113: // dialog.open();
114: // if(dialog.getReturnCode() == Window.OK){
115: // str = dialog.getValue();
116: // }
117: // return str;
118: return null;
119: }
120:
121: @Override
122: protected String[] parseString(String stringList) {
123: String[] items = stringList.split(","); //$NON-NLS-1$
124: return items;
125: }
126:
127: }
128:
129: }
|