package CH.ifa.draw.application;

import java.io.PrintStream;

import CH.ifa.draw.DrawPlugin;
import CH.ifa.draw.standard.NullDrawing;
import de.renew.draw.ui.ontology.AbstractCommand;
import de.renew.plugin.command.CLCommand;


/**
 * A command that closes a drawing.
 *
 * @author Michael Duvigneau
 **/
public class CloseDrawingCommand extends AbstractCommand implements CLCommand {

    /**
     * Create a new command with the title "Close Drawing"
     */
    public CloseDrawingCommand() {
        super("Close Drawing");
    }

    /**
     * This command is executable only if a drawing to close is
     * available.
     *
     * @return <code>true</code> if there exists a current drawing.
     **/
    @Override
    public final boolean isExecutable() {
        DrawApplication app = DrawPlugin.getGui();
        if (app == null) {
            return false;
        }
        return !(app.drawing() instanceof NullDrawing);
    }

    /**
     * Closes the current drawing.
     **/
    @Override
    public final void execute() {
        DrawApplication app = DrawPlugin.getGui();
        app.closeCurrentDrawing();
    }

    @Override
    public void execute(String[] args, PrintStream response) {
        response.append("trying to close current drawing...");
        execute();
    }

    @Override
    public String getDescription() {
        return "Close the current drawing.";
    }
}