KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > ui > wizards > NewBookmarkMainWizardPage


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.wizards;
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.IEntry;
30 import org.eclipse.jface.wizard.WizardPage;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.events.ModifyEvent;
33 import org.eclipse.swt.events.ModifyListener;
34 import org.eclipse.swt.layout.GridData;
35 import org.eclipse.swt.layout.GridLayout;
36 import org.eclipse.swt.widgets.Composite;
37 import org.eclipse.swt.widgets.Text;
38
39
40 /**
41  * The NewBookmarkMainWizardPage is used to specify the bookmark name
42  * and the DN of the target entry.
43  *
44  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
45  * @version $Rev$, $Date$
46  */

47 public class NewBookmarkMainWizardPage extends WizardPage implements WidgetModifyListener
48 {
49
50     /** The entry. */
51     private IEntry entry;
52
53     /** The bookmark name text. */
54     private Text bookmarkNameText;
55
56     /** The bookmark entry widget. */
57     private EntryWidget bookmarkEntryWidget;
58
59
60     /**
61      * Creates a new instance of NewBookmarkMainWizardPage.
62      *
63      * @param pageName the page name
64      * @param entry the entry
65      * @param wizard the wizard
66      */

67     public NewBookmarkMainWizardPage( String JavaDoc pageName, IEntry entry, NewBookmarkWizard wizard )
68     {
69         super( pageName );
70         setTitle( "New Bookmark" );
71         setDescription( "Please enter the bookmark parameters." );
72         // setImageDescriptor(BrowserUIPlugin.getDefault().getImageDescriptor(BrowserUIConstants.IMG_ATTRIBUTE_WIZARD));
73
setPageComplete( false );
74
75         this.entry = entry;
76     }
77
78
79     /**
80      * {@inheritDoc}
81      */

82     public void dispose()
83     {
84         super.dispose();
85         bookmarkEntryWidget.removeWidgetModifyListener( this );
86     }
87
88
89     /**
90      * Validates this page.
91      */

92     private void validate()
93     {
94         if ( bookmarkNameText != null && !bookmarkNameText.isDisposed() )
95         {
96             setPageComplete( bookmarkEntryWidget.getDn() != null && !"".equals( bookmarkNameText.getText() ) );
97         }
98     }
99
100
101     /**
102      * {@inheritDoc}
103      */

104     public void setVisible( boolean visible )
105     {
106         super.setVisible( visible );
107         if ( visible )
108         {
109             validate();
110         }
111     }
112
113
114     /**
115      * {@inheritDoc}
116      */

117     public void createControl( Composite parent )
118     {
119         Composite composite = new Composite( parent, SWT.NONE );
120         GridLayout gl = new GridLayout( 1, false );
121         composite.setLayout( gl );
122         composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
123
124         Composite innerComposite = BaseWidgetUtils.createColumnContainer( composite, 3, 1 );
125
126         BaseWidgetUtils.createLabel( innerComposite, "Bookmark Name:", 1 );
127         bookmarkNameText = BaseWidgetUtils.createText( innerComposite, entry.getDn().toString(), 2 );
128         bookmarkNameText.setFocus();
129         bookmarkNameText.addModifyListener( new ModifyListener()
130         {
131             public void modifyText( ModifyEvent e )
132             {
133                 validate();
134             }
135         } );
136
137         BaseWidgetUtils.createLabel( innerComposite, "Bookmark DN:", 1 );
138         bookmarkEntryWidget = new EntryWidget();
139         bookmarkEntryWidget.addWidgetModifyListener( this );
140         bookmarkEntryWidget.createWidget( innerComposite );
141         bookmarkEntryWidget.setInput( entry.getConnection(), entry.getDn() );
142
143         setControl( composite );
144     }
145
146
147     /**
148      * {@inheritDoc}
149      */

150     public void widgetModified( WidgetModifyEvent event )
151     {
152         validate();
153     }
154
155
156     /**
157      * Gets the bookmark dn.
158      *
159      * @return the bookmark dn
160      */

161     public DN getBookmarkDn()
162     {
163         return bookmarkEntryWidget.getDn();
164     }
165
166
167     /**
168      * Gets the bookmark name.
169      *
170      * @return the bookmark name
171      */

172     public String JavaDoc getBookmarkName()
173     {
174         return bookmarkNameText.getText();
175     }
176
177
178     /**
179      * Saves the dialog settings.
180      */

181     public void saveDialogSettings()
182     {
183         bookmarkEntryWidget.saveDialogSettings();
184     }
185
186 }
187
Popular Tags