KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > dialogs > properties > SchemaPropertyPage


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.dialogs.properties;
22
23
24 import java.io.File JavaDoc;
25 import java.text.DateFormat JavaDoc;
26 import java.util.Date JavaDoc;
27
28 import org.apache.directory.ldapstudio.browser.common.jobs.RunnableContextJobAdapter;
29 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
30 import org.apache.directory.ldapstudio.browser.core.ConnectionManager;
31 import org.apache.directory.ldapstudio.browser.core.jobs.ReloadSchemasJob;
32 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
33 import org.apache.directory.ldapstudio.browser.core.model.schema.Schema;
34 import org.apache.directory.ldapstudio.browser.core.utils.Utils;
35
36 import org.eclipse.swt.SWT;
37 import org.eclipse.swt.events.SelectionEvent;
38 import org.eclipse.swt.events.SelectionListener;
39 import org.eclipse.swt.layout.GridData;
40 import org.eclipse.swt.widgets.Button;
41 import org.eclipse.swt.widgets.Composite;
42 import org.eclipse.swt.widgets.Control;
43 import org.eclipse.swt.widgets.Group;
44 import org.eclipse.swt.widgets.Text;
45 import org.eclipse.ui.IWorkbenchPropertyPage;
46 import org.eclipse.ui.dialogs.PropertyPage;
47
48
49 public class SchemaPropertyPage extends PropertyPage implements IWorkbenchPropertyPage
50 {
51
52     private Text dnText;
53
54     private Text ctText;
55
56     private Text mtText;
57
58     private Button reloadSchemaButton;
59
60     private Text cachePathText;
61
62     private Text cacheDateText;
63
64     private Text cacheSizeText;
65
66
67     public SchemaPropertyPage()
68     {
69         super();
70         super.noDefaultAndApplyButton();
71     }
72
73
74     protected Control createContents( Composite parent )
75     {
76
77         Composite composite = BaseWidgetUtils.createColumnContainer( parent, 1, 1 );
78
79         Group infoGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ),
80             "Schema Information", 1 );
81         Composite infoComposite = BaseWidgetUtils.createColumnContainer( infoGroup, 2, 1 );
82         Composite infoGroupLeft = BaseWidgetUtils.createColumnContainer( infoComposite, 2, 1 );
83
84         BaseWidgetUtils.createLabel( infoGroupLeft, "Schema DN:", 1 );
85         dnText = BaseWidgetUtils.createWrappedLabeledText( infoGroupLeft, "", 1 );
86
87         BaseWidgetUtils.createLabel( infoGroupLeft, "Create Timestamp:", 1 );
88         ctText = BaseWidgetUtils.createWrappedLabeledText( infoGroupLeft, "", 1 );
89
90         BaseWidgetUtils.createLabel( infoGroupLeft, "Modify Timestamp:", 1 );
91         mtText = BaseWidgetUtils.createWrappedLabeledText( infoGroupLeft, "", 1 );
92
93         reloadSchemaButton = BaseWidgetUtils.createButton( infoComposite, "", 1 );
94         GridData gd = new GridData();
95         gd.verticalAlignment = SWT.BOTTOM;
96         reloadSchemaButton.setLayoutData( gd );
97         reloadSchemaButton.addSelectionListener( new SelectionListener()
98         {
99             public void widgetSelected( SelectionEvent e )
100             {
101                 reloadSchema();
102             }
103
104
105             public void widgetDefaultSelected( SelectionEvent e )
106             {
107             }
108         } );
109
110         BaseWidgetUtils.createSpacer( composite, 1 );
111         BaseWidgetUtils.createSpacer( composite, 1 );
112
113         Group cacheGroup = BaseWidgetUtils.createGroup( BaseWidgetUtils.createColumnContainer( composite, 1, 1 ),
114             "Schema Cache", 1 );
115         Composite cacheComposite = BaseWidgetUtils.createColumnContainer( cacheGroup, 2, 1 );
116
117         BaseWidgetUtils.createLabel( cacheComposite, "Cache Location:", 1 );
118         cachePathText = BaseWidgetUtils.createWrappedLabeledText( cacheComposite, "", 1 );
119
120         BaseWidgetUtils.createLabel( cacheComposite, "Cache Date:", 1 );
121         cacheDateText = BaseWidgetUtils.createWrappedLabeledText( cacheComposite, "", 1 );
122
123         BaseWidgetUtils.createLabel( cacheComposite, "Cache Size:", 1 );
124         cacheSizeText = BaseWidgetUtils.createWrappedLabeledText( cacheComposite, "", 1 );
125
126         IConnection connection = ConnectionPropertyPage.getConnection( getElement() );
127         this.connectionUpdated( connection );
128
129         return composite;
130     }
131
132
133     private void reloadSchema()
134     {
135         final IConnection connection = ConnectionPropertyPage.getConnection( getElement() );
136         ReloadSchemasJob job = new ReloadSchemasJob( new IConnection[]
137             { connection } );
138         RunnableContextJobAdapter.execute( job );
139         this.connectionUpdated( connection );
140     }
141
142
143     private void connectionUpdated( IConnection connection )
144     {
145
146         if ( !this.dnText.isDisposed() )
147         {
148             Schema schema = null;
149             if ( connection != null )
150             {
151                 schema = connection.getSchema();
152             }
153
154             if ( schema != null && schema.getDn() != null )
155             {
156                 dnText.setText( schema.getDn().toString() );
157             }
158             else
159             {
160                 dnText.setText( "-" );
161             }
162
163             if ( schema != null && schema.getCreateTimestamp() != null )
164             {
165                 ctText.setText( schema.getCreateTimestamp() );
166             }
167             else
168             {
169                 ctText.setText( "-" );
170             }
171
172             if ( schema != null && schema.getModifyTimestamp() != null )
173             {
174                 mtText.setText( schema.getModifyTimestamp() );
175             }
176             else
177             {
178                 mtText.setText( "-" );
179             }
180
181             if ( schema != null )
182             {
183                 reloadSchemaButton.setText( "Reload Schema" );
184             }
185             else
186             {
187                 reloadSchemaButton.setText( "Load Schema" );
188             }
189
190             if ( connection != null )
191             {
192                 String JavaDoc cacheFileName = ConnectionManager.getSchemaCacheFileName( connection.getName() );
193                 File JavaDoc cacheFile = new File JavaDoc( cacheFileName );
194                 if ( cacheFile.exists() )
195                 {
196                     cachePathText.setText( cacheFile.getPath() );
197                     DateFormat JavaDoc format = DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.MEDIUM );
198                     cacheDateText.setText( format.format( new Date JavaDoc( cacheFile.lastModified() ) ) );
199                     cacheSizeText.setText( Utils.formatBytes( cacheFile.length() ) );
200                 }
201                 else
202                 {
203                     cachePathText.setText( "-" );
204                     cacheDateText.setText( "-" );
205                     cacheSizeText.setText( "-" );
206                 }
207             }
208
209             if ( connection != null && connection.isOpened() )
210             {
211                 reloadSchemaButton.setEnabled( true );
212             }
213             else
214             {
215                 reloadSchemaButton.setEnabled( true );
216             }
217         }
218     }
219
220
221     public boolean isDisposed()
222     {
223         return this.dnText.isDisposed();
224     }
225
226 }
227
Popular Tags