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());
}
}
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);
}
}
}
}
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;
}
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);
}
}
}
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);
}
Aggregations