Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 15ac306aa4076b543d5b9506e119e9382e19fa70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*******************************************************************************
 * Copyright (c) 2001, 2008 Oracle Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Oracle Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.common.internal.resource;

import java.util.EventObject;

import org.eclipse.core.resources.IResource;

/**
 * @author cbateman
 * 
 */
public class ResourceLifecycleEvent extends EventObject
{
    /**
     * 
     */
    private static final long serialVersionUID = -8692801944833729L;

    /**
     * the type of lifecycle event this enum is not closed and may add new
     * fields in the future
     */
    public enum EventType
    {
        /**
         * Indicates that the resource is no longer accessible (as testable with
         * IResource.isAccessible). The reasonType will indicate why.
         */
        RESOURCE_INACCESSIBLE,

        /**
         * Indicates that the resource being tracked has changed in some way,
         * use ReasonType to determine specifics
         */
        RESOURCE_CHANGED,

        /**
         * Indicates that the resource being tracked hass been added. Use
         * ReasonType to determine specifics.
         */
        RESOURCE_ADDED;
    }

    /**
     * encodes the cause of the event if the event type provides one this enum
     * is not closed and may add new fields in the future
     */
    public enum ReasonType
    {
        /**
         * The resource was deleted from the workspace, this event is pre change
         * if the event is project and post change otherwise
         */
        RESOURCE_DELETED,
        /**
         * The resource was delete from it's container. This fired when the
         * PARENT of the resource being deleted is registered for lifecycle
         * events (i.e. _affectedResource.getParent() == registeredResource)
         */
        RESOURCE_DELETED_FROM_CONTAINER,
        /**
         * The resource's project was deleted. This event is pre-change. Note
         * that if the tracked resource is a project, RESOURCE_DELETED will be
         * fired, not this event.
         */
        RESOURCE_PROJECT_DELETED,
        /**
         * The resource's project was closed. This event is pre-change
         */
        RESOURCE_PROJECT_CLOSED,
        /**
         * Occurs when the contents of a non-project resource has changed
         */
        RESOURCE_CHANGED_CONTENTS,
        /**
         * Occurs when a project resource is added
         */
        PROJECT_OPENED,
        /**
         * Occurs when a non-project resource is added to a container. This is
         * fired if the resource being added was in the list of resources
         * registered for lifecycle events (i.e. _affectedResource ==
         * registeredResource).
         */
        RESOURCE_ADDED,
        /**
         * Occurs when a non-project resource is added to a container. This is
         * fired if the PARENT of the resource being added was in the resources
         * registered for lifecycle events (i.e. _affectedResource.getParent() =
         * registeredResource)
         */
        RESOURCE_ADDED_TO_CONTAINER,
        /**
         * Occurs when a resource has becomes added or inaccessible due to a
         * move operation. This event is fired when the resource being moved is
         * the one of interest.
         */
        RESOURCE_MOVED,
        /**
         * Occurs when a resource has becomes added or inaccessible due to a
         * move operation. This event is fired when the PARENT of resource being
         * moved is the one of interest.
         */
        RESOURCE_MOVED_CONTAINER
    }

    private final IResource _affectedResource;
    private final EventType _eventType;
    private final ReasonType _reasonType;

    /**
     * @param source 
     * @param affectedResource
     * @param eventType
     * @param reasonType
     */
    public ResourceLifecycleEvent(final LifecycleListener source,
            final IResource affectedResource,
            final EventType eventType, final ReasonType reasonType)
    {
        super(source);
        _affectedResource = affectedResource;
        _eventType = eventType;
        _reasonType = reasonType;
    }

    /**
     * @return the affected resource
     */
    public IResource getAffectedResource()
    {
        return _affectedResource;
    }

    /**
     * @return the event that has occurred
     */
    public EventType getEventType()
    {
        return _eventType;
    }

    /**
     * @return the cause of the event
     */
    public ReasonType getReasonType()
    {
        return _reasonType;
    }

    @Override
    public String toString()
    {
        return String.format(
                "ResourceLifecycleEvent: Res = %s, Event=%s, Reason=%s", //$NON-NLS-1$
                getAffectedResource(), getEventType(), getReasonType());
    }
}

Back to the top