KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > SaveContext


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.core.internal.resources;
12
13 import org.eclipse.core.resources.*;
14 import org.eclipse.core.runtime.*;
15
16 public class SaveContext implements ISaveContext {
17     protected Plugin plugin;
18     protected int kind;
19     protected boolean needDelta;
20     protected boolean needSaveNumber;
21     protected SafeFileTable fileTable;
22     protected int previousSaveNumber;
23     protected IProject project;
24
25     protected SaveContext(Plugin plugin, int kind, IProject project) throws CoreException {
26         this.plugin = plugin;
27         this.kind = kind;
28         this.project = project;
29         needDelta = false;
30         needSaveNumber = false;
31         String JavaDoc pluginId = plugin.getBundle().getSymbolicName();
32         fileTable = new SafeFileTable(pluginId);
33         previousSaveNumber = getWorkspace().getSaveManager().getSaveNumber(pluginId);
34     }
35
36     public void commit() throws CoreException {
37         if (needSaveNumber) {
38             String JavaDoc pluginId = plugin.getBundle().getSymbolicName();
39             IPath oldLocation = getWorkspace().getMetaArea().getSafeTableLocationFor(pluginId);
40             getWorkspace().getSaveManager().setSaveNumber(pluginId, getSaveNumber());
41             fileTable.setLocation(getWorkspace().getMetaArea().getSafeTableLocationFor(pluginId));
42             fileTable.save();
43             oldLocation.toFile().delete();
44         }
45     }
46
47     /**
48      * @see ISaveContext
49      */

50     public IPath[] getFiles() {
51         return getFileTable().getFiles();
52     }
53
54     protected SafeFileTable getFileTable() {
55         return fileTable;
56     }
57
58     /**
59      * @see ISaveContext
60      */

61     public int getKind() {
62         return kind;
63     }
64
65     /**
66      * @see ISaveContext
67      */

68     public Plugin getPlugin() {
69         return plugin;
70     }
71
72     /**
73      * @see ISaveContext
74      */

75     public int getPreviousSaveNumber() {
76         return previousSaveNumber;
77     }
78
79     /**
80      * @see ISaveContext
81      */

82     public IProject getProject() {
83         return project;
84     }
85
86     /**
87      * @see ISaveContext
88      */

89     public int getSaveNumber() {
90         int result = getPreviousSaveNumber() + 1;
91         return result > 0 ? result : 1;
92     }
93
94     protected Workspace getWorkspace() {
95         return (Workspace) ResourcesPlugin.getWorkspace();
96     }
97
98     public boolean isDeltaNeeded() {
99         return needDelta;
100     }
101
102     /**
103      * @see ISaveContext
104      */

105     public IPath lookup(IPath file) {
106         return getFileTable().lookup(file);
107     }
108
109     /**
110      * @see ISaveContext
111      */

112     public void map(IPath file, IPath location) {
113         getFileTable().map(file, location);
114     }
115
116     /**
117      * @see ISaveContext
118      */

119     public void needDelta() {
120         needDelta = true;
121     }
122
123     /**
124      * @see ISaveContext
125      */

126     public void needSaveNumber() {
127         needSaveNumber = true;
128     }
129 }
130
Popular Tags