001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.web.shared;
017
018import com.smartgwt.client.widgets.Window;
019import com.smartgwt.client.widgets.events.CloseClickHandler;
020import com.smartgwt.client.widgets.events.CloseClientEvent;
021import com.smartgwt.client.widgets.layout.VStack;
022import org.modeshape.web.client.Console;
023
024/**
025 *
026 * @author kulikov
027 */
028public abstract class ModalForm {
029    private final VStack layout = new VStack();
030    private final Window window = new Window();
031    private final Form form;
032    
033    public ModalForm(final Console console, 
034            int width, int height, String title, Form form) {
035        this.form = form;
036        this.form.setTop(22);
037        initWindow(title, width, height);
038    }
039    
040    private void initWindow(String title, int width, int height) {
041        window.addChild(layout);        
042        window.setTitle(title);
043        window.setCanDragReposition(true);
044        window.setCanDragResize(false);
045        window.setShowMinimizeButton(false);
046        window.setShowCloseButton(true);
047        window.setWidth(width);
048        window.setHeight(height);
049        window.setAutoCenter(true);
050        
051        window.addCloseClickHandler(new CloseClickHandler() {
052            @Override
053            public void onCloseClick(CloseClientEvent event) {
054                hide();
055            }            
056        });
057        
058        window.addChild(form);
059        form.setWidth100();
060        form.setHeight100();
061    }
062    
063    /**
064     * Shows this dialog modal.
065     */
066    public void showModal() {
067        form.init();
068        window.show();
069    }
070    
071    /**
072     * Hides this dialog.
073     */
074    public void hide() {
075        window.hide();
076    }
077    
078}