01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.refactoring;
05:
06: import org.apache.xmlbeans.XmlOptions;
07: import org.eclipse.core.resources.IProject;
08: import org.eclipse.core.runtime.IProgressMonitor;
09: import org.eclipse.core.runtime.OperationCanceledException;
10: import org.eclipse.ltk.core.refactoring.Change;
11: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
12: import org.terracotta.dso.TcPlugin;
13:
14: import com.terracottatech.config.TcConfigDocument;
15: import com.terracottatech.config.TcConfigDocument.TcConfig;
16:
17: public class ConfigUndoneChange extends Change {
18: private TcConfig fConfig;
19: private IProject fProject;
20:
21: public ConfigUndoneChange(IProject project, TcConfig config) {
22: super ();
23: fProject = project;
24: fConfig = config;
25: }
26:
27: public Object getModifiedElement() {
28: return null;
29: }
30:
31: public String getName() {
32: return "TCConfigUndoneUpdate";
33: }
34:
35: public void initializeValidationData(IProgressMonitor pm) {/**/
36: }
37:
38: public RefactoringStatus isValid(IProgressMonitor pm)
39: throws OperationCanceledException {
40: return new RefactoringStatus();
41: }
42:
43: public Change perform(IProgressMonitor pm) {
44: TcPlugin plugin = TcPlugin.getDefault();
45: TcConfig config = (TcConfig) plugin.getConfiguration(fProject)
46: .copy();
47:
48: try {
49: XmlOptions xmlOpts = plugin.getXmlOptions();
50: TcConfigDocument doc = TcConfigDocument.Factory
51: .newInstance(xmlOpts);
52: doc.setTcConfig(fConfig);
53: plugin.setConfigurationFromString(fProject, plugin
54: .configDocumentAsString(doc));
55: } catch (Exception e) {
56: e.printStackTrace();
57: }
58:
59: // create the undo change
60: return new ConfigUndoneChange(fProject, config);
61: }
62: }
|