Revision 447 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/task/impl/BaseTaskStatus.java

View differences:

BaseTaskStatus.java
24 24
import java.util.Date;
25 25

  
26 26
import org.gvsig.tools.ToolsLocator;
27
import org.gvsig.tools.task.TaskStatus;
27
import org.gvsig.tools.observer.ObservableHelper;
28
import org.gvsig.tools.observer.Observer;
29
import org.gvsig.tools.task.SimpleTaskStatus;
28 30
import org.gvsig.tools.task.TaskStatusManager;
29 31

  
30 32

  
......
33 35
 * @version $Id$
34 36
 *
35 37
 */
36
public class BaseTaskStatus implements TaskStatus {
38
public class BaseTaskStatus implements SimpleTaskStatus {
37 39
    private Date lastModification = null;
38 40

  
39 41
    protected long minValue = 0;
......
50 52
    protected boolean isRunning = true;
51 53
    
52 54
    protected TaskStatusManager manager = null;
55

  
56
	private boolean isCancellable;
57

  
58
	private boolean isCancellationRequested;
59

  
60
	private ObservableHelper observers = null;
53 61
    
54 62
    public BaseTaskStatus(String tittle) {
55 63
    	this.manager =  ToolsLocator.getTaskStatusManager();
......
60 68
        this.isAbortedByError = false;
61 69
        this.isRunning = true;
62 70
        this.message = null;
71
        this.isCancellable = false;
72
        this.isCancellationRequested = false;
73
        this.code = this.manager.getNewCode();
74
        this.observers = new ObservableHelper();
63 75
        this.touch();
64
        this.code = this.manager.getNewCode();
65 76
    }
66 77
    
67 78
    public BaseTaskStatus(String tittle, long minValue, long maxValue) {
......
70 81
        this.maxValue = maxValue;
71 82
    }
72 83
    
84
    public void setRangeOfValues(long min, long max) {
85
        this.minValue = min;
86
        this.maxValue = max;
87
    }
88
    
73 89
    protected void touch() {
74 90
    	Date now = new Date(); 
75
    	if( (now.getTime() - this.lastModification.getTime()) > 2000 ) {
91
    	if( this.lastModification!=null && (now.getTime() - this.lastModification.getTime()) > 2000 ) {
76 92
    		this.message = null;
77 93
    	}
78 94
        this.lastModification = now;
79 95
        this.manager.update(this);
96
        this.observers.notifyObservers(this, null);
80 97
    }
81 98
    
82 99
    public Date getLastModification() {
......
121 138
    	String progress;
122 139
    	
123 140
        if( !this.isRunning ) {
124
            return this.tittle;
141
            return "" ;
125 142
        }
126 143
        if( this.maxValue == this.minValue ) {
127 144
        	// No se puede calcular ya que no se ha indicado el numero de elementos
......
131 148
            progress = " (" + (this.curValue-this.minValue) + " / " + (this.maxValue-this.minValue) + ")" ;
132 149
        }
133 150
    	if( this.message == null ) {
134
            return this.tittle + progress;
151
            return progress;
135 152
    	} else {
136 153
            return this.message + progress;
137 154
    	}
......
165 182
    public boolean isRunning() {
166 183
        return this.isRunning;
167 184
    }
185

  
186
	public TaskStatusManager getManager() {
187
		return this.manager;
188
	}
189

  
190
	public boolean isIndeterminate() {
191
		return this.minValue == this.maxValue;
192
	}
193

  
194
	public void remove() {
195
		this.manager.remove(this);
196
	}
197

  
198
	public boolean isCancellable() {
199
		return this.isCancellable;
200
	}
201

  
202
	public void setCancellable(boolean cancellable) {
203
		this.isCancellable = cancellable;
204
	}
205

  
206
	public boolean isCancellationRequested() {
207
		return this.isCancellationRequested;
208
	}
209

  
210
	public void cancelRequest() {
211
		this.isCancellationRequested = true;
212
	}
213

  
214
	public void addObserver(Observer o) {
215
		this.observers.addObserver(o);
216
	}
217

  
218
	public void deleteObserver(Observer o) {
219
		this.observers.deleteObserver(o);
220
	}
221

  
222
	public void deleteObservers() {
223
		this.observers.deleteObservers();
224
	}
225

  
168 226
}

Also available in: Unified diff