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.types.Alignment; 019import com.smartgwt.client.types.Overflow; 020import com.smartgwt.client.types.VerticalAlignment; 021import com.smartgwt.client.widgets.Button; 022import com.smartgwt.client.widgets.Label; 023import com.smartgwt.client.widgets.events.ClickEvent; 024import com.smartgwt.client.widgets.events.ClickHandler; 025import com.smartgwt.client.widgets.layout.HLayout; 026import org.modeshape.web.client.contents.PropertiesEditor.PropertyRecord; 027import org.modeshape.web.client.grid.TabGrid; 028import org.modeshape.web.client.peditor.BaseEditor; 029import org.modeshape.web.client.peditor.ValueEditor; 030import org.modeshape.web.shared.JcrNode; 031import org.modeshape.web.shared.JcrProperty; 032 033/** 034 * 035 * @author kulikov 036 */ 037@SuppressWarnings("synthetic-access") 038public class PropertiesEditor extends TabGrid<PropertyRecord, JcrProperty> { 039 040 private JcrNode node; 041 private final Contents contents; 042 043 public PropertiesEditor(Contents contents) { 044 super("Properties"); 045 this.contents = contents; 046 } 047 048 public void show(JcrNode node) { 049 this.node = node; 050 setValues(node.getProperties()); 051 } 052 053 @Override 054 protected PropertyRecord[] records() { 055 PropertyRecord[] records = new PropertyRecord[100]; 056 for (int i = 0; i < records.length; i++) { 057 records[i] = new PropertyRecord(); 058 } 059 return records; 060 } 061 062 @Override 063 protected HLayout tableHeader() { 064 HLayout header = new HLayout(); 065 header.setHeight(30); 066 header.setBackgroundColor("#e6f1f6"); 067 068 Label name = new Label("<b>Name</b>"); 069 name.setWidth100(); 070 071 Label value = new Label("<b>Value</b>"); 072 value.setWidth100(); 073 074 header.addMember(name); 075 header.addMember(value); 076 077 return header; 078 } 079 080 @Override 081 protected HLayout toolBar() { 082 HLayout header = new HLayout(); 083 header.setBackgroundColor("#ffffff"); 084 header.setAlign(Alignment.LEFT); 085 header.setDefaultLayoutAlign(Alignment.LEFT); 086 header.setLayoutAlign(Alignment.LEFT); 087 header.setDefaultLayoutAlign(VerticalAlignment.CENTER); 088 header.setLayoutAlign(VerticalAlignment.CENTER); 089 header.setAlign(VerticalAlignment.CENTER); 090 header.setHeight(30); 091 header.setContents("Click respective to edit property value"); 092 return header; 093 } 094 095 @Override 096 protected void updateRecord(int pos, PropertyRecord record, JcrProperty value) { 097 record.setValue(value); 098 } 099 100 protected class PropertyRecord extends HLayout { 101 //visible height of the recorod 102 private final static int RECORD_HEIGHT = 30; 103 104 private Label name = new Label(); 105 private Label value = new Label(); 106 107 private Button editButton = new Button(); 108 private ValueEditor<String> editor; 109 110 public PropertyRecord() { 111 super(); 112 setStyleName("grid"); 113 setHeight(RECORD_HEIGHT); 114 115 setDefaultLayoutAlign(VerticalAlignment.CENTER); 116 setDefaultLayoutAlign(Alignment.LEFT); 117 118 setLayoutAlign(VerticalAlignment.CENTER); 119 setLayoutAlign(Alignment.CENTER); 120 121 setAlign(VerticalAlignment.CENTER); 122 setAlign(Alignment.LEFT); 123 124 name.setIcon("icons/sprocket.png"); 125 name.setStyleName("text"); 126 name.setWidth100(); 127 128 129 value.setStyleName("text"); 130 value.setWidth100(); 131 value.setOverflow(Overflow.HIDDEN); 132 value.setAlign(Alignment.RIGHT); 133 value.setLayoutAlign(Alignment.RIGHT); 134 135 editButton.setTitle("..."); 136 editButton.setWidth(RECORD_HEIGHT); 137 editButton.setHeight(RECORD_HEIGHT); 138 139 addMember(name); 140 addMember(value); 141 addMember(editButton); 142 } 143 144 private void setValue(final JcrProperty property) { 145 name.setContents(property.getName()); 146 value.setContents(property.getDisplayValue()); 147 editor = BaseEditor.getValueEditor(property.getName(), 148 property.getType(), PropertiesEditor.this.contents); 149 editButton.addClickHandler(new ClickHandler() { 150 @Override 151 public void onClick(ClickEvent event) { 152 //show modal form with reference to property.getValue() 153 editor.setValue(node, property.getName(), property.getValue()); 154 } 155 }); 156 } 157 } 158 159}