1 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 40 public Object getModifiedElement() { 41 return fConfig; 42 } 43 44 47 public void initializeValidationData(IProgressMonitor pm) { 48 } 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); String 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 getOldValue(ILaunchConfiguration config) throws CoreException; 82 83 protected abstract Change getUndo(String oldValue) throws CoreException; 84 } 85 | Popular Tags |