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 public String getColumnName(final int column) {
058 if (column == 1) {
059 return "Service";
060 } else if (column == 2) {
061 return "Module";
062 } else if (column == 3) {
063 return "Start";
064 } else if (column == 4) {
065 return "Stop";
066 } else if (column == 5) {
067 return "Duration";
068 } else if (column == 6) {
069 return "%";
070 } else if (column == 7) {
071 return "Position";
072 } else if (column == 8) {
073 return "Parameters";
074 } else {
075 return "";
076 }
077 }
078
079 public int getRowCount() {
080 return process.length;
081 }
082
083 public int getColumnCount() {
084 return 9;
085 }
086
087 public Object getValueAt(final int row, final int col) {
088 // System.out.println("row: " + row + " col: " + col);
089 final ServiceProcess sp = getServiceProcess(row);
090 if (sp == null) {
091 return "";
092 }
093 long current = System.currentTimeMillis();
094 if (sp.getStop() != 0) {
095 current = sp.getStop();
096 }
097 switch (col) {
098 case 0: if (wasFailure(row)) {
099 return errorIcon;
100 } else if (wasSuccess(row)) {
101 return successIcon;
102 } else if (isWaiting(row)) {
103 return waitingIcon;
104 } else if (isRunning(row)) {
105 return runningIcon;
106 }
107 break;
108 case 1: return sp.getService().getPluginActionName();
109 case 2: return sp.getQedeq().getName();
110 case 3: return DateUtility.getIsoTime(sp.getStart());
111 case 4: return sp.getStop() != 0 ? DateUtility.getIsoTime(sp.getStop()) : "";
112 case 5: return DateUtility.getDuration(current - sp.getStart());
113 case 6: return "" + sp.getExecutionPercentage();
114 case 7: return sp.getExecutionActionDescription().replace('\n', ' ');
115 case 8: return sp.getParameterString();
116 default:
117 return "";
118 }
119 return "";
120 }
121
122 public boolean isCellEditable(final int row, final int column) {
123 return false;
124 }
125
126 public void setValueAt(final Object value, final int row, final int col) {
127 }
128
129 public Class getColumnClass(final int col) {
130 return col == 0 ? Icon.class : Object.class;
131 }
132
133 public void fireTableDataChanged() {
134 final ServiceProcess[] changed = KernelContext.getInstance().getServiceProcesses();
135 if (process.length > 0) {
136 super.fireTableRowsUpdated(0, process.length - 1);
137 }
138 if (changed.length > process.length) {
139 super.fireTableRowsInserted(process.length, changed.length - 1);
140 }
141 process = changed;
142 }
143
144 /**
145 * Get service process that is at given row.
146 *
147 * @param row Look into this row.
148 * @return Process of this row. Might be <code>null</code> if row doesn't exist.
149 */
150 public ServiceProcess getServiceProcess(final int row) {
151 if (row < process.length && row >= 0) {
152 return process[row];
153 }
154 return null;
155 }
156
157 /**
158 * Was the process stopped by the user?
159 *
160 * @param row Look at this row.
161 * @return Was the process stopped?
162 */
163 public boolean wasFailure(final int row) {
164 if (row >= 0 && row < process.length) {
165 return getServiceProcess(row).wasFailure();
166 }
167 return false;
168 }
169
170 /**
171 * Was the process finished normally?
172 *
173 * @param row Look at this row.
174 * @return Was the process finished normally?
175 */
176 public boolean wasSuccess(final int row) {
177 if (row >= 0 && row < process.length) {
178 return getServiceProcess(row).wasSuccess();
179 }
180 return false;
181 }
182
183 /**
184 * Is this process currently running?
185 *
186 * @param row Look at this row.
187 * @return Is the process running?
188 */
189 public boolean isRunning(final int row) {
190 if (row >= 0 && row < process.length) {
191 return getServiceProcess(row).isRunning();
192 }
193 return false;
194 }
195
196 /**
197 * Is the selected process waiting?
198 *
199 * @param row Look at this row.
200 * @return Is the process waiting?
201 */
202 public boolean isWaiting(final int row) {
203 if (row >= 0 && row < process.length) {
204 return getServiceProcess(row).isBlocked();
205 }
206 return false;
207 }
208
209 }
|