Handling Project Events
Project events allow you to be informed of newly created subprojects and the modification of existing projects, the partners of a project, the phases of a project, or the cubes and access rights for a project. The icc.db.Project and icc.db.Phase classes provide additional functionality to help you in storing and maintaining project and phase information.
1. Creation events
A project CREATION event is posted when a subproject is newly created. The event object is an Integer array that includes the subproject's and parent project's identifiers. The event source is null.
The following example assumes the user is interested in retrieving the project information for each newly created subproject.
public void handleProjectEvent(Event event) {
switch (event.type) {
case Event.CREATION:
Integer id = ((Integer[]) event.object)[0];
// retrieve the project information
this.send(new Package(IDCard.SERVICE,
Project.retrieve(id)));
break;
}
}
Note: It is assumed that the instance method send sends a package through the speaker and catches any IOException that may be thrown.
2. Edit events
A project EDIT event is posted when project information is altered, including project partners, phases and access rights. The event object is either the project identifier, an Access object or array if altering access rights, or a Phase object or array if altering phase information. The event source is always null.
The following example maintains and updates all project related information locally stored in the Project and Phase classes.
public void handleProjectEvent(Event event) {
switch (event.type) {
case Event.EDIT:
if (event.object instanceof Integer) {
Integer id = (Integer) event.object;
// retrieve the altered project information
this.send(new Package(IDCard.SERVICE,
Project.retrieve(id)));
} else if (event.object instanceof Access) {
Access ac = (Access) event.object;
// update the project's access information
Project.alterAccess(ac);
} else if (event.object instanceof Access[]) {
Access[] acs = (Access[]) event.object;
// update the project's access information
for (int i = 0; i < acs.length; i++)
Project.alterAccess(acs[i]);
} else if (event.object instanceof Phase) {
Phase phase = (Phase) event.object;
phase.put();
} else if (event.object instanceof Phase[]) {
Phase[] phases = (Phase[]) event.object;
if (phases.length > 0) {
Integer id = phases[0].project();
// update the project's phases
Project.get(id).phases = phases;
Phase.replace(id, phases);
}
}
break;
}
}
Note: It is assumed that the instance method send sends a package through the speaker and catches any IOException that may be thrown.
Last modified on 12 June 1999 by Rudi Stouffs |