KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > buildpath > AddExternalArchivesOperation


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.buildpath;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IProgressMonitor;
18
19 import org.eclipse.jdt.core.IJavaProject;
20 import org.eclipse.jdt.core.JavaModelException;
21
22 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
23 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.DialogPackageExplorerActionGroup;
24 import org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage.ClasspathModifierQueries.IAddArchivesQuery;
25
26 /**
27  * Operation to add external archives (.jar and .zip files) to the buildpath
28  *
29  * @see org.eclipse.jdt.internal.corext.buildpath.ClasspathModifier#addExternalJars(IAddArchivesQuery, IJavaProject, IProgressMonitor)
30  */

31 public class AddExternalArchivesOperation extends ClasspathModifierOperation {
32
33     /**
34      * Constructor
35      *
36      * @param listener a <code>IClasspathModifierListener</code> that is notified about
37      * changes on classpath entries or <code>null</code> if no such notification is
38      * necessary.
39      * @param informationProvider a provider to offer information to the action
40      *
41      * @see IClasspathInformationProvider
42      * @see ClasspathModifier
43      */

44     public AddExternalArchivesOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) {
45         super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_AddJarCP_tooltip, IClasspathInformationProvider.ADD_LIB_TO_BP);
46     }
47
48     /**
49      * Method which runs the actions with a progress monitor.<br>
50      *
51      * This operation requires the following query from the provider:
52      * <li>IAddArchivesQuery</li>
53      *
54      * @param monitor a progress monitor, can be <code>null</code>
55      */

56     public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc {
57         List JavaDoc result= null;
58         fException= null;
59         try {
60             IJavaProject project= fInformationProvider.getJavaProject();
61             IAddArchivesQuery query= fInformationProvider.getExternalArchivesQuery();
62             result= addExternalJars(query, project, monitor);
63         } catch (CoreException e) {
64             fException= e;
65             result= null;
66         }
67        super.handleResult(result, monitor);
68     }
69
70     /**
71      * This particular operation is always valid.
72      *
73      * @param elements a list of elements
74      * @param types an array of types for each element, that is,
75      * the type at position 'i' belongs to the selected element
76      * at position 'i'
77      *
78      * @return <code>true</code> if the operation can be
79      * executed on the provided list of elements, <code>
80      * false</code> otherwise.
81      * @throws JavaModelException
82      */

83     public boolean isValid(List JavaDoc elements, int[] types) throws JavaModelException {
84         return types.length == 1 && types[0] == DialogPackageExplorerActionGroup.JAVA_PROJECT;
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.jdt.internal.corext.buildpath.ClasspathModifierOperation#getDescription(int)
89      */

90     public String JavaDoc getDescription(int type) {
91         return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_toBuildpath_archives;
92     }
93
94 }
95
Popular Tags