use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState in project cogtool by cogtool.
the class DemoScriptCmd method exportScriptToCSV.
public static boolean exportScriptToCSV(Script script, Project project, Interaction interaction, IUndoableEditSequence editSeq) {
Demonstration demo = script.getDemonstration();
TaskApplication ta = demo.getTaskApplication();
Design design = ta.getDesign();
AUndertaking task = ta.getTask();
String name = project.getName();
name += "_" + design.getName();
name += "_" + task.getName();
File dest = null;
if (interaction != null) {
dest = interaction.selectCSVFileDest(name);
} else {
dest = new File(CogTool.exportCSVKludgeDir, name + ".txt");
}
if (dest == null) {
return false;
}
FileWriter fw = null;
BufferedWriter buffer = null;
try {
fw = new FileWriter(dest);
buffer = new BufferedWriter(fw);
CSVSupport.writeCell("Format version:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(FORMAT_VERSION, buffer);
CSVSupport.addLineEnding(buffer);
Date now = new Date();
String date = DateFormat.getDateTimeInstance().format(now);
CSVSupport.writeCell("Date and Time:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(date, buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Project Name:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(project.getName(), buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Design Name:", buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(design.getName(), buffer);
CSVSupport.addLineEnding(buffer);
CSVSupport.writeCell("Task Hierarchy:", buffer);
String taskName = task.getFullName();
String[] cells = taskName.split(":");
for (String cell : cells) {
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(cell, buffer);
}
CSVSupport.addLineEnding(buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.addLineEnding(buffer);
buffer.write("\"Frame\",\"Action\",\"Widget-Name\"," + "\"Displayed-Label\",\"Widget-Type\"");
CSVSupport.addLineEnding(buffer);
IWidget lastMovedToWidget = null;
Iterator<DefaultModelGeneratorState> stepStates = script.getStepStates().iterator();
while (stepStates.hasNext()) {
DefaultModelGeneratorState stepState = stepStates.next();
AScriptStep step = stepState.getScriptStep();
TransitionSource stepFocus = step.getStepFocus();
String frameName = step.getCurrentFrame().getName();
String actionName = KeyDisplayUtil.convertActionToMenuText(step.getLocalizedString());
if ((!(step instanceof LookAtScriptStep)) && (!(step instanceof ThinkScriptStep)) && (!(step instanceof TextActionSegment))) {
actionName = step.getLocalizedActionString(actionName, lastMovedToWidget);
}
lastMovedToWidget = stepState.getLastMovedToWidget();
String widgetName = "";
String widgetType = "";
String widgetTitle = "";
if (stepFocus != null) {
widgetName = stepFocus.getName();
if (stepFocus instanceof IWidget) {
IWidget w = (IWidget) stepFocus;
widgetType = w.getWidgetType().toString();
String s = w.getTitle();
if (s != null) {
widgetTitle = s;
}
}
}
CSVSupport.writeCell(frameName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(actionName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetName, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetTitle, buffer);
CSVSupport.addSeparator(buffer);
CSVSupport.writeCell(widgetType, buffer);
CSVSupport.addLineEnding(buffer);
}
Frame resultFrame = demo.getResultFrame();
if (resultFrame != null) {
CSVSupport.writeCell(resultFrame.getName(), buffer);
}
if (interaction != null) {
interaction.setStatusMessage(L10N.get("DSO.ExportCompletedPre", "Export completed to ") + dest + L10N.get("DSO.ExportCompletePost", "."));
}
} catch (IOException e) {
if (interaction != null) {
interaction.reportProblem("File I/O Error", e.getMessage());
} else {
e.printStackTrace();
}
return false;
} finally {
try {
if (buffer != null) {
buffer.close();
}
if (fw != null) {
fw.close();
}
} catch (IOException e) {
if (interaction != null) {
interaction.reportProblem("File I/O Error on Close", e.getMessage());
} else {
e.printStackTrace();
}
return false;
}
}
return true;
}
use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState in project cogtool by cogtool.
the class ScriptViewerUI method setViewEnabledState.
/**
* Enables or disables LIDs as appropriate
*
* Primarily used to enable Edit Think Duration or edit Delay Duration.
*
* @param selnState the selection state on which to base enabling/disabling
* @param availability NORMAL or CONTEXT
* @see ListenerIdentifierMap
*/
protected void setViewEnabledState(SEDemoSelectionState selnState, Boolean availability) {
setEnabled(SEDemoLID.RecomputeScript, availability, false);
setEnabled(SEDemoLID.RegenerateScript, availability, false);
setEnabled(SEDemoLID.ChangeWaitProperties, availability, false);
setEnabled(SEDemoLID.ChangeThinkProperties, availability, false);
setEnabled(CogToolLID.Delete, availability, false);
setEnabled(SEDemoLID.InsertThink, availability, false);
setEnabled(SEDemoLID.InsertLookAt, availability, false);
setEnabled(SEDemoLID.InsertDelay, availability, false);
DefaultModelGeneratorState state = (availability == ListenerIdentifierMap.CONTEXT) ? contextSelection.getSelectedState() : selection.getSelectedState();
setEnabled(ProjectLID.EditScript, availability, (state != null));
}
use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState in project cogtool by cogtool.
the class ScriptViewerUI method getParameters.
@Override
public Object getParameters(ListenerIdentifier originalLID, ListenerIdentifier transmutedLID, boolean isContextSelection) {
Object parameters = super.getParameters(originalLID, transmutedLID, isContextSelection);
if (parameters != UNSET) {
return parameters;
}
if (ProjectLID.EditScript.equals(originalLID)) {
DefaultModelGeneratorState stepState = contextSelection.getSelectedState();
TableItem item = view.getScriptEditorList().getItemList().get(stepState);
return item.getData(SWTListGroupScript.SCRIPT_DATA_KEY);
}
if (DesignEditorLID.EditFrame.equals(originalLID)) {
return uiModel.getCurrentFrame().getFrame();
}
return selection;
}
use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState in project cogtool by cogtool.
the class SEDemoUI method updateView.
/**
* Update the view: Set the View's List with the current ScriptSteps
*/
@Override
protected void updateView() {
Iterator<DefaultModelGeneratorState> states = script.getStepStates().iterator();
SWTListMultiColumn swtList = view.getScriptEditorList();
swtList.setListContents(states);
swtList.addListItem(script.getDemonstration().getResultFrame());
TableItem item = selection.getSelectedStateRow();
Table t = view.getHistoryTable();
if (item == null) {
TableItem[] items = t.getItems();
if (items.length > 0) {
t.showItem(t.getItem(items.length - 1));
}
} else {
t.showItem(item);
}
}
use of edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState in project cogtool by cogtool.
the class SEDemoSelectionState method setSelectedState.
public void setSelectedState(TableItem stateRow) {
DefaultModelGeneratorState stepState = null;
if (stateRow == null) {
// highlight last item
table.setSelection(table.getItemCount() - 1);
} else {
table.setSelection(stateRow);
Object selectedState = stateRow.getData();
if (selectedState instanceof DefaultModelGeneratorState) {
stepState = (DefaultModelGeneratorState) selectedState;
}
}
previousSelection = stepState;
changeAlert.changedState = stepState;
changeAlert.selected = true;
raiseAlert(changeAlert);
}
Aggregations