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.model.SchemaPool; 29 import org.apache.directory.ldapstudio.schemas.view.views.SchemasView; 30 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.AttributeTypeWrapper; 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.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 RemoveSchemaAction extends Action 45 { 46 47 52 public RemoveSchemaAction() 53 { 54 super( Messages.getString( "RemoveSchemaAction.Remove_the_selected_schema" ) ); setToolTipText( getText() ); 56 setId( PluginConstants.CMD_REMOVE_SCHEMA ); 57 setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, 58 PluginConstants.IMG_REMOVE_SCHEMA ) ); 59 setEnabled( true ); 60 } 61 62 63 66 public void run() 67 { 68 SchemasView view = ( SchemasView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() 69 .findView( SchemasView.ID ); Object selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement(); 71 72 String schemaName = null; 73 74 if ( selection instanceof SchemaWrapper ) 76 { 77 schemaName = ( ( SchemaWrapper ) selection ).getMySchema().getName(); 78 } 79 else if ( selection instanceof AttributeTypeWrapper ) 80 { 81 schemaName = ( ( SchemaWrapper ) ( ( AttributeTypeWrapper ) selection ).getParent().getParent() ) 83 .getMySchema().getName(); 84 } 85 else if ( selection instanceof ObjectClassWrapper ) 86 { 87 schemaName = ( ( SchemaWrapper ) ( ( ObjectClassWrapper ) selection ).getParent().getParent() ) 89 .getMySchema().getName(); 90 } 91 92 if ( schemaName != null ) 93 { 94 SchemaPool pool = SchemaPool.getInstance(); 96 Schema schema = pool.getSchema( schemaName ); 98 99 if ( schema.type == Schema.SchemaType.coreSchema ) 100 { 101 MessageBox messageBox = new MessageBox( 102 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK | SWT.ICON_ERROR ); 103 messageBox 104 .setMessage( Messages.getString( "RemoveSchemaAction.The_schema" ) + schemaName + Messages.getString( "RemoveSchemaAction.Is_a_core_schema_It_cant_be_removed_from_the_pool" ) ); messageBox.open(); 106 return; 107 } 108 if ( schema.hasBeenModified() || schema.hasPendingModification() ) 109 { 110 MessageBox messageBox = new MessageBox( 111 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK | SWT.CANCEL 112 | SWT.ICON_QUESTION ); 113 messageBox.setMessage( Messages 114 .getString( "RemoveSchemaAction.This_schema_has_been_modified_or_has_pending_modifications" ) ); if ( messageBox.open() == SWT.OK ) 116 { 117 pool.removeSchema( schema ); 118 } 119 } 120 else 121 { 122 pool.removeSchema( schema ); 123 } 124 } 125 } 126 } 127 | Popular Tags |