1 20 21 package org.apache.directory.ldapstudio.browser.common.widgets.entryeditor; 22 23 24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator; 25 import org.apache.directory.ldapstudio.browser.common.BrowserCommonConstants; 26 import org.apache.directory.ldapstudio.browser.core.model.IAttribute; 27 import org.apache.directory.ldapstudio.browser.core.model.IValue; 28 import org.apache.directory.ldapstudio.valueeditors.IValueEditor; 29 import org.apache.directory.ldapstudio.valueeditors.ValueEditorManager; 30 import org.eclipse.jface.preference.PreferenceConverter; 31 import org.eclipse.jface.viewers.IColorProvider; 32 import org.eclipse.jface.viewers.IFontProvider; 33 import org.eclipse.jface.viewers.ITableLabelProvider; 34 import org.eclipse.jface.viewers.LabelProvider; 35 import org.eclipse.swt.graphics.Color; 36 import org.eclipse.swt.graphics.Font; 37 import org.eclipse.swt.graphics.FontData; 38 import org.eclipse.swt.graphics.Image; 39 import org.eclipse.swt.graphics.RGB; 40 41 42 54 public class EntryEditorWidgetLabelProvider extends LabelProvider implements ITableLabelProvider, IFontProvider, 55 IColorProvider 56 { 57 58 59 private ValueEditorManager valueEditorManager; 60 61 62 67 public EntryEditorWidgetLabelProvider( ValueEditorManager valueEditorManager ) 68 { 69 this.valueEditorManager = valueEditorManager; 70 } 71 72 73 76 public void dispose() 77 { 78 super.dispose(); 79 valueEditorManager = null; 80 } 81 82 83 86 public final String getColumnText( Object obj, int index ) 87 { 88 if ( obj != null && obj instanceof IValue ) 89 { 90 IValue value = ( IValue ) obj; 91 switch ( index ) 92 { 93 case EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX: 94 return value.getAttribute().getDescription(); 95 case EntryEditorWidgetTableMetadata.VALUE_COLUMN_INDEX: 96 IValueEditor vp = this.valueEditorManager.getCurrentValueEditor( value ); 97 String dv = vp.getDisplayValue( value ); 98 return dv; 99 default: 100 return ""; 101 } 102 } 103 else if ( obj != null && obj instanceof IAttribute ) 104 { 105 IAttribute attribute = ( IAttribute ) obj; 106 if ( index == EntryEditorWidgetTableMetadata.KEY_COLUMN_INDEX ) 107 { 108 return attribute.getDescription() + " (" + attribute.getValueSize() + " values)"; 109 } 110 else 111 { 112 return ""; 113 } 114 } 115 else 116 { 117 return ""; 118 } 119 } 120 121 122 125 public final Image getColumnImage( Object element, int index ) 126 { 127 return null; 128 } 129 130 131 134 public Font getFont( Object element ) 135 { 136 IAttribute attribute = null; 137 IValue value = null; 138 if ( element instanceof IAttribute ) 139 { 140 attribute = ( IAttribute ) element; 141 } 142 else if ( element instanceof IValue ) 143 { 144 value = ( IValue ) element; 145 attribute = value.getAttribute(); 146 } 147 148 if ( value != null ) 150 { 151 if ( value.isEmpty() ) 152 { 153 FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() 154 .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_ERROR_FONT ); 155 return BrowserCommonActivator.getDefault().getFont( fontData ); 156 } 157 } 158 if ( attribute != null && value == null ) 159 { 160 if ( !attribute.isConsistent() ) 161 { 162 FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() 163 .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_ERROR_FONT ); 164 return BrowserCommonActivator.getDefault().getFont( fontData ); 165 } 166 } 167 168 if ( attribute != null ) 170 { 171 if ( attribute.isObjectClassAttribute() ) 172 { 173 FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() 174 .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_OBJECTCLASS_FONT ); 175 return BrowserCommonActivator.getDefault().getFont( fontData ); 176 } 177 else if ( attribute.isMustAttribute() ) 178 { 179 FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() 180 .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_FONT ); 181 return BrowserCommonActivator.getDefault().getFont( fontData ); 182 } 183 else if ( attribute.isOperationalAttribute() ) 184 { 185 FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() 186 .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_FONT ); 187 return BrowserCommonActivator.getDefault().getFont( fontData ); 188 } 189 else 190 { 191 FontData[] fontData = PreferenceConverter.getFontDataArray( BrowserCommonActivator.getDefault() 192 .getPreferenceStore(), BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_FONT ); 193 return BrowserCommonActivator.getDefault().getFont( fontData ); 194 } 195 } 196 else 197 { 198 return null; 199 } 200 } 201 202 203 206 public Color getForeground( Object element ) 207 { 208 IAttribute attribute = null; 209 IValue value = null; 210 if ( element instanceof IAttribute ) 211 { 212 attribute = ( IAttribute ) element; 213 } 214 else if ( element instanceof IValue ) 215 { 216 value = ( IValue ) element; 217 attribute = value.getAttribute(); 218 } 219 220 if ( value != null ) 222 { 223 if ( value.isEmpty() ) 224 { 225 RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(), 226 BrowserCommonConstants.PREFERENCE_ERROR_COLOR ); 227 return BrowserCommonActivator.getDefault().getColor( rgb ); 228 } 229 } 230 if ( attribute != null && value == null ) 231 { 232 if ( !attribute.isConsistent() ) 233 { 234 RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(), 235 BrowserCommonConstants.PREFERENCE_ERROR_COLOR ); 236 return BrowserCommonActivator.getDefault().getColor( rgb ); 237 } 238 } 239 240 if ( attribute != null ) 242 { 243 if ( attribute.isObjectClassAttribute() ) 244 { 245 RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(), 246 BrowserCommonConstants.PREFERENCE_OBJECTCLASS_COLOR ); 247 return BrowserCommonActivator.getDefault().getColor( rgb ); 248 } 249 else if ( attribute.isMustAttribute() ) 250 { 251 RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(), 252 BrowserCommonConstants.PREFERENCE_MUSTATTRIBUTE_COLOR ); 253 return BrowserCommonActivator.getDefault().getColor( rgb ); 254 } 255 else if ( attribute.isOperationalAttribute() ) 256 { 257 RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(), 258 BrowserCommonConstants.PREFERENCE_OPERATIONALATTRIBUTE_COLOR ); 259 return BrowserCommonActivator.getDefault().getColor( rgb ); 260 } 261 else 262 { 263 RGB rgb = PreferenceConverter.getColor( BrowserCommonActivator.getDefault().getPreferenceStore(), 264 BrowserCommonConstants.PREFERENCE_MAYATTRIBUTE_COLOR ); 265 return BrowserCommonActivator.getDefault().getColor( rgb ); 266 } 267 } 268 else 269 { 270 return null; 271 } 272 } 273 274 275 278 public Color getBackground( Object element ) 279 { 280 return null; 281 } 282 283 } 284 | Popular Tags |