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.nt; 017 018import com.google.gwt.user.client.rpc.AsyncCallback; 019import com.smartgwt.client.types.ListGridFieldType; 020import com.smartgwt.client.util.SC; 021import com.smartgwt.client.widgets.grid.ListGrid; 022import com.smartgwt.client.widgets.grid.ListGridField; 023import com.smartgwt.client.widgets.grid.ListGridRecord; 024import java.util.Collection; 025import org.modeshape.web.client.Console; 026import org.modeshape.web.shared.Form; 027import org.modeshape.web.shared.JcrNodeType; 028 029/** 030 * 031 * @author kulikov 032 */ 033public class NodeTypesForm extends Form { 034 private final Console console; 035 private final ListGrid grid = new ListGrid(); 036 037 public NodeTypesForm(Console console) { 038 this.console = console; 039 this.grid.setWidth100(); 040 this.grid.setHeight100(); 041 042 ListGridField[] fields = new ListGridField[5]; 043 044 fields[0] = new ListGridField("icon", " "); 045 fields[0].setCanEdit(false); 046 fields[0].setImageURLPrefix("icons/bullet_"); 047 fields[0].setImageURLSuffix(".png"); 048 fields[0].setWidth(30); 049 fields[0].setType(ListGridFieldType.IMAGE); 050 051 fields[1] = new ListGridField("name", "Type Name"); 052 fields[1].setCanEdit(false); 053 fields[1].setType(ListGridFieldType.TEXT); 054 055 fields[2] = new ListGridField("is_primary", "Primary type"); 056 fields[2].setCanEdit(false); 057 fields[2].setType(ListGridFieldType.BOOLEAN); 058 fields[2].setWidth(30); 059 060 fields[3] = new ListGridField("is_mixin", "Mixin type"); 061 fields[3].setCanEdit(false); 062 fields[3].setType(ListGridFieldType.BOOLEAN); 063 fields[3].setWidth(30); 064 065 fields[4] = new ListGridField("is_abstract", "Abstract"); 066 fields[4].setCanEdit(false); 067 fields[4].setType(ListGridFieldType.BOOLEAN); 068 fields[4].setWidth(30); 069 070 grid.setFields(fields); 071 addMember(grid); 072 } 073 074 @Override 075 public void init() { 076 console.jcrService().nodeTypes(console.contents().repository(), 077 console.contents().workspace(), 078 new AsyncCallback<Collection<JcrNodeType>> () { 079 080 @Override 081 public void onFailure(Throwable caught) { 082 SC.say(caught.getMessage()); 083 } 084 085 @SuppressWarnings( "synthetic-access" ) 086 @Override 087 public void onSuccess(Collection<JcrNodeType> result) { 088 displayNodeTypes(result); 089 } 090 }); 091 } 092 093 private void displayNodeTypes(Collection<JcrNodeType> nodeTypes) { 094 ListGridRecord[] data = new ListGridRecord[nodeTypes.size()]; 095 int i = 0; 096 for (JcrNodeType t : nodeTypes) { 097 data[i] = new ListGridRecord(); 098 data[i].setAttribute("name", t.getName()); 099 data[i].setAttribute("is_primary", t.isPrimary()); 100 data[i].setAttribute("is_mixin", t.isMixin()); 101 data[i].setAttribute("is_abstract", t.isAbstract()); 102 i++; 103 } 104 grid.setData(data); 105 } 106}