use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.
the class LockedPeriodGrid method getUnsavedItems.
@Override
public List<LockedPeriodDTO> getUnsavedItems() {
List<LockedPeriodDTO> unsavedItems = new ArrayList<LockedPeriodDTO>();
List<Record> modifiedRecords = lockedPeriodStore.getModifiedRecords();
for (Record record : modifiedRecords) {
unsavedItems.add((LockedPeriodDTO) record.getModel());
}
return unsavedItems;
}
use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.
the class LockedPeriodGrid method createGrid.
private void createGrid() {
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig columnEnabled = new EditCheckColumnConfig("enabled", I18N.CONSTANTS.enabledColumn(), 55);
columnEnabled.setSortable(false);
ColumnConfig columnPeriodType = new ReadLockedPeriodTypeColumn();
columnPeriodType.setSortable(false);
configs.add(columnEnabled);
configs.add(columnPeriodType);
configs.add(new ReadTextColumn("parentName", I18N.CONSTANTS.parentName(), 150));
configs.add(new ReadTextColumn("name", I18N.CONSTANTS.name(), 100));
configs.add(new EditableLocalDateColumn("fromDate", I18N.CONSTANTS.fromDate(), 100));
configs.add(new EditableLocalDateColumn("toDate", I18N.CONSTANTS.toDate(), 100));
lockedPeriodGrid = new EditorGrid<LockedPeriodDTO>(lockedPeriodStore, new ColumnModel(configs));
lockedPeriodGrid.addListener(Events.OnClick, new Listener<ComponentEvent>() {
@Override
public void handleEvent(ComponentEvent be) {
lockedPeriod = lockedPeriodGrid.getSelectionModel().getSelectedItem();
setDeleteEnabled(lockedPeriodGrid.getSelectionModel().getSelectedItem() != null);
}
});
add(lockedPeriodGrid);
}
use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.
the class LockedPeriodsPresenter method onConfirmDelete.
@Override
public void onConfirmDelete(ConfirmDeleteEvent deleteEvent) {
final LockedPeriodDTO lockedPeriod = view.getValue();
service.execute(new Delete(lockedPeriod), new AsyncCallback<VoidResult>() {
@Override
public void onFailure(Throwable caught) {
MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.errorOnServer() + "\n\n" + caught.getMessage(), null);
}
@Override
public void onSuccess(VoidResult result) {
view.delete(lockedPeriod);
parentModel.getLockedPeriods().remove(lockedPeriod);
}
});
}
use of org.activityinfo.shared.dto.LockedPeriodDTO in project activityinfo by bedatadriven.
the class CreateLockedPeriodHandler method execute.
@Override
public CommandResult execute(CreateLockedPeriod cmd, User user) throws CommandException {
Activity activity = null;
UserDatabase database = null;
Project project = null;
LockedPeriod lockedPeriod = new LockedPeriod();
LockedPeriodDTO lockedPeriodDTO = cmd.getLockedPeriod();
lockedPeriod.setFromDate(lockedPeriodDTO.getFromDate().atMidnightInMyTimezone());
lockedPeriod.setToDate(lockedPeriodDTO.getToDate().atMidnightInMyTimezone());
lockedPeriod.setName(lockedPeriodDTO.getName());
lockedPeriod.setEnabled(lockedPeriodDTO.isEnabled());
int databaseId;
if (cmd.getUserDatabseId() != 0) {
database = em.find(UserDatabase.class, cmd.getUserDatabseId());
lockedPeriod.setUserDatabase(database);
databaseId = database.getId();
} else if (cmd.getProjectId() != 0) {
project = em.find(Project.class, cmd.getProjectId());
lockedPeriod.setProject(project);
databaseId = project.getUserDatabase().getId();
} else if (cmd.getActivityId() != 0) {
activity = em.find(Activity.class, cmd.getActivityId());
lockedPeriod.setActivity(activity);
databaseId = activity.getDatabase().getId();
} else {
throw new CommandException("One of the following must be provdied: userDatabaseId, projectId, activityId");
}
UserDatabase db = em.find(UserDatabase.class, databaseId);
em.persist(lockedPeriod);
db.setLastSchemaUpdate(new Date());
em.persist(db);
if (database != null) {
database.getLockedPeriods().add(lockedPeriod);
}
if (project != null) {
project.getLockedPeriods().add(lockedPeriod);
}
if (activity != null) {
activity.getLockedPeriods().add(lockedPeriod);
}
return new CreateResult(lockedPeriod.getId());
}
Aggregations