1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser; 22 23 24 import org.apache.directory.ldapstudio.browser.core.model.schema.AttributeTypeDescription; 25 import org.apache.directory.ldapstudio.browser.core.model.schema.LdapSyntaxDescription; 26 import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleDescription; 27 import org.eclipse.swt.SWT; 28 import org.eclipse.swt.layout.GridData; 29 import org.eclipse.swt.layout.GridLayout; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Label; 32 import org.eclipse.swt.widgets.Text; 33 import org.eclipse.ui.forms.events.ExpansionAdapter; 34 import org.eclipse.ui.forms.events.ExpansionEvent; 35 import org.eclipse.ui.forms.widgets.FormToolkit; 36 import org.eclipse.ui.forms.widgets.Hyperlink; 37 import org.eclipse.ui.forms.widgets.ScrolledForm; 38 import org.eclipse.ui.forms.widgets.Section; 39 40 41 48 public class MatchingRuleDescriptionDetailsPage extends SchemaDetailsPage 49 { 50 51 52 private Section mainSection; 53 54 55 private Text numericOidText; 56 57 58 private Text namesText; 59 60 61 private Text descText; 62 63 64 private Section flagSection; 65 66 67 private Label isObsoleteText; 68 69 70 private Section syntaxSection; 71 72 73 private Text syntaxDescText; 74 75 76 private Hyperlink syntaxLink; 77 78 79 private Section usedFromSection; 80 81 82 private Hyperlink[] usedFromLinks; 83 84 85 91 public MatchingRuleDescriptionDetailsPage( SchemaPage scheamPage, FormToolkit toolkit ) 92 { 93 super( scheamPage, toolkit ); 94 } 95 96 97 100 public void createContents( final ScrolledForm detailForm ) 101 { 102 this.detailForm = detailForm; 103 detailForm.getBody().setLayout( new GridLayout() ); 104 105 mainSection = toolkit.createSection( detailForm.getBody(), SWT.NONE ); 107 mainSection.setText( "Details" ); 108 mainSection.marginWidth = 0; 109 mainSection.marginHeight = 0; 110 mainSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 111 toolkit.createCompositeSeparator( mainSection ); 112 113 flagSection = toolkit.createSection( detailForm.getBody(), SWT.NONE ); 115 flagSection.setText( "Flags" ); 116 flagSection.marginWidth = 0; 117 flagSection.marginHeight = 0; 118 flagSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 119 toolkit.createCompositeSeparator( flagSection ); 120 121 Composite flagClient = toolkit.createComposite( flagSection, SWT.WRAP ); 123 GridLayout flagLayout = new GridLayout(); 124 flagLayout.numColumns = 1; 125 flagLayout.marginWidth = 0; 126 flagLayout.marginHeight = 0; 127 flagClient.setLayout( flagLayout ); 128 flagSection.setClient( flagClient ); 129 130 isObsoleteText = toolkit.createLabel( flagClient, "Obsolete", SWT.CHECK ); 131 isObsoleteText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 132 isObsoleteText.setEnabled( false ); 133 134 syntaxSection = toolkit.createSection( detailForm.getBody(), SWT.NONE ); 136 syntaxSection.setText( "Syntax" ); 137 syntaxSection.marginWidth = 0; 138 syntaxSection.marginHeight = 0; 139 syntaxSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 140 toolkit.createCompositeSeparator( syntaxSection ); 141 142 Composite syntaxClient = toolkit.createComposite( syntaxSection, SWT.WRAP ); 144 GridLayout syntaxLayout = new GridLayout(); 145 syntaxLayout.numColumns = 2; 146 syntaxLayout.marginWidth = 0; 147 syntaxLayout.marginHeight = 0; 148 syntaxClient.setLayout( syntaxLayout ); 149 syntaxSection.setClient( syntaxClient ); 150 151 toolkit.createLabel( syntaxClient, "Syntax OID:", SWT.NONE ); 152 syntaxLink = toolkit.createHyperlink( syntaxClient, "", SWT.WRAP ); 153 syntaxLink.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 154 syntaxLink.addHyperlinkListener( this ); 155 156 toolkit.createLabel( syntaxClient, "Syntax Description:", SWT.NONE ); 157 syntaxDescText = toolkit.createText( syntaxClient, "", SWT.NONE ); 158 syntaxDescText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 159 syntaxDescText.setEditable( false ); 160 161 usedFromSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE ); 163 usedFromSection.setText( "Used from" ); 164 usedFromSection.marginWidth = 0; 165 usedFromSection.marginHeight = 0; 166 usedFromSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 167 toolkit.createCompositeSeparator( usedFromSection ); 168 usedFromSection.addExpansionListener( new ExpansionAdapter() 169 { 170 public void expansionStateChanged( ExpansionEvent e ) 171 { 172 detailForm.reflow( true ); 173 } 174 } ); 175 176 createRawSection(); 178 } 179 180 181 184 public void setInput( Object input ) 185 { 186 MatchingRuleDescription mrd = null; 187 if ( input instanceof MatchingRuleDescription ) 188 { 189 mrd = ( MatchingRuleDescription ) input; 190 } 191 192 createMainContent( mrd ); 194 195 isObsoleteText.setEnabled( mrd != null && mrd.isObsolete() ); 197 198 String lsdOid = null; 200 LdapSyntaxDescription lsd = null; 201 if ( mrd != null ) 202 { 203 lsdOid = mrd.getSyntaxDescriptionNumericOID(); 204 if ( lsdOid != null && mrd.getSchema().hasLdapSyntaxDescription( lsdOid ) ) 205 { 206 lsd = mrd.getSchema().getLdapSyntaxDescription( lsdOid ); 207 } 208 } 209 syntaxLink.setText( getNonNullString( lsd != null ? lsd.getNumericOID() : lsdOid ) ); 210 syntaxLink.setHref( lsd ); 211 syntaxLink.setUnderlined( lsd != null ); 212 syntaxLink.setEnabled( lsd != null ); 213 syntaxDescText.setText( getNonNullString( lsd != null ? lsd.getDesc() : null ) ); 214 syntaxSection.layout(); 215 216 createUsedFromContents( mrd ); 218 createRawContents( mrd ); 219 220 detailForm.reflow( true ); 221 } 222 223 224 231 private void createMainContent( MatchingRuleDescription mrd ) 232 { 233 if ( mainSection.getClient() != null ) 235 { 236 mainSection.getClient().dispose(); 237 } 238 239 Composite mainClient = toolkit.createComposite( mainSection, SWT.WRAP ); 241 GridLayout mainLayout = new GridLayout( 2, false ); 242 mainClient.setLayout( mainLayout ); 243 mainSection.setClient( mainClient ); 244 245 if ( mrd != null ) 247 { 248 toolkit.createLabel( mainClient, "Numeric OID:", SWT.NONE ); 249 numericOidText = toolkit.createText( mainClient, getNonNullString( mrd.getNumericOID() ), SWT.NONE ); 250 numericOidText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 251 numericOidText.setEditable( false ); 252 253 toolkit.createLabel( mainClient, "Matching rule names:", SWT.NONE ); 254 namesText = toolkit.createText( mainClient, getNonNullString( mrd.toString() ), SWT.NONE ); 255 namesText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 256 namesText.setEditable( false ); 257 258 toolkit.createLabel( mainClient, "Descripton:", SWT.NONE ); 259 descText = toolkit.createText( mainClient, getNonNullString( mrd.getDesc() ), SWT.WRAP | SWT.MULTI ); 260 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 261 gd.widthHint = detailForm.getForm().getSize().x - 100 - 60; 262 descText.setLayoutData( gd ); 263 descText.setEditable( false ); 264 } 265 266 mainSection.layout(); 267 } 268 269 270 277 private void createUsedFromContents( MatchingRuleDescription mrd ) 278 { 279 if ( usedFromSection.getClient() != null ) 281 { 282 usedFromSection.getClient().dispose(); 283 } 284 285 Composite usedFromClient = toolkit.createComposite( usedFromSection, SWT.WRAP ); 287 usedFromClient.setLayout( new GridLayout() ); 288 usedFromSection.setClient( usedFromClient ); 289 290 if ( mrd != null ) 292 { 293 AttributeTypeDescription[] usedFromATDs = mrd.getUsedFromAttributeTypeDescriptions(); 294 if ( usedFromATDs != null && usedFromATDs.length > 0 ) 295 { 296 usedFromSection.setText( "Used from (" + usedFromATDs.length + ")" ); 297 usedFromLinks = new Hyperlink[usedFromATDs.length]; 298 for ( int i = 0; i < usedFromATDs.length; i++ ) 299 { 300 usedFromLinks[i] = toolkit.createHyperlink( usedFromClient, usedFromATDs[i].toString(), SWT.WRAP ); 301 usedFromLinks[i].setHref( usedFromATDs[i] ); 302 usedFromLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 303 usedFromLinks[i].setUnderlined( true ); 304 usedFromLinks[i].setEnabled( true ); 305 usedFromLinks[i].addHyperlinkListener( this ); 306 } 307 } 308 else 309 { 310 usedFromSection.setText( "Used from (0)" ); 311 usedFromLinks = new Hyperlink[0]; 312 Text usedFromText = toolkit.createText( usedFromClient, getNonNullString( null ), SWT.NONE ); 313 usedFromText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 314 usedFromText.setEditable( false ); 315 } 316 } 317 else 318 { 319 usedFromSection.setText( "Used from" ); 320 } 321 322 usedFromSection.layout(); 323 } 324 325 } 326 | Popular Tags |