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.ModelMgr;
031: import jfb.tools.activitymgr.core.beans.Task;
032: import jfb.tools.activitymgr.ui.util.AbstractTableMgr;
033: import jfb.tools.activitymgr.ui.util.SafeRunner;
034: import jfb.tools.activitymgr.ui.util.TableOrTreeColumnsMgr;
035:
036: import org.apache.log4j.Logger;
037: import org.eclipse.jface.viewers.TableViewer;
038: import org.eclipse.swt.SWT;
039: import org.eclipse.swt.layout.GridData;
040: import org.eclipse.swt.layout.GridLayout;
041: import org.eclipse.swt.widgets.Composite;
042: import org.eclipse.swt.widgets.Table;
043:
044: /**
045: * Composant gérant l'historique des tâche adffiché dans le dialogue de choix d'un tâche.
046: */
047: public class TaskChooserTable extends AbstractTableMgr {
048:
049: /** Logger */
050: private static Logger log = Logger.getLogger(TaskChooserTree.class);
051:
052: /** Constantes associées aux colonnes */
053: public static final int TASK_PATH_COLUMN_IDX = 0;
054: public static final int TASK_COLUMN_IDX = 1;
055: private static TableOrTreeColumnsMgr tableColsMgr;
056:
057: /** Viewer */
058: private TableViewer tableViewer;
059:
060: /** Composant parent */
061: private Composite parent;
062:
063: /**
064: * Constructeur par défaut.
065: * @param parentComposite composant parent.
066: * @param layoutData données du layout.
067: * @param tasks la liste des taches à afficher.
068: */
069: public TaskChooserTable(Composite parentComposite,
070: Object layoutData, Task[] tasks) {
071: // Création du composite parent
072: parent = new Composite(parentComposite, SWT.NONE);
073: parent.setLayoutData(layoutData);
074: parent.setLayout(new GridLayout());
075:
076: // Table
077: final Table table = new Table(parent, SWT.FULL_SELECTION
078: | SWT.BORDER | SWT.HIDE_SELECTION | SWT.SINGLE);
079: GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
080: gridData.heightHint = 300;
081: table.setLayoutData(gridData);
082: table.setLinesVisible(true);
083: table.setHeaderVisible(true);
084: table.setEnabled(true);
085:
086: // Création du viewer
087: tableViewer = new TableViewer(table);
088: tableViewer.setContentProvider(this );
089: tableViewer.setLabelProvider(this );
090:
091: // Configuration des colonnes
092: tableColsMgr = new TableOrTreeColumnsMgr();
093: tableColsMgr.addColumn("TASK_PATH", "Task path", 150, SWT.LEFT);
094: tableColsMgr.addColumn("TASK", "Task name", 200, SWT.LEFT);
095: tableColsMgr.configureTable(tableViewer);
096:
097: // Initialisation du tableau
098: tableViewer.setInput(tasks);
099: }
100:
101: /* (non-Javadoc)
102: * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
103: */
104: public String getColumnText(final Object element,
105: final int columnIndex) {
106: log.debug("ITableLabelProvider.getColumnText(" + element + ", "
107: + columnIndex + ")");
108: SafeRunner safeRunner = new SafeRunner() {
109: public Object runUnsafe() throws Exception {
110: Task task = (Task) element;
111: String text = null;
112: switch (columnIndex) {
113: case (TASK_PATH_COLUMN_IDX):
114: text = ModelMgr.getTaskCodePath(task);
115: break;
116: case (TASK_COLUMN_IDX):
117: text = task.getName();
118: break;
119: default:
120: throw new Error("Colonne inconnue");
121: }
122: return text;
123: }
124: };
125: // Exécution
126: return (String) safeRunner.run(parent.getShell(), "");
127: }
128:
129: /* (non-Javadoc)
130: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
131: */
132: public Object[] getElements(final Object inputElement) {
133: return (Task[]) inputElement;
134: }
135:
136: /**
137: * Retourne le viewer associé au tableau.
138: * @return le viewer associé au tableau.
139: */
140: public TableViewer getTableViewer() {
141: return tableViewer;
142: }
143:
144: }
|