preparing new release
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / QuantumSaveParticipant.java
1 package com.quantum;
2
3 import java.io.File;
4
5 import com.quantum.model.BookmarkCollection;
6 import com.quantum.view.subset.SubsetContentProvider;
7
8 import org.eclipse.core.resources.ISaveContext;
9 import org.eclipse.core.resources.ISaveParticipant;
10 import org.eclipse.core.runtime.CoreException;
11 import org.eclipse.core.runtime.Path;
12
13
14 class QuantumSaveParticipant implements ISaveParticipant {
15         
16         /**
17         * @see org.eclipse.core.resources.ISaveParticipant#doneSaving(ISaveContext)
18         */
19         public void doneSaving(ISaveContext context) {
20         }
21         /**
22          * @see org.eclipse.core.resources.ISaveParticipant#prepareToSave(ISaveContext)
23          */
24         public void prepareToSave(ISaveContext context) throws CoreException {
25         }
26
27         /**
28          * @see org.eclipse.core.resources.ISaveParticipant#rollback(ISaveContext)
29          */
30         public void rollback(ISaveContext context) {
31         }
32
33         /**
34          * @see org.eclipse.core.resources.ISaveParticipant#saving(ISaveContext)
35          */
36         public void saving(ISaveContext context) throws CoreException {
37                 switch (context.getKind()) {
38                         case ISaveContext.FULL_SAVE :
39                                 QuantumPlugin quantumPluginInstance = QuantumPlugin.getDefault();
40                                 // save the plug in state 
41                                 if (BookmarkCollection.getInstance().isAnythingChanged()
42                                         || SubsetContentProvider.getInstance().hasChanged()) {
43
44                                         int saveNumber = context.getSaveNumber();
45                                         String saveFileName = Messages.getString("QuantumPlugin.saveDir") + "-" + Integer.toString(saveNumber) + Messages.getString("QuantumPlugin.saveFileExtension"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
46                                         File f = quantumPluginInstance.getStateLocation().append(saveFileName).toFile();
47
48                                         // if we fail to write, an exception is thrown and we do not update the path 
49                                         quantumPluginInstance.writeImportantState(f);
50
51                                         context.map(new Path(Messages.getString("QuantumPlugin.saveDir")), new Path(saveFileName)); //$NON-NLS-1$
52                                         context.needSaveNumber();
53
54                                 } else {
55                                         System.out.println("Not saving unchanged bookmarks"); //$NON-NLS-1$
56                                 }
57                                 break;
58                         case ISaveContext.PROJECT_SAVE :
59                                 // get the project related to this save operation 
60                                 //IProject project = context.getProject(); 
61                                 // save its information, if necessary 
62                                 break;
63                         case ISaveContext.SNAPSHOT :
64                                 // This operation needs to be really fast because 
65                                 // snapshots can be requested frequently by the 
66                                 // workspace. 
67                                 break;
68                 }
69         }
70 }