001: /*
002: * ProblemsPanel.java
003: *
004: * Created on February 27, 2007, 10:55 AM
005: */
006:
007: package it.businesslogic.ireport.gui.logpane;
008:
009: import it.businesslogic.ireport.compiler.ErrorLocator;
010: import it.businesslogic.ireport.compiler.xml.SourceLocation;
011: import it.businesslogic.ireport.gui.JReportFrame;
012: import it.businesslogic.ireport.gui.MainFrame;
013: import it.businesslogic.ireport.gui.event.ReportFrameActivatedEvent;
014: import it.businesslogic.ireport.gui.event.ReportFrameActivatedListener;
015: import it.businesslogic.ireport.util.I18n;
016: import it.businesslogic.ireport.util.LanguageChangedEvent;
017: import it.businesslogic.ireport.util.LanguageChangedListener;
018: import javax.swing.JTabbedPane;
019: import javax.swing.SwingUtilities;
020: import javax.swing.table.DefaultTableModel;
021:
022: /**
023: *
024: * @author gtoffoli
025: */
026: public class ProblemsPanel extends javax.swing.JPanel implements
027: ReportFrameActivatedListener {
028:
029: private ErrorLocator errorLocator = null;
030:
031: /** Creates new form ProblemsPanel */
032: public ProblemsPanel() {
033: initComponents();
034: errorLocator = new ErrorLocator();
035: jTable1.getColumnModel().getColumn(0).setMinWidth(20);
036: jTable1.getColumnModel().getColumn(0).setMaxWidth(20);
037: jTable1.getColumnModel().getColumn(0).setPreferredWidth(20);
038:
039: jTable1.getColumnModel().getColumn(0).setCellRenderer(
040: new ProblemIconTableCellRenderer());
041: jTable1.getColumnModel().getColumn(1).setPreferredWidth(300);
042: jTable1.getColumnModel().getColumn(2).setPreferredWidth(150);
043: jTable1.getColumnModel().getColumn(3).setPreferredWidth(550);
044:
045: MainFrame.getMainInstance().addReportFrameActivatedListener(
046: this );
047: setName(I18n.getFormattedString("problems",
048: "Problems ({0,number})",
049: new Object[] { new Integer(0) }));
050:
051: I18n
052: .addOnLanguageChangedListener(new LanguageChangedListener() {
053: public void languageChanged(LanguageChangedEvent evt) {
054: applyI18n();
055: }
056: });
057:
058: }
059:
060: public void updateProblemsList() {
061: JReportFrame rf = MainFrame.getMainInstance()
062: .getActiveReportFrame();
063:
064: if (rf != null) {
065: setProblems(rf.getReportProblems());
066: } else {
067: DefaultTableModel dtm = (DefaultTableModel) jTable1
068: .getModel();
069: dtm.setRowCount(0);
070: }
071: this .updateUI();
072: }
073:
074: public void setProblems(java.util.List problems) {
075: DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
076: dtm.setRowCount(0);
077: for (int i = 0; i < problems.size(); ++i) {
078: ProblemItem pi = (ProblemItem) problems.get(i);
079: addProblem(pi);
080: }
081:
082: updateName();
083: }
084:
085: public void addProblem(ProblemItem pi) {
086: String pWhere = pi.getWhere();
087: String location = "";
088: if (pi.getProblemReference() != null
089: && pi.getProblemReference() instanceof SourceLocation) {
090: SourceLocation sl = (SourceLocation) pi
091: .getProblemReference();
092: location = I18n
093: .getFormattedString(
094: "LineColumn",
095: "Line {0,number,integer}, Column {1,number,integer}",
096: new Object[] {
097: new Integer(sl.getLineNumber()),
098: new Integer(sl.getColumnNumber()) });
099: }
100: DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
101: dtm.addRow(new Object[] { pi, pi.getDescription(), location,
102: pWhere });
103: }
104:
105: /** This method is called from within the constructor to
106: * initialize the form.
107: * WARNING: Do NOT modify this code. The content of this method is
108: * always regenerated by the Form Editor.
109: */
110: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
111: private void initComponents() {
112: java.awt.GridBagConstraints gridBagConstraints;
113:
114: jScrollPane1 = new javax.swing.JScrollPane();
115: jTable1 = new javax.swing.JTable();
116:
117: setLayout(new java.awt.GridBagLayout());
118:
119: jScrollPane1.setBackground(new java.awt.Color(255, 255, 255));
120: jTable1.setModel(new javax.swing.table.DefaultTableModel(
121: new Object[][] {
122:
123: }, new String[] { " ", "Description", "Location",
124: "Element" }) {
125: Class[] types = new Class[] { java.lang.Object.class,
126: java.lang.String.class, java.lang.Object.class,
127: java.lang.Object.class };
128: boolean[] canEdit = new boolean[] { false, false, false,
129: false };
130:
131: public Class getColumnClass(int columnIndex) {
132: return types[columnIndex];
133: }
134:
135: public boolean isCellEditable(int rowIndex, int columnIndex) {
136: return canEdit[columnIndex];
137: }
138: });
139: jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
140: public void mouseClicked(java.awt.event.MouseEvent evt) {
141: jTable1MouseClicked(evt);
142: }
143: });
144:
145: jScrollPane1.setViewportView(jTable1);
146:
147: gridBagConstraints = new java.awt.GridBagConstraints();
148: gridBagConstraints.gridx = 0;
149: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
150: gridBagConstraints.weightx = 1.0;
151: gridBagConstraints.weighty = 1.0;
152: add(jScrollPane1, gridBagConstraints);
153:
154: }// </editor-fold>//GEN-END:initComponents
155:
156: private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
157:
158: System.out.flush();
159: if (evt.getClickCount() == 2
160: && SwingUtilities.isLeftMouseButton(evt)) {
161:
162: if (jTable1.getSelectedRow() >= 0) {
163: ProblemItem pi = (ProblemItem) jTable1.getValueAt(
164: jTable1.getSelectedRow(), 0);
165: errorLocator.parseError(pi.getWhere(), pi
166: .getDescription());
167: }
168: }
169: }//GEN-LAST:event_jTable1MouseClicked
170:
171: public void reportFrameActivated(ReportFrameActivatedEvent evt) {
172: if (evt.getReportFrame() != null) {
173: setProblems(evt.getReportFrame().getReportProblems());
174: } else {
175: DefaultTableModel dtm = (DefaultTableModel) jTable1
176: .getModel();
177: dtm.setRowCount(0);
178: }
179:
180: errorLocator.setJReportFrame(evt.getReportFrame());
181: }
182:
183: public void updateName() {
184: setName(I18n.getFormattedString("problems",
185: "Problems ({0,number})", new Object[] { new Integer(
186: jTable1.getRowCount()) }));
187:
188: if (this .getParent() != null
189: && this .getParent() instanceof JTabbedPane) {
190: JTabbedPane tp = (JTabbedPane) this .getParent();
191: try {
192:
193: if (jTable1.getRowCount() > 0) {
194: tp.setIconAt(1,
195: ProblemIconTableCellRenderer.errorIcon);
196: tp.setTitleAt(1, "<html><font color=\"red\">"
197: + getName());
198: } else {
199: tp.setIconAt(1, null);
200: tp.setTitleAt(1, getName());
201: }
202:
203: } catch (Exception ex) {
204:
205: }
206: }
207: }
208:
209: public void applyI18n() {
210: jTable1.getColumnModel().getColumn(1).setHeaderValue(
211: I18n.getString("problemsPanel.table.description",
212: "Description"));
213: jTable1.getColumnModel().getColumn(2).setHeaderValue(
214: I18n.getString("problemsPanel.table.location",
215: "JRXML location"));
216: jTable1.getColumnModel().getColumn(3).setHeaderValue(
217: I18n.getString("problemsPanel.table.object", "Object"));
218: }
219:
220: // Variables declaration - do not modify//GEN-BEGIN:variables
221: private javax.swing.JScrollPane jScrollPane1;
222: private javax.swing.JTable jTable1;
223: // End of variables declaration//GEN-END:variables
224:
225: }
|