Statistics
| Revision:

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 @ 1055

History | View | Annotate | Download (5.59 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
    public boolean isCancelled() {
187
        return status.isCancelled()
188
            || (monitor != null && monitor.isCanceled());
189
    }
190

    
191
    @Override
192
    public void setAutoremove(boolean autoremove) {
193
        status.setAutoremove(autoremove);
194
    }
195

    
196
    @Override
197
    public boolean isAborted() {
198
        return status.isAborted();
199
    }
200

    
201
    @Override
202
    public boolean isRunning() {
203
        return status.isRunning();
204
    }
205

    
206
    @Override
207
    public boolean getAutoRemove() {
208
        return status.getAutoRemove();
209
    }
210

    
211
    @Override
212
    public Date getLastModification() {
213
        return status.getLastModification();
214
    }
215

    
216
    @Override
217
    public TaskStatusManager getManager() {
218
        return status.getManager();
219
    }
220

    
221
    @Override
222
    public boolean isIndeterminate() {
223
        return status.isIndeterminate();
224
    }
225

    
226
    @Override
227
    public boolean isCancellable() {
228
        return status.isCancellable();
229
    }
230

    
231
    @Override
232
        public void pop() {
233
                status.pop();
234
        }
235

    
236
    @Override
237
        public void push() {
238
                status.push();
239
        }
240

    
241
    @Override
242
        public void setIndeterminate() {
243
                status.setIndeterminate();
244
        }
245

    
246
}