svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / swing / threads / AbstractMonitorableTask.java @ 40561
History | View | Annotate | Download (3.61 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 |
package org.gvsig.utils.swing.threads; |
25 |
|
26 |
|
27 |
/**
|
28 |
* @author fjp
|
29 |
*
|
30 |
* Basada en el trabajo de A. Zabala.
|
31 |
* Para usarla, extender de AbstractMonitorableTask e implementar el m?todo run().
|
32 |
* Ejemplo:
|
33 |
*
|
34 |
La tarea se lanza con:
|
35 |
|
36 |
PluginServices.cancelableBackgroundExecution(new WriterTask(layer, writer)); <br>
|
37 |
|
38 |
private class WriterTask extends AbstractMonitorableTask <br>
|
39 |
{ <br>
|
40 |
FLyrVect lyrVect; <br>
|
41 |
IWriter writer; <br>
|
42 |
int rowCount; <br>
|
43 |
public WriterTask(FLyrVect lyr, IWriter writer) throws DriverException, DriverIOException <br>
|
44 |
{ <br>
|
45 |
this.lyrVect = lyr; <br>
|
46 |
this.writer = writer; <br>
|
47 |
|
48 |
setInitialStep(0); <br>
|
49 |
setDeterminatedProcess(true); <br>
|
50 |
setStatusMessage(PluginServices.getText(this, "exportando_features")); <br>
|
51 |
|
52 |
setFinalStep(rowCount); // Importante: Fijarlo en el constructor, para que est? establecido antes del run() <br>
|
53 |
|
54 |
} <br>
|
55 |
public void run() throws Exception { <br>
|
56 |
|
57 |
// Creamos la tabla. <br>
|
58 |
writer.preProcess(); <br>
|
59 |
|
60 |
rowCount = va.getShapeCount(); <br>
|
61 |
for (int i = 0; i < rowCount; i++) { <br>
|
62 |
IGeometry geom = va.getShape(i); <br>
|
63 |
|
64 |
// DO PROGRESS STUFF <br>
|
65 |
reportStep(); <br>
|
66 |
setNote(PluginServices.getText(this, "exporting_") + i); <br>
|
67 |
if (isCanceled()) <br>
|
68 |
break; <br>
|
69 |
|
70 |
// END DO PROGRESS STUFF <br>
|
71 |
|
72 |
if (geom != null) { <br>
|
73 |
Value[] values = sds.getRow(i); <br>
|
74 |
IFeature feat = new DefaultFeature(geom, values, "" + i); <br>
|
75 |
DefaultRowEdited edRow = new DefaultRowEdited(feat, <br>
|
76 |
DefaultRowEdited.STATUS_ADDED, i); <br>
|
77 |
writer.process(edRow); <br>
|
78 |
} <br>
|
79 |
} <br>
|
80 |
writer.postProcess(); <br>
|
81 |
|
82 |
JOptionPane.showMessageDialog( <br>
|
83 |
(JComponent) PluginServices.getMDIManager().getActiveView() <br>
|
84 |
, PluginServices.getText(this, "capa_exportada"), "Export", <br>
|
85 |
JOptionPane.INFORMATION_MESSAGE); <br>
|
86 |
|
87 |
} <br>
|
88 |
|
89 |
} <br>
|
90 |
*/
|
91 |
public abstract class AbstractMonitorableTask extends DefaultCancellableMonitorable implements IMonitorableTask { |
92 |
|
93 |
String statusMessage;
|
94 |
|
95 |
String note;
|
96 |
|
97 |
public String getNote() { |
98 |
return note;
|
99 |
} |
100 |
|
101 |
public void setNote(String note) { |
102 |
this.note = note;
|
103 |
} |
104 |
|
105 |
public String getStatusMessage() { |
106 |
return statusMessage;
|
107 |
} |
108 |
|
109 |
public void setStatusMessage(String statusMessage) { |
110 |
this.statusMessage = statusMessage;
|
111 |
} |
112 |
|
113 |
public int getFinishStep() { |
114 |
return getFinalStep();
|
115 |
} |
116 |
|
117 |
public boolean isDefined() { |
118 |
return isDeterminatedProcess();
|
119 |
} |
120 |
|
121 |
|
122 |
public boolean isFinished() { |
123 |
return (getCurrentStep() >= getFinalStep());
|
124 |
} |
125 |
|
126 |
public void cancel() { |
127 |
setCanceled(true);
|
128 |
} |
129 |
|
130 |
|
131 |
/*
|
132 |
* (non-Javadoc)
|
133 |
* @see com.iver.utiles.swing.threads.IMonitorableTask#finished()
|
134 |
*/
|
135 |
public void finished() { |
136 |
|
137 |
|
138 |
} |
139 |
|
140 |
|
141 |
} |