gvsig-geoprocess / org.gvsig.geoprocess / branches / refactor-2018 / org.gvsig.geoprocess / org.gvsig.geoprocess.lib / org.gvsig.geoprocess.lib.sextante / src / main / java / org / gvsig / geoprocess / lib / sextante / SimpleTaskStatusDelegated.java @ 1057
History | View | Annotate | Download (5.67 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.geoprocess.lib.sextante; |
25 |
|
26 |
import java.util.Date; |
27 |
|
28 |
import es.unex.sextante.core.ITaskMonitor; |
29 |
|
30 |
import org.gvsig.tools.ToolsLocator; |
31 |
import org.gvsig.tools.observer.Observer; |
32 |
import org.gvsig.tools.task.SimpleTaskStatus; |
33 |
import org.gvsig.tools.task.TaskStatusManager; |
34 |
|
35 |
/**
|
36 |
* {@link SimpleTaskStatus} implementation which delegates in a
|
37 |
* {@link ITaskMonitor} and a default {@link SimpleTaskStatus}.
|
38 |
*
|
39 |
* @author gvSIG Team
|
40 |
* @version $Id$
|
41 |
*/
|
42 |
public class SimpleTaskStatusDelegated implements SimpleTaskStatus { |
43 |
|
44 |
private final ITaskMonitor monitor; |
45 |
private final SimpleTaskStatus status; |
46 |
private long min; |
47 |
private long max; |
48 |
|
49 |
/**
|
50 |
* Creates a new {@link SimpleTaskStatusDelegated} with a
|
51 |
* {@link ITaskMonitor} and the name of the task to perform.
|
52 |
*
|
53 |
* @param monitor
|
54 |
* to delegate to
|
55 |
* @param taskName
|
56 |
* name of the task to perform
|
57 |
*/
|
58 |
public SimpleTaskStatusDelegated(ITaskMonitor monitor, String taskName) { |
59 |
this.monitor = monitor;
|
60 |
if (this.monitor != null) { |
61 |
this.monitor.setDeterminate(false); |
62 |
} |
63 |
this.status =
|
64 |
ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus( |
65 |
taskName); |
66 |
this.status.setAutoremove(true); |
67 |
} |
68 |
|
69 |
@Override
|
70 |
public void addObserver(Observer o) { |
71 |
status.addObserver(o); |
72 |
} |
73 |
|
74 |
@Override
|
75 |
public void deleteObserver(Observer o) { |
76 |
status.deleteObserver(o); |
77 |
} |
78 |
|
79 |
@Override
|
80 |
public void deleteObservers() { |
81 |
status.deleteObservers(); |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public void setTittle(String tittle) { |
86 |
status.setTitle(tittle); |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public void setTitle(String title) { |
91 |
status.setTitle(title); |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public void message(String message) { |
96 |
status.message(message); |
97 |
if (this.monitor != null) { |
98 |
monitor.setProgressText(message); |
99 |
} |
100 |
} |
101 |
|
102 |
@Override
|
103 |
public void setRangeOfValues(long min, long max) { |
104 |
this.min = min;
|
105 |
this.max = max;
|
106 |
status.setRangeOfValues(min, max); |
107 |
if (this.monitor != null) { |
108 |
monitor.setDeterminate(true);
|
109 |
} |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public void setCurValue(long value) { |
114 |
status.setCurValue(value); |
115 |
if (this.monitor != null) { |
116 |
monitor.setProgress((int) (value - min), (int) (max - min)); |
117 |
} |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public boolean isCancellationRequested() { |
122 |
return status.isCancellationRequested();
|
123 |
} |
124 |
|
125 |
@Override
|
126 |
public void cancelRequest() { |
127 |
status.cancelRequest(); |
128 |
} |
129 |
|
130 |
@Override
|
131 |
public void terminate() { |
132 |
status.terminate(); |
133 |
if (this.monitor != null) { |
134 |
monitor.close(); |
135 |
} |
136 |
} |
137 |
|
138 |
@Override
|
139 |
public String getTitle() { |
140 |
return status.getTitle();
|
141 |
} |
142 |
|
143 |
@Override
|
144 |
public void cancel() { |
145 |
status.cancel(); |
146 |
} |
147 |
|
148 |
@Override
|
149 |
public String getCode() { |
150 |
return status.getCode();
|
151 |
} |
152 |
|
153 |
@Override
|
154 |
public void abort() { |
155 |
status.abort(); |
156 |
if (this.monitor != null) { |
157 |
monitor.close(); |
158 |
} |
159 |
} |
160 |
|
161 |
@Override
|
162 |
public int getCompleted() { |
163 |
return status.getCompleted();
|
164 |
} |
165 |
|
166 |
@Override
|
167 |
public void remove() { |
168 |
status.remove(); |
169 |
} |
170 |
|
171 |
@Override
|
172 |
public void add() { |
173 |
status.add(); |
174 |
} |
175 |
|
176 |
@Override
|
177 |
public String getLabel() { |
178 |
return status.getLabel();
|
179 |
} |
180 |
|
181 |
@Override
|
182 |
public void setCancellable(boolean cancellable) { |
183 |
status.setCancellable(cancellable); |
184 |
} |
185 |
|
186 |
@Override
|
187 |
public boolean isCancelled() { |
188 |
return status.isCancelled()
|
189 |
|| (monitor != null && monitor.isCanceled());
|
190 |
} |
191 |
|
192 |
@Override
|
193 |
public void setAutoremove(boolean autoremove) { |
194 |
status.setAutoremove(autoremove); |
195 |
} |
196 |
|
197 |
@Override
|
198 |
public boolean isAborted() { |
199 |
return status.isAborted();
|
200 |
} |
201 |
|
202 |
@Override
|
203 |
public boolean isRunning() { |
204 |
return status.isRunning();
|
205 |
} |
206 |
|
207 |
@Override
|
208 |
public boolean getAutoRemove() { |
209 |
return status.getAutoRemove();
|
210 |
} |
211 |
|
212 |
@Override
|
213 |
public Date getLastModification() { |
214 |
return status.getLastModification();
|
215 |
} |
216 |
|
217 |
@Override
|
218 |
public TaskStatusManager getManager() {
|
219 |
return status.getManager();
|
220 |
} |
221 |
|
222 |
@Override
|
223 |
public boolean isIndeterminate() { |
224 |
return status.isIndeterminate();
|
225 |
} |
226 |
|
227 |
@Override
|
228 |
public boolean isCancellable() { |
229 |
return status.isCancellable();
|
230 |
} |
231 |
|
232 |
@Override
|
233 |
public void pop() { |
234 |
status.pop(); |
235 |
} |
236 |
|
237 |
@Override
|
238 |
public void push() { |
239 |
status.push(); |
240 |
} |
241 |
|
242 |
@Override
|
243 |
public void setIndeterminate() { |
244 |
status.setIndeterminate(); |
245 |
} |
246 |
|
247 |
@Override
|
248 |
public void restart() { |
249 |
status.restart(); |
250 |
} |
251 |
|
252 |
} |