Search in sources :

Example 16 with DefaultModelGeneratorState

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;
}
Also used : Frame(edu.cmu.cs.hcii.cogtool.model.Frame) FileWriter(java.io.FileWriter) IOException(java.io.IOException) AScriptStep(edu.cmu.cs.hcii.cogtool.model.AScriptStep) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) ThinkScriptStep(edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep) Design(edu.cmu.cs.hcii.cogtool.model.Design) TransitionSource(edu.cmu.cs.hcii.cogtool.model.TransitionSource) TextActionSegment(edu.cmu.cs.hcii.cogtool.model.TextActionSegment) AUndertaking(edu.cmu.cs.hcii.cogtool.model.AUndertaking) LookAtScriptStep(edu.cmu.cs.hcii.cogtool.model.LookAtScriptStep) TaskApplication(edu.cmu.cs.hcii.cogtool.model.TaskApplication) Demonstration(edu.cmu.cs.hcii.cogtool.model.Demonstration) File(java.io.File) IWidget(edu.cmu.cs.hcii.cogtool.model.IWidget) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 17 with DefaultModelGeneratorState

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));
}
Also used : DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 18 with DefaultModelGeneratorState

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;
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) EventObject(java.util.EventObject) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 19 with DefaultModelGeneratorState

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);
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) TableItem(org.eclipse.swt.widgets.TableItem) SWTListMultiColumn(edu.cmu.cs.hcii.cogtool.view.SWTListMultiColumn) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Example 20 with DefaultModelGeneratorState

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);
}
Also used : EventObject(java.util.EventObject) DefaultModelGeneratorState(edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)

Aggregations

DefaultModelGeneratorState (edu.cmu.cs.hcii.cogtool.model.DefaultModelGeneratorState)21 Demonstration (edu.cmu.cs.hcii.cogtool.model.Demonstration)9 ThinkScriptStep (edu.cmu.cs.hcii.cogtool.model.ThinkScriptStep)7 AUndoableEdit (edu.cmu.cs.hcii.cogtool.util.AUndoableEdit)7 AScriptStep (edu.cmu.cs.hcii.cogtool.model.AScriptStep)6 TableItem (org.eclipse.swt.widgets.TableItem)6 ComputationUndoRedo (edu.cmu.cs.hcii.cogtool.controller.DemoScriptCmd.ComputationUndoRedo)5 TaskApplication (edu.cmu.cs.hcii.cogtool.model.TaskApplication)5 IUndoableEdit (edu.cmu.cs.hcii.cogtool.util.IUndoableEdit)5 DelayScriptStep (edu.cmu.cs.hcii.cogtool.model.DelayScriptStep)4 Frame (edu.cmu.cs.hcii.cogtool.model.Frame)4 HandLocation (edu.cmu.cs.hcii.cogtool.model.HandLocation)4 Script (edu.cmu.cs.hcii.cogtool.model.Script)4 EventObject (java.util.EventObject)4 Table (org.eclipse.swt.widgets.Table)3 AUndertaking (edu.cmu.cs.hcii.cogtool.model.AUndertaking)2 CognitiveModelGenerator (edu.cmu.cs.hcii.cogtool.model.CognitiveModelGenerator)2 Design (edu.cmu.cs.hcii.cogtool.model.Design)2 SEDemoInteraction (edu.cmu.cs.hcii.cogtool.ui.SEDemoInteraction)2 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)2