KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > controller > actions > CreateANewObjectClassAction


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.controller.actions;
22
23
24 import org.apache.directory.ldapstudio.schemas.Activator;
25 import org.apache.directory.ldapstudio.schemas.Messages;
26 import org.apache.directory.ldapstudio.schemas.PluginConstants;
27 import org.apache.directory.ldapstudio.schemas.model.Schema;
28 import org.apache.directory.ldapstudio.schemas.view.views.SchemasView;
29 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper;
30 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.IntermediateNode;
31 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ObjectClassWrapper;
32 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.SchemaWrapper;
33 import org.apache.directory.ldapstudio.schemas.view.wizards.CreateANewObjectClassWizard;
34 import org.eclipse.jface.action.Action;
35 import org.eclipse.jface.viewers.StructuredSelection;
36 import org.eclipse.jface.viewers.TreeSelection;
37 import org.eclipse.jface.wizard.WizardDialog;
38 import org.eclipse.swt.SWT;
39 import org.eclipse.swt.widgets.MessageBox;
40 import org.eclipse.ui.PlatformUI;
41 import org.eclipse.ui.plugin.AbstractUIPlugin;
42
43
44 /**
45  * This class implements the Action for creating a new object class
46  */

47 public class CreateANewObjectClassAction extends Action
48 {
49
50     /**
51      * Default constructor
52      * @param window
53      * @param label
54      */

55     public CreateANewObjectClassAction()
56     {
57         super( Messages.getString( "CreateANewObjectClassAction.Create_a_new_object_class" ) ); //$NON-NLS-1$
58
setToolTipText( getText() );
59         setId( PluginConstants.CMD_CREATE_A_NEW_OBJECTCLASS );
60         setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID,
61             PluginConstants.IMG_CREATE_A_NEW_OBJECTCLASS ) );
62         setEnabled( true );
63     }
64
65
66     /**
67      * {@inheritDoc}
68      */

69     public void run()
70     {
71         SchemasView view = ( SchemasView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
72             .findView( SchemasView.ID ); //$NON-NLS-1$
73
Object JavaDoc selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement();
74
75         Schema schema = null;
76
77         // We have to check on which node we are to get the schema name
78
if ( selection instanceof SchemaWrapper )
79         {
80             schema = ( ( SchemaWrapper ) selection ).getMySchema();
81         }
82         else if ( selection instanceof AttributeTypeWrapper )
83         {
84             schema = ( ( AttributeTypeWrapper ) selection ).getMyAttributeType().getOriginatingSchema();
85         }
86         else if ( selection instanceof ObjectClassWrapper )
87         {
88             schema = ( ( ObjectClassWrapper ) selection ).getMyObjectClass().getOriginatingSchema();
89         }
90         else if ( selection instanceof IntermediateNode )
91         {
92             schema = ( ( SchemaWrapper ) ( ( IntermediateNode ) selection ).getParent() ).getMySchema();
93         }
94         else
95         {
96             MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
97                 SWT.OK | SWT.ICON_ERROR );
98             messageBox.setMessage( Messages.getString( "CreateANewObjectClassAction.A_schema_must_be_selected" ) ); //$NON-NLS-1$
99
messageBox.open();
100             return;
101         }
102
103         // Check if the schema isn't a core schema (core schema can't be modified
104
if ( schema.type == Schema.SchemaType.coreSchema )
105         {
106             MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
107                 SWT.OK | SWT.ICON_ERROR );
108             messageBox
109                 .setMessage( Messages.getString( "CreateANewObjectClassAction.The_schema" ) + schema.getName() + Messages.getString( "CreateANewObjectClassAction.Is_a_core_schema_It_cant_be_modified" ) ); //$NON-NLS-1$ //$NON-NLS-2$
110
messageBox.open();
111         }
112         else
113         {
114             // Instantiates and initializes the wizard
115
CreateANewObjectClassWizard wizard = new CreateANewObjectClassWizard( schema.getName() );
116             wizard.init( PlatformUI.getWorkbench(), StructuredSelection.EMPTY );
117             // Instantiates the wizard container with the wizard and opens it
118
WizardDialog dialog = new WizardDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
119                 wizard );
120             dialog.create();
121             dialog.open();
122         }
123     }
124 }
125
Popular Tags