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.ticket;
016    
017    import javax.swing.JTable;
018    import javax.swing.ListSelectionModel;
019    
020    import org.tastybug.bugwerk.blueprint.event.TicketChangeListener;
021    import org.tastybug.bugwerk.blueprint.model.Ticket;
022    
023    /**
024     * This class is a JTable based display of the base data of a <code>Ticket</code>.
025     * <br>
026     * The table listens for changes at the <code>Ticket</code>, but cannot be edited.
027     * 
028     * <hr>
029     * Copyright 2006 Philipp Bartsch.<br>
030     * <a href="http://www.tastybug.com">www.tastybug.com</a><br>
031     * <hr>
032     * Created on Feb 8, 2006<br>
033     * @author Philipp Bartsch, philipp.bartsch{at}tastybug{dot}com</a>
034     */
035    public class TicketTable extends JTable implements TicketChangeListener {
036    
037        /**The <code>serialVersionUID</code>*/
038        private static final long serialVersionUID = -4230389323961595090L;
039        
040        private TicketTableModel    tableModel;
041        private TicketTableRenderer tableRenderer;
042        
043        /**
044         * Creates the table, displaying the given <code>ticket</code>.
045         *
046         * @param ticket the ticket
047         */
048        public TicketTable (Ticket ticket) {
049            setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
050            tableModel = new TicketTableModel(ticket);
051            tableRenderer = new TicketTableRenderer();
052            
053            setModel(tableModel);
054            setDefaultRenderer(String.class, tableRenderer);
055        }
056    
057        /**
058         * Ignored.
059         *
060         * @see org.tastybug.bugwerk.blueprint.event.TicketChangeListener#performIncidentRemovedEvent(org.tastybug.bugwerk.blueprint.event.TicketChangeListener.IncidentEvent)
061         */
062        public void performIncidentRemovedEvent(IncidentEvent event) {
063            // not interesting
064        }
065    
066        /**
067         * Ignored.
068         *
069         * @see org.tastybug.bugwerk.blueprint.event.TicketChangeListener#performIncidentAddedEvent(org.tastybug.bugwerk.blueprint.event.TicketChangeListener.IncidentEvent)
070         */
071        public void performIncidentAddedEvent(IncidentEvent event) {
072            // not interesting
073        }
074    
075        /**
076         * Updates the UI, notifies the model to reread the changed <code>Ticket</code>.
077         *
078         * @see org.tastybug.bugwerk.blueprint.event.TicketChangeListener#performTicketChangedEvent(org.tastybug.bugwerk.blueprint.event.TicketChangeListener.TicketChangeEvent)
079         */
080        public void performTicketChangedEvent(TicketChangeEvent event) {
081            // neu malen. das model kriegt die aenderung automatisch mit...
082            tableModel.update(event.getTicket());
083            updateUI();
084        }    
085    }