KickJava   Java API By Example, From Geeks To Geeks.

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


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 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 /**
47  * This class implements the Action for "saving as..." a schema
48  */

49 public class SaveAsAction extends Action implements IWorkbenchWindowActionDelegate, IViewActionDelegate
50 {
51     private static Logger logger = Logger.getLogger( SaveAsAction.class );
52
53
54     /**
55      * Default constructor
56      * @param window
57      * @param label
58      */

59     public SaveAsAction()
60     {
61         super( Messages.getString( "SaveAsAction.Save_schema_as" ) ); //$NON-NLS-1$
62
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     /* (non-Javadoc)
71      * @see org.eclipse.jface.action.Action#run()
72      */

73     public void run()
74     {
75         SchemasView view = ( SchemasView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
76             .findView( SchemasView.ID ); //$NON-NLS-1$
77
Object JavaDoc selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement();
78
79         // We have to check on which node we are to get the schema name
80
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 JavaDoc 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, //$NON-NLS-1$ //$NON-NLS-2$
96
"Status Error Message", null ) ); //$NON-NLS-1$
97
logger.debug( "An error occured when saving schema " + schema.getName() ); //$NON-NLS-1$
98
}
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