001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032: package com.vividsolutions.jump.workbench.ui.plugin.wms;
033:
034: import java.util.ArrayList;
035: import java.util.Collection;
036: import java.util.Iterator;
037: import java.util.List;
038:
039: import com.vividsolutions.jump.I18N;
040: import com.vividsolutions.jump.workbench.model.LayerManager;
041: import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
042: import com.vividsolutions.jump.workbench.model.UndoableCommand;
043: import com.vividsolutions.jump.workbench.model.WMSLayer;
044: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
045: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
046: import com.vividsolutions.jump.workbench.ui.GUIUtil;
047: import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
048: import com.vividsolutions.jump.workbench.ui.wizard.WizardDialog;
049: import com.vividsolutions.jump.workbench.ui.wizard.WizardPanel;
050: import com.vividsolutions.wms.MapLayer;
051: import com.vividsolutions.wms.WMService;
052:
053: public class AddWMSQueryPlugIn extends AbstractPlugIn {
054:
055: private String[] cachedURLs;
056: private String lastWMSVersion = WMService.WMS_1_1_1;
057:
058: private static final String CACHED_URL = "AddWMSQueryPlugin.CACHED_URL";
059:
060: public AddWMSQueryPlugIn() {
061: cachedURLs = new String[] { "http://demo.deegree.org/deegree-wms/services" };
062: }
063:
064: private List<String> toLayerNames(List<MapLayer> mapLayers) {
065: ArrayList<String> names = new ArrayList<String>();
066: for (Iterator<MapLayer> i = mapLayers.iterator(); i.hasNext();) {
067: MapLayer layer = i.next();
068: names.add(layer.getName());
069: }
070:
071: return names;
072: }
073:
074: public boolean execute(final PlugInContext context)
075: throws Exception {
076: String s = (String) PersistentBlackboardPlugIn.get(
077: context.getWorkbenchContext()).get(CACHED_URL);
078: if (s != null)
079: cachedURLs = s.split(",");
080:
081: reportNothingToUndoYet(context);
082:
083: WizardDialog d = new WizardDialog(
084: context.getWorkbenchFrame(),
085: I18N
086: .get("ui.plugin.wms.AddWMSQueryPlugIn.connect-to-web-map-server"),
087: context.getErrorHandler());
088:
089: d.init(new WizardPanel[] {
090: new URLWizardPanel(cachedURLs, lastWMSVersion),
091: new MapLayerWizardPanel(), new SRSWizardPanel(),
092: new OneSRSWizardPanel() });
093:
094: //Set size after #init, because #init calls #pack. [Jon Aquino]
095: d.setSize(500, 400);
096: GUIUtil.centreOnWindow(d);
097: d.setVisible(true);
098: if (!d.wasFinishPressed()) {
099: return false;
100: }
101:
102: // title of the layer will be the title of the first WMS layer
103: String title = ((MapLayer) ((List) d
104: .getData(MapLayerWizardPanel.LAYERS_KEY)).get(0))
105: .getTitle();
106:
107: final WMSLayer layer = new WMSLayer(title, context
108: .getLayerManager(), (WMService) d
109: .getData(URLWizardPanel.SERVICE_KEY), (String) d
110: .getData(SRSWizardPanel.SRS_KEY), toLayerNames((List) d
111: .getData(MapLayerWizardPanel.LAYERS_KEY)), ((String) d
112: .getData(URLWizardPanel.FORMAT_KEY)));
113: execute(new UndoableCommand(getName()) {
114: public void execute() {
115: Collection selectedCategories = context
116: .getLayerNamePanel().getSelectedCategories();
117: LayerManager mgr = context.getLayerManager();
118: mgr
119: .addLayerable(
120: selectedCategories.isEmpty() ? StandardCategoryNames.WORKING
121: : selectedCategories.iterator()
122: .next().toString(),
123: layer);
124: }
125:
126: public void unexecute() {
127: context.getLayerManager().remove(layer);
128: }
129: }, context);
130: cachedURLs = (String[]) d.getData(URLWizardPanel.URL_KEY);
131: lastWMSVersion = (String) d.getData(URLWizardPanel.VERSION_KEY);
132:
133: StringBuilder urls = new StringBuilder();
134: for (int i = 0; i < cachedURLs.length; ++i)
135: if (i == cachedURLs.length - 1)
136: urls.append(cachedURLs[i]);
137: else
138: urls.append(cachedURLs[i]).append(",");
139:
140: PersistentBlackboardPlugIn.get(context.getWorkbenchContext())
141: .put(CACHED_URL, urls.toString());
142:
143: return true;
144: }
145: }
|