001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.printing.ui.internal;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.Map;
022:
023: import net.refractions.udig.printing.ui.TemplateFactory;
024:
025: import org.eclipse.jface.preference.PreferencePage;
026: import org.eclipse.swt.SWT;
027: import org.eclipse.swt.layout.GridData;
028: import org.eclipse.swt.layout.GridLayout;
029: import org.eclipse.swt.widgets.Composite;
030: import org.eclipse.swt.widgets.Control;
031: import org.eclipse.swt.widgets.Label;
032: import org.eclipse.swt.widgets.List;
033: import org.eclipse.ui.IWorkbench;
034: import org.eclipse.ui.IWorkbenchPreferencePage;
035:
036: /**
037: * Provides ...TODO summary sentence
038: * <p>
039: * TODO Description
040: * </p><p>
041: * Responsibilities:
042: * <ul>
043: * <li>
044: * <li>
045: * </ul>
046: * </p><p>
047: * Example Use:<pre><code>
048: * PrintingPreferences x = new PrintingPreferences( ... );
049: * TODO code example
050: * </code></pre>
051: * </p>
052: * @author Richard Gould
053: * @since 0.3
054: */
055: public class PrintingPreferences extends PreferencePage implements
056: IWorkbenchPreferencePage {
057:
058: private String defaultTemplate;
059: private List list;
060: private ArrayList templateIds;
061:
062: /**
063: * TODO summary sentence for createContents ...
064: *
065: * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
066: * @param parent
067: * @return
068: */
069: protected Control createContents(Composite parent) {
070: templateIds = new ArrayList();
071:
072: GridData gridData;
073: Composite composite = new Composite(parent, SWT.NULL);
074:
075: GridLayout gridLayout = new GridLayout();
076: int columns = 1;
077: gridLayout.numColumns = columns;
078: composite.setLayout(gridLayout);
079:
080: gridData = new GridData();
081:
082: Label urlLabel = new Label(composite, SWT.NONE);
083: urlLabel
084: .setText(Messages.PrintingPreferences_label_defaultTemplate);
085: urlLabel.setLayoutData(gridData);
086:
087: gridData = new GridData(GridData.FILL_HORIZONTAL);
088:
089: Map templates = PrintingPlugin.getDefault()
090: .getTemplateFactories();
091:
092: list = new List(composite, SWT.SINGLE | SWT.BORDER);
093: list.setLayoutData(gridData);
094:
095: Iterator iter = templates.entrySet().iterator();
096: for (int i = 0; iter.hasNext(); i++) {
097: Map.Entry entry = (Map.Entry) iter.next();
098:
099: TemplateFactory templateFactory = (TemplateFactory) entry
100: .getValue();
101:
102: templateIds.add(i, entry.getKey());
103:
104: if (defaultTemplate.equals(templateFactory.getName())) {
105: list.select(i);
106: }
107:
108: list.add(templateFactory.getName());
109: }
110:
111: return composite;
112: }
113:
114: /**
115: * TODO summary sentence for init ...
116: *
117: * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
118: * @param workbench
119: */
120: public void init(IWorkbench workbench) {
121: defaultTemplate = PrintingPlugin.getDefault()
122: .getPluginPreferences().getString(
123: PrintingPlugin.PREF_DEFAULT_TEMPLATE);
124: }
125:
126: protected void performDefaults() {
127: super .performDefaults();
128: }
129:
130: public boolean performOk() {
131: int selectionIndex = list.getSelectionIndex();
132: if (selectionIndex == -1
133: || selectionIndex > templateIds.size() - 1)
134: return super .performOk();
135: defaultTemplate = (String) templateIds.get(selectionIndex);
136: PrintingPlugin.getDefault().getPluginPreferences().setValue(
137: PrintingPlugin.PREF_DEFAULT_TEMPLATE, defaultTemplate);
138: PrintingPlugin.getDefault().savePluginPreferences();
139: return super.performOk();
140: }
141: }
|