0001: /*
0002: This file is part of BORG.
0003:
0004: BORG is free software; you can redistribute it and/or modify
0005: it under the terms of the GNU General Public License as published by
0006: the Free Software Foundation; either version 2 of the License, or
0007: (at your option) any later version.
0008:
0009: BORG is distributed in the hope that it will be useful,
0010: but WITHOUT ANY WARRANTY; without even the implied warranty of
0011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012: GNU General Public License for more details.
0013:
0014: You should have received a copy of the GNU General Public License
0015: along with BORG; if not, write to the Free Software
0016: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0017:
0018: Copyright 2003 by Mike Berger
0019: */
0020:
0021: package net.sf.borg.ui.task;
0022:
0023: import java.awt.Color;
0024: import java.awt.Component;
0025: import java.awt.FlowLayout;
0026: import java.awt.GridBagConstraints;
0027: import java.awt.GridBagLayout;
0028: import java.awt.event.ActionListener;
0029: import java.util.Collection;
0030: import java.util.Date;
0031: import java.util.Iterator;
0032: import java.util.TreeSet;
0033: import java.util.Vector;
0034:
0035: import javax.swing.ImageIcon;
0036: import javax.swing.JButton;
0037: import javax.swing.JCheckBox;
0038: import javax.swing.JComboBox;
0039: import javax.swing.JLabel;
0040: import javax.swing.JMenu;
0041: import javax.swing.JMenuBar;
0042: import javax.swing.JMenuItem;
0043: import javax.swing.JOptionPane;
0044: import javax.swing.JPanel;
0045: import javax.swing.JScrollPane;
0046: import javax.swing.JTable;
0047: import javax.swing.ListSelectionModel;
0048: import javax.swing.event.TableModelEvent;
0049: import javax.swing.table.TableCellRenderer;
0050:
0051: import net.sf.borg.common.Errmsg;
0052: import net.sf.borg.common.Resource;
0053: import net.sf.borg.model.CategoryModel;
0054: import net.sf.borg.model.Model;
0055: import net.sf.borg.model.TaskModel;
0056: import net.sf.borg.model.TaskTypes;
0057: import net.sf.borg.model.beans.Project;
0058: import net.sf.borg.model.beans.Task;
0059: import net.sf.borg.ui.MultiView;
0060: import net.sf.borg.ui.ResourceHelper;
0061: import net.sf.borg.ui.util.PopupMenuHelper;
0062: import net.sf.borg.ui.util.StripedTable;
0063: import net.sf.borg.ui.util.TablePrinter;
0064: import net.sf.borg.ui.util.TableSorter;
0065:
0066: /**
0067: *
0068: * @author MBERGER
0069: * @version
0070: */
0071:
0072: // task tracker main window
0073: // this view shows a list of tasks in a table format with all kinds
0074: // of sorting/filtering options. It is really like the "main" window
0075: // for a whole task traking application separate from the calendar
0076: // application. In prior non-java versions of BORG, the task tracker
0077: // and calendar apps were completely separate apps.
0078: public class TaskListPanel extends JPanel implements Model.Listener {
0079:
0080: // override class for the default table cell renderer that will change
0081: // the
0082: // colors of table cells
0083: // based on days left before due date
0084: private class DLRenderer extends JLabel implements
0085: TableCellRenderer {
0086:
0087: public DLRenderer() {
0088: super ();
0089: setOpaque(true); // MUST do this for background to show up.
0090: }
0091:
0092: public Component getTableCellRendererComponent(JTable table,
0093: Object obj, boolean isSelected, boolean hasFocus,
0094: int row, int column) {
0095:
0096: JLabel l = (JLabel) defrend_.getTableCellRendererComponent(
0097: table, obj, isSelected, hasFocus, row, column);
0098:
0099: if (obj == null) {
0100: l.setText("--");
0101: l.setHorizontalAlignment(CENTER);
0102: return l;
0103: }
0104:
0105: String nm = table.getColumnName(column);
0106: if (!nm.equals(Resource.getPlainResourceString("Pri"))
0107: && !nm.equals(Resource
0108: .getPlainResourceString("Days_Left")))
0109: return l;
0110:
0111: if (isSelected
0112: && !nm.equals(Resource
0113: .getPlainResourceString("Days_Left")))
0114: return l;
0115:
0116: this .setText(l.getText());
0117: this .setHorizontalAlignment(CENTER);
0118: this .setBackground(l.getBackground());
0119: this .setForeground(l.getForeground());
0120:
0121: int i = ((Integer) obj).intValue();
0122:
0123: // priority
0124: if (nm.equals(Resource.getPlainResourceString("Pri"))) {
0125:
0126: if (i == 1) {
0127: this .setBackground(new Color(255, 120, 120));
0128: } else if (i == 2) {
0129: this .setBackground(new Color(255, 200, 120));
0130: } else if (i == 3) {
0131: this .setBackground(new Color(255, 255, 175));
0132: } else if (i == 4) {
0133: this .setBackground(new Color(220, 220, 255));
0134: } else if (i == 5) {
0135: this .setBackground(new Color(200, 255, 175));
0136: }
0137: return this ;
0138: }
0139:
0140: if (isSelected)
0141: return this ;
0142:
0143: // yellow alert -- <10 days left
0144: if (i < 10)
0145: this .setBackground(new Color(255, 255, 175));
0146:
0147: if (i < 5)
0148: this .setBackground(new Color(255, 200, 120));
0149:
0150: // red alert -- <2 days left
0151: if (i < 2) {
0152: this .setBackground(new Color(255, 120, 120));
0153: }
0154:
0155: return this ;
0156: }
0157: }
0158:
0159: private JMenuItem add = new JMenuItem();
0160:
0161: private JButton addbutton = null;
0162:
0163: private JPanel buttonPanel = null;
0164:
0165: private JCheckBox caseBox = null;
0166:
0167: private JMenuItem change = new JMenuItem();
0168:
0169: private JButton changebutton1 = null;
0170:
0171: private JMenuItem clone = new JMenuItem();
0172:
0173: private JButton clonebutton1 = null;
0174:
0175: private JMenuItem close = new JMenuItem();
0176:
0177: private JButton closebutton1 = null;
0178:
0179: private TableCellRenderer defrend_;
0180:
0181: private JMenuItem delete = new JMenuItem();
0182:
0183: private JButton deletebutton1 = null;
0184:
0185: /**
0186: * This method initializes jPanel2
0187: *
0188: * @return javax.swing.JPanel
0189: */
0190: private JPanel jPanel2 = null;
0191:
0192: private javax.swing.JTextField jTextField3;
0193:
0194: private JComboBox statusBox = null;
0195:
0196: private JLabel statusLabel = null;
0197:
0198: private StripedTable taskTable;
0199:
0200: JComboBox projectBox = null;
0201:
0202: /** Creates new form btgui */
0203: public TaskListPanel() {
0204: super ();
0205: TaskModel.getReference().addListener(this );
0206: try {
0207: initComponents();
0208: taskTable
0209: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
0210: } catch (Exception e) {
0211: // TODO Auto-generated catch block
0212: Errmsg.errmsg(e);
0213: return;
0214: }
0215:
0216: }
0217:
0218: public void print() {
0219:
0220: // print the current table of tasks
0221: try {
0222: TablePrinter.printTable(taskTable);
0223: } catch (Exception e) {
0224: Errmsg.errmsg(e);
0225: }
0226: }
0227:
0228: // refresh is called to update the table of shown tasks due to model
0229: // changes
0230: // or if the user
0231: // changes the filtering criteria
0232: public void refresh() {
0233:
0234: int row = 0;
0235:
0236: // reload project filter
0237: Object o = projectBox.getSelectedItem();
0238: try {
0239: loadProjectBox();
0240: } catch (Exception e1) {
0241: Errmsg.errmsg(e1);
0242: return;
0243: }
0244: if (o != null)
0245: projectBox.setSelectedItem(o);
0246:
0247: // clear all table rows
0248: deleteAll();
0249:
0250: // get any filter string the user has typed
0251: String filt = filter();
0252:
0253: String statfilt = (String) statusBox.getSelectedItem();
0254:
0255: String projfilt = (String) projectBox.getSelectedItem();
0256: Integer projfiltid = null;
0257: if (!projfilt.equals(Resource.getPlainResourceString("All"))) {
0258: try {
0259: projfiltid = TaskView.getProjectId(projfilt);
0260: } catch (Exception e) {
0261: Errmsg.errmsg(e);
0262: return;
0263: }
0264: }
0265:
0266: try {
0267: TaskModel taskmod_ = TaskModel.getReference();
0268: TaskTypes tasktypes = taskmod_.getTaskTypes();
0269: Collection tasks = taskmod_.getTasks();
0270: Iterator ti = tasks.iterator();
0271: while (ti.hasNext()) {
0272:
0273: Task task = (Task) ti.next();
0274:
0275: // get the task state
0276: String st = task.getState();
0277:
0278: if (statfilt.equals(Resource
0279: .getPlainResourceString("All_Open"))) {
0280: if (TaskModel.isClosed(task)) {
0281: continue;
0282: }
0283: } else if (!statfilt.equals(Resource
0284: .getPlainResourceString("All"))
0285: && !statfilt.equals(st))
0286: continue;
0287:
0288: Integer pid = task.getProject();
0289: if (projfiltid != null) {
0290: if (pid == null
0291: || pid.intValue() != projfiltid.intValue())
0292: continue;
0293: }
0294:
0295: // category
0296: if (!CategoryModel.getReference().isShown(
0297: task.getCategory()))
0298: continue;
0299:
0300: // filter on user filter string
0301: if (filt.length() != 0) {
0302:
0303: // check if string is in description
0304: // or resolution
0305: String d = task.getDescription();
0306: String r = task.getResolution();
0307:
0308: if (r == null)
0309: r = "";
0310: if (d == null)
0311: d = "";
0312:
0313: if (caseBox.isSelected()) {
0314: if (d.indexOf(filt) == -1
0315: && r.indexOf(filt) == -1)
0316: continue;
0317: } else {
0318: String lfilt = filt.toLowerCase();
0319: String ld = d.toLowerCase();
0320: String lr = r.toLowerCase();
0321: if (ld.indexOf(lfilt) == -1
0322: && lr.indexOf(lfilt) == -1)
0323: continue;
0324: }
0325:
0326: }
0327:
0328: // if we get here - we are displaying this task as a row
0329: // so fill in an array of objects for the row
0330: Object[] ro = new Object[12];
0331: ro[0] = task.getTaskNumber(); // task number
0332: ro[1] = task.getState(); // task state
0333: ro[2] = task.getType(); // task type
0334: ro[3] = task.getCategory();
0335: ro[4] = task.getPriority();
0336: ro[5] = task.getStartDate(); // task start date
0337: ro[6] = task.getDueDate(); // task due date
0338:
0339: if (task.getDueDate() != null) {
0340: ro[7] = new Integer(TaskModel.daysBetween(task
0341: .getStartDate(), task.getDueDate()));
0342: } else {
0343: ro[7] = null;
0344: }
0345:
0346: // calc elapsed time
0347: Date end = null;
0348: if (task.getState().equals(
0349: tasktypes.getFinalState(task.getType()))) {
0350: end = task.getCD();
0351: } else {
0352: end = new Date();
0353: }
0354:
0355: if (end == null) {
0356: ro[8] = null;
0357: } else {
0358: ro[8] = new Integer(TaskModel.daysBetween(task
0359: .getStartDate(), end));
0360: }
0361:
0362: // calculate days left - today - duedate
0363: if (ro[6] == null)
0364: ro[9] = null;
0365: else {
0366: Date dd = (Date) ro[6];
0367: ro[9] = new Integer(TaskModel.daysLeft(dd));
0368: }
0369:
0370: // strip newlines from the description
0371: String de = task.getDescription();
0372: String tmp = "";
0373: for (int i = 0; de != null && i < de.length(); i++) {
0374: char c = de.charAt(i);
0375: if (c == '\n' || c == '\r') {
0376: tmp += ' ';
0377: continue;
0378: }
0379:
0380: tmp += c;
0381: }
0382: ro[10] = tmp;
0383:
0384: String ps = "";
0385:
0386: if (pid != null) {
0387: Project p = TaskModel.getReference().getProject(
0388: pid.intValue());
0389: if (p != null) {
0390: String tt = p.getDescription();
0391:
0392: for (int i = 0; tt != null && i < tt.length(); i++) {
0393: char c = tt.charAt(i);
0394: if (c == '\n' || c == '\r') {
0395: ps += ' ';
0396: continue;
0397: }
0398:
0399: ps += c;
0400: }
0401: }
0402: }
0403:
0404: ro[11] = ps;
0405:
0406: // add the task row to table
0407: addRow(taskTable, ro);
0408: row++;
0409: }
0410:
0411: } catch (Exception e) {
0412: Errmsg.errmsg(e);
0413: }
0414:
0415: // apply default sort to the table
0416: defsort();
0417: }
0418:
0419: public void showTasksForProject(Project p) {
0420:
0421: statusBox.setSelectedIndex(0);
0422: String ps = TaskView.getProjectString(p);
0423: projectBox.setSelectedItem(ps);
0424: refresh();
0425:
0426: }
0427:
0428: private void addActionPerformed(java.awt.event.ActionEvent evt) {
0429: // ask controller to bring up new task editor
0430:
0431: task_add();
0432: }
0433:
0434: // add a row to the sorted table
0435: private void addRow(JTable t, Object[] ro) {
0436: TableSorter tm = (TableSorter) t.getModel();
0437: tm.addRow(ro);
0438: tm.tableChanged(new TableModelEvent(tm));
0439: }
0440:
0441: private void changeActionPerformed(java.awt.event.ActionEvent evt) {
0442:
0443: // get task number from column 0 of selected row
0444: int row = taskTable.getSelectedRow();
0445: if (row == -1)
0446: return;
0447: TableSorter tm = (TableSorter) taskTable.getModel();
0448: Integer num = (Integer) tm.getValueAt(row, 0);
0449:
0450: // ask borg class to bring up a task editor window
0451: task_change(num.intValue());
0452:
0453: }
0454:
0455: private void cloneActionPerformed(java.awt.event.ActionEvent evt) {
0456:
0457: // get task number from column 0 of selected row
0458: int row = taskTable.getSelectedRow();
0459: if (row == -1)
0460: return;
0461: TableSorter tm = (TableSorter) taskTable.getModel();
0462: Integer num = (Integer) tm.getValueAt(row, 0);
0463:
0464: // ask borg class to bring up a task editor window
0465: task_clone(num.intValue());
0466:
0467: }
0468:
0469: private void closeActionPerformed(java.awt.event.ActionEvent evt) {
0470:
0471: // get the task number from column 0 of the selected row
0472: int row = taskTable.getSelectedRow();
0473: if (row == -1)
0474: return;
0475: TableSorter tm = (TableSorter) taskTable.getModel();
0476: Integer num = (Integer) tm.getValueAt(row, 0);
0477: try {
0478: TaskModel.getReference().close(num.intValue());
0479: } catch (Exception e) {
0480: Errmsg.errmsg(e);
0481: }
0482:
0483: }
0484:
0485: // do the default sort - by days left - column 5
0486: private void defsort() {
0487: TableSorter tm = (TableSorter) taskTable.getModel();
0488: if (!tm.isSorted())
0489: tm.sortByColumn(6);
0490: else
0491: tm.sort();
0492: }
0493:
0494: private void deleteActionPerformed(java.awt.event.ActionEvent evt) {
0495:
0496: // delete selected row
0497:
0498: // get task number from column 0 of the selected row
0499: int row = taskTable.getSelectedRow();
0500: if (row == -1)
0501: return;
0502: TableSorter tm = (TableSorter) taskTable.getModel();
0503: Integer num = (Integer) tm.getValueAt(row, 0);
0504:
0505: // prompt for ok
0506: int ret = JOptionPane.showConfirmDialog(null, Resource
0507: .getResourceString("Really_delete_number_")
0508: + num, "", JOptionPane.YES_NO_OPTION);
0509: if (ret == JOptionPane.YES_OPTION) {
0510: // delete the task
0511: try {
0512: TaskModel taskmod_ = TaskModel.getReference();
0513: taskmod_.delete(num.intValue());
0514: } catch (Exception e) {
0515: Errmsg.errmsg(e);
0516: }
0517: }
0518:
0519: }
0520:
0521: // delete all rows from the sorted table
0522: private void deleteAll() {
0523: TableSorter tm = (TableSorter) taskTable.getModel();
0524: tm.setRowCount(0);
0525: tm.tableChanged(new TableModelEvent(tm));
0526: }
0527:
0528: // get the filter string typed by the user
0529: private String filter() {
0530: return (jTextField3.getText());
0531: }
0532:
0533: /**
0534: * This method initializes addbutton
0535: *
0536: * @return javax.swing.JButton
0537: */
0538: private JButton getAddbutton() {
0539: if (addbutton == null) {
0540: addbutton = new JButton();
0541: addbutton.setText(Resource.getPlainResourceString("Add"));
0542: addbutton.setIcon(new ImageIcon(getClass().getResource(
0543: "/resource/Add16.gif")));
0544: addbutton
0545: .addActionListener(new java.awt.event.ActionListener() {
0546: public void actionPerformed(
0547: java.awt.event.ActionEvent e) {
0548: task_add();
0549: }
0550: });
0551: }
0552: return addbutton;
0553: }
0554:
0555: private ActionListener getAL(JMenuItem mnuitm) {
0556: return mnuitm.getActionListeners()[0];
0557: }
0558:
0559: /**
0560: * This method initializes buttonPanel
0561: *
0562: * @return javax.swing.JPanel
0563: */
0564: private JPanel getButtonPanel() {
0565: if (buttonPanel == null) {
0566: buttonPanel = new JPanel();
0567: buttonPanel.setLayout(new FlowLayout());
0568: buttonPanel.add(getAddbutton(), null);
0569: buttonPanel.add(getChangebutton1(), null);
0570: buttonPanel.add(getDeletebutton1(), null);
0571: buttonPanel.add(getClosebutton1(), null);
0572: buttonPanel.add(getClonebutton1(), null);
0573: }
0574: return buttonPanel;
0575: }
0576:
0577: /**
0578: * This method initializes caseBox
0579: *
0580: * @return javax.swing.JCheckBox
0581: */
0582: private JCheckBox getCaseBox() {
0583: if (caseBox == null) {
0584: caseBox = new JCheckBox();
0585: caseBox.setText(Resource
0586: .getResourceString("case_sensitive"));
0587: }
0588: return caseBox;
0589: }
0590:
0591: /**
0592: * This method initializes changebutton1
0593: *
0594: * @return javax.swing.JButton
0595: */
0596: private JButton getChangebutton1() {
0597: if (changebutton1 == null) {
0598: changebutton1 = new JButton();
0599: changebutton1.setIcon(new ImageIcon(getClass().getResource(
0600: "/resource/Edit16.gif")));
0601: changebutton1.setText(Resource
0602: .getPlainResourceString("Change"));
0603: changebutton1
0604: .addActionListener(new java.awt.event.ActionListener() {
0605: public void actionPerformed(
0606: java.awt.event.ActionEvent e) {
0607: changeActionPerformed(e);
0608: }
0609: });
0610: }
0611: return changebutton1;
0612: }
0613:
0614: /**
0615: * This method initializes clonebutton1
0616: *
0617: * @return javax.swing.JButton
0618: */
0619: private JButton getClonebutton1() {
0620: if (clonebutton1 == null) {
0621: clonebutton1 = new JButton();
0622: clonebutton1.setIcon(new ImageIcon(getClass().getResource(
0623: "/resource/Copy16.gif")));
0624: clonebutton1.setText(Resource
0625: .getPlainResourceString("Clone"));
0626: clonebutton1
0627: .addActionListener(new java.awt.event.ActionListener() {
0628: public void actionPerformed(
0629: java.awt.event.ActionEvent e) {
0630: cloneActionPerformed(e);
0631: }
0632: });
0633: }
0634: return clonebutton1;
0635: }
0636:
0637: /**
0638: * This method initializes closebutton1
0639: *
0640: * @return javax.swing.JButton
0641: */
0642: private JButton getClosebutton1() {
0643: if (closebutton1 == null) {
0644: closebutton1 = new JButton();
0645: closebutton1.setIcon(new ImageIcon(getClass().getResource(
0646: "/resource/greenlight.gif")));
0647: closebutton1.setText(Resource
0648: .getPlainResourceString("Close"));
0649: closebutton1
0650: .addActionListener(new java.awt.event.ActionListener() {
0651: public void actionPerformed(
0652: java.awt.event.ActionEvent e) {
0653: closeActionPerformed(e);
0654: }
0655: });
0656: }
0657: return closebutton1;
0658: }
0659:
0660: /**
0661: * This method initializes deletebutton1
0662: *
0663: * @return javax.swing.JButton
0664: */
0665: private JButton getDeletebutton1() {
0666: if (deletebutton1 == null) {
0667: deletebutton1 = new JButton();
0668: deletebutton1.setIcon(new ImageIcon(getClass().getResource(
0669: "/resource/Delete16.gif")));
0670: deletebutton1.setText(Resource
0671: .getPlainResourceString("Delete"));
0672: deletebutton1
0673: .addActionListener(new java.awt.event.ActionListener() {
0674: public void actionPerformed(
0675: java.awt.event.ActionEvent e) {
0676: deleteActionPerformed(e);
0677: }
0678: });
0679: }
0680: return deletebutton1;
0681: }
0682:
0683: private JPanel getJPanel2() throws Exception {
0684: if (jPanel2 == null) {
0685:
0686: FlowLayout flowLayout = new FlowLayout();
0687: flowLayout.setAlignment(java.awt.FlowLayout.LEFT);
0688: statusLabel = new JLabel();
0689: statusLabel.setText(Resource
0690: .getPlainResourceString("Status")
0691: + ":");
0692: jPanel2 = new JPanel();
0693: jPanel2.setLayout(flowLayout);
0694: jPanel2.add(statusLabel, null);
0695: jPanel2.add(getStatusBox(), null);
0696: JLabel plabel = new JLabel(Resource
0697: .getPlainResourceString("project")
0698: + ":");
0699: JLabel spacer = new JLabel(" ");
0700: jPanel2.add(spacer, null);
0701: jPanel2.add(plabel, null);
0702: jPanel2.add(getProjectBox());
0703: }
0704: return jPanel2;
0705: }
0706:
0707: private JComboBox getProjectBox() throws Exception {
0708: if (projectBox == null) {
0709: projectBox = new JComboBox();
0710: loadProjectBox();
0711: projectBox
0712: .addActionListener(new java.awt.event.ActionListener() {
0713: public void actionPerformed(
0714: java.awt.event.ActionEvent evt) {
0715: refresh();
0716: }
0717: });
0718: }
0719: return projectBox;
0720: }
0721:
0722: /**
0723: * This method initializes statusBox
0724: *
0725: * @return javax.swing.JComboBox
0726: */
0727: private JComboBox getStatusBox() {
0728: if (statusBox == null) {
0729: statusBox = new JComboBox();
0730: setStatuses(statusBox);
0731: statusBox
0732: .addActionListener(new java.awt.event.ActionListener() {
0733: public void actionPerformed(
0734: java.awt.event.ActionEvent evt) {
0735: refresh();
0736: }
0737: });
0738: }
0739: return statusBox;
0740: }
0741:
0742: /**
0743: * This method is called from within the constructor to initialize the form.
0744: * WARNING: Do NOT modify this code. The content of this method is always
0745: * regenerated by the FormEditor.
0746: */
0747:
0748: private void initComponents() throws Exception {
0749:
0750: initMenuBar();
0751:
0752: GridBagConstraints gridBagConstraints = new GridBagConstraints();
0753: gridBagConstraints.gridx = 0;
0754: gridBagConstraints.fill = GridBagConstraints.BOTH;
0755: gridBagConstraints.gridwidth = 5;
0756: gridBagConstraints.gridy = 4;
0757: change.setIcon(new ImageIcon(getClass().getResource(
0758: "/resource/Edit16.gif")));
0759: add.setIcon(new ImageIcon(getClass().getResource(
0760: "/resource/Add16.gif")));
0761: JScrollPane jScrollPane1 = new JScrollPane();
0762: taskTable = new StripedTable();
0763:
0764: JButton jButton21 = new JButton();
0765: jTextField3 = new javax.swing.JTextField();
0766: GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
0767: gridBagConstraints2.gridx = 4;
0768: gridBagConstraints2.gridy = 1;
0769:
0770: GridBagConstraints gridBagConstraints15 = new GridBagConstraints();
0771: GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
0772: GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
0773: GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
0774:
0775: this .setLayout(new GridBagLayout());
0776: gridBagConstraints8.gridx = 2;
0777: gridBagConstraints8.gridy = 1;
0778: gridBagConstraints8.fill = java.awt.GridBagConstraints.HORIZONTAL;
0779: gridBagConstraints8.insets = new java.awt.Insets(4, 4, 4, 4);
0780: gridBagConstraints9.gridx = 3;
0781: gridBagConstraints9.gridy = 1;
0782: gridBagConstraints9.weightx = 1.0;
0783: gridBagConstraints9.fill = java.awt.GridBagConstraints.HORIZONTAL;
0784: gridBagConstraints9.gridwidth = 1;
0785: gridBagConstraints9.insets = new java.awt.Insets(4, 4, 4, 4);
0786: gridBagConstraints11.gridx = 0;
0787: gridBagConstraints11.gridy = 3;
0788: gridBagConstraints11.weightx = 1.0;
0789: gridBagConstraints11.weighty = 1.0;
0790: gridBagConstraints11.fill = java.awt.GridBagConstraints.BOTH;
0791: gridBagConstraints11.gridwidth = 5;
0792: gridBagConstraints11.insets = new java.awt.Insets(4, 4, 4, 4);
0793: gridBagConstraints15.gridx = 0;
0794: gridBagConstraints15.gridy = 0;
0795: gridBagConstraints15.gridwidth = 5;
0796: gridBagConstraints15.fill = java.awt.GridBagConstraints.HORIZONTAL;
0797:
0798: jButton21.setIcon(new javax.swing.ImageIcon(getClass()
0799: .getResource("/resource/Find16.gif")));
0800: ResourceHelper.setText(jButton21, "Filter:");
0801: jButton21
0802: .addActionListener(new java.awt.event.ActionListener() {
0803: public void actionPerformed(
0804: java.awt.event.ActionEvent evt) {
0805: jButton21ActionPerformed(evt);
0806: }
0807: });
0808:
0809: this .add(jButton21, gridBagConstraints8);
0810: this .add(jTextField3, gridBagConstraints9);
0811: this .add(jScrollPane1, gridBagConstraints11);
0812: this .add(getJPanel2(), gridBagConstraints15);
0813:
0814: this .add(getCaseBox(), gridBagConstraints2);
0815:
0816: this .add(getButtonPanel(), gridBagConstraints);
0817:
0818: defrend_ = taskTable.getDefaultRenderer(Integer.class);
0819:
0820: // set renderer to the custom one for integers
0821: taskTable.setDefaultRenderer(Integer.class,
0822: new TaskListPanel.DLRenderer());
0823:
0824: // use a sorted table model
0825: taskTable
0826: .setModel(new TableSorter(
0827: new String[] {
0828: Resource
0829: .getPlainResourceString("Item_#"),
0830: Resource
0831: .getPlainResourceString("Status"),
0832: Resource.getPlainResourceString("Type"),
0833: Resource
0834: .getPlainResourceString("Category"),
0835: Resource.getPlainResourceString("Pri"),
0836: Resource
0837: .getPlainResourceString("Start_Date"),
0838: Resource
0839: .getPlainResourceString("Due_Date"),
0840: Resource
0841: .getPlainResourceString("duration"),
0842: Resource
0843: .getPlainResourceString("elapsed_time"),
0844: Resource
0845: .getPlainResourceString("Days_Left"),
0846: Resource
0847: .getPlainResourceString("Description"),
0848: Resource
0849: .getPlainResourceString("project") },
0850: new Class[] { java.lang.Integer.class,
0851: java.lang.String.class,
0852: java.lang.String.class,
0853: java.lang.String.class,
0854: java.lang.Integer.class, Date.class,
0855: Date.class, Integer.class,
0856: java.lang.Integer.class,
0857: java.lang.Integer.class,
0858: java.lang.String.class,
0859: java.lang.String.class }));
0860:
0861: // set up for sorting when a column header is clicked
0862: TableSorter tm = (TableSorter) taskTable.getModel();
0863: tm.addMouseListenerToHeaderInTable(taskTable);
0864:
0865: // clear all rows
0866: deleteAll();
0867:
0868: jScrollPane1.setViewportView(taskTable);
0869: jScrollPane1
0870: .setBorder(javax.swing.BorderFactory
0871: .createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
0872: taskTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
0873: // taskTable.setGridColor(java.awt.Color.blue);
0874: // taskTable.setPreferredSize(new java.awt.Dimension(1000, 500));
0875: taskTable.addMouseListener(new java.awt.event.MouseAdapter() {
0876: public void mouseClicked(java.awt.event.MouseEvent evt) {
0877: mouseClick(evt);
0878: }
0879: });
0880:
0881: new PopupMenuHelper(taskTable, new PopupMenuHelper.Entry[] {
0882: new PopupMenuHelper.Entry(getAL(add), "Add"),
0883: new PopupMenuHelper.Entry(getAL(change), "Change"),
0884: new PopupMenuHelper.Entry(getAL(clone), "Clone"),
0885: new PopupMenuHelper.Entry(getAL(delete), "Delete"),
0886: new PopupMenuHelper.Entry(getAL(close), "Close") });
0887:
0888: // set column widths
0889: // taskTable.getColumnModel().getColumn(0).setPreferredWidth(50);
0890: // taskTable.getColumnModel().getColumn(2).setPreferredWidth(80);
0891: // taskTable.getColumnModel().getColumn(3).setPreferredWidth(80);
0892: // taskTable.getColumnModel().getColumn(4).setPreferredWidth(50);
0893: taskTable.getColumnModel().getColumn(5).setPreferredWidth(100);
0894: taskTable.getColumnModel().getColumn(6).setPreferredWidth(100);
0895: // taskTable.getColumnModel().getColumn(7).setPreferredWidth(60);
0896: // taskTable.getColumnModel().getColumn(8).setPreferredWidth(60);
0897: // taskTable.getColumnModel().getColumn(9).setPreferredWidth(60);
0898: taskTable.getColumnModel().getColumn(10).setPreferredWidth(400);
0899: // taskTable.getColumnModel().getColumn(11).setPreferredWidth(80);
0900: // taskTable.setPreferredScrollableViewportSize(new Dimension(1200,
0901: // 400));
0902:
0903: refresh();
0904:
0905: }
0906:
0907: private void initMenuBar() {
0908:
0909: JMenuBar menuBar = new JMenuBar();
0910: JMenu fileMenu = new JMenu();
0911:
0912: JMenu editMenu = new JMenu();
0913:
0914: ResourceHelper.setText(fileMenu, "File");
0915:
0916: menuBar.add(fileMenu);
0917:
0918: menuBar.add(editMenu);
0919: ResourceHelper.setText(editMenu, "Action");
0920: ResourceHelper.setText(add, "Add");
0921: add.addActionListener(new java.awt.event.ActionListener() {
0922: public void actionPerformed(java.awt.event.ActionEvent evt) {
0923: addActionPerformed(evt);
0924: }
0925: });
0926:
0927: ResourceHelper.setText(change, "Change");
0928: change.addActionListener(new java.awt.event.ActionListener() {
0929: public void actionPerformed(java.awt.event.ActionEvent evt) {
0930: changeActionPerformed(evt);
0931: }
0932: });
0933:
0934: ResourceHelper.setText(clone, "Clone");
0935: clone.addActionListener(new java.awt.event.ActionListener() {
0936: public void actionPerformed(java.awt.event.ActionEvent evt) {
0937: cloneActionPerformed(evt);
0938: }
0939: });
0940:
0941: editMenu.add(clone);
0942:
0943: ResourceHelper.setText(delete, "Delete");
0944: delete.setName("delete");
0945: delete.addActionListener(new java.awt.event.ActionListener() {
0946: public void actionPerformed(java.awt.event.ActionEvent evt) {
0947: deleteActionPerformed(evt);
0948: }
0949: });
0950:
0951: editMenu.add(delete);
0952:
0953: ResourceHelper.setText(close, "Close");
0954: close.addActionListener(new java.awt.event.ActionListener() {
0955: public void actionPerformed(java.awt.event.ActionEvent evt) {
0956: closeActionPerformed(evt);
0957: }
0958: });
0959:
0960: editMenu.add(close);
0961:
0962: }
0963:
0964: private void jButton21ActionPerformed(java.awt.event.ActionEvent evt) {
0965: // just call refresh when filter button pressed
0966: refresh();
0967: }
0968:
0969: private void loadProjectBox() throws Exception {
0970: projectBox.removeAllItems();
0971: projectBox.addItem(Resource.getPlainResourceString("All"));
0972: try {
0973: Collection projects = TaskModel.getReference()
0974: .getProjects();
0975: Iterator pi = projects.iterator();
0976: while (pi.hasNext()) {
0977: Project p = (Project) pi.next();
0978: projectBox.addItem(TaskView.getProjectString(p));
0979: }
0980: }
0981: // ignore exception if projects not supported
0982: catch (Exception e) {
0983: }
0984: }
0985:
0986: private void mouseClick(java.awt.event.MouseEvent evt) {
0987:
0988: // ask controller to bring up task editor on double click
0989: if (evt.getClickCount() < 2)
0990: return;
0991:
0992: // changeActionPerformed(null);
0993: showChildren();
0994: }
0995:
0996: private void setStatuses(JComboBox s) {
0997:
0998: s.addItem(Resource.getPlainResourceString("All_Open"));
0999: s.addItem(Resource.getPlainResourceString("All"));
1000: TaskTypes t = TaskModel.getReference().getTaskTypes();
1001: TreeSet ts = new TreeSet();
1002: Vector types = t.getTaskTypes();
1003: Iterator it = types.iterator();
1004: while (it.hasNext()) {
1005: String type = (String) it.next();
1006: Collection states = t.getStates(type);
1007: Iterator it2 = states.iterator();
1008: while (it2.hasNext()) {
1009: ts.add(it2.next());
1010: }
1011: }
1012: it = ts.iterator();
1013: while (it.hasNext()) {
1014: s.addItem(it.next());
1015: }
1016: }
1017:
1018: private void showChildren() {
1019:
1020: // get task number from column 0 of selected row
1021: int row = taskTable.getSelectedRow();
1022: if (row == -1)
1023: return;
1024: TableSorter tm = (TableSorter) taskTable.getModel();
1025: Integer num = (Integer) tm.getValueAt(row, 0);
1026:
1027: // ask borg class to bring up a task editor window
1028: task_change(num.intValue());
1029:
1030: }
1031:
1032: // show task view - to add a new task
1033: private void task_add() {
1034: try {
1035: // display the task editor
1036: String projfilt = (String) projectBox.getSelectedItem();
1037: Integer projfiltid = null;
1038: if (!projfilt
1039: .equals(Resource.getPlainResourceString("All"))) {
1040: try {
1041: projfiltid = TaskView.getProjectId(projfilt);
1042: } catch (Exception e) {
1043: Errmsg.errmsg(e);
1044: return;
1045: }
1046: }
1047: MultiView.getMainView().addView(
1048: new TaskView(null, TaskView.T_ADD, projfiltid));
1049:
1050: } catch (Exception e) {
1051: Errmsg.errmsg(e);
1052: }
1053: }
1054:
1055: // show the task view - to edit a task
1056: private void task_change(int tasknum) {
1057:
1058: try {
1059: // get the task from the data model
1060: TaskModel taskmod_ = TaskModel.getReference();
1061: Task task = taskmod_.getTask(tasknum);
1062: if (task == null)
1063: return;
1064:
1065: // display the task editor
1066: MultiView.getMainView().addView(
1067: new TaskView(task, TaskView.T_CHANGE, null));
1068:
1069: } catch (Exception e) {
1070: Errmsg.errmsg(e);
1071: }
1072:
1073: }
1074:
1075: private void task_clone(int tasknum) {
1076:
1077: try {
1078: // get the task
1079: TaskModel taskmod_ = TaskModel.getReference();
1080: Task task = taskmod_.getTask(tasknum);
1081: if (task == null)
1082: return;
1083:
1084: // display the task editor
1085: MultiView.getMainView().addView(
1086: new TaskView(task, TaskView.T_CLONE, null));
1087:
1088: } catch (Exception e) {
1089: Errmsg.errmsg(e);
1090: }
1091:
1092: }
1093:
1094: public void remove() {
1095: // TODO Auto-generated method stub
1096:
1097: }
1098: }
|