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.SchemaWrapper; 30 import org.apache.log4j.Logger; 31 import org.eclipse.core.runtime.IStatus; 32 import org.eclipse.core.runtime.Status; 33 import org.eclipse.jface.action.Action; 34 import org.eclipse.jface.action.IAction; 35 import org.eclipse.jface.dialogs.ErrorDialog; 36 import org.eclipse.jface.viewers.ISelection; 37 import org.eclipse.jface.viewers.TreeSelection; 38 import org.eclipse.ui.IViewActionDelegate; 39 import org.eclipse.ui.IViewPart; 40 import org.eclipse.ui.IWorkbenchWindow; 41 import org.eclipse.ui.IWorkbenchWindowActionDelegate; 42 import org.eclipse.ui.PlatformUI; 43 import org.eclipse.ui.plugin.AbstractUIPlugin; 44 45 46 49 public class SaveAsAction extends Action implements IWorkbenchWindowActionDelegate, IViewActionDelegate 50 { 51 private static Logger logger = Logger.getLogger( SaveAsAction.class ); 52 53 54 59 public SaveAsAction() 60 { 61 super( Messages.getString( "SaveAsAction.Save_schema_as" ) ); setToolTipText( getText() ); 63 setId( PluginConstants.CMD_SAVE_AS ); 64 setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, 65 PluginConstants.IMG_SAVE_AS ) ); 66 setEnabled( true ); 67 } 68 69 70 73 public void run() 74 { 75 SchemasView view = ( SchemasView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() 76 .findView( SchemasView.ID ); Object selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement(); 78 79 if ( selection != null ) 81 { 82 if ( selection instanceof SchemaWrapper ) 83 { 84 Schema schema = ( ( SchemaWrapper ) selection ).getMySchema(); 85 86 try 87 { 88 schema.saveas(); 89 } 90 catch ( Exception e ) 91 { 92 ErrorDialog 93 .openError( 94 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), 95 Messages.getString( "SaveAsAction.Error" ), Messages.getString( "SaveAsAction.An_error_occurred_when_saving_schemas" ) + schema.getName(), new Status( IStatus.ERROR, Activator.PLUGIN_ID, 0, "Status Error Message", null ) ); logger.debug( "An error occured when saving schema " + schema.getName() ); } 99 } 100 } 101 } 102 103 104 public void dispose() 105 { 106 } 107 108 109 public void init( IWorkbenchWindow window ) 110 { 111 } 112 113 114 public void run( IAction action ) 115 { 116 this.run(); 117 } 118 119 120 public void selectionChanged( IAction action, ISelection selection ) 121 { 122 } 123 124 125 public void init( IViewPart view ) 126 { 127 } 128 } 129 | Popular Tags |