KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > actions > AddExtensionAction


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.actions;
22
23
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26
27 import org.apache.directory.ldapstudio.Messages;
28 import org.eclipse.jface.action.Action;
29 import org.eclipse.jface.action.IAction;
30 import org.eclipse.swt.custom.BusyIndicator;
31 import org.eclipse.ui.IWorkbenchWindow;
32 import org.eclipse.update.search.BackLevelFilter;
33 import org.eclipse.update.search.EnvironmentFilter;
34 import org.eclipse.update.search.UpdateSearchRequest;
35 import org.eclipse.update.search.UpdateSearchScope;
36 import org.eclipse.update.ui.UpdateJob;
37 import org.eclipse.update.ui.UpdateManagerUI;
38
39
40 /**
41  * This class implements the Add Extension Action.
42  * It uses Eclipse built-in extension system to allow users
43  * to add extensions to LDAP Studio.
44  *
45  * @author <a HREF="mailto:dev@directory.apache.org">Apache Directory Project</a>
46  * @version $Rev$, $Date$
47  */

48 public class AddExtensionAction extends Action implements IAction
49 {
50     private IWorkbenchWindow window;
51
52
53     /**
54      * Default constructor
55      * @param window
56      * the window it is attached to
57      */

58     public AddExtensionAction( IWorkbenchWindow window )
59     {
60         this.window = window;
61         setId( "org.apache.directory.ldapstudio.newExtensions" ); //$NON-NLS-1$
62
setText( Messages.getString( "AddExtensionAction.Add_Extensions" ) ); //$NON-NLS-1$
63
setToolTipText( Messages.getString( "AddExtensionAction.Search_for_new_extensions" ) ); //$NON-NLS-1$
64
}
65
66
67     /**
68      * Runs the action
69      */

70     public void run()
71     {
72         BusyIndicator.showWhile( window.getShell().getDisplay(), new Runnable JavaDoc()
73         {
74             public void run()
75             {
76                 UpdateJob job = new UpdateJob(
77                     Messages.getString( "AddExtensionAction.Searching_new_extensions" ), getSearchRequest() ); //$NON-NLS-1$
78
UpdateManagerUI.openInstaller( window.getShell(), job );
79             }
80
81
82             private UpdateSearchRequest getSearchRequest()
83             {
84                 UpdateSearchRequest result = new UpdateSearchRequest( UpdateSearchRequest
85                     .createDefaultSiteSearchCategory(), new UpdateSearchScope() );
86                 result.addFilter( new BackLevelFilter() );
87                 result.addFilter( new EnvironmentFilter() );
88                 UpdateSearchScope scope = new UpdateSearchScope();
89                 try
90                 {
91                     String JavaDoc homeBase = System.getProperty(
92                         "ldapstudio.homebase", Messages.getString( "AddExtensionAction.LDAP_Studio_Home_Base" ) ); //$NON-NLS-1$ //$NON-NLS-2$
93
URL JavaDoc url = new URL JavaDoc( homeBase );
94                     scope.addSearchSite( Messages.getString( "AddExtensionAction.LDAP_Studio_Site" ), url, null ); //$NON-NLS-1$
95
}
96                 catch ( MalformedURLException JavaDoc e )
97                 {
98                     // TODO: handle exception
99
}
100                 result.setScope( scope );
101                 return result;
102             }
103         } );
104     }
105 }
Popular Tags