开发者

I have a modal Window implemented in SmartGWT - how can I close it when someone clicks off of the window?

I've created a class that extends the Window SmartGWT class, and it is set to be modal. I am trying to make the Window close when a user clicks off the window. I have tried to link it up to a FocusChangedHandler with no luck. Has anyone done something like this before?


/**
 * Sets up a modal Dialog box that lets the user edit attributes associated
 * with the properties of the {@link LabElement} that are given. 
 * 
 * @author Therin Irwin
 */
public class EditorDialog extends Window {

    final DynamicForm dyn = new DynamicForm();
    final RichTextEditor richTextEditor = new RichTextEditor();
    final List attrItems = new ArrayList();

    /**
     * Creates a new Edi开发者_开发百科torDialog with a RichTextEditor and a list of
     * attributes for the element.
     * 
     * @param name the name of the element being edited.
     * @param attr the List of String attributes of the element that can be
     * edited.
     * @param hasText true if the element supports text inside, false if not.
     */
    public EditorDialog(String name, List attr, boolean hasText) {
        super();

        VLayout vert = new VLayout();
        this.setShowMinimizeButton(false);  
        this.setIsModal(true);  
        this.setShowModalMask(true);  
        this.setTitle(name + " Editor");
        richTextEditor.setWidth(550);
        richTextEditor.setHeight(100);

        richTextEditor.setPadding(5);
        richTextEditor.setCanDragResize(true); 
        richTextEditor.setResizeFrom("B");
        richTextEditor.setShowEdges(true);

        if (attr == null || attr.size() == 0) {
            richTextEditor.setHeight(300);
        }
        else {
            int i = 0;
            FormItem[] fi = new FormItem[attr.size()];

            for (String at : attr) {
                TextItem temp = new TextItem(at, at);
                attrItems.add(temp);
                fi[i++] = temp;
            }

            dyn.setFields(fi);
            dyn.setPadding(5);
            dyn.setTop(100);
        } 

        if (hasText)
            vert.addMember(richTextEditor);

        if (!(attr == null || attr.size() == 0))
            vert.addMember(dyn);

        this.addItem(vert);
        this.centerInPage();
        this.setAutoSize(true);
    }

    /**
     * Returns the text of the RichTextEditor.
     * 
     * @return the text entered into the RichTextEditor.
     */
    public String getRichText() {
        return richTextEditor.getValue();
    }

    /**
     * Sets the text in the RichTextEditor to String value.
     * 
     * @param value the String to put as the contents of the RichTextEditor.
     */
    public void setRichText(String value) {
        richTextEditor.setValue(value);
    }

    /**
     * Returns the List of TextItems that hold the user-entered values for
     * attributes.
     * 
     * @return the TextItems associated with each attribute, in order.
     */
    public DynamicForm getFormItems() {
        return dyn;
    }

    public TextItem getFormItem(int item) {
        return (TextItem) dyn.getFields()[item];
    }
}


@Therin I guess according to your requirement, you need to implement this property of Window:

this.setDismissOnOutsideClick(true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜