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.eclipse.swt.SWT; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Composite; 30 import org.eclipse.swt.widgets.Text; 31 import org.eclipse.ui.forms.events.ExpansionAdapter; 32 import org.eclipse.ui.forms.events.ExpansionEvent; 33 import org.eclipse.ui.forms.widgets.FormToolkit; 34 import org.eclipse.ui.forms.widgets.Hyperlink; 35 import org.eclipse.ui.forms.widgets.ScrolledForm; 36 import org.eclipse.ui.forms.widgets.Section; 37 38 39 46 public class LdapSyntaxDescriptionDetailsPage extends SchemaDetailsPage 47 { 48 49 50 private Section mainSection; 51 52 53 private Text numericOidText; 54 55 56 private Text descText; 57 58 59 private Section usedFromSection; 60 61 62 private Hyperlink[] usedFromLinks; 63 64 65 71 public LdapSyntaxDescriptionDetailsPage( SchemaPage schemaPage, FormToolkit toolkit ) 72 { 73 super( schemaPage, toolkit ); 74 } 75 76 77 80 public void createContents( final ScrolledForm detailForm ) 81 { 82 83 this.detailForm = detailForm; 84 detailForm.getBody().setLayout( new GridLayout() ); 85 86 mainSection = toolkit.createSection( detailForm.getBody(), SWT.NONE ); 88 mainSection.setText( "Details" ); 89 mainSection.marginWidth = 0; 90 mainSection.marginHeight = 0; 91 mainSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 92 toolkit.createCompositeSeparator( mainSection ); 93 94 usedFromSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE ); 96 usedFromSection.setText( "Used from" ); 97 usedFromSection.marginWidth = 0; 98 usedFromSection.marginHeight = 0; 99 usedFromSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 100 toolkit.createCompositeSeparator( usedFromSection ); 101 usedFromSection.addExpansionListener( new ExpansionAdapter() 102 { 103 public void expansionStateChanged( ExpansionEvent e ) 104 { 105 detailForm.reflow( true ); 106 } 107 } ); 108 109 createRawSection(); 111 } 112 113 114 117 public void setInput( Object input ) 118 { 119 LdapSyntaxDescription lsd = null; 120 if ( input instanceof LdapSyntaxDescription ) 121 { 122 lsd = ( LdapSyntaxDescription ) input; 123 } 124 125 createMainContent( lsd ); 126 createUsedFromContents( lsd ); 127 createRawContents( lsd ); 128 129 detailForm.reflow( true ); 130 } 131 132 133 140 private void createMainContent( LdapSyntaxDescription lsd ) 141 { 142 if ( mainSection.getClient() != null ) 144 { 145 mainSection.getClient().dispose(); 146 } 147 148 Composite mainClient = toolkit.createComposite( mainSection, SWT.WRAP ); 150 GridLayout mainLayout = new GridLayout( 2, false ); 151 mainClient.setLayout( mainLayout ); 152 mainSection.setClient( mainClient ); 153 154 if ( lsd != null ) 156 { 157 toolkit.createLabel( mainClient, "Numeric OID:", SWT.NONE ); 158 numericOidText = toolkit.createText( mainClient, getNonNullString( lsd.getNumericOID() ), SWT.NONE ); 159 numericOidText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 160 numericOidText.setEditable( false ); 161 162 toolkit.createLabel( mainClient, "Descripton:", SWT.NONE ); 163 descText = toolkit.createText( mainClient, getNonNullString( lsd.getDesc() ), SWT.WRAP | SWT.MULTI ); 164 GridData gd = new GridData( GridData.FILL_HORIZONTAL ); 165 gd.widthHint = detailForm.getForm().getSize().x - 100 - 60; 166 descText.setLayoutData( gd ); 167 descText.setEditable( false ); 168 } 169 170 mainSection.layout(); 171 } 172 173 174 181 private void createUsedFromContents( LdapSyntaxDescription lsd ) 182 { 183 if ( usedFromSection.getClient() != null && !usedFromSection.getClient().isDisposed() ) 185 { 186 usedFromSection.getClient().dispose(); 187 } 188 189 Composite usedFromClient = toolkit.createComposite( usedFromSection, SWT.WRAP ); 191 usedFromClient.setLayout( new GridLayout() ); 192 usedFromSection.setClient( usedFromClient ); 193 194 if ( lsd != null ) 196 { 197 AttributeTypeDescription[] usedFromATDs = lsd.getUsedFromAttributeTypeDescription(); 198 if ( usedFromATDs != null && usedFromATDs.length > 0 ) 199 { 200 usedFromSection.setText( "Used from (" + usedFromATDs.length + ")" ); 201 usedFromLinks = new Hyperlink[usedFromATDs.length]; 202 for ( int i = 0; i < usedFromATDs.length; i++ ) 203 { 204 usedFromLinks[i] = toolkit.createHyperlink( usedFromClient, usedFromATDs[i].toString(), SWT.WRAP ); 205 usedFromLinks[i].setHref( usedFromATDs[i] ); 206 usedFromLinks[i].setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 207 usedFromLinks[i].setUnderlined( true ); 208 usedFromLinks[i].setEnabled( true ); 209 usedFromLinks[i].addHyperlinkListener( this ); 210 } 211 } 212 else 213 { 214 usedFromSection.setText( "Used from (0)" ); 215 usedFromLinks = new Hyperlink[0]; 216 Text usedFromText = toolkit.createText( usedFromClient, getNonNullString( null ), SWT.NONE ); 217 usedFromText.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 218 usedFromText.setEditable( false ); 219 } 220 } 221 else 222 { 223 usedFromSection.setText( "Used from" ); 224 } 225 226 usedFromSection.layout(); 227 } 228 229 } 230 | Popular Tags |