KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > editors > schemabrowser > SchemaDetailsPage


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

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 /**
40  * A base implementation used from all schema detail pages.
41  *
42  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
43  * @version $Rev$, $Date$
44  */

45 public abstract class SchemaDetailsPage implements IHyperlinkListener
46 {
47
48     /** The raw section, displays the schema attibute value */
49     protected Section rawSection;
50
51     /** The text with the schema attribute value */
52     protected Text rawText;
53
54     /** The toolkit used to create controls */
55     protected FormToolkit toolkit;
56
57     /** The master schema page */
58     protected SchemaPage schemaPage;
59
60     /** The detail page form */
61     protected ScrolledForm detailForm;
62
63
64     /**
65      * Creates a new instance of SchemaDetailsPage.
66      *
67      * @param schemaPage the master schema page
68      * @param toolkit the toolkit used to create controls
69      */

70     protected SchemaDetailsPage( SchemaPage schemaPage, FormToolkit toolkit )
71     {
72         this.schemaPage = schemaPage;
73         this.toolkit = toolkit;
74     }
75
76
77     /**
78      * Disposes this details page.
79      */

80     public void dispose()
81     {
82     }
83
84
85     /**
86      * {@inheritDoc}
87      */

88     public void linkActivated( HyperlinkEvent e )
89     {
90         Object JavaDoc 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     /**
100      * {@inheritDoc}
101      */

102     public void linkEntered( HyperlinkEvent e )
103     {
104     }
105
106
107     /**
108      * {@inheritDoc}
109      */

110     public void linkExited( HyperlinkEvent e )
111     {
112     }
113
114
115     /**
116      * Sets the input of this details page.
117      *
118      * @param input the input
119      */

120     public abstract void setInput( Object JavaDoc input );
121
122
123     /**
124      * Creates the contents of the details page.
125      *
126      * @param detailForm the parent
127      */

128     protected abstract void createContents( final ScrolledForm detailForm );
129
130
131     /**
132      * Creates the raw content section.
133      */

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     /**
153      * Creates the contents of the raw section.
154      *
155      * @param schemaPart the schema part to display
156      */

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             // detailForm.getForm().getVerticalBar().getSize().x
176
// gd2.widthHint = 10;
177
rawText.setLayoutData( gd2 );
178             rawText.setEditable( false );
179         }
180
181         rawSection.layout();
182
183     }
184
185
186     /**
187      * Helper method, return a dash "-" if the given string is null.
188      *
189      * @param s the string
190      * @return the given string or a dash "-" if the given string is null.
191      */

192     protected String JavaDoc getNonNullString( String JavaDoc s )
193     {
194         return s == null ? "-" : s;
195     }
196
197 }
198
Popular Tags