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.peditor;
017
018import com.smartgwt.client.widgets.form.fields.DateTimeItem;
019import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
020import org.modeshape.web.client.contents.Contents;
021import org.modeshape.web.shared.JcrNode;
022
023/**
024 * Default value editor which is using text representation of the value.
025 * 
026 * @author kulikov
027 */
028public class DateValueEditor extends BaseEditor implements ValueEditor<String> {
029    //form title
030    private final static String TITLE = "Modify property value";
031    
032    //form dimensions
033    private final static int WIDTH = 350;
034    private final static int HEIGHT = 150;
035    
036    //form fields
037    private final DateTimeItem valueEditor = new DateTimeItem("Value");
038    
039    //'controller' - provides access to business logic
040    private final Contents contents;
041    
042    //node/property references
043    private JcrNode node;
044    private String name;
045    
046    /**
047     * Creates this property editor.
048     * 
049     * @param contents Contents view form.
050     */
051    public DateValueEditor(Contents contents) {
052        super(TITLE, WIDTH, HEIGHT);
053        this.contents = contents;
054        
055        valueEditor.setWidth(200);
056        valueEditor.setStartRow(true);
057        valueEditor.setEndRow(true);
058        
059        setControls(valueEditor);
060    }
061    
062    @Override
063    public void setValue(JcrNode node, String name, String value) {
064        this.node = node;
065        this.name = name;
066        
067        valueEditor.setValue(value);
068        
069        showModal();
070    }
071
072    @Override
073    public void onConfirm(ClickEvent event) {
074        contents.setNodeProperty(node, name, valueEditor.getValueAsDate());
075    }
076    
077}