1 18 package org.visualcontent.ui.nodepropertylist; 19 20 import javax.jcr.Property; 21 import javax.jcr.PropertyType; 22 import javax.jcr.RepositoryException; 23 import javax.jcr.Value; 24 25 import org.eclipse.jface.viewers.ITableLabelProvider; 26 import org.eclipse.jface.viewers.LabelProvider; 27 import org.eclipse.swt.graphics.Image; 28 import org.eclipse.ui.ISharedImages; 29 import org.eclipse.ui.PlatformUI; 30 31 class ViewLabelProvider extends LabelProvider implements ITableLabelProvider { 32 35 private final NodePropertyList viewLabelProvider; 36 37 40 ViewLabelProvider(NodePropertyList list) { 41 viewLabelProvider = list; 42 } 43 44 public String getColumnText(Object obj, int index) { 45 String propValue=null; 46 if (obj instanceof Property) { 47 Property property = (Property) obj; 48 try { 49 boolean isMultiValued=property.getDefinition().isMultiple(); 50 if (index == 0) 51 propValue= property.getName() 52 + "[" 53 + PropertyType 54 .nameFromValue(property.getType()) 55 + (isMultiValued? ",multiple values" :"") 56 + "]"; 57 if (index == 1){ 58 if (isMultiValued){ 59 StringBuffer propValueSB = new StringBuffer (); 60 Value[] values = property.getValues(); 61 for (int i = 0; i < values.length; i++) { 62 if (i!=0) { 63 propValueSB.append(","); 64 } 65 propValueSB.append(values[i].getString()); 66 } 67 propValue=propValueSB.toString(); 68 } else { 69 switch (property.getType()) { 70 case PropertyType.BINARY: 71 propValue ="..."; 72 break; 73 default: 74 propValue= property.getValue().getString(); 75 break; 76 } 77 } 78 } 79 } catch (RepositoryException e) { 80 e.printStackTrace(); 82 } 83 } 84 if (propValue==null) propValue=getText(obj); 85 return propValue; 86 } 87 88 public Image getColumnImage(Object obj, int index) { 89 return getImage(obj); 90 } 91 92 public Image getImage(Object obj) { 93 return PlatformUI.getWorkbench().getSharedImages().getImage( 94 ISharedImages.IMG_OBJ_ELEMENT); 95 } 96 } | Popular Tags |