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.MatchingRuleDescription; 26 import org.apache.directory.ldapstudio.browser.core.model.schema.MatchingRuleUseDescription; 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 public class MatchingRuleUseDescriptionDetailsPage extends SchemaDetailsPage 42 { 43 44 45 private Section mainSection; 46 47 48 private Text numericOidText; 49 50 51 private Hyperlink nameLink; 52 53 54 private Text descText; 55 56 57 private Section flagSection; 58 59 60 private Label isObsoleteText; 61 62 63 private Section appliesSection; 64 65 66 private Hyperlink[] appliesLinks; 67 68 69 75 public MatchingRuleUseDescriptionDetailsPage( SchemaPage schemaPage, FormToolkit toolkit ) 76 { 77 super( schemaPage, toolkit ); 78 } 79 80 81 84 public void createContents( final ScrolledForm detailForm ) 85 { 86 87 this.detailForm = detailForm; 88 detailForm.getBody().setLayout( new GridLayout() ); 89 90 mainSection = toolkit.createSection( detailForm.getBody(), SWT.NONE ); 92 mainSection.setText( "Details" ); 93 mainSection.marginWidth = 0; 94 mainSection.marginHeight = 0; 95 mainSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 96 toolkit.createCompositeSeparator( mainSection ); 97 98 flagSection = toolkit.createSection( detailForm.getBody(), SWT.NONE ); 100 flagSection.setText( "Flags" ); 101 flagSection.marginWidth = 0; 102 flagSection.marginHeight = 0; 103 flagSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 104 toolkit.createCompositeSeparator( flagSection ); 105 106 Composite flagClient = toolkit.createComposite( flagSection, SWT.WRAP ); 108 GridLayout flagLayout = new GridLayout(); 109 flagLayout.numColumns = 1; 110 flagLayout.marginWidth = 0; 111 flagLayout.marginHeight = 0; 112 flagClient.setLayout( flagLayout ); 113 flagSection.setClient( flagClient ); 114 115 isObsoleteText = toolkit.createLabel( flagClient, "Obsolete", SWT.CHECK ); 116 isObsoleteText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 117 isObsoleteText.setEnabled( false ); 118 119 appliesSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE ); 121 appliesSection.setText( "Applies" ); 122 appliesSection.marginWidth = 0; 123 appliesSection.marginHeight = 0; 124 appliesSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 125 toolkit.createCompositeSeparator( appliesSection ); 126 appliesSection.addExpansionListener( new ExpansionAdapter() 127 { 128 public void expansionStateChanged( ExpansionEvent e ) 129 { 130 detailForm.reflow( true ); 131 } 132 } ); 133 134 super.createRawSection(); 136 } 137 138 139 142 public void setInput( Object input ) 143 { 144 MatchingRuleUseDescription mrud = null; 145 if ( input instanceof MatchingRuleUseDescription ) 146 { 147 mrud = ( MatchingRuleUseDescription ) input; 148 } 149 150 this.createMainContent( mrud ); 152 153 isObsoleteText.setEnabled( mrud != null && mrud.isObsolete() ); 155 156 this.createAppliesContents( mrud ); 158 super.createRawContents( mrud ); 159 160 this.detailForm.reflow( true ); 161 } 162 163 164 171 private void createMainContent( MatchingRuleUseDescription mrud ) 172 { 173 if ( mainSection.getClient() != null ) 175 { 176 mainSection.getClient().dispose(); 177 } 178 179 Composite mainClient = toolkit.createComposite( mainSection, SWT.WRAP ); 181 GridLayout mainLayout = new GridLayout( 2, false ); 182 mainClient.setLayout( mainLayout ); 183 mainSection.setClient( mainClient ); 184 185 if ( mrud != null ) 187 { 188 toolkit.createLabel( mainClient, "Numeric OID:", SWT.NONE ); 189 numericOidText = toolkit.createText( mainClient, getNonNullString( mrud.getNumericOID() ), SWT.NONE ); 190 numericOidText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 191 numericOidText.setEditable( false ); 192 193 toolkit.createLabel( mainClient, "Matching rule names:", SWT.NONE ); 194 nameLink = toolkit.createHyperlink( mainClient, "", SWT.WRAP ); 195 nameLink.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 196 nameLink.addHyperlinkListener( this ); 197 198 MatchingRuleDescription mrd = mrud.getSchema().hasMatchingRuleDescription( mrud.getNumericOID() ) ? mrud 199 .getSchema().getMatchingRuleDescription( mrud.getNumericOID() ) : null; 200 nameLink.setText( getNonNullString( mrd != null ? mrd.toString() : mrud.toString() ) ); 201 nameLink.setHref( mrd ); 202 nameLink.setUnderlined( mrd != null ); 203 nameLink.setEnabled( mrd != null ); 204 205 toolkit.createLabel( mainClient, "Descripton:", SWT.NONE ); 206 descText = toolkit.createText( mainClient, getNonNullString( mrud.getDesc() ), SWT.WRAP | SWT.MULTI ); 207 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 208 gd.widthHint = detailForm.getForm().getSize().x - 100 - 60; 209 descText.setLayoutData( gd ); 210 descText.setEditable( false ); 211 } 212 213 mainSection.layout(); 214 } 215 216 217 224 private void createAppliesContents( MatchingRuleUseDescription mrud ) 225 { 226 if ( appliesSection.getClient() != null ) 228 { 229 appliesSection.getClient().dispose(); 230 } 231 232 Composite appliesClient = toolkit.createComposite( appliesSection, SWT.WRAP ); 234 appliesClient.setLayout( new GridLayout() ); 235 appliesSection.setClient( appliesClient ); 236 237 if ( mrud != null ) 239 { 240 String [] names = mrud.getAppliesAttributeTypeDescriptionOIDs(); 241 if ( names != null && names.length > 0 ) 242 { 243 appliesSection.setText( "Applies (" + names.length + ")" ); 244 appliesLinks = new Hyperlink[names.length]; 245 for ( int i = 0; i < names.length; i++ ) 246 { 247 if ( mrud.getSchema().hasAttributeTypeDescription( names[i] ) ) 248 { 249 AttributeTypeDescription appliesAtd = mrud.getSchema().getAttributeTypeDescription( names[i] ); 250 appliesLinks[i] = toolkit.createHyperlink( appliesClient, appliesAtd.toString(), SWT.WRAP ); 251 appliesLinks[i].setHref( appliesAtd ); 252 appliesLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 253 appliesLinks[i].setUnderlined( true ); 254 appliesLinks[i].setEnabled( true ); 255 appliesLinks[i].addHyperlinkListener( this ); 256 } 257 else 258 { 259 appliesLinks[i] = toolkit.createHyperlink( appliesClient, names[i], SWT.WRAP ); 260 appliesLinks[i].setHref( null ); 261 appliesLinks[i].setUnderlined( false ); 262 appliesLinks[i].setEnabled( false ); 263 } 264 } 265 } 266 else 267 { 268 appliesSection.setText( "Applies (0)" ); 269 appliesLinks = new Hyperlink[0]; 270 Text usedFromText = toolkit.createText( appliesClient, getNonNullString( null ), SWT.NONE ); 271 usedFromText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 272 usedFromText.setEditable( false ); 273 } 274 } 275 else 276 { 277 appliesSection.setText( "Applies" ); 278 } 279 280 appliesSection.layout(); 281 } 282 283 } 284 | Popular Tags |