KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > valueeditors > dn > DnDialog


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.valueeditors.dn;
22
23
24 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
25 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent;
26 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener;
27 import org.apache.directory.ldapstudio.browser.common.widgets.search.EntryWidget;
28 import org.apache.directory.ldapstudio.browser.core.model.DN;
29 import org.apache.directory.ldapstudio.browser.core.model.IConnection;
30 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsActivator;
31 import org.apache.directory.ldapstudio.valueeditors.ValueEditorsConstants;
32 import org.eclipse.jface.dialogs.Dialog;
33 import org.eclipse.jface.dialogs.IDialogConstants;
34 import org.eclipse.swt.SWT;
35 import org.eclipse.swt.layout.GridData;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Control;
38 import org.eclipse.swt.widgets.Shell;
39
40
41 public class DnDialog extends Dialog implements WidgetModifyListener
42 {
43
44     public static final String JavaDoc DIALOG_TITLE = "DN Editor";
45
46     private EntryWidget entryWidget;
47
48     private IConnection connection;
49
50     private DN dn;
51
52
53     public DnDialog( Shell parentShell, IConnection connection, DN dn )
54     {
55         super( parentShell );
56         super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
57         this.connection = connection;
58         this.dn = dn;
59     }
60
61
62     protected void configureShell( Shell shell )
63     {
64         super.configureShell( shell );
65         shell.setText( DIALOG_TITLE );
66         shell.setImage( ValueEditorsActivator.getDefault().getImage( ValueEditorsConstants.IMG_DNEDITOR ) );
67     }
68
69
70     public boolean close()
71     {
72         this.entryWidget.removeWidgetModifyListener( this );
73         return super.close();
74     }
75
76
77     protected void okPressed()
78     {
79         this.dn = this.entryWidget.getDn();
80         this.entryWidget.saveDialogSettings();
81         super.okPressed();
82     }
83
84
85     protected Control createButtonBar( Composite parent )
86     {
87         Control control = super.createButtonBar( parent );
88         widgetModified( null );
89         return control;
90     }
91
92
93     protected Control createDialogArea( Composite parent )
94     {
95
96         Composite composite = ( Composite ) super.createDialogArea( parent );
97         GridData gd = new GridData( GridData.FILL_BOTH );
98         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 3 / 2;
99         composite.setLayoutData( gd );
100
101         Composite innerComposite = BaseWidgetUtils.createColumnContainer( composite, 2, 1 );
102         this.entryWidget = new EntryWidget( connection, dn );
103         this.entryWidget.addWidgetModifyListener( this );
104         this.entryWidget.createWidget( innerComposite );
105
106         applyDialogFont( composite );
107         return composite;
108     }
109
110
111     public void widgetModified( WidgetModifyEvent event )
112     {
113         if ( getButton( IDialogConstants.OK_ID ) != null )
114         {
115             getButton( IDialogConstants.OK_ID ).setEnabled(
116                 this.entryWidget.getDn() != null && !"".equals( this.entryWidget.getDn().toString() ) );
117         }
118     }
119
120
121     public DN getDn()
122     {
123         return this.dn;
124     }
125
126 }
127
Popular Tags