001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2014, Michael Meyling <mime@qedeq.org>.
004 *
005 * "Hilbert II" is free software; you can redistribute
006 * it and/or modify it under the terms of the GNU General Public
007 * License as published by the Free Software Foundation; either
008 * version 2 of the License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU General Public License for more details.
014 */
015
016 package org.qedeq.gui.se.pane;
017
018 import javax.swing.Icon;
019 import javax.swing.ImageIcon;
020 import javax.swing.table.AbstractTableModel;
021
022 import org.qedeq.base.utility.DateUtility;
023 import org.qedeq.kernel.bo.KernelContext;
024 import org.qedeq.kernel.bo.common.QedeqBo;
025 import org.qedeq.kernel.bo.common.ServiceJob;
026
027 /**
028 * Table model for QEDEQ module specific error pane.
029 *
030 * @author Michael Meyling
031 */
032
033 public class ProcessListModel extends AbstractTableModel {
034
035 /** Error icon. */
036 private static ImageIcon errorIcon = new ImageIcon(
037 ModuleErrorAndWarningListPane.class.getResource(
038 "/images/eclipse/error_tsk.gif"));
039
040 /** Warning icon. */
041 private static ImageIcon runningIcon = new ImageIcon(
042 ModuleErrorAndWarningListPane.class.getResource(
043 "/images/eclipse/progress_ok.gif"));
044
045 /** Waiting icon. */
046 private static ImageIcon waitingIcon = new ImageIcon(
047 ModuleErrorAndWarningListPane.class.getResource(
048 "/images/eclipse/waiting.gif"));
049
050 /** Complete icon. */
051 private static ImageIcon successIcon = new ImageIcon(
052 ModuleErrorAndWarningListPane.class.getResource(
053 "/images/eclipse/complete_task.gif"));
054
055 /** Last process info. */
056 private ServiceJob[] process = new ServiceJob[] {};
057
058 /** Should only running tasks be chosen? */
059 private boolean onlyRunning = true;
060
061 public String getColumnName(final int column) {
062 if (column == 1) {
063 return "Service";
064 } else if (column == 2) {
065 return "Module";
066 } else if (column == 3) {
067 return "Start";
068 } else if (column == 4) {
069 return "Stop";
070 } else if (column == 5) {
071 return "Duration";
072 } else if (column == 6) {
073 return "%";
074 } else if (column == 7) {
075 return "Position";
076 } else if (column == 8) {
077 return "Parameters";
078 } else {
079 return "";
080 }
081 }
082
083 public int getRowCount() {
084 return process.length;
085 }
086
087 public int getColumnCount() {
088 return 9;
089 }
090
091 public Object getValueAt(final int row, final int col) {
092 // System.out.println("row: " + row + " col: " + col);
093 final ServiceJob sp = getServiceProcess(row);
094 if (sp == null) {
095 return "";
096 }
097 long current = System.currentTimeMillis();
098 if (sp.getStop() != 0) {
099 current = sp.getStop();
100 }
101 switch (col) {
102 case 0: if (wasFailure(row)) {
103 return errorIcon;
104 } else if (wasInterrupted(row)) {
105 return errorIcon;
106 } else if (wasSuccess(row)) {
107 return successIcon;
108 } else if (isWaiting(row)) {
109 return waitingIcon;
110 } else if (isRunning(row)) {
111 return runningIcon;
112 }
113 break;
114 case 1: return sp.getActionName();
115 case 2: return getNameList(sp.getCurrentlyProcessedModules());
116 case 3: return DateUtility.getIsoTime(sp.getStart());
117 case 4: return sp.getStop() != 0 ? DateUtility.getIsoTime(sp.getStop()) : "";
118 case 5: return DateUtility.getDuration(current - sp.getStart());
119 case 6: return "" + sp.getExecutionPercentage();
120 case 7: return sp.getExecutionActionDescription().replace('\n', ' ');
121 case 8: return (sp.getModuleServiceCall() != null ? sp.getModuleServiceCall().getConfigParametersString() + "; "
122 + sp.getModuleServiceCall().getParametersString() : "");
123 default:
124 return "";
125 }
126 return "";
127 }
128
129 private String getNameList(final QedeqBo[] list) {
130 final StringBuffer result = new StringBuffer();
131 for (int i = 0; i < list.length; i++) {
132 if (i > 0) {
133 result.append(", ");
134 }
135 result.append(list[i].getName());
136 }
137 return result.toString();
138 }
139
140 public boolean isCellEditable(final int row, final int column) {
141 return false;
142 }
143
144 public void setValueAt(final Object value, final int row, final int col) {
145 }
146
147 public Class getColumnClass(final int col) {
148 return col == 0 ? Icon.class : Object.class;
149 }
150
151 public void fireTableDataChanged() {
152 final ServiceJob[] changed;
153 if (getOnlyRunning()) {
154 changed = KernelContext.getInstance().getRunningServiceProcesses();
155 } else {
156 changed = KernelContext.getInstance().getServiceProcesses();
157 }
158 if (process.length > 0) {
159 super.fireTableRowsUpdated(0, process.length - 1);
160 }
161 if (changed.length > process.length) {
162 super.fireTableRowsInserted(process.length, changed.length - 1);
163 }
164 process = changed;
165 }
166
167 public boolean getOnlyRunning() {
168 return onlyRunning;
169 }
170
171 public void setOnlyRunning(final boolean onlyRunning) {
172 this.onlyRunning = onlyRunning;
173 }
174
175 /**
176 * Get service process that is at given row.
177 *
178 * @param row Look into this row.
179 * @return Process of this row. Might be <code>null</code> if row doesn't exist.
180 */
181 public ServiceJob getServiceProcess(final int row) {
182 if (row < process.length && row >= 0) {
183 return process[row];
184 }
185 return null;
186 }
187
188 /**
189 * Was the process finished normally?
190 *
191 * @param row Look at this row.
192 * @return Was the process finished normally?
193 */
194 public boolean wasSuccess(final int row) {
195 if (row >= 0 && row < process.length) {
196 return getServiceProcess(row).wasSuccess();
197 }
198 return false;
199 }
200
201 /**
202 * Did the process stop with an exception?
203 *
204 * @param row Look at this row.
205 * @return Was the process stopped by an exception?
206 */
207 public boolean wasFailure(final int row) {
208 if (row >= 0 && row < process.length) {
209 return getServiceProcess(row).wasFailure();
210 }
211 return false;
212 }
213
214 /**
215 * Was the process stopped by the user?
216 *
217 * @param row Look at this row.
218 * @return Was the process stopped?
219 */
220 public boolean wasInterrupted(final int row) {
221 if (row >= 0 && row < process.length) {
222 return getServiceProcess(row).wasInterrupted();
223 }
224 return false;
225 }
226
227 /**
228 * Is this process currently running?
229 *
230 * @param row Look at this row.
231 * @return Is the process running?
232 */
233 public boolean isRunning(final int row) {
234 if (row >= 0 && row < process.length) {
235 return getServiceProcess(row).isRunning();
236 }
237 return false;
238 }
239
240 /**
241 * Is the selected process waiting?
242 *
243 * @param row Look at this row.
244 * @return Is the process waiting?
245 */
246 public boolean isWaiting(final int row) {
247 if (row >= 0 && row < process.length) {
248 return getServiceProcess(row).isBlocked();
249 }
250 return false;
251 }
252
253 }
|