KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > views > SchemaElementsViewLabelProvider


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. 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,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.schemas.view.views;
22
23
24 import org.apache.directory.ldapstudio.schemas.Activator;
25 import org.apache.directory.ldapstudio.schemas.PluginConstants;
26 import org.apache.directory.ldapstudio.schemas.view.ViewUtils;
27 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper;
28 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ITreeNode;
29 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ObjectClassWrapper;
30 import org.eclipse.jface.preference.IPreferenceStore;
31 import org.eclipse.jface.viewers.LabelProvider;
32 import org.eclipse.swt.graphics.Image;
33 import org.eclipse.ui.ISharedImages;
34 import org.eclipse.ui.PlatformUI;
35
36
37 /**
38  * This class implements the label provider for the Schema Elements View.
39  *
40  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
41  * @version $Rev$, $Date$
42  */

43 public class SchemaElementsViewLabelProvider extends LabelProvider
44 {
45     /** The preferences store */
46     private IPreferenceStore store;
47
48
49     /**
50      * Creates a new instance of SchemaElementsViewLabelProvider.
51      */

52     public SchemaElementsViewLabelProvider()
53     {
54         store = Activator.getDefault().getPreferenceStore();
55     }
56
57
58     /* (non-Javadoc)
59      * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
60      */

61     public String JavaDoc getText( Object JavaDoc obj )
62     {
63         String JavaDoc label = ""; //$NON-NLS-1$
64

65         int labelValue = store.getInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL );
66         boolean abbreviate = store.getBoolean( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_ABBREVIATE );
67         int abbreviateMaxLength = store.getInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_ABBREVIATE_MAX_LENGTH );
68         boolean secondaryLabelDisplay = store
69             .getBoolean( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_DISPLAY );
70         int secondaryLabelValue = store.getInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL );
71         boolean secondaryLabelAbbreviate = store
72             .getBoolean( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_ABBREVIATE );
73         int secondaryLabelAbbreviateMaxLength = store
74             .getInt( PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH );
75
76         if ( obj instanceof AttributeTypeWrapper )
77         {
78             if ( labelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_FIRST_NAME )
79             {
80                 label = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames()[0];
81             }
82             else if ( labelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_ALL_ALIASES )
83             {
84                 label = ViewUtils.concateAliases( ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames() );
85             }
86             else if ( labelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_OID )
87             {
88                 label = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getOid();
89             }
90             else
91             // Default
92
{
93                 label = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames()[0];
94             }
95         }
96         else if ( obj instanceof ObjectClassWrapper )
97         {
98             if ( labelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_FIRST_NAME )
99             {
100                 label = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames()[0];
101             }
102             else if ( labelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_ALL_ALIASES )
103             {
104                 label = ViewUtils.concateAliases( ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames() );
105             }
106             else if ( labelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_OID )
107             {
108                 label = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getOid();
109             }
110             else
111             // Default
112
{
113                 label = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames()[0];
114             }
115         }
116         else
117         // Default
118
{
119             label = obj.toString();
120         }
121
122         if ( abbreviate && ( abbreviateMaxLength < label.length() ) )
123         {
124             label = label.substring( 0, abbreviateMaxLength ) + "..."; //$NON-NLS-1$
125
}
126
127         if ( secondaryLabelDisplay )
128         {
129             String JavaDoc secondaryLabel = ""; //$NON-NLS-1$
130
if ( obj instanceof AttributeTypeWrapper )
131             {
132                 if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_FIRST_NAME )
133                 {
134                     secondaryLabel = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames()[0];
135                 }
136                 else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_ALL_ALIASES )
137                 {
138                     secondaryLabel = ViewUtils.concateAliases( ( ( AttributeTypeWrapper ) obj ).getMyAttributeType()
139                         .getNames() );
140                 }
141                 else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_OID )
142                 {
143                     secondaryLabel = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getOid();
144                 }
145             }
146             else if ( obj instanceof ObjectClassWrapper )
147             {
148                 if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_FIRST_NAME )
149                 {
150                     secondaryLabel = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames()[0];
151                 }
152                 else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_ALL_ALIASES )
153                 {
154                     secondaryLabel = ViewUtils.concateAliases( ( ( ObjectClassWrapper ) obj ).getMyObjectClass()
155                         .getNames() );
156                 }
157                 else if ( secondaryLabelValue == PluginConstants.PREFS_SCHEMA_ELEMENTS_VIEW_LABEL_OID )
158                 {
159                     secondaryLabel = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getOid();
160                 }
161             }
162
163             if ( secondaryLabelAbbreviate && ( secondaryLabelAbbreviateMaxLength < secondaryLabel.length() ) )
164             {
165                 secondaryLabel = secondaryLabel.substring( 0, secondaryLabelAbbreviateMaxLength ) + "..."; //$NON-NLS-1$
166
}
167
168             label += " [" + secondaryLabel + "]"; //$NON-NLS-1$ //$NON-NLS-2$
169
}
170
171         return label;
172     }
173
174
175     /* (non-Javadoc)
176      * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
177      */

178     public Image getImage( Object JavaDoc obj )
179     {
180         if ( obj instanceof ITreeNode )
181         {
182             return ( ( ITreeNode ) obj ).getImage();
183         }
184
185         // Default
186
return PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJS_WARN_TSK );
187     }
188 }
189
Popular Tags