1 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.apache.directory.ldapstudio.schemas.view.views.wrappers.SchemaWrapper; 31 import org.eclipse.jface.preference.IPreferenceStore; 32 import org.eclipse.jface.viewers.LabelProvider; 33 import org.eclipse.swt.graphics.Image; 34 import org.eclipse.ui.ISharedImages; 35 import org.eclipse.ui.PlatformUI; 36 37 38 44 public class SchemasViewLabelProvider extends LabelProvider 45 { 46 47 private IPreferenceStore store; 48 49 50 53 public SchemasViewLabelProvider() 54 { 55 store = Activator.getDefault().getPreferenceStore(); 56 } 57 58 59 62 public String getText( Object obj ) 63 { 64 String label = ""; 66 int labelValue = store.getInt( PluginConstants.PREFS_SCHEMAS_VIEW_LABEL ); 67 boolean abbreviate = store.getBoolean( PluginConstants.PREFS_SCHEMAS_VIEW_ABBREVIATE ); 68 int abbreviateMaxLength = store.getInt( PluginConstants.PREFS_SCHEMAS_VIEW_ABBREVIATE_MAX_LENGTH ); 69 70 if ( obj instanceof AttributeTypeWrapper ) 71 { 72 if ( labelValue == PluginConstants.PREFS_SCHEMAS_VIEW_LABEL_FIRST_NAME ) 73 { 74 label = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames()[0]; 75 } 76 else if ( labelValue == PluginConstants.PREFS_SCHEMAS_VIEW_LABEL_ALL_ALIASES ) 77 { 78 label = ViewUtils.concateAliases( ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames() ); 79 } 80 else if ( labelValue == PluginConstants.PREFS_SCHEMAS_VIEW_LABEL_OID ) 81 { 82 label = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getOid(); 83 } 84 else 85 { 87 label = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames()[0]; 88 } 89 } 90 else if ( obj instanceof ObjectClassWrapper ) 91 { 92 if ( labelValue == PluginConstants.PREFS_SCHEMAS_VIEW_LABEL_FIRST_NAME ) 93 { 94 label = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames()[0]; 95 } 96 else if ( labelValue == PluginConstants.PREFS_SCHEMAS_VIEW_LABEL_ALL_ALIASES ) 97 { 98 label = ViewUtils.concateAliases( ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames() ); 99 } 100 else if ( labelValue == PluginConstants.PREFS_SCHEMAS_VIEW_LABEL_OID ) 101 { 102 label = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getOid(); 103 } 104 else 105 { 107 label = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames()[0]; 108 } 109 } 110 else if ( obj instanceof SchemaWrapper ) 111 { 112 label = ( ( SchemaWrapper ) obj ).getMySchema().getName(); 113 } 114 else 115 { 117 label = obj.toString(); 118 } 119 120 if ( abbreviate && ( abbreviateMaxLength < label.length() ) 121 && ( ( obj instanceof ObjectClassWrapper ) || ( obj instanceof AttributeTypeWrapper ) ) ) 122 { 123 label = label.substring( 0, abbreviateMaxLength ) + "..."; } 125 126 return label; 127 } 128 129 130 133 public Image getImage( Object obj ) 134 { 135 if ( obj instanceof ITreeNode ) 136 { 137 return ( ( ITreeNode ) obj ).getImage(); 138 } 139 140 return PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJS_WARN_TSK ); 142 } 143 } 144 | Popular Tags |