1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
public abstract class TableViewerForEditors extends Composite{
private Table tab;
protected TableViewer tbv;
private ListenerControl leListenerControlTac;
private ListenerSelection leListenerSelectionTac;
protected IPreferenceStore lesPrefs;
/**
* @param parent
* @param style
* @param input
*/
public TableViewerForEditors(Composite parent, int style, Object input) {
super(parent,style);
this.setLayout(new FillLayout());
leListenerControlTac = new ListenerControl(this);
leListenerSelectionTac = new ListenerSelection(this);
createTable();
tbv = new TableViewer(tab);
createColumns();
configureViewer();
tbv.setInput(input);
miseEnForme(lesPrefs);
//Ajout des listeners
for(TableColumn tac : tab.getColumns()){
tac.addSelectionListener(this.leListenerSelectionTac);
tac.addControlListener(this.leListenerControlTac);
}
if (lesPrefs != null){
String nomClasse = getClass().getSimpleName();
String temoin = lesPrefs.getString(nomClasse + PreferencesCst.TEMOIN);
String sortKey = nomClasse+ PreferencesCst.SEP_POINT;
sortKey += PreferencesCst.SORT;
//Mise en place des tailles par défaut
if (!temoin.equalsIgnoreCase(PreferencesCst.OK)){
for(TableColumn tac : tab.getColumns()){
tac.setWidth(tac.getWidth());
}
String nomColonne = tab.getSortColumn().getText();
lesPrefs.setValue(sortKey, nomColonne);
//Mise en place de la colonne trié
}else{
String nomColonne = lesPrefs.getString(sortKey);
for(TableColumn tac : tab.getColumns()){
if (tac.getText().equalsIgnoreCase(nomColonne)){
tab.setSortColumn(tac);
}
}
}
}
}
/**
* @param lesPrefs
* Méthode permettant d'appliquer la dernière mise en forme de la vue
*/
protected void miseEnForme(IPreferenceStore lesPrefs){
if (lesPrefs != null){
String nomClasse = getClass().getSimpleName();
String temoin = lesPrefs.getString(nomClasse + PreferencesCst.TEMOIN);
if (temoin.equalsIgnoreCase(PreferencesCst.OK)){
int place = 0;
int size = 0;
String param = PreferencesCst.EMPTY;
String paramPlace = PreferencesCst.EMPTY;
String paramSize = PreferencesCst.EMPTY;
int[] order = new int[tab.getColumnCount()];
int i = 0;
//Mise en place de l'ordre des colonnes
for(TableColumn tac : tab.getColumns()){
param = nomClasse + PreferencesCst.SEP_POINT;
param += tac.getText();
paramPlace = param
+ PreferencesCst.SEP_POINT
+ PreferencesCst.PLACE;
paramSize = param
+ PreferencesCst.SEP_POINT
+ PreferencesCst.SIZE;
place = lesPrefs.getInt(paramPlace);
order[i] = place;
size = lesPrefs.getInt(paramSize);
tac.setWidth(size);
i++;
}
tab.setColumnOrder(order);
}
}
}
/**
* Méthode créant la table
*/
private void createTable(){
tab = new Table(this, SWT.NONE);
// GridData gridData = new GridData(GridData.FILL_BOTH);
// gridData.grabExcessVerticalSpace = true;
// tab.setLayoutData(gridData);
tab.setLinesVisible(true);
tab.setHeaderVisible(true);
}
/**
* <p>Méthode servant à créer toutes les colonnes de la table.</p><br>
*
* <p>à implémenter dans toute classe héritant de TableViewerForEditors.</p>
*/
protected abstract void createColumns();
/**
* <p>Méthode servant à instancier le content, le label ainsi que
* le fichier de préférences.</p> <br>
*
* <p>à implémenter dans toute classe héritant de TableViewerForEditors.</p>
*/
protected abstract void configureViewer();
/**
* @param text
* @param tooltip
* @param style
* @param sorter
* @param initialDirection
* @param keepDirection
* @param autoPack
*
* <p> Sert à créer une colonne dans la table</p><br>
* @return
*/
public TableSortSelectionListener createTableColumn(
String text,
String tooltip,
int style,
AbstractInvertableTableSorter sorter,
int initialDirection,
boolean keepDirection,
boolean autoPack)
{
return createTableColumn(text, tooltip, style, sorter, initialDirection, keepDirection, autoPack, 50);
}
/**
* @param text
* @param tooltip
* @param style
* @param sorter
* @param initialDirection
* @param keepDirection
* @param autoPack
* @param width
*
* <p> Sert à créer une colonne dans la table</p><br>
* @return
*/
public TableSortSelectionListener createTableColumn(
String text,
String tooltip,
int style,
AbstractInvertableTableSorter sorter,
int initialDirection,
boolean keepDirection,
boolean autoPack,
int width)
{
TableColumn column = new TableColumn(this.tab, style);
column.setText(text);
column.setToolTipText(tooltip);
column.setResizable(true);
column.setMoveable(true);
column.setWidth(width);
return new TableSortSelectionListener(this.tbv, column, sorter,initialDirection, keepDirection, autoPack);
}
/**
* @param text
* @param tooltip
* @param style
*
* <p> Sert à créer une colonne dans la table</p><br>
* @return
*/
public TableColumn createTableColumn(
String text,
String tooltip,
int style)
{
return createTableColumn(text,tooltip,style,50);
}
/**
* @param text
* @param tooltip
* @param style
* @param width
*
* <p> Sert à créer une colonne dans la table</p><br>
* @return
*/
public TableColumn createTableColumn(
String text,
String tooltip,
int style,
int width)
{
TableColumn column = new TableColumn(tab, style);
column.setText(text);
column.setToolTipText(tooltip);
column.setWidth(width);
TableSorter sorter2 = new TableSorter(tbv.getTable().indexOf(column));
@SuppressWarnings("unused")
TableSortSelectionListener sortListener = new TableSortSelectionListener(tbv, column, sorter2,SWT.UP, false, true);
return column;
}
/**
* @return
*/
public Table getTab() {
return tab;
}
/**
* @param tab
*/
public void setTab(Table tab) {
this.tab = tab;
}
/**
* @return
*/
public TableViewer getTbv() {
return tbv;
}
/**
* @param tbv
*/
public void setTbv(TableViewer tbv) {
this.tbv = tbv;
}
/**
* @return
*/
public IPreferenceStore getLesPrefs() {
return lesPrefs;
}
} |
Partager