KickJava   Java API By Example, From Geeks To Geeks.

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


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.view.editors.schema.SchemaEditor;
28 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditorInput;
29 import org.apache.directory.ldapstudio.schemas.view.editors.schema.SchemaEditorSourceCodePage;
30 import org.apache.directory.ldapstudio.schemas.view.views.SchemasView;
31 import org.apache.directory.ldapstudio.schemas.view.views.wrappers.SchemaWrapper;
32 import org.apache.log4j.Logger;
33 import org.eclipse.jface.action.Action;
34 import org.eclipse.jface.viewers.TreeSelection;
35 import org.eclipse.ui.IWorkbenchPage;
36 import org.eclipse.ui.PartInitException;
37 import org.eclipse.ui.PlatformUI;
38 import org.eclipse.ui.forms.editor.FormEditor;
39 import org.eclipse.ui.plugin.AbstractUIPlugin;
40
41
42 /**
43  * This class implements the Action for deleting an element (object class or attribute type).
44  *
45  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
46  * @version $Rev$, $Date$
47  */

48 public class OpenSchemaSourceCode extends Action
49 {
50     /**
51      * Creates a new instance of OpenSchemaSourceCode.
52      */

53     public OpenSchemaSourceCode()
54     {
55         super( Messages.getString( "OpenSchemaSourceCode.View_source_code" ) ); //$NON-NLS-1$
56
setToolTipText( getText() );
57         setId( PluginConstants.CMD_OPEN_SCHEMA_SOURCE_CODE );
58         setImageDescriptor( AbstractUIPlugin
59             .imageDescriptorFromPlugin( Activator.PLUGIN_ID, PluginConstants.IMG_SCHEMA ) );
60         setEnabled( true );
61     }
62
63
64     /* (non-Javadoc)
65      * @see org.eclipse.jface.action.Action#run()
66      */

67     public void run()
68     {
69         SchemasView view = ( SchemasView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
70             .findView( SchemasView.ID );
71
72         Object JavaDoc selection = ( ( TreeSelection ) view.getViewer().getSelection() ).getFirstElement();
73
74         if ( selection instanceof SchemaWrapper )
75         {
76             SchemaWrapper schemaWrapper = ( SchemaWrapper ) selection;
77             try
78             {
79                 IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
80                 FormEditor editor = ( FormEditor ) page.openEditor(
81                     new SchemaEditorInput( schemaWrapper.getMySchema() ), SchemaEditor.ID );
82                 editor.setActivePage( SchemaEditorSourceCodePage.ID );
83             }
84             catch ( PartInitException e )
85             {
86                 Logger.getLogger( OpenSchemaSourceCode.class ).debug( "error when opening the editor" ); //$NON-NLS-1$
87
}
88         }
89     }
90 }
91
Popular Tags