1 20 21 package org.apache.directory.ldapstudio.schemas.controller.actions; 22 23 24 import java.io.File ; 25 26 import org.apache.directory.ldapstudio.schemas.Activator; 27 import org.apache.directory.ldapstudio.schemas.Messages; 28 import org.apache.directory.ldapstudio.schemas.PluginConstants; 29 import org.apache.directory.ldapstudio.schemas.model.Schema; 30 import org.apache.directory.ldapstudio.schemas.model.SchemaPool; 31 import org.apache.log4j.Logger; 32 import org.eclipse.jface.action.Action; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.swt.widgets.FileDialog; 35 import org.eclipse.ui.PlatformUI; 36 import org.eclipse.ui.plugin.AbstractUIPlugin; 37 38 39 42 public class OpenLocalFileAction extends Action 43 { 44 private static Logger logger = Logger.getLogger( OpenLocalFileAction.class ); 45 46 47 50 public OpenLocalFileAction() 51 { 52 super( Messages.getString( "OpenLocalFileAction.Open_a_schema_file" ) ); setToolTipText( getText() ); 54 setId( PluginConstants.CMD_OPEN_LOCAL ); 55 setActionDefinitionId( PluginConstants.CMD_OPEN_LOCAL ); 56 setImageDescriptor( AbstractUIPlugin.imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_OPEN ) ); 57 setEnabled( true ); 58 } 59 60 61 64 public void run() 65 { 66 FileDialog fd = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OPEN ); 67 fd.setText( Messages.getString( "OpenLocalFileAction.Open_a_schema_file" ) ); fd.setFilterPath( Activator.getDefault().getPreferenceStore() 69 .getString( PluginConstants.PREFS_OPEN_FILE_DIALOG ) ); 70 String [] filterExt = 71 { "*.schema", "*.*" }; fd.setFilterExtensions( filterExt ); 73 String selected = fd.open(); 74 if ( selected != null ) 76 { 77 SchemaPool pool = SchemaPool.getInstance(); 78 try 79 { 80 pool.addSchema( Schema.localPathToURL( selected ) ); 81 } 82 catch ( Exception e ) 83 { 84 logger.debug( "Error when opening a schema file" ); } 86 87 Activator.getDefault().getPreferenceStore().putValue( PluginConstants.PREFS_OPEN_FILE_DIALOG, 88 new File ( selected ).getParent() ); 89 } 90 } 91 } 92 | Popular Tags |