OW2 Consortium elastic-grid

Rev

Rev 515 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
515 jeje 1
/**
2
 * Elastic Grid
530 jeje 3
 * Copyright (C) 2008-2010 Elastic Grid, LLC.
515 jeje 4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as
7
 * published by the Free Software Foundation, either version 3 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
package com.elasticgrid.admin.client.widget.cluster;
19
 
20
import com.elasticgrid.admin.client.AppEvents;
21
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
22
import com.extjs.gxt.ui.client.event.ButtonEvent;
23
import com.extjs.gxt.ui.client.event.ComponentEvent;
24
import com.extjs.gxt.ui.client.event.KeyListener;
25
import com.extjs.gxt.ui.client.event.SelectionListener;
26
import com.extjs.gxt.ui.client.mvc.AppEvent;
27
import com.extjs.gxt.ui.client.mvc.Dispatcher;
28
import com.extjs.gxt.ui.client.util.IconHelper;
29
import com.extjs.gxt.ui.client.widget.Dialog;
30
import com.extjs.gxt.ui.client.widget.Status;
31
import com.extjs.gxt.ui.client.widget.button.Button;
32
import com.extjs.gxt.ui.client.widget.form.FileUploadField;
33
import com.extjs.gxt.ui.client.widget.form.TextField;
34
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
35
import com.extjs.gxt.ui.client.widget.toolbar.FillToolItem;
36
 
37
public class DeployApplicationDialog extends Dialog {
38
    protected TextField<String> clusterName;
39
    protected FileUploadField oar;
40
    protected Button reset;
41
    protected Button deploy;
42
    protected Status status;
43
 
44
    public DeployApplicationDialog() {
45
        FormLayout layout = new FormLayout();
46
        layout.setLabelWidth(150);
47
        layout.setDefaultWidth(200);
48
        setLayout(layout);
49
 
50
        setButtonAlign(HorizontalAlignment.LEFT);
51
        setButtons("");
52
        setIcon(IconHelper.createStyle("application"));
53
        setHeading("Deploy application...");
54
        setModal(true);
55
        setBodyBorder(true);
56
        setBodyStyle("padding: 8px;");
57
        setWidth(400);
58
        setResizable(false);
59
 
60
        KeyListener keyListener = new KeyListener() {
61
            @Override
62
            public void componentKeyUp(ComponentEvent event) {
63
                validate();
64
            }
65
        };
66
 
67
        clusterName = new TextField<String>();
68
        clusterName.setFieldLabel("Cluster Name");
69
        clusterName.addKeyListener(keyListener);
70
        add(clusterName);
71
 
72
        oar = new FileUploadField();
73
        oar.setFieldLabel("Application to deploy");
74
        oar.setAllowBlank(false);
75
        add(oar);
76
 
77
        setFocusWidget(clusterName);
78
    }
79
 
80
    @Override
81
    protected void createButtons() {
82
        super.createButtons();
83
        status = new Status();
84
        status.setBusy("please wait...");
85
        status.hide();
86
        status.setAutoWidth(true);
87
        getButtonBar().add(status);
88
 
89
        getButtonBar().add(new FillToolItem());
90
 
91
        reset = new Button("Reset");
92
        reset.addSelectionListener(new SelectionListener<ButtonEvent>() {
93
            @Override
94
            public void componentSelected(ButtonEvent ce) {
95
                clusterName.reset();
96
                validate();
97
                clusterName.focus();
98
            }
99
 
100
        });
101
 
102
        deploy = new Button("Deploy");
103
        deploy.disable();
104
        deploy.addSelectionListener(new SelectionListener<ButtonEvent>() {
105
            @Override
106
            public void componentSelected(ButtonEvent ce) {
107
                onSubmit();
108
            }
109
        });
110
 
111
        addButton(reset);
112
        addButton(deploy);
113
    }
114
 
115
    protected void onSubmit() {
116
        status.show();
117
        getButtonBar().disable();
118
        AppEvent ae = new AppEvent(AppEvents.DEPLOY_APPLICATION);
119
        ae.setData(oar.getFileInput().getSrc());      // TODO: give the filename?
120
        Dispatcher.forwardEvent(ae);
121
        hide();
122
    }
123
 
124
    protected boolean hasValue(TextField<String> field) {
125
        return field.getValue() != null && field.getValue().length() > 0;
126
    }
127
 
128
    protected void validate() {
129
        deploy.setEnabled(hasValue(clusterName));
130
    }
131
 
132
}