org.electrocodeogram.cpc.core.api.hub.event
Class EclipseFileChangeEvent

java.lang.Object
  extended by org.electrocodeogram.cpc.core.api.hub.event.CPCEvent
      extended by org.electrocodeogram.cpc.core.api.hub.event.EclipseEvent
          extended by org.electrocodeogram.cpc.core.api.hub.event.EclipseFileChangeEvent
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<CPCEvent>

public class EclipseFileChangeEvent
extends EclipseEvent

This event is generated whenever a file is moved or removed.
Package/folder renames/moves and project renames will also generate corresponding events of this type for all contained files.
This event is only generated for files which are of interest to CPC (see: CoreConfigurationUtils.isSupportedFile(String)).

Due to performance considerations this event will not be generated for files which are only modified. If you require knowledge about simple file content modifications, you should register your own IResourceChangeListener directly with Eclipse.

Generated by CPCResourceChangeListener and by the IEventHubListener which consumes EclipseFileChangeEvents and updates the IStoreProvider.
See also: setPostStoreProviderMoveUpdate(boolean).

Author:
vw

Nested Class Summary
static class EclipseFileChangeEvent.Type
          The type of the EclipseFileChangeEvent.
 
Field Summary
protected  java.lang.String newFilePath
           
protected  java.lang.String newProject
           
protected  boolean postStoreProviderMoveUpdate
           
protected  EclipseFileChangeEvent.Type type
           
 
Fields inherited from class org.electrocodeogram.cpc.core.api.hub.event.EclipseEvent
fileLocatedInWorkspace, fileLocatedInWorkspaceCached, filePath, project, supportedFile, supportedFileCached, user
 
Constructor Summary
EclipseFileChangeEvent(java.lang.String user, java.lang.String project)
          Creates a new EclipseFileChangeEvent for the given user and project.
 
Method Summary
 java.lang.Object clone()
          Clones this EclipseFileChangeEvent instance.
 java.lang.String getNewFilePath()
          Retrieves the new relative path of this file after a move.
 java.lang.String getNewProject()
          Retrieves the new project name for this file after a move.
 EclipseFileChangeEvent.Type getType()
          Retrieves the type of this event.
 boolean isPostStoreProviderMoveUpdate()
          True if this event was generated after the IStoreProvider has been updated to reflect the new location of the file corresponding to this event.
 boolean isValid()
          Checks if this event has been fully initialised.
 void setNewFilePath(java.lang.String newFilePath)
          Sets the new relative path of this file after a move.
 void setNewProject(java.lang.String newProject)
          Sets the new project name for this file after a move.
 void setPostStoreProviderMoveUpdate(boolean postStoreProviderUpdate)
          To be used only by the code which updates the IStoreProvider to reflect a file move.
 void setType(EclipseFileChangeEvent.Type type)
          Sets the type of this event.
 java.lang.String toString()
          Every event should implement a sensible toString method for use in debugging log messages.
 
Methods inherited from class org.electrocodeogram.cpc.core.api.hub.event.EclipseEvent
getFilePath, getProject, getUser, isFileLocatedInWorkspace, isSupportedFile, setFilePath, subToString
 
Methods inherited from class org.electrocodeogram.cpc.core.api.hub.event.CPCEvent
checkSeal, compareTo, getCreationTime, seal
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

protected EclipseFileChangeEvent.Type type

newProject

protected java.lang.String newProject

newFilePath

protected java.lang.String newFilePath

postStoreProviderMoveUpdate

protected boolean postStoreProviderMoveUpdate
Constructor Detail

EclipseFileChangeEvent

public EclipseFileChangeEvent(java.lang.String user,
                              java.lang.String project)
Creates a new EclipseFileChangeEvent for the given user and project.

Parameters:
user - the current user, never null.
project - the project for the file affected by this event, never null.
Method Detail

getType

public EclipseFileChangeEvent.Type getType()
Retrieves the type of this event.

Returns:
the type of this event, never null.

setType

public void setType(EclipseFileChangeEvent.Type type)
Sets the type of this event.

Parameters:
type - the type of this event, never null.

getNewProject

public java.lang.String getNewProject()
Retrieves the new project name for this file after a move.

Returns:
new project name after move, NULL if type is not EclipseFileChangeEvent.Type.MOVED, never null otherwise.

setNewProject

public void setNewProject(java.lang.String newProject)
Sets the new project name for this file after a move.
Must not be set if the type of this event is not EclipseFileChangeEvent.Type.MOVED. Required and non-null otherwise.

Parameters:
newProject - new project name after move, may be NULL.

getNewFilePath

public java.lang.String getNewFilePath()
Retrieves the new relative path of this file after a move.
The path is relative to the project returned by getNewProject().

Returns:
new project relative path after move, NULL if type is not EclipseFileChangeEvent.Type.MOVED, never null otherwise.

setNewFilePath

public void setNewFilePath(java.lang.String newFilePath)
Sets the new relative path of this file after a move.
Must not be set if the type of this event is not EclipseFileChangeEvent.Type.MOVED. Required and non-null otherwise.

Parameters:
newFilePath - new project relative path after move, may be null.

isPostStoreProviderMoveUpdate

public boolean isPostStoreProviderMoveUpdate()
True if this event was generated after the IStoreProvider has been updated to reflect the new location of the file corresponding to this event.
By default this value is false.

NOTE: The CPC Sensor will not generate events with this value set to true.
It is up to the code which processes EclipseFileChangeEvents and updates the IStoreProvider to create a new event with this value being set to true.

Returns:
true if IStoreProvider was already updated or false if this can not be guaranteed. false is also returned for all other event types besides EclipseFileChangeEvent.Type.MOVED.

setPostStoreProviderMoveUpdate

public void setPostStoreProviderMoveUpdate(boolean postStoreProviderUpdate)
To be used only by the code which updates the IStoreProvider to reflect a file move. Typically an IEventHubListener which consumes EclipseFileChangeEvents.

The code which sets this value to true must be able to guarantee that the new event will never be dispatched before the original EclipseFileChangeEvent with the value false was dispatched.

NOTE: The new EclipseFileChangeEvent should be generated by calling clone() and not by manually copying over all fields.

See Also:
isPostStoreProviderMoveUpdate(), clone()

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clones this EclipseFileChangeEvent instance.

Overrides:
clone in class CPCEvent
Throws:
java.lang.CloneNotSupportedException - never thrown
See Also:
setPostStoreProviderMoveUpdate(boolean)

isValid

public boolean isValid()
Description copied from class: CPCEvent
Checks if this event has been fully initialised.
Will return false if one of the mandatory fields of the event has not yet been filled out.

Subclasses should override this method but should never return true. Instead they should delegate to the super class implementation once all validity checks on their level have passed.

The CPCEvent.isValid() implementation always returns true.

Overrides:
isValid in class EclipseEvent
Returns:
true if this event is valid, false otherwise.
See Also:
IEventHubRegistry.dispatch(CPCEvent)

toString

public java.lang.String toString()
Description copied from class: CPCEvent
Every event should implement a sensible toString method for use in debugging log messages.

Specified by:
toString in class CPCEvent
Returns:
debug string representation, never null.