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.repo;
017
018import com.smartgwt.client.types.ListGridFieldType;
019import com.smartgwt.client.widgets.grid.ListGrid;
020import com.smartgwt.client.widgets.grid.ListGridField;
021import com.smartgwt.client.widgets.grid.ListGridRecord;
022import java.util.Collection;
023import org.modeshape.web.client.Console;
024import org.modeshape.web.shared.BaseCallback;
025import org.modeshape.web.shared.Form;
026import org.modeshape.web.shared.JcrRepositoryDescriptor;
027import org.modeshape.web.shared.Param;
028
029/**
030 *
031 * @author kulikov
032 */
033public class DescriptorForm extends Form {
034
035    private final Console console;
036    private final ListGrid grid = new ListGrid();
037
038    public DescriptorForm(Console console) {
039        this.console = console;
040        this.grid.setWidth100();
041        this.grid.setHeight100();
042
043        ListGridField[] fields = new ListGridField[3];
044
045        fields[0] = new ListGridField("icon", " ");
046        fields[0].setCanEdit(false);
047        fields[0].setImageURLPrefix("icons/bullet_");
048        fields[0].setImageURLSuffix(".png");
049        fields[0].setWidth(30);
050        fields[0].setType(ListGridFieldType.IMAGE);
051
052        fields[1] = new ListGridField("name", "Parameter name");
053        fields[1].setCanEdit(false);
054        fields[1].setType(ListGridFieldType.TEXT);
055
056        fields[2] = new ListGridField("value", "Value");
057        fields[2].setCanEdit(false);
058        fields[2].setType(ListGridFieldType.TEXT);
059
060        grid.setFields(fields);
061        addMember(grid);
062    }
063
064    @Override
065    public void init() {
066        console.jcrService().repositoryInfo(console.repository(), new BaseCallback<JcrRepositoryDescriptor>() {
067            @Override
068            public void onSuccess(JcrRepositoryDescriptor descriptor) {
069                Collection<Param> params = descriptor.info();
070                ListGridRecord[] data = new ListGridRecord[params.size()];
071                int i = 0;
072                for (Param p : params) {
073                    ListGridRecord record = new ListGridRecord();
074                    record.setAttribute("icon", "blue");
075                    record.setAttribute("name", p.getName());
076                    record.setAttribute("value", p.getValue());
077                    data[i++] = record;
078                }
079                
080                grid.setData(data);
081            }
082        });
083    }
084}