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.log4j.Logger; 34 import org.eclipse.core.runtime.IStatus; 35 import org.eclipse.core.runtime.Status; 36 import org.eclipse.jface.action.Action; 37 import org.eclipse.jface.action.IAction; 38 import org.eclipse.jface.dialogs.ErrorDialog; 39 import org.eclipse.jface.viewers.ISelection; 40 import org.eclipse.jface.viewers.TreeSelection; 41 import org.eclipse.ui.IViewActionDelegate; 42 import org.eclipse.ui.IViewPart; 43 import org.eclipse.ui.IWorkbenchWindow; 44 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 45 import org.eclipse.ui.PlatformUI; 46 import org.eclipse.ui.plugin.AbstractUIPlugin; 47 48 49 52 public class SaveAction extends Action implements IWorkbenchWindowActionDelegate, IViewActionDelegate 53 { 54 private static Logger logger = Logger.getLogger( SaveAction.class ); 55 56 57 62 public SaveAction() 63 { 64 super( Messages.getString( "SaveAction.Save_schema" ) ); setToolTipText( getText() ); 66 setId( PluginConstants.CMD_SAVE ); 67 setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_SAVE ) ); 68 setEnabled( true ); 69 } 70 71 72 75 public void run() 76 { 77 SchemasView view = ( SchemasView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() 78 .findView( SchemasView.ID ); Object selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement(); 80 81 if ( selection != null ) 83 { 84 85 Schema schema = null; 86 87 if ( selection instanceof SchemaWrapper ) 88 { 89 schema = ( ( SchemaWrapper ) selection ).getMySchema(); 90 } 91 else if ( selection instanceof AttributeTypeWrapper ) 92 { 93 schema = ( ( AttributeTypeWrapper ) selection ).getMyAttributeType().getOriginatingSchema(); 94 } 95 else if ( selection instanceof ObjectClassWrapper ) 96 { 97 schema = ( ( ObjectClassWrapper ) selection ).getMyObjectClass().getOriginatingSchema(); 98 } 99 else if ( selection instanceof IntermediateNode ) 100 { 101 schema = ( ( SchemaWrapper ) ( ( IntermediateNode ) selection ).getParent() ).getMySchema(); 102 } 103 104 if ( schema != null ) 105 { 106 try 107 { 108 schema.save(); 109 } 110 catch ( Exception e ) 111 { 112 ErrorDialog 113 .openError( 114 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 115 Messages.getString( "SaveAction.Error" ), Messages.getString( "SaveAction.An_error_occurred_when_saving_schema" ) + schema.getName(), new Status( IStatus.ERROR, Activator.PLUGIN_ID, 0, "Status Error Message", null ) ); logger.debug( "An error occured when saving schema " + schema.getName() ); } 118 } 119 } 120 } 121 122 123 public void dispose() 124 { 125 } 126 127 128 public void init( IWorkbenchWindow window ) 129 { 130 } 131 132 133 public void run( IAction action ) 134 { 135 this.run(); 136 } 137 138 139 public void selectionChanged( IAction action, ISelection selection ) 140 { 141 } 142 143 144 public void init( IViewPart view ) 145 { 146 } 147 } 148 | Popular Tags |