1 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 47 public class CreateANewObjectClassAction extends Action 48 { 49 50 55 public CreateANewObjectClassAction() 56 { 57 super( Messages.getString( "CreateANewObjectClassAction.Create_a_new_object_class" ) ); 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 69 public void run() 70 { 71 SchemasView view = ( SchemasView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() 72 .findView( SchemasView.ID ); Object selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement(); 74 75 Schema schema = null; 76 77 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" ) ); messageBox.open(); 100 return; 101 } 102 103 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" ) ); messageBox.open(); 111 } 112 else 113 { 114 CreateANewObjectClassWizard wizard = new CreateANewObjectClassWizard( schema.getName() ); 116 wizard.init( PlatformUI.getWorkbench(), StructuredSelection.EMPTY ); 117 WizardDialog dialog = new WizardDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 119 wizard ); 120 dialog.create(); 121 dialog.open(); 122 } 123 } 124 } 125 | Popular Tags |