1 20 21 package org.apache.directory.ldapstudio.browser.ui.actions; 22 23 24 import org.apache.directory.ldapstudio.browser.common.actions.BrowserAction; 25 import org.apache.directory.ldapstudio.browser.core.model.IConnection; 26 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription; 27 import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription; 28 import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleDescription; 29 import org.apache.directory.ldapstudio.browser.core.model.schema.ObjectClassDescription; 30 import org.apache.directory.ldapstudio.browser.ui.BrowserUIConstants; 31 import org.apache.directory.ldapstudio.browser.ui.BrowserUIPlugin; 32 import org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser.SchemaBrowserManager; 33 import org.eclipse.jface.resource.ImageDescriptor; 34 35 36 42 public class OpenSchemaBrowserAction extends BrowserAction 43 { 44 47 public static final int MODE_NONE = 0; 48 49 52 public static final int MODE_OBJECTCLASS = 10; 53 54 57 public static final int MODE_ATTRIBUTETYPE = 20; 58 59 62 public static final int MODE_EQUALITYMATCHINGRULE = 30; 63 64 67 public static final int MODE_SUBSTRINGMATCHINGRULE = 31; 68 69 72 public static final int MODE_ORDERINGMATCHINGRULE = 32; 73 74 77 public static final int MODE_SYNTAX = 40; 78 79 protected int mode; 80 81 82 85 public OpenSchemaBrowserAction() 86 { 87 super(); 88 this.mode = MODE_NONE; 89 } 90 91 92 98 public OpenSchemaBrowserAction( int mode ) 99 { 100 super(); 101 this.mode = mode; 102 } 103 104 105 108 public void run() 109 { 110 if ( mode == MODE_NONE ) 111 { 112 SchemaBrowserManager.setInput( getConnection(), null ); 113 } 114 else if ( mode == MODE_OBJECTCLASS ) 115 { 116 SchemaBrowserManager.setInput( getConnection(), getOcd() ); 117 } 118 else if ( mode == MODE_ATTRIBUTETYPE ) 119 { 120 SchemaBrowserManager.setInput( getConnection(), getAtd() ); 121 } 122 else if ( mode == MODE_EQUALITYMATCHINGRULE ) 123 { 124 SchemaBrowserManager.setInput( getConnection(), getEmrd() ); 125 } 126 else if ( mode == MODE_SUBSTRINGMATCHINGRULE ) 127 { 128 SchemaBrowserManager.setInput( getConnection(), getSmrd() ); 129 } 130 else if ( mode == MODE_ORDERINGMATCHINGRULE ) 131 { 132 SchemaBrowserManager.setInput( getConnection(), getOmrd() ); 133 } 134 else if ( mode == MODE_SYNTAX ) 135 { 136 SchemaBrowserManager.setInput( getConnection(), getLsd() ); 137 } 138 else 139 { 140 SchemaBrowserManager.setInput( getConnection(), null ); 141 } 142 } 143 144 145 148 public String getText() 149 { 150 if ( mode == MODE_NONE ) 151 { 152 return "Open Schema Browser"; 153 } 154 else if ( mode == MODE_OBJECTCLASS ) 155 { 156 return "Object Class Description"; 157 } 158 else if ( mode == MODE_ATTRIBUTETYPE ) 159 { 160 return "Attribute Type Description"; 161 } 162 else if ( mode == MODE_EQUALITYMATCHINGRULE ) 163 { 164 return "Equality Matching Rule Description"; 165 } 166 else if ( mode == MODE_SUBSTRINGMATCHINGRULE ) 167 { 168 return "Substring Matching Rule Description"; 169 } 170 else if ( mode == MODE_ORDERINGMATCHINGRULE ) 171 { 172 return "Ordering Matching Rule Description"; 173 } 174 else if ( mode == MODE_SYNTAX ) 175 { 176 return "Syntax Description"; 177 } 178 else 179 { 180 return "Open Schema Browser"; 181 } 182 } 183 184 185 188 public ImageDescriptor getImageDescriptor() 189 { 190 if ( mode == MODE_NONE ) 191 { 192 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_BROWSER_SCHEMABROWSEREDITOR ); 193 } 194 else if ( mode == MODE_OBJECTCLASS ) 195 { 196 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_OCD ); 197 } 198 else if ( mode == MODE_ATTRIBUTETYPE ) 199 { 200 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_ATD ); 201 } 202 else if ( mode == MODE_EQUALITYMATCHINGRULE ) 203 { 204 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_MRD_EQUALITY ); 205 } 206 else if ( mode == MODE_SUBSTRINGMATCHINGRULE ) 207 { 208 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_MRD_SUBSTRING ); 209 } 210 else if ( mode == MODE_ORDERINGMATCHINGRULE ) 211 { 212 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_MRD_ORDERING ); 213 } 214 else if ( mode == MODE_SYNTAX ) 215 { 216 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_LSD ); 217 } 218 else 219 { 220 return BrowserUIPlugin.getDefault().getImageDescriptor( BrowserUIConstants.IMG_BROWSER_SCHEMABROWSEREDITOR ); 221 } 222 } 223 224 225 228 public String getCommandId() 229 { 230 return null; 231 } 232 233 234 237 public boolean isEnabled() 238 { 239 240 if ( mode == MODE_NONE ) 241 { 242 return true; 243 } 244 else if ( mode == MODE_OBJECTCLASS ) 245 { 246 return getOcd() != null; 247 } 248 else if ( mode == MODE_ATTRIBUTETYPE ) 249 { 250 return getAtd() != null; 251 } 252 else if ( mode == MODE_EQUALITYMATCHINGRULE ) 253 { 254 return getEmrd() != null; 255 } 256 else if ( mode == MODE_SUBSTRINGMATCHINGRULE ) 257 { 258 return getSmrd() != null; 259 } 260 else if ( mode == MODE_ORDERINGMATCHINGRULE ) 261 { 262 return getOmrd() != null; 263 } 264 else if ( mode == MODE_SYNTAX ) 265 { 266 return getLsd() != null; 267 } 268 else 269 { 270 return false; 271 } 272 } 273 274 275 281 private LdapSyntaxDescription getLsd() 282 { 283 AttributeTypeDescription atd = getAtd(); 284 285 if ( atd != null && atd.getSyntaxDescriptionNumericOIDTransitive() != null 286 && atd.getSchema().hasLdapSyntaxDescription( atd.getSyntaxDescriptionNumericOIDTransitive() ) ) 287 { 288 return atd.getSchema().getLdapSyntaxDescription( atd.getSyntaxDescriptionNumericOIDTransitive() ); 289 } 290 291 return null; 292 } 293 294 295 301 private ObjectClassDescription getOcd() 302 { 303 if ( getSelectedAttributes().length == 0 && getSelectedValues().length == 1 304 && getSelectedValues()[0].getAttribute().isObjectClassAttribute() ) 305 { 306 String ocdName = getSelectedValues()[0].getStringValue(); 307 if ( ocdName != null 308 && getSelectedValues()[0].getAttribute().getEntry().getConnection().getSchema() 309 .hasObjectClassDescription( ocdName ) ) 310 { 311 return getSelectedValues()[0].getAttribute().getEntry().getConnection().getSchema() 312 .getObjectClassDescription( ocdName ); 313 } 314 } 315 316 return null; 317 } 318 319 320 326 private AttributeTypeDescription getAtd() 327 { 328 if ( ( getSelectedValues().length + getSelectedAttributes().length ) + getSelectedAttributeHierarchies().length == 1 ) 329 { 330 AttributeTypeDescription atd = null; 331 if ( getSelectedValues().length == 1 ) 332 { 333 atd = getSelectedValues()[0].getAttribute().getAttributeTypeDescription(); 334 } 335 else if ( getSelectedAttributes().length == 1 ) 336 { 337 atd = getSelectedAttributes()[0].getAttributeTypeDescription(); 338 } 339 else if ( getSelectedAttributeHierarchies().length == 1 && getSelectedAttributeHierarchies()[0].size() == 1 ) 340 { 341 atd = getSelectedAttributeHierarchies()[0].getAttribute().getAttributeTypeDescription(); 342 } 343 344 return atd; 345 } 346 347 return null; 348 } 349 350 351 356 private IConnection getConnection() 357 { 358 if ( ( getSelectedValues().length + getSelectedAttributes().length ) + getSelectedAttributeHierarchies().length == 1 ) 359 { 360 IConnection connection = null; 361 if ( getSelectedValues().length == 1 ) 362 { 363 connection = getSelectedValues()[0].getAttribute().getEntry().getConnection(); 364 } 365 else if ( getSelectedAttributes().length == 1 ) 366 { 367 connection = getSelectedAttributes()[0].getEntry().getConnection(); 368 } 369 else if ( getSelectedAttributeHierarchies().length == 1 && getSelectedAttributeHierarchies()[0].size() == 1 ) 370 { 371 connection = getSelectedAttributeHierarchies()[0].getAttribute().getEntry().getConnection(); 372 } 373 374 return connection; 375 } 376 else if ( getSelectedConnections().length == 1 ) 377 { 378 return getSelectedConnections()[0]; 379 } 380 else if ( getSelectedEntries().length == 1 ) 381 { 382 return getSelectedEntries()[0].getConnection(); 383 } 384 else if ( getSelectedSearchResults().length == 1 ) 385 { 386 return getSelectedSearchResults()[0].getEntry().getConnection(); 387 } 388 else if ( getSelectedBookmarks().length == 1 ) 389 { 390 return getSelectedBookmarks()[0].getConnection(); 391 } 392 else if ( getSelectedSearches().length == 1 ) 393 { 394 return getSelectedSearches()[0].getConnection(); 395 } 396 397 return null; 398 } 399 400 401 407 private MatchingRuleDescription getEmrd() 408 { 409 AttributeTypeDescription atd = getAtd(); 410 411 if ( atd != null && atd.getEqualityMatchingRuleDescriptionOIDTransitive() != null 412 && atd.getSchema().hasMatchingRuleDescription( atd.getEqualityMatchingRuleDescriptionOIDTransitive() ) ) 413 { 414 return atd.getSchema().getMatchingRuleDescription( atd.getEqualityMatchingRuleDescriptionOIDTransitive() ); 415 } 416 417 return null; 418 } 419 420 421 427 private MatchingRuleDescription getSmrd() 428 { 429 AttributeTypeDescription atd = getAtd(); 430 431 if ( atd != null && atd.getSubstringMatchingRuleDescriptionOIDTransitive() != null 432 && atd.getSchema().hasMatchingRuleDescription( atd.getSubstringMatchingRuleDescriptionOIDTransitive() ) ) 433 { 434 return atd.getSchema().getMatchingRuleDescription( atd.getSubstringMatchingRuleDescriptionOIDTransitive() ); 435 } 436 437 return null; 438 } 439 440 441 447 private MatchingRuleDescription getOmrd() 448 { 449 AttributeTypeDescription atd = getAtd(); 450 451 if ( atd != null && atd.getOrderingMatchingRuleDescriptionOIDTransitive() != null 452 && atd.getSchema().hasMatchingRuleDescription( atd.getOrderingMatchingRuleDescriptionOIDTransitive() ) ) 453 { 454 return atd.getSchema().getMatchingRuleDescription( atd.getOrderingMatchingRuleDescriptionOIDTransitive() ); 455 } 456 457 return null; 458 } 459 } 460 | Popular Tags |