KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > events > ResourceChangeEvent


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.events;
12
13 import java.util.*;
14 import org.eclipse.core.internal.resources.*;
15 import org.eclipse.core.resources.*;
16
17 public class ResourceChangeEvent extends EventObject implements IResourceChangeEvent {
18
19     private static final IMarkerDelta[] NO_MARKER_DELTAS = new IMarkerDelta[0];
20     private static final long serialVersionUID = 1L;
21     IResourceDelta delta;
22     IResource resource;
23
24     /**
25      * The build trigger for this event, or 0 if not applicable.
26      */

27     private int trigger = 0;
28     int type;
29
30     protected ResourceChangeEvent(Object JavaDoc source, int type, IResource resource) {
31         super(source);
32         this.resource = resource;
33         this.type = type;
34     }
35
36     public ResourceChangeEvent(Object JavaDoc source, int type, int buildKind, IResourceDelta delta) {
37         super(source);
38         this.delta = delta;
39         this.trigger = buildKind;
40         this.type = type;
41     }
42
43     /**
44      * @see IResourceChangeEvent#findMarkerDeltas(String, boolean)
45      */

46     public IMarkerDelta[] findMarkerDeltas(String JavaDoc findType, boolean includeSubtypes) {
47         if (delta == null)
48             return NO_MARKER_DELTAS;
49         ResourceDeltaInfo info = ((ResourceDelta) delta).getDeltaInfo();
50         if (info == null)
51             return NO_MARKER_DELTAS;
52         //Map of IPath -> MarkerSet containing MarkerDelta objects
53
Map markerDeltas = info.getMarkerDeltas();
54         if (markerDeltas == null || markerDeltas.size() == 0)
55             return NO_MARKER_DELTAS;
56         ArrayList matching = new ArrayList();
57         Iterator deltaSets = markerDeltas.values().iterator();
58         while (deltaSets.hasNext()) {
59             MarkerSet deltas = (MarkerSet) deltaSets.next();
60             IMarkerSetElement[] elements = deltas.elements();
61             for (int i = 0; i < elements.length; i++) {
62                 MarkerDelta markerDelta = (MarkerDelta) elements[i];
63                 //our inclusion test depends on whether we are considering subtypes
64
if (findType == null || (includeSubtypes ? markerDelta.isSubtypeOf(findType) : markerDelta.getType().equals(findType)))
65                     matching.add(markerDelta);
66             }
67         }
68         return (IMarkerDelta[]) matching.toArray(new IMarkerDelta[matching.size()]);
69     }
70
71     /**
72      * @see IResourceChangeEvent#getBuildKind()
73      */

74     public int getBuildKind() {
75         return trigger;
76     }
77
78     /**
79      * @see IResourceChangeEvent#getDelta()
80      */

81     public IResourceDelta getDelta() {
82         return delta;
83     }
84
85     /**
86      * @see IResourceChangeEvent#getResource()
87      */

88     public IResource getResource() {
89         return resource;
90     }
91
92     /**
93      * @see IResourceChangeEvent#getType()
94      */

95     public int getType() {
96         return type;
97     }
98
99     public void setDelta(IResourceDelta value) {
100         delta = value;
101     }
102 }
103
Popular Tags