1 20 21 package org.apache.directory.ldapstudio.browser.ui.editors.schemabrowser; 22 23 24 import org.apache.directory.ldapstudio.browser.core.model.schema.SchemaPart; 25 import org.eclipse.swt.SWT; 26 import org.eclipse.swt.layout.GridData; 27 import org.eclipse.swt.layout.GridLayout; 28 import org.eclipse.swt.widgets.Composite; 29 import org.eclipse.swt.widgets.Text; 30 import org.eclipse.ui.forms.events.ExpansionAdapter; 31 import org.eclipse.ui.forms.events.ExpansionEvent; 32 import org.eclipse.ui.forms.events.HyperlinkEvent; 33 import org.eclipse.ui.forms.events.IHyperlinkListener; 34 import org.eclipse.ui.forms.widgets.FormToolkit; 35 import org.eclipse.ui.forms.widgets.ScrolledForm; 36 import org.eclipse.ui.forms.widgets.Section; 37 38 39 45 public abstract class SchemaDetailsPage implements IHyperlinkListener 46 { 47 48 49 protected Section rawSection; 50 51 52 protected Text rawText; 53 54 55 protected FormToolkit toolkit; 56 57 58 protected SchemaPage schemaPage; 59 60 61 protected ScrolledForm detailForm; 62 63 64 70 protected SchemaDetailsPage( SchemaPage schemaPage, FormToolkit toolkit ) 71 { 72 this.schemaPage = schemaPage; 73 this.toolkit = toolkit; 74 } 75 76 77 80 public void dispose() 81 { 82 } 83 84 85 88 public void linkActivated( HyperlinkEvent e ) 89 { 90 Object obj = e.getHref(); 91 if ( obj instanceof SchemaPart ) 92 { 93 schemaPage.getSchemaBrowser().setInput( 94 new SchemaBrowserInput( schemaPage.getConnection(), ( SchemaPart ) obj ) ); 95 } 96 } 97 98 99 102 public void linkEntered( HyperlinkEvent e ) 103 { 104 } 105 106 107 110 public void linkExited( HyperlinkEvent e ) 111 { 112 } 113 114 115 120 public abstract void setInput( Object input ); 121 122 123 128 protected abstract void createContents( final ScrolledForm detailForm ); 129 130 131 134 protected void createRawSection() 135 { 136 rawSection = toolkit.createSection( detailForm.getBody(), Section.TWISTIE ); 137 rawSection.setText( "Raw Schema Definition" ); 138 rawSection.marginWidth = 0; 139 rawSection.marginHeight = 0; 140 rawSection.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) ); 141 toolkit.createCompositeSeparator( rawSection ); 142 rawSection.addExpansionListener( new ExpansionAdapter() 143 { 144 public void expansionStateChanged( ExpansionEvent e ) 145 { 146 detailForm.reflow( true ); 147 } 148 } ); 149 } 150 151 152 157 protected void createRawContents( SchemaPart schemaPart ) 158 { 159 160 if ( rawSection.getClient() != null && !rawSection.getClient().isDisposed() ) 161 { 162 rawSection.getClient().dispose(); 163 } 164 165 Composite client = toolkit.createComposite( rawSection, SWT.WRAP ); 166 client.setLayout( new GridLayout() ); 167 rawSection.setClient( client ); 168 169 if ( schemaPart != null ) 170 { 171 rawText = toolkit.createText( client, getNonNullString( schemaPart.getLine().getValueAsString() ), SWT.WRAP 172 | SWT.MULTI ); 173 GridData gd2 = new GridData( GridData.FILL_HORIZONTAL ); 174 gd2.widthHint = detailForm.getForm().getSize().x - 100 - 60; 175 rawText.setLayoutData( gd2 ); 178 rawText.setEditable( false ); 179 } 180 181 rawSection.layout(); 182 183 } 184 185 186 192 protected String getNonNullString( String s ) 193 { 194 return s == null ? "-" : s; 195 } 196 197 } 198 | Popular Tags |