KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > ui > nodepropertylist > ViewLabelProvider


1 /**
2  * VC Browser - Visualizes the content of a JSR 170 compatible repository
3  * Copyright (C) 2006 Sandro Böhme
4  *
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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     /**
33      *
34      */

35     private final NodePropertyList viewLabelProvider;
36
37     /**
38      * @param list
39      */

40     ViewLabelProvider(NodePropertyList list) {
41         viewLabelProvider = list;
42     }
43
44     public String JavaDoc getColumnText(Object JavaDoc obj, int index) {
45         String JavaDoc 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 JavaDoc propValueSB = new StringBuffer JavaDoc();
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                 // TODO Auto-generated catch block
81
e.printStackTrace();
82             }
83         }
84         if (propValue==null) propValue=getText(obj);
85         return propValue;
86     }
87
88     public Image getColumnImage(Object JavaDoc obj, int index) {
89         return getImage(obj);
90     }
91
92     public Image getImage(Object JavaDoc obj) {
93         return PlatformUI.getWorkbench().getSharedImages().getImage(
94                 ISharedImages.IMG_OBJ_ELEMENT);
95     }
96 }
Popular Tags