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

半腔热情 提交于 2020-01-06 04:35:46

问题


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 EditorDialog 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];
    }
}

回答1:


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

this.setDismissOnOutsideClick(true);


来源:https://stackoverflow.com/questions/5160443/i-have-a-modal-window-implemented-in-smartgwt-how-can-i-close-it-when-someone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!