
package de.ugoe.cs.quest.ui.swt.commands;

import java.security.InvalidParameterException;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;

import de.ugoe.cs.quest.CommandHelpers;
import de.ugoe.cs.quest.SequenceInstanceOf;
import de.ugoe.cs.quest.ui.GlobalDataContainer;
import de.ugoe.cs.quest.ui.swt.SequencesDialog;
import de.ugoe.cs.util.console.Command;
import de.ugoe.cs.util.console.Console;

/**
 * <p>
 * Command to show sequences.
 * </p>
 * 
 * @author Jeffrey Hall, Steffen Herbold
 */
public class CMDshowSequences implements Command {

    /*
     * (non-Javadoc)
     * 
     * @see de.ugoe.cs.util.console.Command#help()
     */
    @Override
    public void help() {
        Console.println("Usage: showSequences <sequencesName>");
    }

    /*
     * (non-Javadoc)
     * 
     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
     */
    @Override
    public void run(List<Object> parameters) {
        String sequencesName;
        try {
            sequencesName = (String) parameters.get(0);
        }
        catch (Exception e) {
            throw new InvalidParameterException();
        }

        Object dataObject = GlobalDataContainer.getInstance().getData(sequencesName);
        if (dataObject == null) {
            CommandHelpers.objectNotFoundMessage(sequencesName);
            return;
        }
        if (!SequenceInstanceOf.isCollectionOfSequences(dataObject)) {
            CommandHelpers.objectNotType(sequencesName, "Collection<List<Event<?>>>");
            return;
        }

        Shell shell = new Shell(SWT.NONE);
        shell.open();
        shell.layout();
        shell.setSize(0, 0);
        SequencesDialog sequencesDialog = new SequencesDialog(shell, SWT.NONE);
        sequencesDialog.open(sequencesName);
        shell.dispose();
    }
}
