1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.io;
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * This is an abstract task for uploading or saving a data layer.
|
---|
6 | * @since 2025
|
---|
7 | */
|
---|
8 | public abstract class AbstractIOTask implements Runnable {
|
---|
9 |
|
---|
10 | /** indicates whether the task has been canceled */
|
---|
11 | private boolean canceled;
|
---|
12 | /** indicates whether the task has been failed */
|
---|
13 | private boolean failed;
|
---|
14 | /** the last exception caught */
|
---|
15 | private Exception lastException;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Contructs a new {@code AbstractIOTask}.
|
---|
19 | */
|
---|
20 | public AbstractIOTask() {
|
---|
21 | canceled = false;
|
---|
22 | failed = false;
|
---|
23 | lastException = null;
|
---|
24 | }
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Replies true if the task has been canceled
|
---|
28 | *
|
---|
29 | * @return true if the task has been canceled
|
---|
30 | */
|
---|
31 | public boolean isCanceled() {
|
---|
32 | return canceled;
|
---|
33 | }
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Set whether this task has been canceled
|
---|
37 | *
|
---|
38 | * @param canceled true, if the task has been canceled; false otherwise
|
---|
39 | */
|
---|
40 | protected void setCanceled(boolean canceled) {
|
---|
41 | this.canceled = canceled;
|
---|
42 | }
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Replies true if the task has been failed
|
---|
46 | *
|
---|
47 | * @return true if the task has been failed
|
---|
48 | */
|
---|
49 | public boolean isFailed() {
|
---|
50 | return failed || lastException != null;
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Sets whether the task has been failed
|
---|
55 | *
|
---|
56 | * @param failed whether the task has been failed
|
---|
57 | */
|
---|
58 | protected void setFailed(boolean failed) {
|
---|
59 | this.failed = failed;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Replies the last exception caught
|
---|
64 | *
|
---|
65 | * @return the last exception caught; null, if no exception was caught
|
---|
66 | */
|
---|
67 | public Exception getLastException() {
|
---|
68 | return lastException;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Sets the last exception caught
|
---|
73 | *
|
---|
74 | * @param lastException the last exception
|
---|
75 | */
|
---|
76 | protected void setLastException(Exception lastException) {
|
---|
77 | this.lastException = lastException;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Replies true if this task was successful, i.e. if it wasn't
|
---|
82 | * canceled and didn't fail
|
---|
83 | *
|
---|
84 | * @return true if this task was successful
|
---|
85 | */
|
---|
86 | public boolean isSuccessful() {
|
---|
87 | return !isCanceled() && !isFailed();
|
---|
88 | }
|
---|
89 |
|
---|
90 | /**
|
---|
91 | * Cancel the task
|
---|
92 | */
|
---|
93 | public abstract void cancel();
|
---|
94 | }
|
---|