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.AttributeType; 28 import org.apache.directory.ldapstudio.schemas.model.ObjectClass; 29 import org.apache.directory.ldapstudio.schemas.model.Schema; 30 import org.apache.directory.ldapstudio.schemas.view.views.SchemasView; 31 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper; 32 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.ObjectClassWrapper; 33 import org.eclipse.jface.action.Action; 34 import org.eclipse.jface.viewers.TreeSelection; 35 import org.eclipse.swt.SWT; 36 import org.eclipse.swt.widgets.MessageBox; 37 import org.eclipse.ui.PlatformUI; 38 import org.eclipse.ui.plugin.AbstractUIPlugin; 39 40 41 44 public class DeleteAction extends Action 45 { 46 private enum ItemType 47 { 48 attributeType, objectClass 49 } 50 51 52 57 public DeleteAction() 58 { 59 super( Messages.getString( "DeleteAction.Delete_the_selected_item" ) ); setToolTipText( getText() ); 61 setId( PluginConstants.CMD_DELETE ); 62 setImageDescriptor( AbstractUIPlugin 63 .imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_DELETE ) ); 64 setEnabled( true ); 65 } 66 67 68 71 public void run() 72 { 73 SchemasView view = ( SchemasView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() 74 .findView( SchemasView.ID ); Object selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement(); 76 77 Schema schema = null; 78 ItemType item = null; 79 80 if ( selection instanceof AttributeTypeWrapper ) 81 { 82 schema = ( ( AttributeTypeWrapper ) selection ).getMyAttributeType().getOriginatingSchema(); 84 item = DeleteAction.ItemType.attributeType; 85 } 86 else if ( selection instanceof ObjectClassWrapper ) 87 { 88 schema = ( ( ObjectClassWrapper ) selection ).getMyObjectClass().getOriginatingSchema(); 90 item = DeleteAction.ItemType.objectClass; 91 } 92 else 93 { 94 MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 95 SWT.OK | SWT.ICON_ERROR ); 96 messageBox.setMessage( Messages.getString( "DeleteAction.This_item_cant_be_deleted" ) ); messageBox.open(); 98 return; 99 } 100 101 if ( schema.type == Schema.SchemaType.coreSchema ) 103 { 104 MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 105 SWT.OK | SWT.ICON_ERROR ); 106 messageBox 107 .setMessage( Messages.getString( "DeleteAction.The_schema" ) + schema.getName() + Messages.getString( "DeleteAction.Is_a_core_schema_It_cant_be_modified" ) ); messageBox.open(); 109 } 110 else 111 { 112 if ( item == DeleteAction.ItemType.attributeType ) 113 { 114 AttributeType attributeType = ( ( AttributeTypeWrapper ) selection ).getMyAttributeType(); 115 MessageBox messageBox = new MessageBox( 116 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK | SWT.CANCEL 117 | SWT.ICON_QUESTION ); 118 messageBox 119 .setMessage( Messages.getString( "DeleteAction.Are_you_sure_you_want_to_delete_the_attribute_type" ) + attributeType.getNames()[0] + Messages.getString( "DeleteAction.Interrogation" ) ); if ( messageBox.open() == SWT.OK ) 121 { 122 schema.removeAttributeType( attributeType ); 123 } 124 } 125 else if ( item == DeleteAction.ItemType.objectClass ) 126 { 127 ObjectClass objectClass = ( ( ObjectClassWrapper ) selection ).getMyObjectClass(); 128 MessageBox messageBox = new MessageBox( 129 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK | SWT.CANCEL 130 | SWT.ICON_QUESTION ); 131 messageBox 132 .setMessage( Messages.getString( "DeleteAction.Are_you_sure_you_want_to_delete_the_object_class" ) + objectClass.getNames()[0] + Messages.getString( "DeleteAction.Interrogation" ) ); if ( messageBox.open() == SWT.OK ) 134 { 135 schema.removeObjectClass( objectClass ); 136 } 137 } 138 } 139 } 140 } 141 | Popular Tags |