FileDocCategorySizeDatePackage
Lesson8.javaAPI DocExample2758Thu Feb 17 20:00:56 GMT 2000com.togethersoft.modules.tutorial

Lesson8.java

/*----------------------------------------------------------------------------
Copyright (c)2000 TogetherSoft LLC. Patents pending. All rights reserved.
----------------------------------------------------------------------------*/

package com.togethersoft.modules.tutorial;

import com.togethersoft.openapi.ide.IdeContext;
import com.togethersoft.openapi.ide.IdeScript;
import com.togethersoft.openapi.ide.message.IdeMessageManager;
import com.togethersoft.openapi.ide.message.IdeMessageManagerAccess;
import com.togethersoft.openapi.ide.message.IdeMessageType;
import com.togethersoft.openapi.ide.progress.IdeProgressIndicatorAccess;
import com.togethersoft.openapi.ide.progress.IdeProgressIndicator;
import com.togethersoft.openapi.ide.progress.IdeProgress;

/**
 * This script shows how to use Together's progress indicator. You can use the java.text.MessageFormat's
 * format in the ProgressIndicator.start method to produce a nice output.
 * @author TogetherSoft LLC
 */
public class Lesson8 implements IdeScript {
    public void run(IdeContext context) {
        IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson8 script: started");
        IdeProgressIndicator progressIndicator = IdeProgressIndicatorAccess.getProgressIndicator();
        IdeProgress progress = progressIndicator.start("myID", true, 70,
            "Step {0, number, integer} of {1, number, integer}. {3, number, percent} completed. ({2})");
        for (int i = 0; i < 70; i++) {
            if (progress.isCancelRequested()) {
                break;
            }
            try { Thread.sleep(600); }
            catch(Exception e) { }
            progress.setCount(i);
            if (i % 10 == 0) {
                progress.setStep(getDescription(i / 10));
            }
        }
        progress.stop();
        IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson8 script: finished");
    }

    private String getDescription(int stage) {
        switch (stage) {
            case 0:
                return "You can stop this demo by pressing Cancel button";
            case 1:
                return "Indicator supports java.text.MessageFormat's syntax";
            case 2:
                return "Use it to create nice-looking output messages";
            case 3:
                return "You can create cancelabe/non-cancelable indicators";
            case 4:
                return "You can create delayed indicators (see API docs)";
            case 5:
                return "Together's progress indicator is very flexible!";
            case 6:
                return "See ide.progress package description in API docs";
        }
        return "";
    }
}