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.project.ui.internal;
018:
019: import java.util.Collection;
020: import java.util.HashMap;
021: import java.util.List;
022:
023: import net.refractions.udig.project.internal.Layer;
024: import net.refractions.udig.project.internal.render.impl.Styling;
025:
026: import org.eclipse.jface.viewers.ISelectionChangedListener;
027: import org.eclipse.jface.viewers.IStructuredContentProvider;
028: import org.eclipse.jface.viewers.IStructuredSelection;
029: import org.eclipse.jface.viewers.LabelProvider;
030: import org.eclipse.jface.viewers.ListViewer;
031: import org.eclipse.jface.viewers.SelectionChangedEvent;
032: import org.eclipse.jface.viewers.StructuredSelection;
033: import org.eclipse.jface.viewers.Viewer;
034: import org.eclipse.jface.wizard.WizardPage;
035: import org.eclipse.swt.SWT;
036: import org.eclipse.swt.layout.GridData;
037: import org.eclipse.swt.layout.GridLayout;
038: import org.eclipse.swt.widgets.Composite;
039:
040: /**
041: * A wizard page for choosing the layer's styles
042: *
043: * @author jeichar
044: * @since 0.3
045: */
046: public class MapStylePage extends WizardPage {
047:
048: List layers;
049: Layer currentLayer;
050: HashMap map = new HashMap();
051:
052: /**
053: * Construct <code>MapNewPage</code>.
054: *
055: * @param layers The selected layers
056: */
057: protected MapStylePage(List layers) {
058: super (Messages.MapStylePage_editStyles,
059: Messages.MapStylePage_editStyles, Images
060: .getDescriptor(ImageConstants.NEWMAP_WIZBAN));
061: setDescription(Messages.MapStylePage_editStyles_description);
062: this .layers = layers;
063: }
064:
065: /**
066: * TODO summary sentence for createControl ...
067: *
068: * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
069: * @param parent
070: */
071: public void createControl(Composite parent) {
072: Composite composite = new Composite(parent, SWT.NONE);
073: composite.setLayout(new GridLayout(2, false));
074:
075: final ListViewer layersView = new ListViewer(composite,
076: SWT.BORDER);
077: layersView.setContentProvider(new IStructuredContentProvider() {
078:
079: public Object[] getElements(Object inputElement) {
080: if (inputElement instanceof List) {
081: return ((List) inputElement).toArray();
082: }
083: return null;
084: }
085:
086: public void dispose() {
087: // do nothing
088: }
089:
090: public void inputChanged(Viewer viewer, Object oldInput,
091: Object newInput) {
092: // do nothing
093: }
094: });
095:
096: layersView.setLabelProvider(new LabelProvider() {
097: /**
098: * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
099: */
100: public String getText(Object element) {
101: if (element instanceof Layer) {
102: return ((Layer) element).getName();
103: }
104: return null;
105: }
106: });
107: layersView.setInput(layers);
108: layersView.getControl().setLayoutData(
109: new GridData(SWT.FILL, SWT.FILL, true, true));
110:
111: final ListViewer styleView = new ListViewer(composite,
112: SWT.BORDER);
113: styleView.setContentProvider(new IStructuredContentProvider() {
114:
115: public Object[] getElements(Object inputElement) {
116: if (inputElement instanceof Collection) {
117: return ((Collection) inputElement).toArray();
118: }
119: return null;
120: }
121:
122: public void dispose() {
123: // do nothing
124: }
125:
126: public void inputChanged(Viewer viewer, Object oldInput,
127: Object newInput) {
128: viewer.refresh();
129: }
130: });
131: styleView.setLabelProvider(new LabelProvider() {
132: /**
133: * TODO summary sentence for getText ...
134: *
135: * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
136: * @param element
137: */
138: public String getText(Object element) {
139: if (element instanceof String) {
140: return (String) element;
141: }
142: return null;
143: }
144: });
145: styleView
146: .addSelectionChangedListener(new ISelectionChangedListener() {
147:
148: public void selectionChanged(
149: SelectionChangedEvent event) {
150: if (event.getSelection() instanceof IStructuredSelection) {
151: //IStructuredSelection sel = (IStructuredSelection) event.getSelection();
152: /*
153: * FIXME: Style is no longer used? for( Iterator iter = sel.iterator();
154: * iter.hasNext(); ) { String styleName = (String) iter.next(); if(
155: * styleName.equals("default")) return; StyleImpl style=(StyleImpl)
156: * RenderFactory.eINSTANCE.createStyle(); style.setStyle(
157: * Styling.getStyle(((Integer)Styling.STYLES.get(styleName)).intValue(),
158: * currentLayer.getMetadata().getTypeName()) ); // currentLayer.setStyle(style);
159: * map.put(currentLayer, styleName); }
160: */
161: }
162: }
163:
164: });
165: styleView.getControl().setLayoutData(
166: new GridData(SWT.FILL, SWT.FILL, true, true));
167:
168: layersView
169: .addSelectionChangedListener(new ISelectionChangedListener() {
170:
171: public void selectionChanged(
172: SelectionChangedEvent event) {
173: if (event.getSelection() instanceof IStructuredSelection) {
174: IStructuredSelection selection = (IStructuredSelection) event
175: .getSelection();
176: Object o = selection.getFirstElement();
177: if (selection.size() > 1)
178: layersView.setSelection(
179: new StructuredSelection(o),
180: true);
181: currentLayer = (Layer) o;
182: styleView.setInput(Styling
183: .getStyleNames(currentLayer));
184: Object s = map.get(currentLayer);
185: if (s != null)
186: styleView
187: .setSelection(new StructuredSelection(
188: map.get(currentLayer)));
189: }
190: }
191:
192: });
193: setControl(composite);
194: setPageComplete(true);
195: }
196:
197: /**
198: * @see org.eclipse.jface.wizard.WizardPage#canFlipToNextPage()
199: */
200: public boolean canFlipToNextPage() {
201: return false;
202: }
203:
204: }
|