001 /* 002 * This program is free software; you can redistribute it and/or modify 003 * it under the terms of the GNU General Public License as published by 004 * the Free Software Foundation; version 2 of the License. 005 * 006 * This program is distributed in the hope that it will be useful, 007 * but WITHOUT ANY WARRANTY; without even the implied warranty of 008 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 009 * GNU General Public License for more details. 010 * 011 * You should have received a copy of the GNU General Public License along 012 * with this program; if not, write to the Free Software Foundation, Inc., 013 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 014 */ 015 package org.tastybug.bugwerk.bugtrail.widget.queue; 016 017 import java.util.Arrays; 018 import java.util.Iterator; 019 020 import javax.swing.JTable; 021 import javax.swing.ListSelectionModel; 022 023 import org.tastybug.bugwerk.blueprint.event.TicketChangeListener; 024 import org.tastybug.bugwerk.blueprint.model.Incident; 025 import org.tastybug.bugwerk.blueprint.model.Ticket; 026 import org.tastybug.bugwerk.blueprint.model.TicketQueue; 027 import org.tastybug.bugwerk.bugtrap.base.worker.QueueWorker; 028 import org.tastybug.bugwerk.bugtrap.base.worker.QueueWorkerListener; 029 030 /** 031 * This JTable displays the number of all- / unreported tickets in the connected ticket queue. 032 * <br> 033 * Internally, the table is a <code>QueueWorker</code>, i.e. it listens for activity on the queue 034 * and refreshes the content upon necessity. The table is not editable. 035 * <br> 036 * Use it like this: 037 * <pre> 038 * TicketQueueStatisticsTable table = new TicketQueueStatisticsTable(); 039 * table.connectQueue(Adapters.getAdapter("myProject").getTicketQueue()); 040 * </pre> 041 * <br> 042 * 043 * <hr> 044 * Copyright 2006 Philipp Bartsch.<br> 045 * <a href="http://www.tastybug.com">www.tastybug.com</a><br> 046 * <hr> 047 * Created on Feb 9, 2006<br> 048 * @author Philipp Bartsch, philipp.bartsch{at}tastybug{dot}com</a> 049 */ 050 public class TicketQueueStatisticsTable extends JTable implements QueueWorker, TicketChangeListener { 051 052 /**The <code>serialVersionUID</code>*/ 053 private static final long serialVersionUID = -3098845399152685004L; 054 055 private TicketQueue ticketQueue; 056 private TicketQueueStatisticsTableModel tableModel; 057 private TicketQueueStatisticsTableRenderer tableRenderer; 058 059 060 /** 061 * Creates the table. Renderer and model are embedded as soon as the target 062 * ticket queue is declared. 063 */ 064 public TicketQueueStatisticsTable () { 065 setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 066 } 067 068 /** 069 * Updates table model and UI. 070 * 071 * @see org.tastybug.bugwerk.blueprint.event.TicketQueueChangeListener#performTicketRemovedEvent(org.tastybug.bugwerk.blueprint.event.TicketQueueChangeListener.TicketQueueEvent) 072 */ 073 public void performTicketRemovedEvent(TicketQueueEvent event) { 074 tableModel.update(); 075 updateUI(); 076 } 077 078 /** 079 * Updates table model and UI. 080 * 081 * @see org.tastybug.bugwerk.blueprint.event.TicketQueueChangeListener#performTicketAddedEvent(org.tastybug.bugwerk.blueprint.event.TicketQueueChangeListener.TicketQueueEvent) 082 */ 083 public void performTicketAddedEvent(TicketQueueEvent event) { 084 tableModel.update(); 085 updateUI(); 086 } 087 088 /** 089 * Updates table model and UI. 090 * 091 * @see org.tastybug.bugwerk.blueprint.event.TicketChangeListener#performIncidentRemovedEvent(org.tastybug.bugwerk.blueprint.event.TicketChangeListener.IncidentEvent) 092 */ 093 public void performIncidentRemovedEvent(IncidentEvent event) { 094 updateUI(); 095 } 096 097 /** 098 * Updates table model and UI. 099 * 100 * @see org.tastybug.bugwerk.blueprint.event.TicketChangeListener#performIncidentAddedEvent(org.tastybug.bugwerk.blueprint.event.TicketChangeListener.IncidentEvent) 101 */ 102 public void performIncidentAddedEvent(IncidentEvent event) { 103 updateUI(); 104 } 105 106 /** 107 * Updates table model and UI. 108 * 109 * @see org.tastybug.bugwerk.blueprint.event.TicketChangeListener#performTicketChangedEvent(org.tastybug.bugwerk.blueprint.event.TicketChangeListener.TicketChangeEvent) 110 */ 111 public void performTicketChangedEvent(TicketChangeEvent event) { 112 updateUI(); 113 } 114 115 /** 116 * Registers the queue that is to be displayed; former queue will be dropped. 117 * 118 * @see org.tastybug.bugwerk.bugtrap.base.worker.QueueWorker#connectQueue(org.tastybug.bugwerk.blueprint.model.TicketQueue) 119 */ 120 public void connectQueue(TicketQueue queue) { 121 // unregister from the old queue when necessary 122 if (ticketQueue != null) 123 for (Iterator tickets = Arrays.asList(ticketQueue.getTickets()).iterator(); tickets.hasNext();) 124 ((Ticket)tickets.next()).removeTicketChangeListener(this); 125 ticketQueue = queue; 126 tableModel = new TicketQueueStatisticsTableModel(ticketQueue); 127 tableRenderer = new TicketQueueStatisticsTableRenderer(); 128 129 setModel(tableModel); 130 setDefaultRenderer(String.class, tableRenderer); 131 132 // als listener an der queue anmelden 133 ticketQueue.addTicketQueueChangeListener(this); 134 135 for (Iterator tickets = Arrays.asList(ticketQueue.getTickets()).iterator(); tickets.hasNext();) 136 ((Ticket)tickets.next()).addTicketChangeListener(this); 137 138 updateUI(); 139 } 140 141 /** 142 * Does nothing as you cannot listen to this queue worker. 143 * 144 * @see org.tastybug.bugwerk.bugtrap.base.worker.QueueWorker#addQueueWorkerListener(org.tastybug.bugwerk.bugtrap.base.worker.QueueWorkerListener) 145 */ 146 public void addQueueWorkerListener(QueueWorkerListener qwListener) { 147 // ignored 148 } 149 150 /** 151 * Does nothing as you cannot listen to this queue worker. 152 * 153 * @see org.tastybug.bugwerk.bugtrap.base.worker.QueueWorker#removeQueueWorkerListener(org.tastybug.bugwerk.bugtrap.base.worker.QueueWorkerListener) 154 */ 155 public boolean removeQueueWorkerListener(QueueWorkerListener qwListener) { 156 return true; 157 } 158 159 /** 160 * Returns an empty array. 161 * 162 * @see org.tastybug.bugwerk.bugtrap.base.worker.QueueWorker#getQueueWorkerListeners() 163 */ 164 public QueueWorkerListener[] getQueueWorkerListeners() { 165 return new QueueWorkerListener[0]; 166 } 167 168 /** 169 * Updates table model and UI. 170 * 171 * @see org.tastybug.bugwerk.bugtrap.base.worker.QueueWorker#processQueue(boolean) 172 */ 173 public void processQueue(boolean isUserDriven) { 174 updateUI(); 175 } 176 177 /** 178 * Does nothing. 179 * 180 * @see org.tastybug.bugwerk.bugtrap.base.worker.QueueWorker#fireIncidentProcessedEvent(org.tastybug.bugwerk.blueprint.model.Incident, boolean, java.lang.String) 181 */ 182 public void fireIncidentProcessedEvent(Incident arg0, boolean arg1, String arg2) { 183 // 184 } 185 186 /** 187 * Does nothing. 188 * 189 * @see org.tastybug.bugwerk.bugtrap.base.worker.QueueWorker#fireTicketProcessedEvent(org.tastybug.bugwerk.blueprint.model.Ticket, boolean, java.lang.String) 190 */ 191 public void fireTicketProcessedEvent(Ticket arg0, boolean arg1, String arg2) { 192 // 193 } 194 }