KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > localstore > CollectSyncStatusVisitor


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.localstore;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15 import org.eclipse.core.internal.resources.*;
16 import org.eclipse.core.internal.utils.Messages;
17 import org.eclipse.core.resources.IResourceStatus;
18 import org.eclipse.core.resources.ResourcesPlugin;
19 import org.eclipse.core.runtime.*;
20 import org.eclipse.osgi.util.NLS;
21
22 //
23
/**
24  * Visits a unified tree, and collects local sync information in
25  * a multi-status. At the end of the visit, the resource tree will NOT
26  * be synchronized with the file system, but all discrepancies between
27  * the two will be recorded in the returned status.
28  */

29 public class CollectSyncStatusVisitor extends RefreshLocalVisitor {
30     protected List JavaDoc affectedResources;
31     /**
32      * Determines how to treat cases where the resource is missing from
33      * the local file system. When performing a deletion with force=false,
34      * we don't care about files that are out of sync because they do not
35      * exist in the file system.
36      */

37     private boolean ignoreLocalDeletions = false;
38     protected MultiStatus status;
39
40     /**
41      * Creates a new visitor, whose sync status will have the given title.
42      */

43     public CollectSyncStatusVisitor(String JavaDoc multiStatusTitle, IProgressMonitor monitor) {
44         super(monitor);
45         status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IStatus.INFO, multiStatusTitle, null);
46     }
47
48     protected void changed(Resource target) {
49         String JavaDoc message = NLS.bind(Messages.localstore_resourceIsOutOfSync, target.getFullPath());
50         status.add(new ResourceStatus(IResourceStatus.OUT_OF_SYNC_LOCAL, target.getFullPath(), message));
51         if (affectedResources == null)
52             affectedResources = new ArrayList JavaDoc(20);
53         affectedResources.add(target);
54         resourceChanged = true;
55     }
56
57     protected void createResource(UnifiedTreeNode node, Resource target) {
58         changed(target);
59     }
60
61     protected void deleteResource(UnifiedTreeNode node, Resource target) {
62         if (!ignoreLocalDeletions)
63             changed(target);
64     }
65
66     protected void fileToFolder(UnifiedTreeNode node, Resource target) {
67         changed(target);
68     }
69
70     protected void folderToFile(UnifiedTreeNode node, Resource target) {
71         changed(target);
72     }
73
74     /**
75      * Returns the list of resources that were not synchronized with
76      * the local file system, or <code>null</code> if all resources
77      * are synchronized.
78      */

79     public List JavaDoc getAffectedResources() {
80         return affectedResources;
81     }
82
83     /**
84      * Returns the sync status that has been collected as a result of this visit.
85      */

86     public MultiStatus getSyncStatus() {
87         return status;
88     }
89
90     protected void makeLocal(UnifiedTreeNode node, Resource target) {
91         changed(target);
92     }
93
94     protected void refresh(Container parent) {
95         changed(parent);
96     }
97
98     protected void resourceChanged(UnifiedTreeNode node, Resource target) {
99         changed(target);
100     }
101
102     /**
103      * Instructs this visitor to ignore changes due to local deletions
104      * in the file system.
105      */

106     public void setIgnoreLocalDeletions(boolean value) {
107         this.ignoreLocalDeletions = value;
108     }
109 }
110
Popular Tags