KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > schemas > controller > actions > OpenLocalFileAction


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  *
19  */

20
21 package org.apache.directory.ldapstudio.schemas.controller.actions;
22
23
24 import java.io.File JavaDoc;
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 /**
40  * This class implements the Action for opening a local file schema
41  */

42 public class OpenLocalFileAction extends Action
43 {
44     private static Logger logger = Logger.getLogger( OpenLocalFileAction.class );
45
46
47     /**
48      * Creates a new instance of OpenLocalFileAction.
49      */

50     public OpenLocalFileAction()
51     {
52         super( Messages.getString( "OpenLocalFileAction.Open_a_schema_file" ) ); //$NON-NLS-1$
53
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     /**
62      * {@inheritDoc}
63      */

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" ) ); //$NON-NLS-1$
68
fd.setFilterPath( Activator.getDefault().getPreferenceStore()
69             .getString( PluginConstants.PREFS_OPEN_FILE_DIALOG ) );
70         String JavaDoc[] filterExt =
71             { "*.schema", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
72
fd.setFilterExtensions( filterExt );
73         String JavaDoc selected = fd.open();
74         // selected == null if 'cancel' has been pushed
75
if ( selected != null )
76         {
77             SchemaPool pool = SchemaPool.getInstance();
78             try
79             {
80                 pool.addSchema( Schema.localPathToURL( selected ) );
81             }
82             catch ( Exception JavaDoc e )
83             {
84                 logger.debug( "Error when opening a schema file" ); //$NON-NLS-1$
85
}
86
87             Activator.getDefault().getPreferenceStore().putValue( PluginConstants.PREFS_OPEN_FILE_DIALOG,
88                 new File JavaDoc( selected ).getParent() );
89         }
90     }
91 }
92
Popular Tags