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 HierarchyViewLabelProvider extends LabelProvider 45 { 46 47 private IPreferenceStore store; 48 49 50 53 public HierarchyViewLabelProvider() 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_HIERARCHY_VIEW_LABEL ); 67 boolean abbreviate = store.getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE ); 68 int abbreviateMaxLength = store.getInt( PluginConstants.PREFS_HIERARCHY_VIEW_ABBREVIATE_MAX_LENGTH ); 69 boolean secondaryLabelDisplay = store.getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_DISPLAY ); 70 int secondaryLabelValue = store.getInt( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL ); 71 boolean secondaryLabelAbbreviate = store 72 .getBoolean( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE ); 73 int secondaryLabelAbbreviateMaxLength = store 74 .getInt( PluginConstants.PREFS_HIERARCHY_VIEW_SECONDARY_LABEL_ABBREVIATE_MAX_LENGTH ); 75 76 if ( obj instanceof AttributeTypeWrapper ) 77 { 78 if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ) 79 { 80 label = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames()[0]; 81 } 82 else if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ) 83 { 84 label = ViewUtils.concateAliases( ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames() ); 85 } 86 else if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ) 87 { 88 label = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getOid(); 89 } 90 else 91 { 93 label = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames()[0]; 94 } 95 } 96 else if ( obj instanceof ObjectClassWrapper ) 97 { 98 if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ) 99 { 100 label = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames()[0]; 101 } 102 else if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ) 103 { 104 label = ViewUtils.concateAliases( ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames() ); 105 } 106 else if ( labelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ) 107 { 108 label = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getOid(); 109 } 110 else 111 { 113 label = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames()[0]; 114 } 115 } 116 else if ( obj instanceof SchemaWrapper ) 117 { 118 label = ( ( SchemaWrapper ) obj ).getMySchema().getName(); 119 } 120 else 121 { 123 label = obj.toString(); 124 } 125 126 if ( abbreviate && ( abbreviateMaxLength < label.length() ) 127 && ( ( obj instanceof ObjectClassWrapper ) || ( obj instanceof AttributeTypeWrapper ) ) ) 128 { 129 label = label.substring( 0, abbreviateMaxLength ) + "..."; } 131 132 if ( secondaryLabelDisplay ) 133 { 134 String secondaryLabel = ""; if ( obj instanceof AttributeTypeWrapper ) 136 { 137 if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ) 138 { 139 secondaryLabel = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getNames()[0]; 140 } 141 else if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ) 142 { 143 secondaryLabel = ViewUtils.concateAliases( ( ( AttributeTypeWrapper ) obj ).getMyAttributeType() 144 .getNames() ); 145 } 146 else if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ) 147 { 148 secondaryLabel = ( ( AttributeTypeWrapper ) obj ).getMyAttributeType().getOid(); 149 } 150 } 151 else if ( obj instanceof ObjectClassWrapper ) 152 { 153 if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_FIRST_NAME ) 154 { 155 secondaryLabel = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getNames()[0]; 156 } 157 else if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_ALL_ALIASES ) 158 { 159 secondaryLabel = ViewUtils.concateAliases( ( ( ObjectClassWrapper ) obj ).getMyObjectClass() 160 .getNames() ); 161 } 162 else if ( secondaryLabelValue == PluginConstants.PREFS_HIERARCHY_VIEW_LABEL_OID ) 163 { 164 secondaryLabel = ( ( ObjectClassWrapper ) obj ).getMyObjectClass().getOid(); 165 } 166 } 167 168 if ( secondaryLabelAbbreviate && ( secondaryLabelAbbreviateMaxLength < secondaryLabel.length() ) ) 169 { 170 secondaryLabel = secondaryLabel.substring( 0, secondaryLabelAbbreviateMaxLength ) + "..."; } 172 173 label += " [" + secondaryLabel + "]"; } 175 176 return label; 177 } 178 179 180 183 public Image getImage( Object obj ) 184 { 185 if ( obj instanceof ITreeNode ) 186 { 187 return ( ( ITreeNode ) obj ).getImage(); 188 } 189 190 return PlatformUI.getWorkbench().getSharedImages().getImage( ISharedImages.IMG_OBJS_WARN_TSK ); 192 } 193 } 194 | Popular Tags |