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.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 48 public class OpenSchemaSourceCode extends Action 49 { 50 53 public OpenSchemaSourceCode() 54 { 55 super( Messages.getString( "OpenSchemaSourceCode.View_source_code" ) ); 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 67 public void run() 68 { 69 SchemasView view = ( SchemasView ) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() 70 .findView( SchemasView.ID ); 71 72 Object 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" ); } 88 } 89 } 90 } 91 | Popular Tags |