01: /*
02: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
03: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
04: * under the terms of the GNU Lesser General Public License as published by the Free Software
05: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
06: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
07: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
08: */
09: package net.refractions.udig.project.internal.command.navigation;
10:
11: import java.util.Iterator;
12: import java.util.List;
13:
14: import net.refractions.udig.project.command.MapCommand;
15: import net.refractions.udig.project.command.NavCommand;
16: import net.refractions.udig.project.command.PostDeterminedEffectCommand;
17: import net.refractions.udig.project.command.UndoableComposite;
18: import net.refractions.udig.project.internal.render.ViewportModel;
19: import net.refractions.udig.project.internal.render.impl.ViewportModelImpl;
20:
21: import org.eclipse.core.runtime.IProgressMonitor;
22: import org.eclipse.core.runtime.SubProgressMonitor;
23:
24: /**
25: * TODO Purpose of net.refractions.udig.project.internal.command.navigation
26: * <p>
27: * </p>
28: *
29: * @author Jesse
30: * @since 1.0.0
31: */
32: public class NavComposite extends UndoableComposite implements
33: NavCommand {
34:
35: ViewportModel model;
36:
37: /**
38: * Creates a new instance of NavComposite
39: *
40: * @param navCommands an ordered list of Nav commands
41: */
42: public NavComposite(List navCommands) {
43: super (navCommands);
44: }
45:
46: /**
47: * @see net.refractions.udig.project.internal.command.navigation.NavCommand#setViewportModel(net.refractions.udig.project.ViewportModelControl)
48: */
49: public void setViewportModel(ViewportModel model) {
50: this .model = model;
51: for (Iterator iter = commands.iterator(); iter.hasNext();) {
52: NavCommand command = (NavCommand) iter.next();
53: command.setViewportModel(model);
54: }
55: }
56:
57: public void run(IProgressMonitor monitor) throws Exception {
58: execute(monitor);
59: }
60:
61: public boolean execute(IProgressMonitor monitor) throws Exception {
62: monitor.beginTask(getName(), 12 * commands.size());
63: monitor.worked(2);
64:
65: ViewportModelImpl hack = (ViewportModelImpl) model;
66: hack.setFiringEvents(false);
67:
68: boolean changedState = false;
69: for (Iterator<? extends MapCommand> iter = commands.iterator(); iter
70: .hasNext();) {
71: NavCommand command = (NavCommand) iter.next();
72:
73: if (!iter.hasNext())
74: hack.setFiringEvents(true);
75: command.setMap(getMap());
76: SubProgressMonitor subProgressMonitor = new SubProgressMonitor(
77: monitor, 10);
78: if (command instanceof PostDeterminedEffectCommand) {
79: boolean change = ((PostDeterminedEffectCommand) command)
80: .execute(subProgressMonitor);
81: changedState = changedState || change;
82: } else {
83: command.run(subProgressMonitor);
84: changedState = true;
85: }
86: subProgressMonitor.done();
87: }
88: monitor.done();
89:
90: return changedState;
91: }
92:
93: }
|