use of org.eclipse.swt.events.SelectionEvent in project cogtool by cogtool.
the class SEDemoUI method addSelectionChangeListeners.
/**
* Add the selection Change event listeners.
*/
protected void addSelectionChangeListeners() {
SWTselectionChangeHandler = new SelectionListener() {
public void widgetSelected(SelectionEvent evt) {
SWTList swtList = view.getScriptEditorList();
TableItem[] selectedItems = swtList.getSelectionObject();
for (TableItem selectedItem : selectedItems) {
// TODO: Currently supports only single selection.
Object data = selectedItem.getData();
if (data instanceof Frame) {
selection.setSelectedState(null);
} else {
// should be instanceof DefaultModelGeneratorState!!!
AScriptStep step = ((DefaultModelGeneratorState) data).getScriptStep();
if (step instanceof HearScriptStep) {
if (interaction.askEditFrame()) {
Frame f = step.getCurrentFrame();
performAction(DesignEditorLID.EditFrame, f);
}
TableItem previousSelectedRow = swtList.getRowItem(selection.getPreviousSelection());
selection.setSelectedState(previousSelectedRow);
} else {
selection.setSelectedState(selectedItem);
}
}
}
centerSelectedRegion();
setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
// Let selection change handle changing the frame
}
public void widgetDefaultSelected(SelectionEvent evt) {
SWTList swtList = view.getScriptEditorList();
TableItem[] selectedItems = swtList.getSelectionObject();
// TODO: Currently supports only single selection.
for (TableItem selectedItem : selectedItems) {
Object data = selectedItem.getData();
if (data instanceof DefaultModelGeneratorState) {
DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
AScriptStep step = stepState.getScriptStep();
// In case we need this; not a context selection
// in truth, but we can re-use the structure.
contextSelection.setSelectedState(stepState);
if (editable) {
if (step instanceof DelayScriptStep) {
performAction(SEDemoLID.ChangeWaitProperties, contextSelection);
} else if (step instanceof ThinkScriptStep) {
performAction(SEDemoLID.ChangeThinkProperties, contextSelection);
} else if (isEditable(step)) {
performAction(SEDemoLID.Edit, contextSelection);
}
}
}
}
}
};
view.addSWTListSelectionHandler(SWTselectionChangeHandler);
AlertHandler selectionChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
SEDemoSelectionState.StepStateSelectionChange event = (SEDemoSelectionState.StepStateSelectionChange) alert;
if (event != null) {
if (event.selected) {
DefaultModelGeneratorState stepState = event.changedState;
uiModel.setCurrentOverride(script, script.getPreviousState(stepState));
Frame resultFrame = null;
if (stepState != null) {
resultFrame = stepState.getScriptStep().getCurrentFrame();
} else {
resultFrame = script.getDemonstration().getResultFrame();
}
try {
setCurrentFrame(resultFrame);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Changing current demonstration frame", ex);
}
} else {
// deselect item.
uiModel.setCurrentOverride(script, script.getLastState());
}
}
}
};
selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
use of org.eclipse.swt.events.SelectionEvent in project cogtool by cogtool.
the class ScriptViewerUI method addSelectionChangeListeners.
/**
* Add the selection Change event listeners.
*/
protected void addSelectionChangeListeners() {
SWTselectionChangeHandler = new SelectionListener() {
public void widgetSelected(SelectionEvent evt) {
SWTList swtList = view.getScriptEditorList();
TableItem[] selectedItems = swtList.getSelectionObject();
for (TableItem selectedItem : selectedItems) {
// TODO: Currently supports only single selection.
Object data = selectedItem.getData();
if (data instanceof Frame) {
selection.setSelectedState(null);
} else {
selection.setSelectedState(selectedItem);
}
}
setViewEnabledState(selection, ListenerIdentifierMap.NORMAL);
// Let selection change handle changing the frame
}
public void widgetDefaultSelected(SelectionEvent evt) {
SWTList swtList = view.getScriptEditorList();
TableItem[] selectedItems = swtList.getSelectionObject();
// TODO: Currently supports only single selection.
for (TableItem selectedItem : selectedItems) {
Object data = selectedItem.getData();
if (data instanceof DefaultModelGeneratorState) {
Script s = (Script) selectedItem.getData(SWTListGroupScript.SCRIPT_DATA_KEY);
DefaultModelGeneratorState stepState = (DefaultModelGeneratorState) data;
// In case we need this; not a context selection
// in truth, but we can re-use the structure.
contextSelection.setSelectedState(stepState);
performAction(ProjectLID.EditScript, s);
}
}
}
};
view.addSWTListSelectionHandler(SWTselectionChangeHandler);
AlertHandler selectionChangeHandler = new AlertHandler() {
public void handleAlert(EventObject alert) {
SEDemoSelectionState.StepStateSelectionChange event = (SEDemoSelectionState.StepStateSelectionChange) alert;
if (event != null) {
if (event.selected) {
DefaultModelGeneratorState stepState = event.changedState;
Frame resultFrame = null;
Script script = getSelectedScript(stepState);
AUndertaking t = script.getDemonstration().getTaskApplication().getTask();
if (stepState != null) {
resultFrame = stepState.getScriptStep().getCurrentFrame();
} else if (script != null) {
resultFrame = script.getDemonstration().getResultFrame();
}
DefaultModelGeneratorState overrideState = script.getPreviousState(stepState);
if (overrideState == null) {
TaskGroup group = (TaskGroup) task;
List<AUndertaking> siblingTasks = group.getUndertakings();
int currentTaskIndex = siblingTasks.indexOf(t);
CognitiveModelGenerator modelGen = script.getModelGenerator();
while ((overrideState == null) && (0 <= --currentTaskIndex)) {
AUndertaking prevSibling = siblingTasks.get(currentTaskIndex);
TaskApplication ta = project.getTaskApplication(prevSibling, design);
if (ta != null) {
script = ta.getScript(modelGen);
if (script != null) {
overrideState = script.getLastState();
}
}
}
}
uiModel.setCurrentOverride(script, overrideState);
try {
setCurrentFrame(resultFrame);
} catch (GraphicsUtil.ImageException ex) {
throw new RcvrImageException("Changing current demonstration frame", ex);
}
}
}
}
};
selection.addHandler(this, SEDemoSelectionState.StepStateSelectionChange.class, selectionChangeHandler);
}
use of org.eclipse.swt.events.SelectionEvent in project cogtool by cogtool.
the class StoppableProgressBar method addBelowBar.
@Override
protected void addBelowBar() {
super.addBelowBar();
// box, tying it to the given pausable "process" object.
if (stopListener != null) {
stopButton = new Button(shell, SWT.PUSH);
stopButton.setText(STOP_LABEL);
stopButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
stopListener.stop();
stopButton.setEnabled(false);
}
});
FormData data = new FormData();
// Replace positioning for cancelButton if present
if (cancelButton != null) {
data.left = new FormAttachment(50, 3);
data.top = new FormAttachment(bar, 5, SWT.BOTTOM);
cancelButton.setLayoutData(data);
data = new FormData();
data.right = new FormAttachment(50, -3);
data.top = new FormAttachment(bar, 5, SWT.BOTTOM);
} else {
data.left = new FormAttachment(bar, 0, SWT.CENTER);
data.top = new FormAttachment(bar, 5, SWT.BOTTOM);
}
stopButton.setLayoutData(data);
}
}
use of org.eclipse.swt.events.SelectionEvent in project cogtool by cogtool.
the class ThreadProgressBar method addBelowBar.
@Override
protected void addBelowBar() {
FormData data = new FormData();
// at the top of the dialog box otherwise
if (statusLabel != null) {
data.top = new FormAttachment(statusLabel, 10, SWT.BOTTOM);
data.bottom = new FormAttachment(statusLabel, 25, SWT.BOTTOM);
} else {
data.top = new FormAttachment(0, 10);
data.bottom = new FormAttachment(0, 25);
}
data.left = new FormAttachment(0, 20);
data.right = new FormAttachment(100, -20);
bar.setLayoutData(data);
// box, tying it to the given cancelable "process" object.
if (cancelListener != null) {
cancelButton = new Button(shell, SWT.PUSH);
cancelButton.setText(L10N.get("B.Cancel", "Cancel"));
cancelButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
// Called from the main UI thread
cancelListener.cancel();
cancelButton.setEnabled(false);
}
});
data = new FormData();
data.left = new FormAttachment(bar, 0, SWT.CENTER);
data.top = new FormAttachment(bar, 5, SWT.BOTTOM);
cancelButton.setLayoutData(data);
}
}
use of org.eclipse.swt.events.SelectionEvent in project cogtool by cogtool.
the class ActionPropertySet method createEmptyComposite.
protected Composite createEmptyComposite() {
Composite c = new Composite(actionSettings, SWT.NONE);
c.setLayout(new FormLayout());
ListenerIdentifierMap lidMap = view.getLIDMap();
designNameLabel = new DisplayLabel(c, SWT.NONE);
designNameLabel.setText(nameLabel);
designName = new View.PerformActionText(c, SWT.SINGLE | SWT.BORDER) {
@Override
protected void onFocus() {
super.onFocus();
view.getTransmuter().setLIDEnabledState();
}
@Override
protected boolean doChangeAction() {
Design design = (Design) designName.getData();
DesignEditorUI.DesignRenameParameters parms = new DesignEditorUI.DesignRenameParameters(design, designName.getText());
boolean changed = view.performAction(ProjectLID.RenameDesign, parms, true);
if (!changed) {
designName.setText(design.getName());
}
return changed;
}
};
inputDevicesLabel = new DisplayLabel(c, SWT.NONE);
inputDevicesLabel.setText(L10N.get("APS.InputDevices", "Input Devices") + ":");
outputDevicesLabel = new DisplayLabel(c, SWT.NONE);
outputDevicesLabel.setText(L10N.get("APS.OutputDevices", "Output Devices") + ":");
for (int i = 0; i < DeviceType.DISPLAY_ORDER.length; i++) {
deviceButtons[i] = new Button(c, SWT.CHECK);
deviceButtons[i].setText(DeviceType.DISPLAY_ORDER[i].getName());
deviceButtons[i].setEnabled(false);
deviceButtons[i].setSelection(false);
}
addDevices = new Button(c, SWT.PUSH);
addDevices.setText(addDevicesLabel);
addDevices.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
view.performAction(DesignEditorLID.AddDesignDevices);
}
});
lidMap.addWidget(DesignEditorLID.AddDesignDevices, addDevices, ListenerIdentifierMap.NORMAL);
skinLabel = new DisplayLabel(c, SWT.NONE);
skinLabel.setText(DESIGN_SKIN);
skinCombo = new ComboWithEnableFix(c, SWT.DROP_DOWN | SWT.READ_ONLY);
for (int i = 1; i < SkinType.DISPLAY.length - 1; i++) {
// Don't allow None or Palm
skinCombo.add(SkinType.DISPLAY[i].getName());
}
skinCombo.select(0);
skinCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent evt) {
switch(skinCombo.getSelectionIndex()) {
case 0:
default:
{
view.performAction(DesignEditorLID.SkinWireFrame);
break;
}
case 1:
{
view.performAction(DesignEditorLID.SkinMacOSX);
break;
}
case 2:
{
view.performAction(DesignEditorLID.SkinWinXP);
break;
}
}
}
});
frameTreeLabel = new DisplayLabel(c, SWT.NONE);
frameTreeLabel.setText(FRAMES);
frameTree = new Tree(c, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
frameTree.setLinesVisible(true);
updater = new TreeItemUpdater.FrameItemUpdater(frameTree);
return c;
}
Aggregations