svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / swing / threads / PipeTask.java @ 40561
History | View | Annotate | Download (2.42 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 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 3
|
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 |
/*
|
25 |
* Created on 10-nov-2006 by azabala
|
26 |
*
|
27 |
*/
|
28 |
package org.gvsig.utils.swing.threads; |
29 |
|
30 |
|
31 |
/**
|
32 |
* @author alzabord
|
33 |
*
|
34 |
* TODO To change the template for this generated type comment go to
|
35 |
* Window - Preferences - Java - Code Style - Code Templates
|
36 |
*/
|
37 |
public class PipeTask implements IMonitorableTask { |
38 |
|
39 |
private IPipedTask task1;
|
40 |
private IPipedTask task2;
|
41 |
private boolean canceled = false; |
42 |
|
43 |
private IPipedTask currentTask = null; |
44 |
|
45 |
|
46 |
public PipeTask(IPipedTask task1, IPipedTask task2){
|
47 |
this.task1 = task1;
|
48 |
this.task2 = task2;
|
49 |
this.currentTask = task1;
|
50 |
} |
51 |
|
52 |
|
53 |
public int getInitialStep() { |
54 |
return 0; |
55 |
} |
56 |
|
57 |
public int getFinishStep() { |
58 |
return currentTask.getFinishStep();
|
59 |
} |
60 |
|
61 |
public int getCurrentStep() { |
62 |
return currentTask.getCurrentStep();
|
63 |
} |
64 |
|
65 |
public String getStatusMessage() { |
66 |
return currentTask.getStatusMessage();
|
67 |
} |
68 |
|
69 |
public String getNote() { |
70 |
if(currentTask != null){ |
71 |
return currentTask.getNote();
|
72 |
}else{
|
73 |
return ""; |
74 |
} |
75 |
} |
76 |
|
77 |
public boolean isDefined() { |
78 |
return currentTask.isDefined();
|
79 |
} |
80 |
|
81 |
public void cancel() { |
82 |
currentTask.cancel(); |
83 |
canceled = true;
|
84 |
} |
85 |
|
86 |
public void run() throws Exception { |
87 |
currentTask.run(); |
88 |
if(currentTask.isCanceled())
|
89 |
return;
|
90 |
Object result = currentTask.getResult();
|
91 |
currentTask = task2; |
92 |
currentTask.setEntry(result); |
93 |
currentTask.run(); |
94 |
} |
95 |
|
96 |
public boolean isCanceled() { |
97 |
return currentTask.isCanceled();
|
98 |
} |
99 |
|
100 |
public boolean isFinished() { |
101 |
return task1.isFinished() && task2.isFinished();
|
102 |
} |
103 |
|
104 |
public void finished() { |
105 |
|
106 |
} |
107 |
} |