KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > apacheds > configuration > actions > NewServerConfigurationAction


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 package org.apache.directory.ldapstudio.apacheds.configuration.actions;
21
22
23 import org.apache.directory.ldapstudio.apacheds.configuration.Activator;
24 import org.apache.directory.ldapstudio.apacheds.configuration.editor.ServerConfigurationEditor;
25 import org.apache.directory.ldapstudio.apacheds.configuration.editor.ServerConfigurationEditorInput;
26 import org.apache.directory.ldapstudio.apacheds.configuration.model.ServerConfiguration;
27 import org.apache.directory.ldapstudio.apacheds.configuration.model.ServerConfigurationParser;
28 import org.apache.directory.ldapstudio.apacheds.configuration.model.ServerConfigurationParserException;
29 import org.eclipse.core.runtime.Status;
30 import org.eclipse.jface.action.Action;
31 import org.eclipse.jface.action.IAction;
32 import org.eclipse.jface.viewers.ISelection;
33 import org.eclipse.swt.SWT;
34 import org.eclipse.swt.widgets.MessageBox;
35 import org.eclipse.ui.IWorkbenchPage;
36 import org.eclipse.ui.IWorkbenchWindow;
37 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
38 import org.eclipse.ui.PartInitException;
39 import org.eclipse.ui.PlatformUI;
40
41
42 /**
43  * This class implements the New Server Configuration Action.
44  *
45  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
46  * @version $Rev$, $Date$
47  */

48 public class NewServerConfigurationAction extends Action implements IWorkbenchWindowActionDelegate
49 {
50     /* (non-Javadoc)
51      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
52      */

53     public void run( IAction action )
54     {
55         ServerConfigurationParser parser = new ServerConfigurationParser();
56         ServerConfiguration serverConfiguration = null;
57         
58         try
59         {
60             serverConfiguration = parser.parse( Activator.class.getResourceAsStream( "default-server.xml" ) );
61         }
62         catch ( ServerConfigurationParserException e )
63         {
64             MessageBox messageBox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
65                 SWT.OK | SWT.ICON_ERROR );
66             messageBox.setText( "Error!" );
67             messageBox.setMessage( "An error occurred when reading the file." + "\n" + e.getMessage() );
68             messageBox.open();
69             return;
70         }
71
72         IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
73         try
74         {
75             page.openEditor( new ServerConfigurationEditorInput( serverConfiguration ), ServerConfigurationEditor.ID );
76         }
77         catch ( PartInitException e )
78         {
79             Activator.getDefault().getLog().log(
80                 new Status( Status.ERROR, Activator.PLUGIN_ID, Status.OK, e.getMessage(), e.getCause() ) );
81             return;
82         }
83     }
84
85
86     /* (non-Javadoc)
87      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
88      */

89     public void selectionChanged( IAction action, ISelection selection )
90     {
91     }
92
93
94     /* (non-Javadoc)
95      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
96      */

97     public void dispose()
98     {
99     }
100
101
102     /* (non-Javadoc)
103      * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
104      */

105     public void init( IWorkbenchWindow window )
106     {
107     }
108 }
109
Popular Tags