View Javadoc

1   /*
2    * XMLCV - Gestion de CV sous forme XML
3    * 
4    * Copyright (C) 2004-2005, Damien Raude-Morvan
5    * 
6    * This file is part of XMLCV.
7    *
8    * XMLCV is free software; you can redistribute it and/or modify
9    * it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * XMLCV is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   *
18   * You should have received a copy of the GNU General Public License
19   * along with XMLCV; if not, write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21   * 
22   * Contacts :
23   * - Sébastien Mathy <smathy@tuxfamily.org>
24   * - Emmanuel Berre <eberre@tuxfamily.org>
25   * - Damien Raude-Morvan <drazzib@drazzib.com>
26   */
27  package org.xmlcv.gui.tables;
28  
29  import javax.swing.table.AbstractTableModel;
30  
31  import org.xmlcv.model.RealisationBean;
32  import org.xmlcv.model.AuteursBean.Auteur;
33  import org.xmlcv.model.CvDocumentBean.Cv.Realisations;
34  
35  /***
36   * @version $Revision: 114 $
37   * @author <a href="mailto:drazzib@drazzib.com">Damien Raude-Morvan</a>
38   */
39  public class ProjectsTableModel extends AbstractTableModel {
40  
41  	private static String[] columnNames = new String[] { "Titre", "Date",
42  			"Description", "Lieux", "Outils", "Auteurs"
43  
44  	};
45  
46  	private static final int TITRE = 0;
47  
48  	private static final int DATE = 1;
49  
50  	private static final int DESCRIPTION = 2;
51  
52  	private static final int LIEUX = 3;
53  
54  	private static final int OUTILS = 4;
55  
56  	private static final int AUTEURS = 5;
57  
58  	private Realisations _realisations;
59  
60  	public ProjectsTableModel(Realisations pRealisations) {
61  		assert pRealisations != null;
62  
63  		this._realisations = pRealisations;
64  	}
65  
66  	/*
67  	 * (non-Javadoc)
68  	 * 
69  	 * @see javax.swing.table.TableModel#getColumnCount()
70  	 */
71  	public int getColumnCount() {
72  		return 6;
73  	}
74  
75  	/*
76  	 * (non-Javadoc)
77  	 * 
78  	 * @see javax.swing.table.AbstractTableModel#getColumnName(int)
79  	 */
80  	public String getColumnName(int col) {
81  		return ProjectsTableModel.columnNames[col];
82  	}
83  
84  	/*
85  	 * (non-Javadoc)
86  	 * 
87  	 * @see javax.swing.table.TableModel#getRowCount()
88  	 */
89  	public int getRowCount() {
90  		return this._realisations.sizeOfRealisationArray();
91  	}
92  
93  	/*
94  	 * (non-Javadoc)
95  	 * 
96  	 * @see javax.swing.table.TableModel#getValueAt(int, int)
97  	 */
98  	public Object getValueAt(int row, int column) {
99  
100 		String label = null;
101 
102 		RealisationBean realisation = this._realisations
103 				.getRealisationArray(row);
104 
105 		switch (column) {
106 		case TITRE:
107 			if (realisation.getTitre() != null) {
108 				label = realisation.getTitre().getStringValue();
109 				// Récupération de l'URL realisation.getTitre().getUrl();
110 			}
111 			break;
112 
113 		case DATE:
114 			label = realisation.getDate();
115 			break;
116 
117 		case DESCRIPTION:
118 			if (realisation.getDescription() != null) {
119 				label = new String(realisation.getDescription()
120 						.getStringValue()).trim();
121 			}
122 			break;
123 
124 		case LIEUX:
125 			label = realisation.getLieux();
126 			break;
127 
128 		case OUTILS:
129 			label = realisation.getOutils();
130 			break;
131 
132 		case AUTEURS:
133 			if (realisation.getAuteurs() != null) {
134 				Auteur[] auteurs = realisation.getAuteurs().getAuteurArray();
135 				for (int i = 0; i < auteurs.length; i++) {
136 					if (auteurs[i].getPrenom() != null
137 							&& auteurs[i].getNom() != null) {
138 						label = label + auteurs[i].getPrenom()
139 								+ " " + auteurs[i].getNom() + " "; //$NON-NLS-1$ //$NON-NLS-2$
140 					}
141 				}
142 				label = label + "..."; //$NON-NLS-1$
143 			}
144 			break;
145 		}
146 
147 		return label;
148 
149 	}
150 
151 }