KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > common > wizards > AttributeWizard


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.wizards;
22
23
24 import org.apache.directory.ldapstudio.browser.common.BrowserCommonActivator;
25 import org.apache.directory.ldapstudio.browser.core.model.IEntry;
26 import org.eclipse.jface.viewers.IStructuredSelection;
27 import org.eclipse.jface.wizard.IWizardPage;
28 import org.eclipse.jface.wizard.Wizard;
29 import org.eclipse.jface.wizard.WizardPage;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.ui.INewWizard;
35 import org.eclipse.ui.IWorkbench;
36 import org.eclipse.ui.PlatformUI;
37
38
39 /**
40  * The AttributeWizard is used to create a new attribute or
41  * to modify an existing attribute description.
42  *
43  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
44  * @version $Rev$, $Date$
45  */

46 public class AttributeWizard extends Wizard implements INewWizard
47 {
48
49     /** The type page. */
50     private AttributeTypeWizardPage typePage;
51
52     /** The options page. */
53     private AttributeOptionsWizardPage optionsPage;
54
55     /** The initial show subschema attributes only. */
56     private boolean initialShowSubschemaAttributesOnly;
57
58     /** The initial hide existing attributes. */
59     private boolean initialHideExistingAttributes;
60
61     /** The initial attribute description. */
62     private String JavaDoc initialAttributeDescription;
63
64     /** The initial entry. */
65     private IEntry initialEntry;
66
67     /** The final attribute description. */
68     private String JavaDoc finalAttributeDescription = null;
69
70
71     /**
72      * Creates a new instance of AttributeWizard with an empty
73      * attriute description.
74      */

75     public AttributeWizard()
76     {
77         super.setWindowTitle( "New Attribute" );
78         super.setNeedsProgressMonitor( false );
79         this.initialShowSubschemaAttributesOnly = true;
80         this.initialHideExistingAttributes = true;
81         this.initialAttributeDescription = "";
82         this.initialEntry = null;
83     }
84
85
86     /**
87      * Creates a new instance of AttributeWizard with the given initial attribute desription
88      *
89      * @param title the title
90      * @param entry the entry
91      * @param showSubschemaAttributesOnly the show subschema attributes only
92      * @param hideExistingAttributes the hide existing attributes
93      * @param attributeDescription the attribute description
94      */

95     public AttributeWizard( String JavaDoc title, boolean showSubschemaAttributesOnly, boolean hideExistingAttributes,
96         String JavaDoc attributeDescription, IEntry entry )
97     {
98         super.setWindowTitle( title );
99         super.setNeedsProgressMonitor( false );
100         this.initialShowSubschemaAttributesOnly = showSubschemaAttributesOnly;
101         this.initialHideExistingAttributes = hideExistingAttributes;
102         this.initialAttributeDescription = attributeDescription;
103         this.initialEntry = entry;
104     }
105
106
107     /**
108      * Gets the id.
109      *
110      * @return the id
111      */

112     public static String JavaDoc getId()
113     {
114         return AttributeWizard.class.getName();
115     }
116
117
118     /**
119      * {@inheritDoc}}
120      */

121     public void init( IWorkbench workbench, IStructuredSelection selection )
122     {
123     }
124
125
126     /**
127      * {@inheritDoc}}
128      */

129     public void addPages()
130     {
131         if ( initialEntry != null )
132         {
133             typePage = new AttributeTypeWizardPage( AttributeTypeWizardPage.class.getName(), initialEntry,
134                 initialAttributeDescription, initialShowSubschemaAttributesOnly, initialHideExistingAttributes, this );
135             addPage( typePage );
136
137             optionsPage = new AttributeOptionsWizardPage( AttributeOptionsWizardPage.class.getName(),
138                 initialAttributeDescription, this );
139             addPage( optionsPage );
140         }
141         else
142         {
143             IWizardPage page = new DummyWizardPage();
144             addPage( page );
145         }
146     }
147
148
149     /**
150      * {@inheritDoc}
151      */

152     public void createPageControls( Composite pageContainer )
153     {
154         super.createPageControls( pageContainer );
155
156         // set help context ID
157
PlatformUI.getWorkbench().getHelpSystem().setHelp( typePage.getControl(),
158             BrowserCommonActivator.PLUGIN_ID + "." + "tools_attribute_wizard" );
159         PlatformUI.getWorkbench().getHelpSystem().setHelp( optionsPage.getControl(),
160             BrowserCommonActivator.PLUGIN_ID + "." + "tools_attribute_wizard" );
161     }
162
163     /**
164      * A dummy wizard page to show the user that no entry is selected.
165      *
166      * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
167      * @version $Rev$, $Date$
168      */

169     class DummyWizardPage extends WizardPage
170     {
171
172         /**
173          * Creates a new instance of DummyWizardPage.
174          */

175         protected DummyWizardPage()
176         {
177             super( "" );
178             super.setTitle( "No entry selected" );
179             super.setDescription( "In order to use the attribute creation wizard please select an entry." );
180             // super.setImageDescriptor(BrowserUIPlugin.getDefault().getImageDescriptor(BrowserUIConstants.IMG_ATTRIBUTE_WIZARD));
181
super.setPageComplete( true );
182         }
183
184
185         /**
186          * {@inheritDoc}
187          */

188         public void createControl( Composite parent )
189         {
190             Composite composite = new Composite( parent, SWT.NONE );
191             GridLayout gl = new GridLayout( 1, false );
192             composite.setLayout( gl );
193             composite.setLayoutData( new GridData( GridData.FILL_BOTH ) );
194
195             setControl( composite );
196         }
197     }
198
199
200     /**
201      * {@inheritDoc}
202      */

203     public boolean performFinish()
204     {
205         finalAttributeDescription = getAttributeDescription();
206         return true;
207     }
208
209
210     /**
211      * Gets the attribute description.
212      *
213      * @return the attribute description
214      */

215     public String JavaDoc getAttributeDescription()
216     {
217         if ( finalAttributeDescription != null )
218         {
219             return finalAttributeDescription;
220         }
221
222         return typePage.getAttributeType() + optionsPage.getAttributeOptions();
223     }
224
225 }
226
Popular Tags