KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > dialogs > RenameEntryDialog


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.common.dialogs;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.common.widgets.BaseWidgetUtils;
26 import org.apache.directory.ldapstudio.browser.common.widgets.DnBuilderWidget;
27 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyEvent;
28 import org.apache.directory.ldapstudio.browser.common.widgets.WidgetModifyListener;
29 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
30 import org.apache.directory.ldapstudio.browser.core.model.RDN;
31 import org.eclipse.jface.dialogs.Dialog;
32 import org.eclipse.jface.dialogs.IDialogConstants;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.layout.GridData;
35 import org.eclipse.swt.widgets.Button;
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 RenameEntryDialog extends Dialog implements WidgetModifyListener
42 {
43
44     public static final String JavaDoc DELETE_OLD_RDN_DIALOGSETTING_KEY = RenameEntryDialog.class.getName() + ".deleteOldRdn";
45
46     public static final String JavaDoc DIALOG_TITLE = "Rename Entry";
47
48     private IEntry entry;
49
50     private DnBuilderWidget dnBuilderWidget;
51
52     private Button deleteOldRdnButton;
53
54     private Button simulateRenameButton;
55
56     private Button okButton;
57
58     private RDN rdn;
59
60     private boolean deleteOldRdn;
61
62     private boolean simulateRename;
63
64
65     public RenameEntryDialog( Shell parentShell, IEntry entry )
66     {
67         super( parentShell );
68         super.setShellStyle( super.getShellStyle() | SWT.RESIZE );
69         this.entry = entry;
70         this.rdn = null;
71
72         if ( BrowserCommonActivator.getDefault().getDialogSettings().get( DELETE_OLD_RDN_DIALOGSETTING_KEY ) == null )
73             BrowserCommonActivator.getDefault().getDialogSettings().put( DELETE_OLD_RDN_DIALOGSETTING_KEY, true );
74         this.deleteOldRdn = BrowserCommonActivator.getDefault().getDialogSettings().getBoolean( DELETE_OLD_RDN_DIALOGSETTING_KEY );
75     }
76
77
78     protected void configureShell( Shell shell )
79     {
80         super.configureShell( shell );
81         shell.setText( DIALOG_TITLE );
82     }
83
84
85     public boolean close()
86     {
87         this.dnBuilderWidget.removeWidgetModifyListener( this );
88         this.dnBuilderWidget.dispose();
89         return super.close();
90     }
91
92
93     protected void okPressed()
94     {
95         this.rdn = this.dnBuilderWidget.getRdn();
96         this.deleteOldRdn = this.deleteOldRdnButton.getSelection();
97         this.simulateRename = this.simulateRenameButton.getSelection();
98
99         BrowserCommonActivator.getDefault().getDialogSettings().put( DELETE_OLD_RDN_DIALOGSETTING_KEY, this.deleteOldRdn );
100         this.dnBuilderWidget.saveDialogSettings();
101
102         super.okPressed();
103     }
104
105
106     protected void createButtonsForButtonBar( Composite parent )
107     {
108         okButton = createButton( parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true );
109         createButton( parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false );
110     }
111
112
113     protected Control createDialogArea( Composite parent )
114     {
115
116         Composite composite = ( Composite ) super.createDialogArea( parent );
117         GridData gd = new GridData( GridData.FILL_BOTH );
118         gd.widthHint = convertHorizontalDLUsToPixels( IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH ) * 3 / 2;
119         composite.setLayoutData( gd );
120
121         BaseWidgetUtils.createLabel( composite, "Please enter the new RDN of the selected entry.", 1 );
122
123         this.dnBuilderWidget = new DnBuilderWidget( true, false );
124         this.dnBuilderWidget.addWidgetModifyListener( this );
125         this.dnBuilderWidget.createContents( composite );
126         this.dnBuilderWidget.setInput( this.entry.getConnection(), this.entry.getSubschema().getAllAttributeNames(),
127             this.entry.getRdn(), null );
128
129         this.deleteOldRdnButton = BaseWidgetUtils.createCheckbox( composite, "Delete old RDN", 1 );
130         this.deleteOldRdnButton.setSelection( this.deleteOldRdn );
131
132         this.simulateRenameButton = BaseWidgetUtils.createCheckbox( composite,
133             "Simulate subtree renaming by searching/adding/deleting recursively", 1 );
134         this.simulateRenameButton.setSelection( false );
135         this.simulateRenameButton.setEnabled( false );
136
137         applyDialogFont( composite );
138         return composite;
139     }
140
141
142     public void widgetModified( WidgetModifyEvent event )
143     {
144         if ( this.okButton != null )
145         {
146             this.okButton.setEnabled( this.dnBuilderWidget.getRdn() != null );
147         }
148     }
149
150
151     public RDN getRdn()
152     {
153         return this.rdn;
154     }
155
156
157     public boolean isDeleteOldRdn()
158     {
159         return this.deleteOldRdn;
160     }
161
162
163     public boolean isSimulateRename()
164     {
165         return simulateRename;
166     }
167
168 }
169
Popular Tags