svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / test / java / org / gvsig / gui / beans / progresspanel / SampleProcess.java @ 40561
History | View | Annotate | Download (3.63 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.gui.beans.progresspanel; |
25 |
|
26 |
import org.gvsig.gui.beans.Messages; |
27 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
28 |
import org.gvsig.gui.beans.incrementabletask.IncrementableProcess; |
29 |
|
30 |
/* gvSIG. Geographic Information System of the Valencian Government
|
31 |
*
|
32 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
33 |
* of the Valencian Government (CIT)
|
34 |
*
|
35 |
* This program is free software; you can redistribute it and/or
|
36 |
* modify it under the terms of the GNU General Public License
|
37 |
* as published by the Free Software Foundation; either version 2
|
38 |
* of the License, or (at your option) any later version.
|
39 |
*
|
40 |
* This program is distributed in the hope that it will be useful,
|
41 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
42 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
43 |
* GNU General Public License for more details.
|
44 |
*
|
45 |
* You should have received a copy of the GNU General Public License
|
46 |
* along with this program; if not, write to the Free Software
|
47 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
48 |
* MA 02110-1301, USA.
|
49 |
*
|
50 |
*/
|
51 |
|
52 |
/**
|
53 |
* Process that adds a layer with derivative geometries, according the configuration.
|
54 |
*
|
55 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
56 |
*/
|
57 |
public class SampleProcess extends IncrementableProcess { |
58 |
public SampleProcess(String title, String label) { |
59 |
super(title);
|
60 |
|
61 |
this.label = label;
|
62 |
this.isPausable = true; |
63 |
} |
64 |
|
65 |
/**
|
66 |
* Sample process.
|
67 |
* <br>
|
68 |
* "cancelProcess" is a shared object that, if you want allow to cancel the process,
|
69 |
* you should read it once in a while and check if it's canceled, if true, throw an InterrupedException
|
70 |
*
|
71 |
* @throws InterruptedException if fails the process
|
72 |
*/
|
73 |
public void process() throws InterruptedException { |
74 |
try {
|
75 |
percentage = 0;
|
76 |
|
77 |
for (int i = 1; i <= 20; i++) { |
78 |
percentage = i * 5;
|
79 |
|
80 |
if (cancelProcess.isCanceled()) {
|
81 |
throw new InterruptedException(); |
82 |
} |
83 |
|
84 |
log.addLine("Paso: " + i);
|
85 |
Thread.sleep(1000); |
86 |
} |
87 |
|
88 |
percentage = 100;
|
89 |
log.addLine(Messages.getText("Process_finished_successfully"));
|
90 |
return;
|
91 |
} |
92 |
catch (Exception ex) { |
93 |
if (! cancelProcess.isCanceled()) {
|
94 |
// Next line must be uncommented
|
95 |
//NotificationManager.showMessageError(Messages.getText("Failed_the_process"), ex);
|
96 |
log.addLine(Messages.getText("Failed_the_process"));
|
97 |
} |
98 |
|
99 |
/* CANCELLATION PROCESS */
|
100 |
|
101 |
// Must restore the changes
|
102 |
//....
|
103 |
|
104 |
throw new InterruptedException(); |
105 |
} |
106 |
finally {
|
107 |
/* Summary of the process */
|
108 |
log.addLine(" Proceso de ejemplo con barra de progreso durante 20 segundos");
|
109 |
|
110 |
// Ends the progress panel
|
111 |
iTask.getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).doClick(); |
112 |
} |
113 |
} |
114 |
} |