use of edu.cmu.cs.hcii.cogtool.model.HearScriptStep 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);
}
Aggregations