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.client.contents;
017
018import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
019import com.smartgwt.client.widgets.form.fields.StaticTextItem;
020import com.smartgwt.client.widgets.form.fields.TextItem;
021import org.modeshape.web.shared.ModalDialog;
022
023/**
024 * Dialog asking node's name and primary type and creating new node.
025 *
026 * @author kulikov
027 */
028public class AddNodeDialog extends ModalDialog {
029
030    private TextItem name = new TextItem();
031    private ComboBoxItem primaryType = new ComboBoxItem();
032    private Contents contents;
033    
034    public AddNodeDialog(Contents contents) {
035        super("Create new node", 450, 250);
036        this.contents = contents;
037
038        name.setName("name");
039        name.setTitle("Node name");
040        name.setDefaultValue("");
041        name.setWidth(250);
042        name.setRequired(true);
043        name.setVisible(true);
044        name.setStartRow(true);
045        name.setEndRow(true);
046
047        primaryType.setName("primaryType");
048        primaryType.setTitle("Primary Type");
049        primaryType.setDefaultValue("nt:unstructured");
050        primaryType.setWidth(250);
051        primaryType.setRequired(true);
052        primaryType.setStartRow(true);
053        primaryType.setEndRow(true);
054
055        StaticTextItem description = new StaticTextItem();
056        description.setValue("Please specify the name of node and choose type");
057        description.setTitle("");
058        description.setStartRow(true);
059        description.setEndRow(true);
060
061        setControls(description, name, primaryType);
062    }
063
064    public void setPrimaryTypes(String[] primaryTypes) {
065        primaryType.setValueMap(primaryTypes);
066    }
067    
068    @Override
069    public void onConfirm(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
070        contents.addNode(name.getValueAsString(), primaryType.getValueAsString());
071    }
072}