0001: /*
0002: * Copyright (c) 2004-2006, Jean-François Brazeau. All rights reserved.
0003: *
0004: * Redistribution and use in source and binary forms, with or without
0005: * modification, are permitted provided that the following conditions are met:
0006: *
0007: * 1. Redistributions of source code must retain the above copyright notice,
0008: * this list of conditions and the following disclaimer.
0009: *
0010: * 2. Redistributions in binary form must reproduce the above copyright
0011: * notice, this list of conditions and the following disclaimer in the
0012: * documentation and/or other materials provided with the distribution.
0013: *
0014: * 3. The name of the author may not be used to endorse or promote products
0015: * derived from this software without specific prior written permission.
0016: *
0017: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
0018: * IMPLIEDWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
0019: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
0020: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
0021: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
0022: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
0023: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
0024: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
0025: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
0026: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0027: */
0028: package jfb.tools.activitymgr.ui;
0029:
0030: import java.text.SimpleDateFormat;
0031: import java.util.ArrayList;
0032: import java.util.Calendar;
0033: import java.util.GregorianCalendar;
0034:
0035: import jfb.tools.activitymgr.core.DbException;
0036: import jfb.tools.activitymgr.core.ModelException;
0037: import jfb.tools.activitymgr.core.ModelMgr;
0038: import jfb.tools.activitymgr.core.beans.Collaborator;
0039: import jfb.tools.activitymgr.core.beans.Contribution;
0040: import jfb.tools.activitymgr.core.beans.Duration;
0041: import jfb.tools.activitymgr.core.beans.Task;
0042: import jfb.tools.activitymgr.core.util.StringHelper;
0043: import jfb.tools.activitymgr.ui.CollaboratorsUI.ICollaboratorListener;
0044: import jfb.tools.activitymgr.ui.DatabaseUI.IDbStatusListener;
0045: import jfb.tools.activitymgr.ui.DurationsUI.IDurationListener;
0046: import jfb.tools.activitymgr.ui.TasksUI.ITaskListener;
0047: import jfb.tools.activitymgr.ui.dialogs.DialogException;
0048: import jfb.tools.activitymgr.ui.dialogs.ITaskChooserValidator;
0049: import jfb.tools.activitymgr.ui.dialogs.TaskChooserTreeWithHistoryDialog;
0050: import jfb.tools.activitymgr.ui.util.AbstractTableMgr;
0051: import jfb.tools.activitymgr.ui.util.ICollaboratorSelectionListener;
0052: import jfb.tools.activitymgr.ui.util.SWTHelper;
0053: import jfb.tools.activitymgr.ui.util.SafeRunner;
0054: import jfb.tools.activitymgr.ui.util.SelectableCollaboratorPanel;
0055: import jfb.tools.activitymgr.ui.util.TableOrTreeColumnsMgr;
0056: import jfb.tools.activitymgr.ui.util.WeekContributions;
0057:
0058: import org.apache.log4j.Logger;
0059: import org.eclipse.jface.dialogs.Dialog;
0060: import org.eclipse.jface.viewers.CellEditor;
0061: import org.eclipse.jface.viewers.ComboBoxCellEditor;
0062: import org.eclipse.jface.viewers.DialogCellEditor;
0063: import org.eclipse.jface.viewers.IBaseLabelProvider;
0064: import org.eclipse.jface.viewers.ICellModifier;
0065: import org.eclipse.jface.viewers.IStructuredSelection;
0066: import org.eclipse.jface.viewers.ITableFontProvider;
0067: import org.eclipse.jface.viewers.LabelProviderChangedEvent;
0068: import org.eclipse.jface.viewers.StructuredSelection;
0069: import org.eclipse.jface.viewers.TableViewer;
0070: import org.eclipse.swt.SWT;
0071: import org.eclipse.swt.custom.CCombo;
0072: import org.eclipse.swt.dnd.Clipboard;
0073: import org.eclipse.swt.dnd.TextTransfer;
0074: import org.eclipse.swt.events.KeyAdapter;
0075: import org.eclipse.swt.events.KeyEvent;
0076: import org.eclipse.swt.events.KeyListener;
0077: import org.eclipse.swt.events.MenuEvent;
0078: import org.eclipse.swt.events.MenuListener;
0079: import org.eclipse.swt.events.SelectionEvent;
0080: import org.eclipse.swt.events.SelectionListener;
0081: import org.eclipse.swt.graphics.Font;
0082: import org.eclipse.swt.graphics.FontData;
0083: import org.eclipse.swt.layout.FillLayout;
0084: import org.eclipse.swt.layout.GridData;
0085: import org.eclipse.swt.layout.GridLayout;
0086: import org.eclipse.swt.widgets.Button;
0087: import org.eclipse.swt.widgets.Composite;
0088: import org.eclipse.swt.widgets.Control;
0089: import org.eclipse.swt.widgets.Event;
0090: import org.eclipse.swt.widgets.Label;
0091: import org.eclipse.swt.widgets.Menu;
0092: import org.eclipse.swt.widgets.MenuItem;
0093: import org.eclipse.swt.widgets.TabItem;
0094: import org.eclipse.swt.widgets.Table;
0095: import org.eclipse.swt.widgets.TableColumn;
0096: import org.eclipse.swt.widgets.TableItem;
0097: import org.eclipse.swt.widgets.Widget;
0098:
0099: /**
0100: * IHM de gestion des contributions.
0101: */
0102: public class ContributionsUI extends AbstractTableMgr implements
0103: IDbStatusListener, ICellModifier, SelectionListener,
0104: MenuListener, ITaskListener, ICollaboratorListener,
0105: ICollaboratorSelectionListener, IDurationListener,
0106: ITableFontProvider {
0107:
0108: /** Logger */
0109: private static Logger log = Logger.getLogger(ContributionsUI.class);
0110:
0111: /** Constantes associées aux colonnes de la table de saisie des contributions */
0112: public static final int TASK_PATH_COLUMN_IDX = 0;
0113: public static final int TASK_NAME_COLUMN_IDX = 1;
0114: public static final int MONDAY_COLUMN_IDX = 2;
0115: public static final int TUESDAY_COLUMN_IDX = 3;
0116: public static final int WEDNESDAY_COLUMN_IDX = 4;
0117: public static final int THURSDAY_COLUMN_IDX = 5;
0118: public static final int FRIDAY_COLUMN_IDX = 6;
0119: public static final int SATURDAY_COLUMN_IDX = 7;
0120: public static final int SUNDAY_COLUMN_IDX = 8;
0121: private static TableOrTreeColumnsMgr tableColsMgr;
0122:
0123: /** Objet utilisé dans le tableau pour marquer la ligne contenant les totaux des contributions */
0124: private static class WeekContributionsSum {
0125:
0126: /** Instance singleton */
0127: private static WeekContributionsSum singleton = new WeekContributionsSum();
0128:
0129: /**
0130: * Constructeur privé (singleton).
0131: */
0132: private WeekContributionsSum() {
0133: }
0134:
0135: /**
0136: * Retourne l'instance singleton de la classe.
0137: * @return l'instance singleton de la classe.
0138: */
0139: public static WeekContributionsSum getInstance() {
0140: return singleton;
0141: }
0142:
0143: }
0144:
0145: /** Initiales des jours de la semaine */
0146: private static final String[] weekDaysInitials = new String[] {
0147: "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN" };
0148:
0149: /** Viewer */
0150: private TableViewer tableViewer;
0151:
0152: /** Items de menu */
0153: private MenuItem newItem;
0154: private MenuItem removeItem;
0155: private MenuItem pasteItem;
0156: private MenuItem exportItem;
0157:
0158: /** Boutons d'action */
0159: private Button previousYearButton;
0160: private Button previousMonthButton;
0161: private Button previousWeekButton;
0162: private Button nextWeekButton;
0163: private Button nextMonthButton;
0164: private Button nextYearButton;
0165:
0166: /** Composant parent */
0167: private Composite parent;
0168:
0169: /** Liste des durées */
0170: private Duration[] durations;
0171:
0172: /** Table présentant la liste des collaborateurs */
0173: private SelectableCollaboratorPanel selectableCollaboratorPanel;
0174:
0175: /** Date associé au Lundi de la semaine */
0176: private Calendar currentMonday;
0177:
0178: /** Label contenant les dates de la semaine */
0179: private Label weekLabel;
0180:
0181: /** Popup permettant de choisir une tache */
0182: private TaskChooserTreeWithHistoryDialog taskChooserDialog;
0183:
0184: /** Editeur de durées */
0185: private ComboBoxCellEditor durationCellEditor;
0186:
0187: /** Presse papier */
0188: private Clipboard clipboard;
0189:
0190: /** Police de caractère utilisée pour les contribution */
0191: private Font normalFont;
0192:
0193: /** Police de caractère utilisée pour la ligne des totaux */
0194: private Font italicFont;
0195:
0196: /**
0197: * Constructeur permettant de placer l'IHM dans un onglet.
0198: * @param tabItem item parent.
0199: */
0200: public ContributionsUI(TabItem tabItem) {
0201: this (tabItem.getParent());
0202: tabItem.setControl(parent);
0203: clipboard = new Clipboard(tabItem.getDisplay());
0204: }
0205:
0206: /**
0207: * Constructeur par défaut.
0208: * @param parentComposite composant parent.
0209: */
0210: public ContributionsUI(Composite parentComposite) {
0211: // Création du composite parent
0212: parent = new Composite(parentComposite, SWT.NONE);
0213: parent.setLayout(new GridLayout(2, false));
0214:
0215: // Liste des collaborateurs
0216: Label collaboratorsLabel = new Label(parent, SWT.NONE);
0217: collaboratorsLabel.setText("Select a collaborator : ");
0218: GridData gridData = new GridData(SWT.FILL, SWT.FILL, false,
0219: false);
0220: gridData.verticalAlignment = SWT.CENTER;
0221: collaboratorsLabel.setLayoutData(gridData);
0222:
0223: // Date
0224: weekLabel = new Label(parent, SWT.NONE);
0225: weekLabel.setAlignment(SWT.RIGHT);
0226: gridData = new GridData(SWT.FILL, SWT.NONE, false, false);
0227: gridData.verticalAlignment = SWT.RIGHT;
0228: gridData.widthHint = 200;
0229: weekLabel.setLayoutData(gridData);
0230:
0231: // Liste des collaborateurs
0232: gridData = new GridData(SWT.FILL, SWT.FILL, false, true);
0233: gridData.widthHint = 190;
0234: gridData.verticalSpan = 2;
0235: selectableCollaboratorPanel = new SelectableCollaboratorPanel(
0236: parent, gridData);
0237: selectableCollaboratorPanel.addSelectionListener(this );
0238:
0239: // Table
0240: final Table table = new Table(parent, SWT.MULTI
0241: | SWT.FULL_SELECTION | SWT.BORDER | SWT.HIDE_SELECTION);
0242: gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
0243: gridData.heightHint = 75;
0244: table.setLayoutData(gridData);
0245: table.setLinesVisible(true);
0246: table.setHeaderVisible(true);
0247: table.setEnabled(true);
0248:
0249: // Création du viewer
0250: tableViewer = new TableViewer(table);
0251: tableViewer.setCellModifier(this );
0252: tableViewer.setContentProvider(this );
0253: tableViewer.setLabelProvider(this );
0254:
0255: // Création des polices de caractère
0256: FontData tableFont = table.getFont().getFontData()[0];
0257: normalFont = table.getFont();
0258: italicFont = new Font(table.getDisplay(), tableFont.getName(),
0259: tableFont.getHeight(), SWT.ITALIC);
0260:
0261: // Configuration des colonnes
0262: tableColsMgr = new TableOrTreeColumnsMgr();
0263: tableColsMgr.addColumn("TASK_PATH", "Task path", 200, SWT.LEFT);
0264: tableColsMgr.addColumn("TASK NAME", "Task name", 100, SWT.LEFT);
0265: tableColsMgr.addColumn("MONDAY", "MON", 50, SWT.CENTER);
0266: tableColsMgr.addColumn("TUESDAY", "TUE", 50, SWT.CENTER);
0267: tableColsMgr.addColumn("WEDNESDAY", "WED", 50, SWT.CENTER);
0268: tableColsMgr.addColumn("THURSDAY", "TUE", 50, SWT.CENTER);
0269: tableColsMgr.addColumn("FRIDAY", "FRI", 50, SWT.CENTER);
0270: tableColsMgr.addColumn("SATURDAY", "SAT", 50, SWT.CENTER);
0271: tableColsMgr.addColumn("SUNDAY", "SUN", 50, SWT.CENTER);
0272: tableColsMgr.configureTable(tableViewer);
0273:
0274: // Configuration des éditeurs de cellules
0275: CellEditor[] editors = new CellEditor[9];
0276: durationCellEditor = new ComboBoxCellEditor(table,
0277: new String[] {}, SWT.READ_ONLY) {
0278: protected Control createControl(Composite parent) {
0279: CCombo ccombo = (CCombo) super .createControl(parent);
0280: ccombo.setVisibleItemCount(10);
0281: return ccombo;
0282: }
0283: };
0284:
0285: editors[TASK_PATH_COLUMN_IDX] = null; // Read-only column
0286: editors[TASK_NAME_COLUMN_IDX] = new DialogCellEditor(table) {
0287: protected Object openDialogBox(Control cellEditorWindow) {
0288: Object result = null;
0289: // Positionnement de la valeur par défaut
0290: WeekContributions w = (WeekContributions) ((IStructuredSelection) tableViewer
0291: .getSelection()).getFirstElement();
0292: // Préparation du dialogue
0293: taskChooserDialog
0294: .setValidator(buildTaskChooserValidator());
0295: taskChooserDialog.setValue(w.getTask());
0296: if (taskChooserDialog.open() == Dialog.OK) {
0297: result = taskChooserDialog.getValue();
0298: }
0299: return result;
0300: }
0301:
0302: protected void updateContents(Object value) {
0303: Label defaultLabel = getDefaultLabel();
0304: if (defaultLabel == null)
0305: return;
0306: String text = "";
0307: if (value instanceof Task) {
0308: Task task = (Task) value;
0309: text = task.getName();
0310: } else if (value != null) {
0311: text = value.toString();
0312: }
0313: defaultLabel.setText(text);
0314: }
0315: };
0316: editors[MONDAY_COLUMN_IDX] = durationCellEditor;
0317: editors[TUESDAY_COLUMN_IDX] = durationCellEditor;
0318: editors[WEDNESDAY_COLUMN_IDX] = durationCellEditor;
0319: editors[THURSDAY_COLUMN_IDX] = durationCellEditor;
0320: editors[FRIDAY_COLUMN_IDX] = durationCellEditor;
0321: editors[SATURDAY_COLUMN_IDX] = durationCellEditor;
0322: editors[SUNDAY_COLUMN_IDX] = durationCellEditor;
0323: tableViewer.setCellEditors(editors);
0324:
0325: // Configuration du menu popup
0326: final Menu menu = new Menu(table);
0327: menu.addMenuListener(this );
0328: newItem = new MenuItem(menu, SWT.CASCADE);
0329: newItem.setText("New contribution");
0330: newItem.addSelectionListener(this );
0331: pasteItem = new MenuItem(menu, SWT.CASCADE);
0332: pasteItem.setText("Paste (Ctrl + v)");
0333: pasteItem.addSelectionListener(this );
0334: removeItem = new MenuItem(menu, SWT.CASCADE);
0335: removeItem.setText("Remove");
0336: removeItem.addSelectionListener(this );
0337: exportItem = new MenuItem(menu, SWT.CASCADE);
0338: exportItem.setText("Export");
0339: exportItem.addSelectionListener(this );
0340: table.setMenu(menu);
0341:
0342: // Ajout de KeyListeners pour faciliter le 'coller' d'une tache en provenance
0343: // de l'onglet de gestion des tache
0344: // (Rq: les accélérateurs sont ignorés dans les menus contextuels)
0345: KeyListener keyListener = new KeyAdapter() {
0346: public void keyReleased(KeyEvent e) {
0347: Widget simulatedWidget = null;
0348: if ((e.keyCode == 'v') && (e.stateMask == SWT.CTRL))
0349: simulatedWidget = pasteItem;
0350: // else if ...
0351: if (simulatedWidget != null) {
0352: Event event = new Event();
0353: event.widget = simulatedWidget;
0354: SelectionEvent se = new SelectionEvent(event);
0355: widgetSelected(se);
0356: }
0357: }
0358: };
0359: parentComposite.addKeyListener(keyListener);
0360: table.addKeyListener(keyListener);
0361:
0362: // Panneau contenant les boutons de navigation
0363: Composite navigationButtonsPanel = new Composite(parent,
0364: SWT.NONE);
0365: GridLayout layout = new GridLayout(2, true);
0366: layout.marginHeight = 0;
0367: layout.marginWidth = 0;
0368: navigationButtonsPanel.setLayout(layout);
0369: gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
0370: //gridData.horizontalSpan = 2;
0371: navigationButtonsPanel.setLayoutData(gridData);
0372:
0373: // Panneau contenant les boutons 'Précédent'
0374: Composite previousButtonsPanel = new Composite(
0375: navigationButtonsPanel, SWT.NONE);
0376: previousButtonsPanel.setLayout(new FillLayout());
0377: gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
0378: gridData.horizontalAlignment = SWT.LEFT;
0379: previousButtonsPanel.setLayoutData(gridData);
0380: previousYearButton = new Button(previousButtonsPanel, SWT.NONE);
0381: previousYearButton.setText("<< year");
0382: previousYearButton.setToolTipText("Previous year");
0383: previousYearButton.addSelectionListener(this );
0384: previousMonthButton = new Button(previousButtonsPanel, SWT.NONE);
0385: previousMonthButton.setText("<< month");
0386: previousMonthButton.setToolTipText("Previous month");
0387: previousMonthButton.addSelectionListener(this );
0388: previousWeekButton = new Button(previousButtonsPanel, SWT.NONE);
0389: previousWeekButton.setText("<< week");
0390: previousWeekButton.setToolTipText("Previous week");
0391: previousWeekButton.addSelectionListener(this );
0392:
0393: // Panneau contenant les boutons 'Prochains'
0394: Composite nextButtonsPanel = new Composite(
0395: navigationButtonsPanel, SWT.NONE);
0396: nextButtonsPanel.setLayout(new FillLayout());
0397: gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
0398: gridData.horizontalAlignment = SWT.RIGHT;
0399: nextButtonsPanel.setLayoutData(gridData);
0400: nextWeekButton = new Button(nextButtonsPanel, SWT.NONE);
0401: nextWeekButton.setText("week >>");
0402: nextWeekButton.setToolTipText("Next week");
0403: nextWeekButton.addSelectionListener(this );
0404: nextMonthButton = new Button(nextButtonsPanel, SWT.NONE);
0405: nextMonthButton.setText("month >>");
0406: nextMonthButton.setToolTipText("Next month");
0407: nextMonthButton.addSelectionListener(this );
0408: nextYearButton = new Button(nextButtonsPanel, SWT.NONE);
0409: nextYearButton.setText("year >>");
0410: nextYearButton.setToolTipText("Next year");
0411: nextYearButton.addSelectionListener(this );
0412:
0413: // Initialisation du popup de choix des taches
0414: taskChooserDialog = new TaskChooserTreeWithHistoryDialog(parent
0415: .getShell());
0416:
0417: // Recherche du 1° Lundi précédent la date courante
0418: currentMonday = getMondayBefore(new GregorianCalendar());
0419: log.debug("Date courante : " + currentMonday);
0420:
0421: }
0422:
0423: /**
0424: * Retourne le premier lundi précédent la date spécifiée.
0425: * @param date la date.
0426: * @return le premier lundi précédent la date spécifiée.
0427: */
0428: private static Calendar getMondayBefore(Calendar date) {
0429: Calendar dateCursor = (Calendar) date.clone();
0430: while (dateCursor.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY)
0431: dateCursor.add(Calendar.DATE, -1);
0432: return dateCursor;
0433: }
0434:
0435: /* (non-Javadoc)
0436: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
0437: */
0438: public Object[] getElements(Object inputElement) {
0439: // Chargement des données
0440: SafeRunner safeRunner = new SafeRunner() {
0441: public Object runUnsafe() throws Exception {
0442: // Mise à jour des dates de la semaine :
0443: SimpleDateFormat sdf = new SimpleDateFormat(
0444: "dd/MM/yyyy");
0445: Calendar sunday = (Calendar) currentMonday.clone();
0446: sunday.add(Calendar.DATE, 6);
0447: weekLabel.setText("Week : "
0448: + sdf.format(currentMonday.getTime()) + " -> "
0449: + sdf.format(sunday.getTime()));
0450:
0451: // Mise à jour du nom des colonnes
0452: TableColumn[] tableColumns = tableViewer.getTable()
0453: .getColumns();
0454: Calendar date = (Calendar) currentMonday.clone();
0455: for (int i = 2; i < tableColumns.length; i++) {
0456: TableColumn tableColumn = tableColumns[i];
0457: tableColumn.setText(weekDaysInitials[i - 2]
0458: + date.get(Calendar.DAY_OF_MONTH));
0459: date.add(Calendar.DATE, 1);
0460: }
0461:
0462: Collaborator selectedCollaborator = selectableCollaboratorPanel
0463: .getSelectedCollaborator();
0464: ArrayList list = new ArrayList();
0465: if (selectedCollaborator != null) {
0466: // Recherche des taches déclarées pour cet utilisateur
0467: // pour la semaine courante
0468: Calendar fromDate = (Calendar) currentMonday
0469: .clone();
0470: fromDate.add(Calendar.DATE, -7);
0471: Calendar toDate = (Calendar) currentMonday.clone();
0472: toDate.add(Calendar.DATE, 6);
0473: if (selectedCollaborator != null) {
0474: Task[] tasks = ModelMgr.getTasks(
0475: selectedCollaborator, fromDate, toDate);
0476: // Ajout des tâches dans le tableau
0477: for (int i = 0; i < tasks.length; i++) {
0478: Task task = tasks[i];
0479: list.add(getWeekContributions(task));
0480: }
0481: }
0482: }
0483: // Ajout d'un élément nul pour la ligne des totaux
0484: list.add(WeekContributionsSum.getInstance());
0485: // Retour du résultat
0486: return list.toArray();
0487: }
0488: };
0489: // Exécution
0490: Object result = (Object) safeRunner.run(parent.getShell());
0491: return (Object[]) (result != null ? result
0492: : new WeekContributions[] {});
0493: }
0494:
0495: /* (non-Javadoc)
0496: * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
0497: */
0498: public boolean canModify(Object element, String property) {
0499: log.debug("ICellModifier.canModify(" + element + ", "
0500: + property + ")");
0501: boolean canModify = false;
0502: // Cas de la ligne des totaux
0503: if (element == WeekContributionsSum.getInstance()) {
0504: canModify = false;
0505: }
0506: // Cas des autres lignes
0507: else {
0508: int propertyIdx = tableColsMgr.getColumnIndex(property);
0509: switch (propertyIdx) {
0510: case (TASK_PATH_COLUMN_IDX):
0511: canModify = false;
0512: break;
0513: case (TASK_NAME_COLUMN_IDX):
0514: case (MONDAY_COLUMN_IDX):
0515: case (TUESDAY_COLUMN_IDX):
0516: case (WEDNESDAY_COLUMN_IDX):
0517: case (THURSDAY_COLUMN_IDX):
0518: case (FRIDAY_COLUMN_IDX):
0519: case (SATURDAY_COLUMN_IDX):
0520: case (SUNDAY_COLUMN_IDX):
0521: canModify = true;
0522: break;
0523: default:
0524: throw new Error("Colonne inconnue");
0525: }
0526: }
0527: return canModify;
0528: }
0529:
0530: /* (non-Javadoc)
0531: * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String)
0532: */
0533: public Object getValue(Object element, String property) {
0534: log.debug("ICellModifier.getValue(" + element + ", " + property
0535: + ")");
0536: WeekContributions weekContributions = (WeekContributions) element;
0537: Object value = null;
0538: int columnIndex = tableColsMgr.getColumnIndex(property);
0539: switch (columnIndex) {
0540: case (TASK_PATH_COLUMN_IDX):
0541: throw new Error(
0542: "Task path colum is not supposed to be modified");
0543: case (TASK_NAME_COLUMN_IDX):
0544: value = weekContributions.getTask();
0545: break;
0546: case (MONDAY_COLUMN_IDX):
0547: case (TUESDAY_COLUMN_IDX):
0548: case (WEDNESDAY_COLUMN_IDX):
0549: case (THURSDAY_COLUMN_IDX):
0550: case (FRIDAY_COLUMN_IDX):
0551: case (SATURDAY_COLUMN_IDX):
0552: case (SUNDAY_COLUMN_IDX):
0553: Contribution contribution = weekContributions
0554: .getContribution(columnIndex - 2);
0555: value = contribution != null ? getDurationIndex(contribution
0556: .getDurationId())
0557: : null;
0558: // Par défaut on prend la première sélection
0559: if (value == null)
0560: value = new Integer(0);
0561: break;
0562: default:
0563: throw new Error("Colonne inconnue");
0564: }
0565: return value;
0566: }
0567:
0568: /**
0569: * @return le numéro de la durée sélectionnée.
0570: * @param duration le durée considérée.
0571: */
0572: private Integer getDurationIndex(long durationId) {
0573: Integer result = null;
0574: for (int i = 0; i < durations.length && result == null; i++) {
0575: if (durations[i].getId() == durationId)
0576: result = new Integer(i + 1); // +1 car l'index 0 correspond à la valeur "vide"
0577: }
0578: return result;
0579: }
0580:
0581: /* (non-Javadoc)
0582: * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
0583: */
0584: public void modify(final Object element, String property,
0585: final Object value) {
0586: log.debug("ICellModifier.modify(" + element + ", " + property
0587: + ", " + value + ")");
0588: TableItem item = (TableItem) element;
0589: final WeekContributions weekContributions = (WeekContributions) item
0590: .getData();
0591: final IBaseLabelProvider labelProvider = this ;
0592: final int columnIndex = tableColsMgr.getColumnIndex(property);
0593: SafeRunner safeRunner = new SafeRunner() {
0594: public Object runUnsafe() throws Exception {
0595: switch (columnIndex) {
0596: case (TASK_PATH_COLUMN_IDX):
0597: throw new Error(
0598: "Task path colum is not supposed to be modified");
0599: case (TASK_NAME_COLUMN_IDX):
0600: Task task = (Task) value;
0601: weekContributions.setTask(task);
0602: ArrayList nonNullContributions = new ArrayList();
0603: // Récupération des contributions
0604: Contribution[] contributions = weekContributions
0605: .getContributions();
0606: // Suppression des contributions nulles
0607: for (int i = 0; i < contributions.length; i++) {
0608: Contribution contribution = contributions[i];
0609: if (contribution != null)
0610: nonNullContributions.add(contribution);
0611: }
0612: // Mise à jour des contributions
0613: contributions = (Contribution[]) nonNullContributions
0614: .toArray(new Contribution[nonNullContributions
0615: .size()]);
0616: ModelMgr
0617: .changeContributionTask(contributions, task);
0618: // Notification des listeners
0619: notifyLabelProviderListener(new LabelProviderChangedEvent(
0620: labelProvider, weekContributions));
0621: break;
0622: case (MONDAY_COLUMN_IDX):
0623: case (TUESDAY_COLUMN_IDX):
0624: case (WEDNESDAY_COLUMN_IDX):
0625: case (THURSDAY_COLUMN_IDX):
0626: case (FRIDAY_COLUMN_IDX):
0627: case (SATURDAY_COLUMN_IDX):
0628: case (SUNDAY_COLUMN_IDX):
0629: Integer selectedIndex = (Integer) value;
0630: Contribution contribution = weekContributions
0631: .getContribution(columnIndex - 2);
0632: // Cas d'une suppression (choix de la valeu N° 0 de la liste)
0633: if (selectedIndex.intValue() == 0) {
0634: // Suppression effective en base si la contribution existait
0635: if (contribution != null)
0636: ModelMgr.removeContribution(contribution);
0637: weekContributions.setContribution(
0638: columnIndex - 2, null);
0639: }
0640: // Sinon création ou modification
0641: else {
0642: boolean create = (contribution == null);
0643: // Cas d'une création
0644: if (create) {
0645: Collaborator selectedCollaboprator = selectableCollaboratorPanel
0646: .getSelectedCollaborator();
0647: contribution = new Contribution();
0648: contribution
0649: .setContributorId(selectedCollaboprator
0650: .getId());
0651: contribution.setTaskId(weekContributions
0652: .getTask().getId());
0653: Calendar date = (Calendar) currentMonday
0654: .clone();
0655: date.add(Calendar.DATE, columnIndex
0656: - MONDAY_COLUMN_IDX);
0657: contribution.setDate(date);
0658: weekContributions.setContribution(
0659: columnIndex - 2, contribution);
0660: }
0661: // Mise à jour des champs
0662: Duration duration = durations[selectedIndex
0663: .intValue() - 1];
0664: contribution.setDurationId(duration.getId());
0665: if (create)
0666: ModelMgr.createContribution(contribution);
0667: else
0668: ModelMgr.updateContribution(contribution);
0669: }
0670: // Notification des listeners
0671: notifyLabelProviderListener(new LabelProviderChangedEvent(
0672: labelProvider, weekContributions));
0673: // Mise à jour des totaux
0674: tableViewer.refresh(WeekContributionsSum
0675: .getInstance());
0676: break;
0677: default:
0678: throw new Error("Colonne inconnue");
0679: }
0680: return null;
0681: }
0682: };
0683: // Exécution
0684: safeRunner.run(parent.getShell());
0685: }
0686:
0687: /* (non-Javadoc)
0688: * @see org.eclipse.jface.viewers.ITableFontProvider#getFont(java.lang.Object, int)
0689: */
0690: public Font getFont(Object element, int columnIndex) {
0691: return element == WeekContributionsSum.getInstance() ? italicFont
0692: : normalFont;
0693: }
0694:
0695: /* (non-Javadoc)
0696: * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
0697: */
0698: public String getColumnText(final Object element,
0699: final int columnIndex) {
0700: log.debug("ITableLabelProvider.getColumnText(" + element + ", "
0701: + columnIndex + ")");
0702: SafeRunner safeRunner = new SafeRunner() {
0703: public Object runUnsafe() throws Exception {
0704: String text = null;
0705: // Cas de la ligne des totaux
0706: if (element == WeekContributionsSum.getInstance()) {
0707: switch (columnIndex) {
0708: case (TASK_PATH_COLUMN_IDX):
0709: text = "";
0710: break;
0711: case (TASK_NAME_COLUMN_IDX):
0712: text = "Total :";
0713: break;
0714: case (MONDAY_COLUMN_IDX):
0715: case (TUESDAY_COLUMN_IDX):
0716: case (WEDNESDAY_COLUMN_IDX):
0717: case (THURSDAY_COLUMN_IDX):
0718: case (FRIDAY_COLUMN_IDX):
0719: case (SATURDAY_COLUMN_IDX):
0720: case (SUNDAY_COLUMN_IDX):
0721: Calendar cal = (Calendar) currentMonday.clone();
0722: cal.add(Calendar.DATE, columnIndex
0723: - MONDAY_COLUMN_IDX);
0724: long sum = ModelMgr
0725: .getContributionsSum(
0726: null,
0727: selectableCollaboratorPanel
0728: .getSelectedCollaborator(),
0729: new Integer(cal
0730: .get(Calendar.YEAR)),
0731: new Integer(
0732: cal.get(Calendar.MONTH) + 1),
0733: new Integer(
0734: cal
0735: .get(Calendar.DAY_OF_MONTH)));
0736: text = StringHelper.hundredthToEntry(sum);
0737: break;
0738: default:
0739: throw new Error("Colonne inconnue");
0740: }
0741: }
0742: // Cas des autres lignes
0743: else {
0744: WeekContributions weekContributions = (WeekContributions) element;
0745: switch (columnIndex) {
0746: case (TASK_PATH_COLUMN_IDX):
0747: // Construction du chemin de la tache
0748: Task task = weekContributions.getTask();
0749: text = ModelMgr.getTaskCodePath(task);
0750: break;
0751: case (TASK_NAME_COLUMN_IDX):
0752: text = weekContributions.getTask().getName();
0753: break;
0754: case (MONDAY_COLUMN_IDX):
0755: case (TUESDAY_COLUMN_IDX):
0756: case (WEDNESDAY_COLUMN_IDX):
0757: case (THURSDAY_COLUMN_IDX):
0758: case (FRIDAY_COLUMN_IDX):
0759: case (SATURDAY_COLUMN_IDX):
0760: case (SUNDAY_COLUMN_IDX):
0761: Contribution contribution = weekContributions
0762: .getContribution(columnIndex - 2);
0763: text = contribution != null ? StringHelper
0764: .hundredthToEntry(contribution
0765: .getDurationId()) : "";
0766: break;
0767: default:
0768: throw new Error("Colonne inconnue");
0769: }
0770: }
0771: return text;
0772: }
0773: };
0774: // Exécution
0775: return (String) safeRunner.run(parent.getShell(), "");
0776: }
0777:
0778: /* (non-Javadoc)
0779: * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
0780: */
0781: public void widgetSelected(final SelectionEvent e) {
0782: log.debug("SelectionListener.widgetSelected(" + e + ")");
0783: final Object source = e.getSource();
0784: SafeRunner safeRunner = new SafeRunner() {
0785: public Object runUnsafe() throws Exception {
0786: TableItem[] selection = tableViewer.getTable()
0787: .getSelection();
0788: // Cas d'une création
0789: if (newItem.equals(source)) {
0790: // Préparation du dialogue
0791: taskChooserDialog
0792: .setValidator(buildTaskChooserValidator());
0793: // Affichage du popup
0794: Task task = null;
0795: if (taskChooserDialog.open() == Dialog.OK) {
0796: task = (Task) taskChooserDialog.getValue();
0797: log.debug("Selected task=" + task);
0798: addNewLineOrSelectTaskLine(task);
0799: }
0800: }
0801: // Cas d'une demande de 'collage' du contenu du presse papier
0802: else if (pasteItem.equals(source)) {
0803: String taskCodePath = (String) clipboard
0804: .getContents(TextTransfer.getInstance());
0805: Task task = ModelMgr
0806: .getTaskByCodePath(taskCodePath);
0807: ITaskChooserValidator validator = buildTaskChooserValidator();
0808: // Validation de la conformité de la tache pour ajout dans l'IHM
0809: validator.validateChoosenTask(task);
0810: // Sélection de la ligne ou ajout d'une nouvelle ligne
0811: addNewLineOrSelectTaskLine(task);
0812: }
0813: // Cas d'une suppression
0814: else if (removeItem.equals(source)) {
0815: TableItem selectedItem = selection[0];
0816: WeekContributions wc = (WeekContributions) selectedItem
0817: .getData();
0818: // Récupération des contributions
0819: Contribution[] contributions = wc
0820: .getContributions();
0821: // Suppression des contributions nulles
0822: ArrayList list = new ArrayList();
0823: for (int i = 0; i < contributions.length; i++) {
0824: Contribution contribution = contributions[i];
0825: if (contribution != null)
0826: list.add(contribution);
0827: }
0828: if (list.size() > 0) {
0829: // Suppression des contributions non nulles
0830: contributions = (Contribution[]) list
0831: .toArray(new Contribution[list.size()]);
0832: ModelMgr.removeContributions(contributions);
0833: }
0834: // Mise à jour de l'IHM
0835: tableViewer.remove(wc);
0836: }
0837: // Cas d'une demande d'export vers un fichier EXCEL
0838: else if (exportItem.equals(source)) {
0839: SWTHelper.exportToWorkBook(tableViewer.getTable());
0840: }
0841: // Cas d'un changement d'une année en arrière
0842: else if (previousYearButton.equals(source)) {
0843: currentMonday.add(Calendar.YEAR, -1);
0844: currentMonday = getMondayBefore(currentMonday);
0845: tableViewer.refresh();
0846: }
0847: // Cas d'un changement d'un mois en arrière
0848: else if (previousMonthButton.equals(source)) {
0849: currentMonday.add(Calendar.MONTH, -1);
0850: currentMonday = getMondayBefore(currentMonday);
0851: tableViewer.refresh();
0852: }
0853: // Cas d'un changement de semaine en arrière
0854: else if (previousWeekButton.equals(source)) {
0855: currentMonday.add(Calendar.DATE, -7);
0856: tableViewer.refresh();
0857: }
0858: // Cas d'un changement de semaine en avant
0859: else if (nextWeekButton.equals(source)) {
0860: currentMonday.add(Calendar.DATE, 7);
0861: tableViewer.refresh();
0862: }
0863: // Cas d'un changement d'un mois en avant
0864: else if (nextMonthButton.equals(source)) {
0865: currentMonday.add(Calendar.MONTH, 1);
0866: currentMonday = getMondayBefore(currentMonday);
0867: tableViewer.refresh();
0868: }
0869: // Cas d'un changement d'une année en avant
0870: else if (nextYearButton.equals(source)) {
0871: currentMonday.add(Calendar.YEAR, 1);
0872: currentMonday = getMondayBefore(currentMonday);
0873: tableViewer.refresh();
0874: }
0875: return null;
0876: }
0877: };
0878: // Exécution
0879: safeRunner.run(parent.getShell());
0880: }
0881:
0882: /**
0883: * Prépare le dialogue de choix d'une tâche.
0884: */
0885: private ITaskChooserValidator buildTaskChooserValidator() {
0886: // Création du valideur
0887: ITaskChooserValidator taskChooserValidator = new ITaskChooserValidator() {
0888: public void validateChoosenTask(Task selectedTask)
0889: throws DialogException {
0890: if (selectedTask.getSubTasksCount() > 0)
0891: throw new DialogException(
0892: "This is a parent task. Please choose one of its subtasks.",
0893: null);
0894: }
0895: };
0896: // Retour du résultat
0897: return taskChooserValidator;
0898: }
0899:
0900: /**
0901: * Ajoute une ligne dans le tableau ou sélectionne celle déjà existante pour la tache.
0902: * @param task la tache associée à l'ajout ou la sélection.
0903: * @throws DbException levée en cas d'incident technique d'accès à la BDD.
0904: * @throws ModelException levée en cas d'incident fonctionnel.
0905: */
0906: private void addNewLineOrSelectTaskLine(Task task)
0907: throws DbException, ModelException {
0908: // La tache est elle déjà associée à une semaine de contributions
0909: WeekContributions weekContributions = null;
0910: TableItem[] items = tableViewer.getTable().getItems();
0911: for (int i = 0; i < items.length; i++) {
0912: Object data = items[i].getData();
0913: if (data instanceof WeekContributions) {
0914: Task currentTask = ((WeekContributions) data).getTask();
0915: if (task.equals(currentTask))
0916: weekContributions = (WeekContributions) data;
0917: }
0918: }
0919: // Si ce n'est pas le cas c'est une nouvelle ligne
0920: if (weekContributions == null) {
0921: weekContributions = getWeekContributions(task);
0922: int itemCount = tableViewer.getTable().getItemCount();
0923: // Ajout dans l'arbre
0924: tableViewer.insert(weekContributions, itemCount - 1);
0925: }
0926: // Sélection
0927: tableViewer.setSelection(new StructuredSelection(
0928: weekContributions), true);
0929: tableViewer.getTable().setFocus();
0930: }
0931:
0932: /**
0933: * Construit la liste des contributions d'une semaine.
0934: * @param task la tache considérée.
0935: * @return la liste des contributions d'une semaine.
0936: * @throws DbException levée en cas d'incident technique d'accès à la BDD.
0937: * @throws ModelException levée en cas d'incident fonctionnel.
0938: */
0939: private WeekContributions getWeekContributions(Task task)
0940: throws DbException, ModelException {
0941: // Création de la ligne de semaine
0942: WeekContributions weekContributions = new WeekContributions();
0943: weekContributions.setTask(task);
0944: // Parcours des jours
0945: Calendar fromDate = (Calendar) currentMonday.clone();
0946: Calendar toDate = (Calendar) currentMonday.clone();
0947: toDate.add(Calendar.DATE, 6);
0948: // Récupération des contributions
0949: Collaborator selectedCollaboprator = selectableCollaboratorPanel
0950: .getSelectedCollaborator();
0951: weekContributions.setContributions(ModelMgr
0952: .getDaysContributions(selectedCollaboprator, task,
0953: fromDate, toDate));
0954: return weekContributions;
0955:
0956: }
0957:
0958: /* (non-Javadoc)
0959: * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
0960: */
0961: public void widgetDefaultSelected(SelectionEvent e) {
0962: widgetSelected(e);
0963: }
0964:
0965: /* (non-Javadoc)
0966: * @see org.eclipse.swt.events.MenuListener#menuShown(org.eclipse.swt.events.MenuEvent)
0967: */
0968: public void menuShown(MenuEvent e) {
0969: log.debug("menuShown(" + e + ")");
0970: boolean collaboratorSelected = (selectableCollaboratorPanel
0971: .getSelectedCollaborator() != null);
0972: TableItem[] selection = tableViewer.getTable().getSelection();
0973: boolean emptySelection = selection.length == 0;
0974: boolean singleSelection = selection.length == 1;
0975: newItem.setEnabled(collaboratorSelected
0976: && (emptySelection || singleSelection));
0977: pasteItem
0978: .setEnabled(collaboratorSelected
0979: && clipboard.getContents(TextTransfer
0980: .getInstance()) != null);
0981: removeItem.setEnabled(collaboratorSelected && singleSelection);
0982: exportItem.setEnabled(collaboratorSelected && true);
0983: }
0984:
0985: /* (non-Javadoc)
0986: * @see org.eclipse.swt.events.MenuListener#menuHidden(org.eclipse.swt.events.MenuEvent)
0987: */
0988: public void menuHidden(MenuEvent e) {
0989: // Do nothing...
0990: }
0991:
0992: /* (non-Javadoc)
0993: * @see jfb.tools.activitymgr.ui.DatabaseUI.DbStatusListener#databaseClosed()
0994: */
0995: public void databaseClosed() {
0996: // Suppression des items de collaborateurs
0997: selectableCollaboratorPanel.databaseClosed();
0998: // Suppression des items de contributions
0999: Table table = tableViewer.getTable();
1000: TableItem[] items = table.getItems();
1001: for (int i = 0; i < items.length; i++) {
1002: items[i].dispose();
1003: }
1004: }
1005:
1006: /**
1007: * Initialise l'IHM avec les données en base.
1008: */
1009: private void initialize() {
1010: // Chargement du référentiel de durées
1011: loadDurations();
1012:
1013: // Chargement des collaborateurs et suppression de l'ancienne sélection
1014: // si elle existe
1015: selectableCollaboratorPanel.initialize();
1016:
1017: // Choix du collaborateur
1018: if (selectableCollaboratorPanel.getCollaboratorsCount() > 0) {
1019: selectableCollaboratorPanel.setSelectedIndex(0);
1020: }
1021:
1022: // Initialisation de la table
1023: tableViewer.setInput(ROOT_NODE);
1024:
1025: }
1026:
1027: /**
1028: * Charge le référentiel de durées.
1029: */
1030: private void loadDurations() {
1031: // Chargement de la liste des durées et des utilisateurs
1032: SafeRunner safeRunner = new SafeRunner() {
1033: public Object runUnsafe() throws Exception {
1034: // Chargement du référentiel de durées
1035: durations = ModelMgr.getActiveDurations();
1036: String[] durationsStr = new String[durations.length + 1];
1037: durationsStr[0] = "";
1038: for (int i = 0; i < durations.length; i++)
1039: durationsStr[i + 1] = StringHelper
1040: .hundredthToEntry(durations[i].getId());
1041: durationCellEditor.setItems(durationsStr);
1042: return null;
1043: }
1044: };
1045: // Exécution
1046: safeRunner.run(parent.getShell());
1047: }
1048:
1049: /* (non-Javadoc)
1050: * @see jfb.tools.activitymgr.ui.util.ICollaboratorSelectionListener#collaboratorSelected(jfb.tools.activitymgr.core.beans.Collaborator)
1051: */
1052: public void collaboratorSelected(Collaborator selectedCollaborator) {
1053: tableViewer.refresh();
1054: }
1055:
1056: /* (non-Javadoc)
1057: * @see jfb.tools.activitymgr.ui.CollaboratorsUI.CollaboratorListener#collaboratorAdded(jfb.tools.activitymgr.core.beans.Collaborator)
1058: */
1059: public void collaboratorAdded(Collaborator collaborator) {
1060: selectableCollaboratorPanel.collaboratorAdded(collaborator);
1061: }
1062:
1063: /* (non-Javadoc)
1064: * @see jfb.tools.activitymgr.ui.CollaboratorsUI.CollaboratorListener#collaboratorRemoved(jfb.tools.activitymgr.core.beans.Collaborator)
1065: */
1066: public void collaboratorRemoved(Collaborator collaborator) {
1067: selectableCollaboratorPanel.collaboratorRemoved(collaborator);
1068: // Dans le cas ou le collaborateur supprimé est celui qui était sélectionné...
1069: if (selectableCollaboratorPanel.getSelectedCollaborator() == null) {
1070: // ... on essaye d'en sélectionner un autre (si il y a d'autres collaborateurs)...
1071: if (selectableCollaboratorPanel.getCollaboratorsCount() > 0)
1072: selectableCollaboratorPanel.setSelectedIndex(0);
1073: // ... et on rafraichit les contributions affichées
1074: tableViewer.refresh();
1075: }
1076: }
1077:
1078: /* (non-Javadoc)
1079: * @see jfb.tools.activitymgr.ui.CollaboratorsUI.CollaboratorListener#collaboratorUpdated(jfb.tools.activitymgr.core.beans.Collaborator)
1080: */
1081: public void collaboratorUpdated(Collaborator collaborator) {
1082: selectableCollaboratorPanel.collaboratorUpdated(collaborator);
1083: }
1084:
1085: /* (non-Javadoc)
1086: * @see jfb.tools.activitymgr.ui.CollaboratorsUI.ICollaboratorListener#collaboratorActivationStatusChanged(jfb.tools.activitymgr.core.beans.Collaborator)
1087: */
1088: public void collaboratorActivationStatusChanged(
1089: Collaborator collaborator) {
1090: selectableCollaboratorPanel
1091: .collaboratorActivationStatusChanged(collaborator);
1092: // Dans le cas ou le collaborateur supprimé est celui qui était sélectionné...
1093: if (selectableCollaboratorPanel.getSelectedCollaborator() == null) {
1094: // ... on essaye d'en sélectionner un autre (si il y a d'autres collaborateurs)...
1095: if (selectableCollaboratorPanel.getCollaboratorsCount() > 0)
1096: selectableCollaboratorPanel.setSelectedIndex(0);
1097: // ... et on rafraichit les contributions affichées
1098: tableViewer.refresh();
1099: }
1100: }
1101:
1102: /* (non-Javadoc)
1103: * @see jfb.tools.activitymgr.ui.DatabaseUI.DbStatusListener#databaseOpened()
1104: */
1105: public void databaseOpened() {
1106: // Annulation de la sélection d'un collaborateur si une sélection
1107: // est en cours (peut arriver si la base a été réinstallée)
1108: selectableCollaboratorPanel.setSelectedCollaborator(null);
1109: initialize();
1110: }
1111:
1112: /* (non-Javadoc)
1113: * @see jfb.tools.activitymgr.ui.DurationsUI.IDurationListener#durationAdded(jfb.tools.activitymgr.core.beans.Duration)
1114: */
1115: public void durationAdded(Duration duration) {
1116: loadDurations();
1117: }
1118:
1119: /* (non-Javadoc)
1120: * @see jfb.tools.activitymgr.ui.DurationsUI.DurationListener#durationRemoved(jfb.tools.activitymgr.core.beans.Duration)
1121: */
1122: public void durationRemoved(Duration duration) {
1123: loadDurations();
1124: }
1125:
1126: /* (non-Javadoc)
1127: * @see jfb.tools.activitymgr.ui.DurationsUI.DurationListener#durationUpdated(jfb.tools.activitymgr.core.beans.Duration, jfb.tools.activitymgr.core.beans.Duration)
1128: */
1129: public void durationUpdated(Duration oldDuration,
1130: Duration newDuration) {
1131: loadDurations();
1132: }
1133:
1134: /* (non-Javadoc)
1135: * @see jfb.tools.activitymgr.ui.DurationsUI.IDurationListener#durationActivationStatusChanged(jfb.tools.activitymgr.core.beans.Duration)
1136: */
1137: public void durationActivationStatusChanged(Duration duration) {
1138: loadDurations();
1139: }
1140:
1141: /* (non-Javadoc)
1142: * @see jfb.tools.activitymgr.ui.TasksUI.TaskListener#taskAdded(jfb.tools.activitymgr.core.beans.Task)
1143: */
1144: public void taskAdded(Task task) {
1145: // Transfert de la notification au popup de choix de tache
1146: taskChooserDialog.taskAdded(task);
1147: // Rien à faire par contre du côté de l'IHM de saisie des contributions car une nouvelle
1148: // tâche ne pouvait forcément pas être déjà affichée
1149: }
1150:
1151: /* (non-Javadoc)
1152: * @see jfb.tools.activitymgr.ui.TasksUI.TaskListener#taskRemoved(jfb.tools.activitymgr.core.beans.Task)
1153: */
1154: public void taskRemoved(final Task removedTask) {
1155: new SafeRunner() {
1156: protected Object runUnsafe() throws Exception {
1157: // Transfert de la notification au popup de choix de tache
1158: taskChooserDialog.taskRemoved(removedTask);
1159: // Parcours des taches présentes dans le tableau
1160: int itemCount = tableViewer.getTable().getItemCount();
1161: int itemIdxToRemove = -1;
1162: for (int i = 0; i < itemCount; i++) {
1163: Object data = tableViewer.getElementAt(i);
1164: if (data != WeekContributionsSum.getInstance()) {
1165: WeekContributions weekContribution = (WeekContributions) data;
1166: Task currentTask = weekContribution.getTask();
1167: // Cas ou la tache supprimée est dans le tableau
1168: // dans ce cas, on sauvegarde le N° pour effectuer
1169: // la suppression par la suite
1170: if (currentTask.getId() == removedTask.getId()) {
1171: itemIdxToRemove = i;
1172: }
1173: // Autre cas : la tache supprimée est la soeur d'une des taches parent
1174: // de la tache en cours ; c'est le cas si le chemin de la tache en cours
1175: // commence par le chemin de la tache qui a été supprimée
1176: else if (currentTask.getPath().startsWith(
1177: removedTask.getPath())) {
1178: String removedTaskFullpath = removedTask
1179: .getFullPath();
1180: String removedTaskSisterFullPath = currentTask
1181: .getFullPath().substring(
1182: 0,
1183: removedTaskFullpath
1184: .length());
1185: // La tache n'est impactée que si sa tache parent se trouvant être la soeur de
1186: // celle qui a été supprimée possède un numéro supérieur à celui de la
1187: // tache supprimée
1188: if (removedTaskSisterFullPath
1189: .compareTo(removedTaskFullpath) > 0) {
1190: // Dans ce cas il faut mettre à jour le chemin de la tache
1191: currentTask = ModelMgr
1192: .getTask(currentTask.getId());
1193: weekContribution.setTask(currentTask);
1194: tableViewer.refresh(weekContribution);
1195: }
1196: }
1197: }
1198: }
1199: // Si on a trouvé l'item supprimé, on le supprime
1200: if (itemIdxToRemove >= 0)
1201: tableViewer.remove(tableViewer
1202: .getElementAt(itemIdxToRemove));
1203: return null;
1204: }
1205:
1206: }.run(parent.getShell());
1207: }
1208:
1209: /* (non-Javadoc)
1210: * @see jfb.tools.activitymgr.ui.TasksUI.TaskListener#taskUpdated(jfb.tools.activitymgr.core.beans.Task)
1211: */
1212: public void taskUpdated(final Task updatedTask) {
1213: // Transfert de la notification au popup de choix de tache
1214: taskChooserDialog.taskUpdated(updatedTask);
1215: // Parcours des taches présentes dans le tableau
1216: int itemCount = tableViewer.getTable().getItemCount();
1217: for (int i = 0; i < itemCount; i++) {
1218: Object data = tableViewer.getElementAt(i);
1219: if (data != WeekContributionsSum.getInstance()) {
1220: WeekContributions weekContribution = (WeekContributions) data;
1221: Task currentTask = weekContribution.getTask();
1222: // Cas ou la tache modifiée est dans le tableau
1223: if (currentTask.getId() == updatedTask.getId()) {
1224: weekContribution.setTask(updatedTask);
1225: tableViewer.refresh(weekContribution);
1226: }
1227: // Autre cas : la tache a modifiée est une tache
1228: // parent de la tache en cours
1229: else if (currentTask.getPath().startsWith(
1230: updatedTask.getFullPath())) {
1231: // Il faut faire un refresh pour que le chemin de code de la tache
1232: // soit mis à jour
1233: tableViewer.refresh(weekContribution);
1234: }
1235: }
1236: }
1237: }
1238:
1239: /* (non-Javadoc)
1240: * @see jfb.tools.activitymgr.ui.TasksUI.ITaskListener#taskMoved(java.lang.String, jfb.tools.activitymgr.core.beans.Task)
1241: */
1242: public void taskMoved(final String oldTaskFullpath,
1243: final Task movedTask) {
1244: new SafeRunner() {
1245: protected Object runUnsafe() throws Exception {
1246: // Transfert de la notification au popup de choix de tache
1247: taskChooserDialog.taskMoved(oldTaskFullpath, movedTask);
1248: // Déduction de l'ancien chemin de la tache à partir de l'ancien
1249: // chemin complet
1250: String oldTaskPath = oldTaskFullpath.substring(0,
1251: oldTaskFullpath.length() - 2);
1252: // Parcours des taches présentes dans le tableau
1253: int itemCount = tableViewer.getTable().getItemCount();
1254: for (int i = 0; i < itemCount; i++) {
1255: Object data = tableViewer.getElementAt(i);
1256: if (data != WeekContributionsSum.getInstance()) {
1257: WeekContributions weekContribution = (WeekContributions) data;
1258: Task currentTask = weekContribution.getTask();
1259: // Cas ou la tache modifiée est dans le tableau
1260: if (currentTask.getId() == movedTask.getId()) {
1261: currentTask = ModelMgr.getTask(currentTask
1262: .getId());
1263: weekContribution.setTask(currentTask);
1264: tableViewer.refresh(weekContribution);
1265: }
1266: // Autre cas : la tache a déplacée est une tache
1267: // parent de la tache en cours
1268: else if (currentTask.getPath().startsWith(
1269: oldTaskFullpath)) {
1270: // Il faut faire un refresh pour que le chemin de code de la tache
1271: // soit mis à jour
1272: currentTask = ModelMgr.getTask(currentTask
1273: .getId());
1274: weekContribution.setTask(currentTask);
1275: tableViewer.refresh(weekContribution);
1276: }
1277: // Autre cas : la tache déplacée est la soeur d'une des taches parent
1278: // de la tache en cours
1279: else if (currentTask.getPath().startsWith(
1280: oldTaskPath)) {
1281: // Dans ce cas il faut mettre à jour le chemin de la tache
1282: currentTask = ModelMgr.getTask(currentTask
1283: .getId());
1284: weekContribution.setTask(currentTask);
1285: tableViewer.refresh(weekContribution);
1286: }
1287: }
1288: }
1289: return null;
1290: }
1291:
1292: }.run(parent.getShell());
1293: }
1294:
1295: }
|