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.StructuredSelection;
034: import org.eclipse.jface.viewers.TreeViewer;
035: import org.eclipse.swt.SWT;
036: import org.eclipse.swt.events.MouseEvent;
037: import org.eclipse.swt.events.MouseListener;
038: import org.eclipse.swt.widgets.Composite;
039: import org.eclipse.swt.widgets.Control;
040: import org.eclipse.swt.widgets.Shell;
041: import org.eclipse.swt.widgets.TreeItem;
042:
043: public class TasksChooserDialog extends AbstractDialog implements
044: MouseListener {
045:
046: /** Logger */
047: private static Logger log = Logger
048: .getLogger(TasksChooserDialog.class);
049:
050: /** Arbre contenant la liste des tâches */
051: private TasksChooserTree tasksTree;
052:
053: /** Valideur */
054: private ITaskChooserValidator validator;
055:
056: /**
057: * Constructeur par défaut.
058: * @param parentShell shell parent.
059: */
060: public TasksChooserDialog(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: TreeItem[] selection = tasksTree.getTreeViewer().getTree()
072: .getSelection();
073: Task selectedTask = null;
074: if (selection.length > 0)
075: selectedTask = (Task) selection[0].getData();
076: log.debug("Selected task = " + selectedTask);
077: if (selectedTask == null)
078: throw new DialogException("Please choose a task", null);
079: if (validator != null)
080: validator.validateChoosenTask(selectedTask);
081: // Validation du choix de la tache
082: return selectedTask;
083: }
084:
085: /* (non-Javadoc)
086: * @see jfb.tools.activitymgr.ui.util.AbstractDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
087: */
088: protected Control createDialogArea(Composite parent) {
089: Composite c = (Composite) super .createDialogArea(parent);
090: tasksTree = new TasksChooserTree(c);
091: TreeViewer viewer = tasksTree.getTreeViewer();
092: viewer.getTree().addMouseListener(this );
093: Task lastValue = (Task) getValue();
094: if (lastValue != null) {
095: viewer.setSelection(new StructuredSelection(lastValue));
096: }
097: return c;
098: }
099:
100: /* (non-Javadoc)
101: * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
102: */
103: public void mouseDoubleClick(MouseEvent e) {
104: okPressed();
105: }
106:
107: /* (non-Javadoc)
108: * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
109: */
110: public void mouseDown(MouseEvent e) {
111: }
112:
113: /* (non-Javadoc)
114: * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
115: */
116: public void mouseUp(MouseEvent e) {
117: }
118:
119: /**
120: * @param validator le nouveau valideur.
121: */
122: public void setValidator(ITaskChooserValidator validator) {
123: this.validator = validator;
124: }
125:
126: }
|