001: /*
002: * Copyright (c) 2004-2006, Jean-François Brazeau. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * 2. Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: *
014: * 3. The name of the author may not be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
018: * IMPLIEDWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
019: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
020: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
021: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
022: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
023: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
024: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
025: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
026: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: */
028: package jfb.tools.activitymgr.ui.dialogs;
029:
030: import jfb.tools.activitymgr.core.beans.Task;
031:
032: import org.apache.log4j.Logger;
033: import org.eclipse.jface.viewers.IStructuredSelection;
034: import org.eclipse.swt.SWT;
035: import org.eclipse.swt.events.MouseAdapter;
036: import org.eclipse.swt.events.MouseEvent;
037: import org.eclipse.swt.layout.GridData;
038: import org.eclipse.swt.widgets.Composite;
039: import org.eclipse.swt.widgets.Control;
040: import org.eclipse.swt.widgets.Label;
041: import org.eclipse.swt.widgets.Shell;
042: import org.eclipse.swt.widgets.Table;
043:
044: public class TaskChooserDialog extends AbstractDialog {
045:
046: /** Logger */
047: private static Logger log = Logger
048: .getLogger(TaskChooserDialog.class);
049:
050: /** Tableau contenant les dernières taches sélectionnées */
051: private TaskChooserTable tasksTable;
052:
053: /** Liste des taches à afficher */
054: private Task[] tasks;
055:
056: /**
057: * Constructeur par défaut.
058: * @param parentShell shell parent.
059: */
060: public TaskChooserDialog(Shell parentShell) {
061: super (parentShell, "Choose a task", null, null);
062: setShellStyle(SWT.RESIZE | SWT.DIALOG_TRIM
063: | SWT.APPLICATION_MODAL);
064: }
065:
066: /* (non-Javadoc)
067: * @see jfb.tools.activitymgr.ui.util.AbstractDialog#validateUserEntry()
068: */
069: protected Object validateUserEntry() throws DialogException {
070: log.debug("validateUserEntry");
071: Task selectedTask = (Task) ((IStructuredSelection) tasksTable
072: .getTableViewer().getSelection()).getFirstElement();
073: // Validation du choix de la tache
074: return selectedTask;
075: }
076:
077: /* (non-Javadoc)
078: * @see jfb.tools.activitymgr.ui.util.AbstractDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
079: */
080: protected Control createDialogArea(Composite parent) {
081: Composite parentComposite = (Composite) super
082: .createDialogArea(parent);
083: GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
084: // Ajout de la liste des taches
085: // Ajout du titre de sélection des taches précédemment sélectionnées
086: Label label = new Label(parentComposite, SWT.NONE);
087: gridData = new GridData(SWT.FILL, SWT.FILL, false, false);
088: gridData.horizontalSpan = 2;
089: label.setLayoutData(gridData);
090: label.setText("Found tasks :");
091: // Ajout de la liste des sélections précédentes
092: gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
093: gridData.horizontalSpan = 2;
094: gridData.heightHint = 300;
095: tasksTable = new TaskChooserTable(parentComposite, gridData,
096: tasks);
097: final Table table = tasksTable.getTableViewer().getTable();
098: table.addMouseListener(new MouseAdapter() {
099: public void mouseDoubleClick(MouseEvent e) {
100: okPressed();
101: }
102: });
103:
104: // Retour du composant parent
105: return parentComposite;
106: }
107:
108: /**
109: * Définit la liste des taches qui doivent être affichées dans le dialogue.
110: * @param tasks la liste des taches.
111: */
112: public void setTasks(Task[] tasks) {
113: this.tasks = tasks;
114: }
115:
116: }
|