01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.tools.edit.behaviour;
16:
17: import java.util.HashSet;
18: import java.util.List;
19: import java.util.Set;
20:
21: import net.refractions.udig.project.IBlackboard;
22: import net.refractions.udig.project.ILayer;
23: import net.refractions.udig.project.ProjectBlackboardConstants;
24: import net.refractions.udig.project.command.UndoableMapCommand;
25: import net.refractions.udig.project.internal.ProjectPlugin;
26: import net.refractions.udig.tools.edit.Behaviour;
27: import net.refractions.udig.tools.edit.EditToolHandler;
28: import net.refractions.udig.tools.edit.support.EditGeom;
29: import net.refractions.udig.tools.edit.support.EditUtils;
30:
31: import com.vividsolutions.jts.geom.Envelope;
32:
33: /**
34: * searches the current map and makes sure that
35: * @author Jesse
36: * @since 1.1.0
37: */
38: public class RefreshLayersBehaviour implements Behaviour {
39:
40: public UndoableMapCommand getCommand(EditToolHandler handler) {
41: List<ILayer> layer = handler.getContext().getMapLayers();
42: for (ILayer layer2 : layer) {
43: IBlackboard properties = layer2.getBlackboard();
44: if (properties
45: .get(ProjectBlackboardConstants.MAP__RENDERING_FILTER) != null) {
46: Envelope env = new Envelope();
47: Set<String> fids = new HashSet<String>();
48: for (EditGeom geom : handler.getEditBlackboard(layer2)
49: .getGeoms()) {
50: if (env.isNull()) {
51: env.init(geom.getShell().getEnvelope());
52: } else {
53: env.expandToInclude(geom.getShell()
54: .getEnvelope());
55: }
56: fids.add(geom.getFeatureIDRef().get());
57: }
58: EditUtils.instance.refreshLayer(layer2, fids, env,
59: true, false);
60:
61: }
62: }
63: return null;
64: }
65:
66: public void handleError(EditToolHandler handler, Throwable error,
67: UndoableMapCommand command) {
68: ProjectPlugin.log("", error); //$NON-NLS-1$
69: }
70:
71: public boolean isValid(EditToolHandler handler) {
72: List<ILayer> layer = handler.getContext().getMapLayers();
73: for (ILayer layer2 : layer) {
74: if (layer2.getBlackboard().get(
75: ProjectBlackboardConstants.MAP__RENDERING_FILTER) != null)
76: return true;
77: }
78: return false;
79: }
80:
81: }
|