KickJava   Java API By Example, From Geeks To Geeks.

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


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.ObjectClass;
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.objectClass.ObjectClassEditor;
28 import org.apache.directory.ldapstudio.schemas.view.editors.objectClass.ObjectClassEditorInput;
29 import org.apache.directory.server.core.tools.schema.ObjectClassLiteral;
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 object class
40  *
41  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
42  * @version $Rev$, $Date$
43  */

44 public class CreateANewObjectClassWizard extends Wizard implements INewWizard
45 {
46     /** The Default Page */
47     private CreateANewObjectClassWizardPage page;
48
49     /** The schema name*/
50     private String JavaDoc schemaName;
51
52
53     /**
54      * Creates a new instance of CreateANewObjectClassWizard.
55      * @param schemaName
56      * the schema name in which should be added the new object class
57      */

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

68     public boolean performFinish()
69     {
70         // Getting the SchemaPool
71
SchemaPool pool = SchemaPool.getInstance();
72
73         // Getting the right schema
74
Schema schema = pool.getSchema( schemaName );
75
76         // Creating the new object class and adding it to the schema
77
ObjectClassLiteral objectClassLiteral = new ObjectClassLiteral( this.page.getOidField() );
78         objectClassLiteral.setNames( new String JavaDoc[]
79             { this.page.getNameField() } );
80         objectClassLiteral.setSuperiors( new String JavaDoc[]
81             { "top" } ); //$NON-NLS-1$
82
ObjectClass objectClass = new ObjectClass( objectClassLiteral, schema );
83         schema.addObjectClass( objectClass );
84
85         // Opening the associated editor
86
ObjectClassEditorInput input = new ObjectClassEditorInput( objectClass );
87         String JavaDoc editorId = ObjectClassEditor.ID;
88         try
89         {
90             PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor( input, editorId );
91         }
92         catch ( PartInitException e )
93         {
94         }
95
96         return true;
97     }
98
99
100     /* (non-Javadoc)
101      * @see org.eclipse.jface.wizard.Wizard#addPages()
102      */

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

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