KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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
12 package org.eclipse.jdt.internal.corext.buildpath;
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IPath;
19 import org.eclipse.core.runtime.IProgressMonitor;
20
21 import org.eclipse.jdt.core.IClasspathEntry;
22 import org.eclipse.jdt.core.IJavaProject;
23 import org.eclipse.jdt.core.JavaModelException;
24
25 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
26
27 /**
28  * Operation to reset all changes and go back to the initial project state.
29  */

30 public class ResetAllOperation extends ClasspathModifierOperation {
31     private IClasspathEntry[] fEntries;
32     private IPath fOutputLocation;
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 ResetAllOperation(IClasspathModifierListener listener, IClasspathInformationProvider informationProvider) {
45         super(listener, informationProvider, NewWizardMessages.NewSourceContainerWorkbookPage_ToolBar_Reset_tooltip, IClasspathInformationProvider.RESET_ALL);
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>IOutputFolderQuery</li>
53      *
54      * @param monitor a progress monitor, can be <code>null</code>
55      */

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

84     public boolean isValid(List JavaDoc elements, int[] types) throws JavaModelException {
85         IJavaProject project= fInformationProvider.getJavaProject();
86         if (project == null)
87             return false;
88         if (fEntries == null) {
89             fEntries= project.getRawClasspath();
90             fOutputLocation= project.getOutputLocation();
91         }
92         if (!project.getOutputLocation().equals(fOutputLocation))
93             return true;
94         IClasspathEntry[] currentEntries= project.getRawClasspath();
95         if (currentEntries.length != fEntries.length)
96             return true;
97         for(int i= 0; i < fEntries.length; i++) {
98             if (!fEntries[i].equals(currentEntries[i]))
99                 return true;
100         }
101         return false;
102     }
103     
104     /**
105      * Get a description for this operation. In this particual case
106      * the description is independent of the selection and it's
107      * provided type.
108      *
109      * @param type the type of the selected object, must be a constant of
110      * <code>DialogPackageExplorerActionGroup</code>.
111      * @return a string describing the operation
112      */

113     public String JavaDoc getDescription(int type) {
114         return NewWizardMessages.PackageExplorerActionGroup_FormText_Default_ResetAll;
115     }
116 }
117
Popular Tags