Search in sources :

Example 1 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cogtool by cogtool.

the class SWTTreeProjectSelectionState method selectItems.

/**
     * Recursively selects all rows in the associated SWT Tree.
     *
     * @param items the next level of children items to select
     */
protected void selectItems(TreeItem[] items) {
    // Select each child item and check if it has child items
    for (TreeItem item : items) {
        addSelectedItem(item);
        // Recursively select any children of the current item
        selectItems(item.getItems());
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem)

Example 2 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cogtool by cogtool.

the class ProjectUI method showContextMenu.

// Override to set the correct context menu on the frame
//    item  item-selected column design  where          selection to use
//(a)  ok        n/a        ok     ok    cell           temporary cell
//(b)  ok        yes        ok    null   task           normal selection
//(c)  ok        no         ok    null   task           temporary task
//(d)  ok        n/a       null    n/a   right of cells temporary task
//(e) null       n/a        ok     ok    design         temporary design
//(f) null       n/a        ok    null   bottom-left    no selection
//(g) null       n/a       null    n/a   bottom-right   no selection
// TODO: dfm -- make the code match the above!!!!!
@Override
public void showContextMenu(int x, int y) {
    // Clear any stale state
    contextSelection.deselectAll();
    // Check which region of the frame was hit
    TreeItem item = tree.getItem(new Point(x, y));
    TreeColumn column = findColumn(x);
    // See if the context invocation was made beyond all designs
    if (column == null) {
        if (item == null) {
            // see (g) above
            showContextMenu();
        } else {
            // see (d) above
            selectOverBox(item.getBounds());
            contextSelection.addSelectedTask((AUndertaking) item.getData());
            showContextMenu(contextSelection, View.CONTEXT);
        }
    } else // If not, the invocation occurred somewhere within the table
    {
        Design design = (Design) column.getData();
        // Detect a context invocation in the table header/footer
        if (item == null) {
            // Detect a context invocation under the "tasks" heading
            if (design == null) {
                // see (f) above
                showContextMenu();
            } else // Otherwise the invocation lies under a design heading
            {
                // see (e) above
                // TODO: Really?  What if something else was selected?
                selectOverBox(computeColumnArea(column));
                contextSelection.setSelectedDesign(design);
                showContextMenu(contextSelection, View.CONTEXT);
            }
        } else // Detect a context invocation inside the table body
        {
            AUndertaking undertaking = (AUndertaking) item.getData();
            // Check for context invocation under the "tasks" column
            if (design == null) {
                // Set up the contextual selection state as necessary
                if (selection.isTaskSelected(undertaking)) {
                    // see (b) above
                    showContextMenu();
                } else {
                    // see (c) above
                    selectOverBox(item.getBounds());
                    contextSelection.addSelectedTask(undertaking);
                    showContextMenu(contextSelection, View.CONTEXT);
                }
            } else // Otherwise at the intersection of a task and a design
            {
                // see (a) above
                selection.setSelectedCell(item, column);
                Rectangle bounds = item.getBounds(tree.indexOf(column));
                if (OSUtils.MACOSX) {
                    // XXX: DIRTY HACK TO fix SWT bug.
                    bounds.y -= 1;
                    bounds.height += 1;
                }
                selectOverBox(bounds);
                // TODO: instead of the following, pass undertaking and
                //       design in to showContextMenuForIntersection()
                Menu contextMenu = view.getContextMenuForIntersection(project, undertaking, design);
                // Set up the contextual selection state as necessary
                contextSelection.setSelectedDesign(design);
                contextSelection.addSelectedTask(undertaking);
                setViewEnabledState(contextSelection, ListenerIdentifierMap.CONTEXT);
                contextMenu.setVisible(true);
            }
        }
    }
}
Also used : Design(edu.cmu.cs.hcii.cogtool.model.Design) TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Menu(org.eclipse.swt.widgets.Menu)

Example 3 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cogtool by cogtool.

the class ProjectUI method commitRenameTask.

// initiateTaskRename
/**
     * Reports a task renaming to the controller.
     * @param item
     */
protected boolean commitRenameTask(boolean activeCommit) {
    boolean success = true;
    if (editor.getEditor() != null) {
        Text text = (Text) editor.getEditor();
        String newName = text.getText();
        TreeItem item = editor.getItem();
        // Get task & parent taskgroup from item, don't use this.selection!
        AUndertaking taskToRename = (AUndertaking) item.getData();
        TreeItem parentItem = item.getParentItem();
        TaskGroup parentGroup = (TaskGroup) ((parentItem != null) ? parentItem.getData() : null);
        cleanupTaskEditor();
        success = performAction((CogToolPref.HCIPA.getBoolean()) ? ProjectLID.HCIPARenameTask : ProjectLID.RenameTask, new ProjectUI.TaskRenameEvent(taskToRename, newName, parentGroup), false);
        if (activeCommit) {
            renameTaskItem = null;
        }
    }
    return success;
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Text(org.eclipse.swt.widgets.Text) ManagedText(edu.cmu.cs.hcii.cogtool.util.ManagedText) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 4 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cogtool by cogtool.

the class ProjectMouseState method dealWithMouseDoubleClick.

@Override
protected void dealWithMouseDoubleClick(MouseEvent me) {
    super.dealWithMouseDoubleClick(me);
    TreeItem item = ui.tree.getItem(new Point(me.x, me.y));
    TreeColumn column = ui.findColumn(me.x);
    // check to see if the group visibility should toggle
    if ((item != null) && (column == null)) {
        // Toggle tree expand when a TaskGroup is double-clicked,
        // but not if double-clicking on the first column to edit the name
        AUndertaking u = (AUndertaking) item.getData();
        if (u.isTaskGroup()) {
            item.setExpanded(!item.getExpanded());
        }
    }
    // If on a valid cell, either edit script or open the script viewer
    if ((item != null) && (column != null) && (column.getData() != null)) {
        AUndertaking u = (AUndertaking) item.getData();
        // At the intersection of a task and design
        ProjectContextSelectionState seln = new ProjectContextSelectionState(ui.getProject());
        seln.setSelectedDesign((Design) column.getData());
        seln.addSelectedTask(u);
        if (u.isTaskGroup()) {
            TaskGroup group = (TaskGroup) u;
            if (GroupNature.SUM.equals(group.getNature())) {
                item.setExpanded(true);
                ui.cleanupTaskEditor();
                //TODO: won't work since repaint won't occur until after we're all done.
                ui.performAction(ProjectLID.ViewGroupScript, seln);
            }
        } else {
            ui.cleanupTaskEditor();
            //TODO: won't work since repaint won't occur until after we're all done.
            ui.performAction(ProjectLID.EditScript, seln);
        }
    } else if ((item != null) && (column != null) && (column.getData() == null)) {
        // In a valid row, first column
        if (ui.treeOperationOccurred == 0) {
            ui.initiateTaskRename(item, true);
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) TreeColumn(org.eclipse.swt.widgets.TreeColumn) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) Point(org.eclipse.swt.graphics.Point) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup)

Example 5 with TreeItem

use of org.eclipse.swt.widgets.TreeItem in project cogtool by cogtool.

the class ProjectUIModel method setGroupAlertHandlers.

// populateRow
protected void setGroupAlertHandlers(TaskGroup group, final TreeItem row) {
    AlertHandler handler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            TaskGroup.TaskChange chg = (TaskGroup.TaskChange) alert;
            if (chg != null) {
                if (chg.isAdd) {
                    TreeItem newRow;
                    if (chg.atIndex == TaskGroup.TaskChange.AT_END) {
                        newRow = new TreeItem(row, SWT.NONE);
                    } else {
                        newRow = new TreeItem(row, SWT.NONE, chg.atIndex);
                    }
                    row.setExpanded(true);
                    populateRow((AUndertaking) chg.element, newRow);
                    redisplayResults(newRow);
                } else {
                    TreeItem rowToDelete = findChildRow((AUndertaking) chg.element, row.getItems());
                    recoverTreeItem(rowToDelete);
                }
            }
        }
    };
    group.addHandler(this, TaskGroup.TaskChange.class, handler);
    handler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            //                    System.out.println("NatureChange!");
            // walk up the group tree and recalculate
            redisplayResults(row);
        }
    };
    group.addHandler(this, TaskGroup.NatureChange.class, handler);
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) TaskGroup(edu.cmu.cs.hcii.cogtool.model.TaskGroup) EventObject(java.util.EventObject)

Aggregations

TreeItem (org.eclipse.swt.widgets.TreeItem)150 Tree (org.eclipse.swt.widgets.Tree)36 SelectionEvent (org.eclipse.swt.events.SelectionEvent)23 GridData (org.eclipse.swt.layout.GridData)23 Point (org.eclipse.swt.graphics.Point)21 ArrayList (java.util.ArrayList)20 TreeColumn (org.eclipse.swt.widgets.TreeColumn)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 Composite (org.eclipse.swt.widgets.Composite)14 TableItem (org.eclipse.swt.widgets.TableItem)14 SelectionListener (org.eclipse.swt.events.SelectionListener)13 Group (org.eclipse.swt.widgets.Group)13 Button (org.eclipse.swt.widgets.Button)12 Table (org.eclipse.swt.widgets.Table)12 Event (org.eclipse.swt.widgets.Event)11 List (java.util.List)10 Label (org.eclipse.swt.widgets.Label)10 CubridGroupNode (com.cubrid.common.ui.spi.model.CubridGroupNode)9 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)9