KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit > refactoring > LaunchConfigChange


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.junit.refactoring;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15
16 import org.eclipse.debug.core.ILaunchConfiguration;
17 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
18
19 import org.eclipse.ltk.core.refactoring.Change;
20 import org.eclipse.ltk.core.refactoring.NullChange;
21 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
22
23 import org.eclipse.jdt.internal.junit.Messages;
24 import org.eclipse.jdt.internal.junit.ui.JUnitMessages;
25
26 public abstract class LaunchConfigChange extends Change {
27
28     protected LaunchConfigurationContainer fConfig;
29
30     private final boolean fShouldFlagWarning;
31
32     public LaunchConfigChange(LaunchConfigurationContainer config, boolean shouldFlagWarning) {
33         fConfig= config;
34         fShouldFlagWarning= shouldFlagWarning;
35     }
36
37     /**
38      * {@inheritDoc}
39      */

40     public Object JavaDoc getModifiedElement() {
41         return fConfig;
42     }
43
44     /**
45      * {@inheritDoc}
46      */

47     public void initializeValidationData(IProgressMonitor pm) {
48         // must be implemented to decide correct value of isValid
49
}
50
51     public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
52         RefactoringStatus refactoringStatus= new RefactoringStatus();
53         if (!fConfig.getConfiguration().exists() && fShouldFlagWarning)
54             refactoringStatus.addError(Messages.format(JUnitMessages.LaunchConfigChange_configDeleted, fConfig.getName()));
55         return refactoringStatus;
56     }
57
58     public Change perform(IProgressMonitor pm) throws CoreException {
59         if (!fConfig.getConfiguration().exists())
60             return new NullChange();
61
62         pm.beginTask("", 1); //$NON-NLS-1$
63
String JavaDoc oldValue= getOldValue(fConfig.getConfiguration());
64
65         ILaunchConfigurationWorkingCopy copy= fConfig.getConfiguration().getWorkingCopy();
66         alterLaunchConfiguration(copy);
67         fConfig.setConfiguration(copy.doSave());
68
69         Change undo= getUndo(oldValue);
70
71         pm.worked(1);
72         return undo;
73     }
74
75     public boolean shouldFlagWarning() {
76         return fShouldFlagWarning;
77     }
78
79     protected abstract void alterLaunchConfiguration(ILaunchConfigurationWorkingCopy copy) throws CoreException;
80
81     protected abstract String JavaDoc getOldValue(ILaunchConfiguration config) throws CoreException;
82
83     protected abstract Change getUndo(String JavaDoc oldValue) throws CoreException;
84 }
85
Popular Tags