@Override
@SuppressWarnings("deprecation")
public void onNewActivity()
{
// 1. Activity
Activity activity = null;
if (enteredActivity != null)
{
activity = new Activity(enteredActivity);
}
else if (selectedActivity != null)
{
activity = selectedActivity;
}
else
{
ShowMessageEvent.fire(this, new Message(SEVERE, "Please specify a name for the activity", true));
return;
}
// 2. Project
Project project = null;
if (enteredProject != null)
{
project = new Project(enteredProject);
}
else if (selectedProject != null)
{
project = selectedProject;
}
activity.setProject(project);
// 3. Duration
if (enteredDuration == null || enteredDuration.isZero())
{
// Start the new activity
ActivityActionEvent.fire(this, START_STOP, activity);
}
else
{
// Just store the new activity
if (!activity.isTransient())
{
activity = activity.copy();
activity.setProject(project);
}
// selectedDate must not be changed!
Date now = new Date();
Date start = selectedDate;
if (start == null)
{
start = now;
}
else
{
start.setHours(now.getHours());
start.setMinutes(now.getMinutes());
start.setSeconds(now.getSeconds());
}
// This is the only valid use case to call
// Activity.setMinutes(long) directly. On the server side it is
// recognized that the activity is stopped and that there's a
// init time, a value for minutes but no end time. In this case
// the end time is calculated on the server
activity.setStart(new Time(start));
activity.setEnd(null);
activity.setDuration(enteredDuration);
ActivityActionEvent.fire(this, SAVE, activity);
}
getView().clear();
reset();
}