1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 /*
24  * Created on 17.10.2003
25  *
26  * To change the template for this generated file go to
27  * Window>Preferences>Java>Code Generation>Code and Comments
28  */
29 package com.sun.star.wizards.web.status;
30 
31 import java.util.List;
32 import java.util.Vector;
33 
34 /**
35  * @author rpiterman
36  *
37  * To change the template for this generated type comment go to
38  * Window>Preferences>Java>Code Generation>Code and Comments
39  */
40 public class Task
41 {
42 
43     private int successfull = 0;
44     private int failed = 0;
45     private int max = 0;
46     private String taskName;
47     private List listeners = new Vector();
48     private String subtaskName;
49 
Task(String taskName_, String subtaskName_, int max_)50     public Task(String taskName_, String subtaskName_, int max_)
51     {
52         taskName = taskName_;
53         subtaskName = subtaskName_;
54         max = max_;
55     }
56 
start()57     public void start()
58     {
59         fireTaskStarted();
60     }
61 
getMax()62     public int getMax()
63     {
64         return max;
65     }
66 
setMax(int max_)67     public void setMax(int max_)
68     {
69         max = max_;
70         fireTaskStatusChanged();
71     }
72 
advance(boolean success_)73     public void advance(boolean success_)
74     {
75         if (success_)
76         {
77             successfull++;
78         }
79         else
80         {
81             failed++;
82         }
83         fireTaskStatusChanged();
84         if (failed + successfull == max)
85         {
86             fireTaskFinished();
87         }
88     }
89 
advance(boolean success_, String nextSubtaskName)90     public void advance(boolean success_, String nextSubtaskName)
91     {
92         advance(success_);
93         setSubtaskName(nextSubtaskName);
94     }
95 
getStatus()96     public int getStatus()
97     {
98         return successfull + failed;
99     }
100 
addTaskListener(TaskListener tl)101     public void addTaskListener(TaskListener tl)
102     {
103         listeners.add(tl);
104     }
105 
removeTaskListener(TaskListener tl)106     public void removeTaskListener(TaskListener tl)
107     {
108         listeners.remove(tl);
109     }
110 
fireTaskStatusChanged()111     protected void fireTaskStatusChanged()
112     {
113         TaskEvent te = new TaskEvent(this, TaskEvent.TASK_STATUS_CHANGED);
114 
115         for (int i = 0; i < listeners.size(); i++)
116         {
117             ((TaskListener) listeners.get(i)).taskStatusChanged(te);
118         }
119     }
120 
fireTaskStarted()121     protected void fireTaskStarted()
122     {
123         TaskEvent te = new TaskEvent(this, TaskEvent.TASK_STARTED);
124 
125         for (int i = 0; i < listeners.size(); i++)
126         {
127             ((TaskListener) listeners.get(i)).taskStarted(te);
128         }
129     }
130 
fireTaskFinished()131     protected void fireTaskFinished()
132     {
133         TaskEvent te = new TaskEvent(this, TaskEvent.TASK_FINISHED);
134 
135         for (int i = 0; i < listeners.size(); i++)
136         {
137             ((TaskListener) listeners.get(i)).taskFinished(te);
138         }
139     }
140 
fireSubtaskNameChanged()141     protected void fireSubtaskNameChanged()
142     {
143         TaskEvent te = new TaskEvent(this, TaskEvent.SUBTASK_NAME_CHANGED);
144 
145         for (int i = 0; i < listeners.size(); i++)
146         {
147             ((TaskListener) listeners.get(i)).subtaskNameChanged(te);
148         }
149     }
150 
151     /**
152      * @return
153      */
getSubtaskName()154     public String getSubtaskName()
155     {
156         return subtaskName;
157     }
158 
159     /**
160      * @return
161      */
getTaskName()162     public String getTaskName()
163     {
164         return taskName;
165     }
166 
167     /**
168      * @param string
169      */
setSubtaskName(String string)170     public void setSubtaskName(String string)
171     {
172         subtaskName = string;
173         fireSubtaskNameChanged();
174     }
175 
176     /**
177      * @return
178      */
getFailed()179     public int getFailed()
180     {
181         return failed;
182     }
183 
184     /**
185      * @return
186      */
getSuccessfull()187     public int getSuccessfull()
188     {
189         return successfull;
190     }
191 }
192