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 package com.sun.star.wizards.ui.event; 24 25 import java.util.List; 26 import java.util.Vector; 27 28 /** 29 * @author rpiterman 30 * 31 * To change the template for this generated type comment go to 32 * Window>Preferences>Java>Code Generation>Code and Comments 33 */ 34 public class Task 35 { 36 37 private int successfull = 0; 38 private int failed = 0; 39 private int max = 0; 40 private String taskName; 41 private List listeners = new Vector(); 42 private String subtaskName; 43 Task(String taskName_, String subtaskName_, int max_)44 public Task(String taskName_, String subtaskName_, int max_) 45 { 46 taskName = taskName_; 47 subtaskName = subtaskName_; 48 max = max_; 49 } 50 start()51 public void start() 52 { 53 fireTaskStarted(); 54 } 55 fail()56 public void fail() 57 { 58 fireTaskFailed(); 59 } 60 getMax()61 public int getMax() 62 { 63 return max; 64 } 65 setMax(int max_)66 public void setMax(int max_) 67 { 68 max = max_; 69 fireTaskStatusChanged(); 70 } 71 advance(boolean success_)72 public void advance(boolean success_) 73 { 74 if (success_) 75 { 76 successfull++; 77 } 78 else 79 { 80 failed++; 81 } 82 fireTaskStatusChanged(); 83 if (failed + successfull == max) 84 { 85 fireTaskFinished(); 86 } 87 } 88 advance(boolean success_, String nextSubtaskName)89 public void advance(boolean success_, String nextSubtaskName) 90 { 91 advance(success_); 92 setSubtaskName(nextSubtaskName); 93 } 94 getStatus()95 public int getStatus() 96 { 97 return successfull + failed; 98 } 99 addTaskListener(TaskListener tl)100 public void addTaskListener(TaskListener tl) 101 { 102 listeners.add(tl); 103 } 104 removeTaskListener(TaskListener tl)105 public void removeTaskListener(TaskListener tl) 106 { 107 listeners.remove(tl); 108 } 109 fireTaskStatusChanged()110 protected void fireTaskStatusChanged() 111 { 112 TaskEvent te = new TaskEvent(this, TaskEvent.TASK_STATUS_CHANGED); 113 114 for (int i = 0; i < listeners.size(); i++) 115 { 116 ((TaskListener) listeners.get(i)).taskStatusChanged(te); 117 } 118 } 119 fireTaskStarted()120 protected void fireTaskStarted() 121 { 122 TaskEvent te = new TaskEvent(this, TaskEvent.TASK_STARTED); 123 124 for (int i = 0; i < listeners.size(); i++) 125 { 126 ((TaskListener) listeners.get(i)).taskStarted(te); 127 } 128 } 129 fireTaskFailed()130 protected void fireTaskFailed() 131 { 132 TaskEvent te = new TaskEvent(this, TaskEvent.TASK_FAILED); 133 134 for (int i = 0; i < listeners.size(); i++) 135 { 136 ((TaskListener) listeners.get(i)).taskFinished(te); 137 } 138 } 139 fireTaskFinished()140 protected void fireTaskFinished() 141 { 142 TaskEvent te = new TaskEvent(this, TaskEvent.TASK_FINISHED); 143 144 for (int i = 0; i < listeners.size(); i++) 145 { 146 ((TaskListener) listeners.get(i)).taskFinished(te); 147 } 148 } 149 fireSubtaskNameChanged()150 protected void fireSubtaskNameChanged() 151 { 152 TaskEvent te = new TaskEvent(this, TaskEvent.SUBTASK_NAME_CHANGED); 153 154 for (int i = 0; i < listeners.size(); i++) 155 { 156 ((TaskListener) listeners.get(i)).subtaskNameChanged(te); 157 } 158 } 159 160 /** 161 * @return 162 */ getSubtaskName()163 public String getSubtaskName() 164 { 165 return subtaskName; 166 } 167 168 /** 169 * @return 170 */ getTaskName()171 public String getTaskName() 172 { 173 return taskName; 174 } 175 176 /** 177 * @param string 178 */ setSubtaskName(String string)179 public void setSubtaskName(String string) 180 { 181 subtaskName = string; 182 fireSubtaskNameChanged(); 183 } 184 185 /** 186 * @return 187 */ getFailed()188 public int getFailed() 189 { 190 return failed; 191 } 192 193 /** 194 * @return 195 */ getSuccessfull()196 public int getSuccessfull() 197 { 198 return successfull; 199 } 200 } 201