KickJava   Java API By Example, From Geeks To Geeks.

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


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.internal.utils.Messages;
14 import org.eclipse.core.internal.utils.Policy;
15 import org.eclipse.core.resources.ISaveContext;
16 import org.eclipse.core.resources.ResourcesPlugin;
17 import org.eclipse.core.runtime.*;
18 import org.eclipse.core.runtime.jobs.Job;
19
20 /**
21  * Performs periodic saving (snapshot) of the workspace.
22  */

23 public class DelayedSnapshotJob extends Job {
24
25     private static final String JavaDoc MSG_SNAPSHOT = Messages.resources_snapshot;
26     private SaveManager saveManager;
27
28     public DelayedSnapshotJob(SaveManager manager) {
29         super(MSG_SNAPSHOT);
30         this.saveManager = manager;
31         setRule(ResourcesPlugin.getWorkspace().getRoot());
32         setSystem(true);
33     }
34
35     /*
36      * @see Job#run()
37      */

38     public IStatus run(IProgressMonitor monitor) {
39         if (monitor.isCanceled())
40             return Status.CANCEL_STATUS;
41         if (ResourcesPlugin.getWorkspace() == null)
42             return Status.OK_STATUS;
43         try {
44             return saveManager.save(ISaveContext.SNAPSHOT, null, Policy.monitorFor(null));
45         } catch (CoreException e) {
46             return e.getStatus();
47         } finally {
48             saveManager.operationCount = 0;
49             saveManager.snapshotRequested = false;
50         }
51     }
52 }
53
Popular Tags