KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.internal.events.ResourceDelta;
14 import org.eclipse.core.internal.events.ResourceDeltaFactory;
15 import org.eclipse.core.internal.utils.Policy;
16 import org.eclipse.core.internal.watson.ElementTree;
17 import org.eclipse.core.resources.*;
18 import org.eclipse.core.runtime.*;
19 import org.eclipse.core.runtime.jobs.ISchedulingRule;
20
21 /**
22  * Standard implementation of the ISavedState interface.
23  */

24 public class SavedState implements ISavedState {
25     ElementTree oldTree;
26     ElementTree newTree;
27     SafeFileTable fileTable;
28     String JavaDoc pluginId;
29     Workspace workspace;
30
31     SavedState(Workspace workspace, String JavaDoc pluginId, ElementTree oldTree, ElementTree newTree) throws CoreException {
32         this.workspace = workspace;
33         this.pluginId = pluginId;
34         this.newTree = newTree;
35         this.oldTree = oldTree;
36         this.fileTable = restoreFileTable();
37     }
38
39     void forgetTrees() {
40         newTree = null;
41         oldTree = null;
42         workspace.saveManager.clearDeltaExpiration(pluginId);
43     }
44
45     public int getSaveNumber() {
46         return workspace.getSaveManager().getSaveNumber(pluginId);
47     }
48
49     protected SafeFileTable getFileTable() {
50         return fileTable;
51     }
52
53     protected SafeFileTable restoreFileTable() throws CoreException {
54         if (fileTable == null)
55             fileTable = new SafeFileTable(pluginId);
56         return fileTable;
57     }
58
59     public IPath lookup(IPath file) {
60         return getFileTable().lookup(file);
61     }
62
63     public IPath[] getFiles() {
64         return getFileTable().getFiles();
65     }
66
67     public void processResourceChangeEvents(IResourceChangeListener listener) {
68         try {
69             final ISchedulingRule rule = workspace.getRoot();
70             try {
71                 workspace.prepareOperation(rule, null);
72                 if (oldTree == null || newTree == null)
73                     return;
74                 workspace.beginOperation(true);
75                 ResourceDelta delta = ResourceDeltaFactory.computeDelta(workspace, oldTree, newTree, Path.ROOT, -1);
76                 forgetTrees(); // free trees to prevent memory leak
77
workspace.getNotificationManager().broadcastChanges(listener, IResourceChangeEvent.POST_BUILD, delta);
78             } finally {
79                 workspace.endOperation(rule, false, null);
80             }
81         } catch (CoreException e) {
82             // this is unlikely to happen, so, just log it
83
Policy.log(e);
84         }
85     }
86 }
87
Popular Tags