1 5 package org.hibernate.eclipse.console; 6 7 import java.io.File ; 8 9 import org.eclipse.core.resources.IProject; 10 import org.eclipse.core.resources.ISaveContext; 11 import org.eclipse.core.resources.ISaveParticipant; 12 import org.eclipse.core.resources.ISavedState; 13 import org.eclipse.core.resources.ResourcesPlugin; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IPath; 16 import org.eclipse.core.runtime.Path; 17 18 22 public class HibernateConsoleSaveParticipant implements ISaveParticipant { 23 24 static final String SAVENAME = "hibernate-console.xml"; 25 26 public void prepareToSave(ISaveContext context) throws CoreException { 27 28 } 29 30 public void saving(ISaveContext context) throws CoreException { 31 switch (context.getKind()) { 32 case ISaveContext.FULL_SAVE: 33 HibernateConsolePlugin myPluginInstance = HibernateConsolePlugin 34 .getDefault(); 35 int saveNumber = context.getSaveNumber(); 37 String saveFileName = SAVENAME + "-" + Integer.toString(saveNumber); 38 File f = myPluginInstance.getStateLocation().append(saveFileName) 39 .toFile(); 40 myPluginInstance.writeStateTo(f); 43 context.map(new Path(SAVENAME), new Path(saveFileName)); 44 context.needSaveNumber(); 45 break; 46 case ISaveContext.PROJECT_SAVE: 47 IProject project = context.getProject(); 49 break; 51 case ISaveContext.SNAPSHOT: 52 break; 56 } 57 58 } 59 60 public void doneSaving(ISaveContext context) { 61 HibernateConsolePlugin myPluginInstance = HibernateConsolePlugin 62 .getDefault(); 63 64 int previousSaveNumber = context.getPreviousSaveNumber(); 66 String oldFileName = "save-" + Integer.toString(previousSaveNumber); 67 File f = myPluginInstance.getStateLocation().append(oldFileName) 68 .toFile(); 69 f.delete(); 71 } 72 73 public void rollback(ISaveContext context) { 74 HibernateConsolePlugin myPluginInstance = HibernateConsolePlugin 75 .getDefault(); 76 77 int saveNumber = context.getSaveNumber(); 80 String saveFileName = "save-" + Integer.toString(saveNumber); 81 File f = myPluginInstance.getStateLocation().append(saveFileName) 82 .toFile(); 83 f.delete(); 84 } 85 86 public void doStart(HibernateConsolePlugin plugin) throws CoreException { 87 ISavedState lastState = ResourcesPlugin.getWorkspace().addSaveParticipant(plugin, this); 88 if (lastState == null) { 89 return; 90 } 91 IPath location = lastState.lookup(new Path(HibernateConsoleSaveParticipant.SAVENAME)); 92 if (location == null) { 93 return; 94 } 95 File f = plugin.getStateLocation().append(location).toFile(); 96 plugin.readStateFrom(f); 97 } 98 99 } 100 | Popular Tags |