001 /* This file is part of the project "Hilbert II" - http://www.qedeq.org
002 *
003 * Copyright 2000-2013, 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.ServiceProcess;
025
026 /**
027 * Table model for QEDEQ module specific error pane.
028 *
029 * @author Michael Meyling
030 */
031
032 public class ProcessListModel extends AbstractTableModel {
033
034 /** Error icon. */
035 private static ImageIcon errorIcon = new ImageIcon(
036 ModuleErrorAndWarningListPane.class.getResource(
037 "/images/eclipse/error_tsk.gif"));
038
039 /** Warning icon. */
040 private static ImageIcon runningIcon = new ImageIcon(
041 ModuleErrorAndWarningListPane.class.getResource(
042 "/images/eclipse/progress_ok.gif"));
043
044 /** Waiting icon. */
045 private static ImageIcon waitingIcon = new ImageIcon(
046 ModuleErrorAndWarningListPane.class.getResource(
047 "/images/eclipse/waiting.gif"));
048
049 /** Complete icon. */
050 private static ImageIcon successIcon = new ImageIcon(
051 ModuleErrorAndWarningListPane.class.getResource(
052 "/images/eclipse/complete_task.gif"));
053
054 /** Last process info. */
055 private ServiceProcess[] process = new ServiceProcess[] {};
056
057 /** Should only running tasks be chosen? */
058 private boolean onlyRunning = true;
059
060 public String getColumnName(final int column) {
061 if (column == 1) {
062 return "Service";
063 } else if (column == 2) {
064 return "Module";
065 } else if (column == 3) {
066 return "Start";
067 } else if (column == 4) {
068 return "Stop";
069 } else if (column == 5) {
070 return "Duration";
071 } else if (column == 6) {
072 return "%";
073 } else if (column == 7) {
074 return "Position";
075 } else if (column == 8) {
076 return "Parameters";
077 } else {
078 return "";
079 }
080 }
081
082 public int getRowCount() {
083 return process.length;
084 }
085
086 public int getColumnCount() {
087 return 9;
088 }
089
090 public Object getValueAt(final int row, final int col) {
091 // System.out.println("row: " + row + " col: " + col);
092 final ServiceProcess sp = getServiceProcess(row);
093 if (sp == null) {
094 return "";
095 }
096 long current = System.currentTimeMillis();
097 if (sp.getStop() != 0) {
098 current = sp.getStop();
099 }
100 switch (col) {
101 case 0: if (wasFailure(row)) {
102 return errorIcon;
103 } else if (wasSuccess(row)) {
104 return successIcon;
105 } else if (isWaiting(row)) {
106 return waitingIcon;
107 } else if (isRunning(row)) {
108 return runningIcon;
109 }
110 break;
111 case 1: return sp.getActionName();
112 case 2: return (sp.getQedeq() != null ? sp.getQedeq().getName() : "");
113 case 3: return DateUtility.getIsoTime(sp.getStart());
114 case 4: return sp.getStop() != 0 ? DateUtility.getIsoTime(sp.getStop()) : "";
115 case 5: return DateUtility.getDuration(current - sp.getStart());
116 case 6: return "" + sp.getExecutionPercentage();
117 case 7: return sp.getExecutionActionDescription().replace('\n', ' ');
118 case 8: return (sp.getPluginCall() != null ? sp.getPluginCall().getParameterString() : "");
119 default:
120 return "";
121 }
122 return "";
123 }
124
125 public boolean isCellEditable(final int row, final int column) {
126 return false;
127 }
128
129 public void setValueAt(final Object value, final int row, final int col) {
130 }
131
132 public Class getColumnClass(final int col) {
133 return col == 0 ? Icon.class : Object.class;
134 }
135
136 public void fireTableDataChanged() {
137 final ServiceProcess[] changed;
138 if (getOnlyRunning()) {
139 changed = KernelContext.getInstance().getRunningServiceProcesses();
140 } else {
141 changed = KernelContext.getInstance().getServiceProcesses();
142 }
143 if (process.length > 0) {
144 super.fireTableRowsUpdated(0, process.length - 1);
145 }
146 if (changed.length > process.length) {
147 super.fireTableRowsInserted(process.length, changed.length - 1);
148 }
149 process = changed;
150 }
151
152 public boolean getOnlyRunning() {
153 return onlyRunning;
154 }
155
156 public void setOnlyRunning(final boolean onlyRunning) {
157 this.onlyRunning = onlyRunning;
158 }
159
160 /**
161 * Get service process that is at given row.
162 *
163 * @param row Look into this row.
164 * @return Process of this row. Might be <code>null</code> if row doesn't exist.
165 */
166 public ServiceProcess getServiceProcess(final int row) {
167 if (row < process.length && row >= 0) {
168 return process[row];
169 }
170 return null;
171 }
172
173 /**
174 * Was the process stopped by the user?
175 *
176 * @param row Look at this row.
177 * @return Was the process stopped?
178 */
179 public boolean wasFailure(final int row) {
180 if (row >= 0 && row < process.length) {
181 return getServiceProcess(row).wasFailure();
182 }
183 return false;
184 }
185
186 /**
187 * Was the process finished normally?
188 *
189 * @param row Look at this row.
190 * @return Was the process finished normally?
191 */
192 public boolean wasSuccess(final int row) {
193 if (row >= 0 && row < process.length) {
194 return getServiceProcess(row).wasSuccess();
195 }
196 return false;
197 }
198
199 /**
200 * Is this process currently running?
201 *
202 * @param row Look at this row.
203 * @return Is the process running?
204 */
205 public boolean isRunning(final int row) {
206 if (row >= 0 && row < process.length) {
207 return getServiceProcess(row).isRunning();
208 }
209 return false;
210 }
211
212 /**
213 * Is the selected process waiting?
214 *
215 * @param row Look at this row.
216 * @return Is the process waiting?
217 */
218 public boolean isWaiting(final int row) {
219 if (row >= 0 && row < process.length) {
220 return getServiceProcess(row).isBlocked();
221 }
222 return false;
223 }
224
225 }
|