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.kernel.bo.common.QedeqBo;
023 import org.qedeq.kernel.se.common.SourceFileException;
024 import org.qedeq.kernel.se.common.SourceFileExceptionList;
025
026 /**
027 * Table model for QEDEQ module specific error pane.
028 *
029 * @author Michael Meyling
030 */
031
032 public class ModuleErrorAndWarningListModel 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 warningIcon = new ImageIcon(
041 ModuleErrorAndWarningListPane.class.getResource(
042 "/images/eclipse/warn_tsk.gif"));
043
044 /** We want to show errors and warnings from this module. */
045 private QedeqBo qedeq;
046
047 /** Errors of current module. Might be <code>null</code>. */
048 private SourceFileExceptionList errors;
049
050 /** Warnings of current module. Might be <code>null</code>. */
051 private SourceFileExceptionList warnings;
052
053 /** Number of errors of current module. */
054 private int maxErrors;
055
056 /** Number of errors plus number of warnings of current module. */
057 private int maxEntries;
058
059 public String getColumnName(final int column) {
060 if (qedeq == null) {
061 return "";
062 }
063 if (column == 1) {
064 return qedeq.getModuleAddress().getUrl();
065 } else if (column == 2) {
066 return "Location";
067 } else if (column == 3) {
068 return "Type";
069 } else {
070 return "";
071 }
072 }
073
074 public int getRowCount() {
075 return maxEntries;
076 }
077
078 public int getColumnCount() {
079 return 4;
080 }
081
082 public Object getValueAt(final int row, final int col) {
083 // System.out.println("row: " + row + " col: " + col);
084 if (qedeq == null) {
085 return "";
086 }
087 final SourceFileException e = getSourceFileException(row);
088 if (e == null) {
089 return "";
090 }
091 switch (col) {
092 case 0: if (isError(row)) {
093 return errorIcon;
094 } else if (isWarning(row)) {
095 return warningIcon;
096 }
097 break;
098 case 1: if (getSourceFileException(row) != null) {
099 return getSourceFileException(row).getMessage();
100 }
101 break;
102 case 2: if (getSourceFileException(row) != null && getSourceFileException(row).getSourceArea() != null) {
103 return "line " + getSourceFileException(row).getSourceArea().getStartPosition().getRow();
104 }
105 break;
106 case 3: if (getSourceFileException(row) != null) {
107 return getSourceFileException(row).getPlugin().getPluginActionName();
108 }
109 break;
110 default:
111 return "";
112 }
113 return "";
114 }
115
116 public boolean isCellEditable(final int row, final int column) {
117 return false;
118 }
119
120 public void setValueAt(final Object value, final int row, final int col) {
121 }
122
123 public Class getColumnClass(final int col) {
124 return col == 0 ? Icon.class : Object.class;
125 }
126
127 /**
128 * Set QEDEQ module.
129 *
130 * @param qedeq QEDEQ module.
131 */
132 public void setQedeq(final QedeqBo qedeq) {
133 this.qedeq = qedeq;
134 }
135
136 /**
137 * Get QEDEQ module.
138 *
139 * @return QEDEQ module.
140 */
141 public QedeqBo getQedeq() {
142 return qedeq;
143 }
144
145 public void fireTableDataChanged() {
146 if (qedeq != null) {
147 this.errors = qedeq.getErrors();
148 this.warnings = qedeq.getWarnings();
149 } else {
150 this.errors = null;
151 this.warnings = null;
152 }
153 maxErrors = 0;
154 if (errors != null) {
155 maxErrors += errors.size();
156 }
157 maxEntries = maxErrors;
158 if (warnings != null) {
159 maxEntries += warnings.size();
160 }
161 super.fireTableDataChanged();
162 }
163
164 /**
165 * Get exception that is at given row.
166 *
167 * @param row Look into this row.
168 * @return Exception of this row. Might be <code>null</code> if row doesn't exist.
169 */
170 public SourceFileException getSourceFileException(final int row) {
171 if (isError(row)) {
172 return errors.get(row);
173 } else if (isWarning(row)) {
174 return warnings.get(row - maxErrors);
175 }
176 return null;
177 }
178
179 /**
180 * Get number of error (that is position in error list) that is in the given row.
181 * If at the given row is no error an IllegalArgumentException is thrown.
182 *
183 * @param row Look at this row.
184 * @return Error list number of error at this row.
185 * @throws IllegalArgumentException At given row is no error.
186 */
187 public int getErrorNumber(final int row) {
188 if (!isError(row)) {
189 throw new IllegalArgumentException("This is not an error row: " + row);
190 }
191 return row;
192 }
193
194 /**
195 * Get number of warning (that is position in warning list) that is in the given row.
196 * If at the given row is no warning an IllegalArgumentException is thrown.
197 *
198 * @param row Look at this row.
199 * @return Warning list number of warning at this row.
200 * @throws IllegalArgumentException At given row is no warning.
201 */
202 public int getWarningNumber(final int row) {
203 if (!isWarning(row)) {
204 throw new IllegalArgumentException("This is not an warning row: " + row);
205 }
206 return row - maxErrors;
207 }
208
209 /**
210 * Is there an error at given row?
211 *
212 * @param row Look at this row.
213 * @return Is there an error?
214 */
215 public boolean isError(final int row) {
216 if (row >= 0 && row < maxErrors) {
217 return true;
218 }
219 return false;
220 }
221
222 /**
223 * Is there an warning at given row?
224 *
225 * @param row Look at this row.
226 * @return Is there an warning?
227 */
228 public boolean isWarning(final int row) {
229 if (row >= maxErrors && row < maxEntries) {
230 return true;
231 }
232 return false;
233 }
234
235 }
|