KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > view > wizards > CreateANewAttributeTypeWizard


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.schemas.view.wizards;
22
23
24 import org.apache.directory.ldapstudio.schemas.model.AttributeType;
25 import org.apache.directory.ldapstudio.schemas.model.Schema;
26 import org.apache.directory.ldapstudio.schemas.model.SchemaPool;
27 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditor;
28 import org.apache.directory.ldapstudio.schemas.view.editors.attributeType.AttributeTypeEditorInput;
29 import org.apache.directory.server.core.tools.schema.AttributeTypeLiteral;
30 import org.eclipse.jface.viewers.IStructuredSelection;
31 import org.eclipse.jface.wizard.Wizard;
32 import org.eclipse.ui.INewWizard;
33 import org.eclipse.ui.IWorkbench;
34 import org.eclipse.ui.PartInitException;
35 import org.eclipse.ui.PlatformUI;
36
37
38 /**
39  * Wizard for creation of a new attribute type
40  */

41 public class CreateANewAttributeTypeWizard extends Wizard implements INewWizard
42 {
43     /** The default page */
44     private CreateANewAttributeTypeWizardPage page;
45
46     /** The schema name */
47     private String JavaDoc schemaName;
48
49
50     /**
51      * Creates a new instance of CreateANewAttributeTypeWizard.
52      *
53      * @param schemaName
54      * the schema name in which should be added the new attribute
55      * type
56      */

57     public CreateANewAttributeTypeWizard( String JavaDoc schemaName )
58     {
59         super();
60         this.schemaName = schemaName;
61     }
62
63
64     /* (non-Javadoc)
65      * @see org.eclipse.jface.wizard.Wizard#performFinish()
66      */

67     public boolean performFinish()
68     {
69         // Getting the SchemaPool
70
SchemaPool pool = SchemaPool.getInstance();
71
72         // Getting the right schema
73
Schema schema = pool.getSchema( schemaName );
74
75         // Creating the new attribute type and adding it to the schema
76
AttributeTypeLiteral attributeTypeLiteral = new AttributeTypeLiteral( this.page.getOidField() );
77         attributeTypeLiteral.setNames( new String JavaDoc[]
78             { this.page.getNameField() } );
79         AttributeType attributeType = new AttributeType( attributeTypeLiteral, schema );
80         schema.addAttributeType( attributeType );
81
82         // Opening the associated editor
83
AttributeTypeEditorInput input = new AttributeTypeEditorInput( attributeType );
84         String JavaDoc editorId = AttributeTypeEditor.ID;
85         try
86         {
87             PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor( input, editorId );
88         }
89         catch ( PartInitException e )
90         {
91             // TODO Log exception.
92
}
93
94         return true;
95     }
96
97
98     /* (non-Javadoc)
99      * @see org.eclipse.jface.wizard.Wizard#addPages()
100      */

101     public void addPages()
102     {
103         this.page = new CreateANewAttributeTypeWizardPage();
104         addPage( page );
105     }
106
107
108     /* (non-Javadoc)
109      * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
110      */

111     public void init( IWorkbench workbench, IStructuredSelection selection )
112     {
113     }
114 }
115
Popular Tags