📄 reservationcontrollerimpl.java
字号:
c.updateReservation(updatedReservation);
}
else
{
c.closeWindow();
}
} else if (evt.isRemoved(c.getReservation())) {
c.deleteReservation();
}
}
}
private void setRestrictions(
Appointment appointment
,Allocatable[] restrictedAllocatables
,Reservation reservation
)
{
for (int i=0;i<restrictedAllocatables.length;i++)
{
Allocatable allocatable = restrictedAllocatables[i];
Appointment[] restriction = reservation.getRestriction(allocatable);
HashSet newRestriction = new HashSet(Arrays.asList(restriction));
newRestriction.add( appointment );
reservation.setRestriction(allocatable,
(Appointment[]) newRestriction.toArray( Appointment.EMPTY_ARRAY)
);
}
}
public void pasteAppointment(
Appointment appointment
,Reservation reservation
,Date start
,Component sourceComponent
,Point point
,Allocatable[] restrictedAllocatables
,boolean asNewReservation
)
throws RaplaException
{
Appointment copy = copyAppointment(appointment);
copy.move(start);
Reservation mutableReservation;
if ( asNewReservation)
{
mutableReservation = (Reservation) getModification().clone( reservation );
Appointment[] appointments = mutableReservation.getAppointments();
for ( int i=0;i<appointments.length;i++)
{
Appointment app = appointments[i];
mutableReservation.removeAppointment( app );
}
}
else
{
mutableReservation = (Reservation) getModification().edit( reservation );
}
mutableReservation.addAppointment(copy);
setRestrictions(copy, restrictedAllocatables, mutableReservation);
getLogger().info("Paste appointment '" + appointment
+ "' for reservation '" + mutableReservation
+ "' at " + start);
save(mutableReservation, sourceComponent);
}
public void moveAppointment(Appointment appointment,Date from,Date newStart,Component sourceComponent,Point p) throws RaplaException {
if ( newStart.equals(from))
return;
getLogger().info("Moving appointment " + appointment + " from " + from + " to " + newStart);
resizeAppointment( appointment, from, newStart, null, sourceComponent, p);
}
public void resizeAppointment(Appointment appointment, Date from, Date newStart, Date newEnd, Component sourceComponent, Point p) throws RaplaException {
boolean resizing = newEnd != null;
long start = appointment.getStart().getTime();
//boolean resizeFirstDay = !resizing || DateTools.isSameDay( start, newStart.getTime() );
Reservation reservation = appointment.getReservation();
Appointment copy = null;
boolean moveSerie = true;
if (appointment.getRepeating() != null) {
String dateString = getRaplaLocale().formatDate(from);
DialogUI dialog = DialogUI.create(
getContext()
,sourceComponent
,true
,getString("move")
,getI18n().format("move_appointment.format"
,dateString)
,new String[] {getString("serie")
,getString("single_appointment")
,getString("cancel")
}
);
dialog.setIcon(getIcon("icon.question"));
dialog.getButton(0).setIcon(getIcon("icon.repeating"));
dialog.getButton(2).setIcon(getIcon("icon.cancel"));
dialog.setDefault(0);
dialog.start(p);
int index = dialog.getSelectedIndex();
if (index == 2 || index == -1)
return;
if (index == 1) {
moveSerie = false;
copy = copyAppointment(appointment);
copy.setRepeatingEnabled(false);
if ( resizing ) {
copy.move(newStart, newEnd);
} else {
copy.move(newStart);
}
}
}
Reservation mutableReservation = (Reservation)getModification().edit(reservation);
Appointment app = mutableReservation.findAppointment(appointment);
if ( app == null) {
getLogger().warn("Can't find the appointment!");
return;
}
// Move the complete serie
if ( moveSerie ) {
// we adjust the start end end-time of the first appointment relative to the next from time
if ( resizing ) {
newStart = new Date( (start - from.getTime()) + newStart.getTime());
newEnd = new Date(( start - from.getTime()) + newEnd.getTime());
app.move(newStart, newEnd);
} else {
newStart = new Date( (start - from.getTime()) + newStart.getTime());
app.move(newStart);
}
} else {
mutableReservation.addAppointment(copy);
setRestrictions(copy
,mutableReservation.getRestrictedAllocatables(app)
,mutableReservation);
app.getRepeating().addException( from );
}
save(mutableReservation,sourceComponent);
}
public boolean save(Reservation reservation,Component sourceComponent,boolean showOnlyWhenConflicts) throws RaplaException {
SaveCommand saveCommand =new SaveCommand(reservation);
save(reservation,sourceComponent,saveCommand,showOnlyWhenConflicts);
return saveCommand.hasSaved();
}
boolean save(Reservation reservation,Component sourceComponent) throws RaplaException {
return save(reservation,sourceComponent,true);
}
void save(Reservation reservation
,Component sourceComponent
,Command saveCommand
,boolean showOnlyWhenConflicts) throws RaplaException {
Conflict[] conflicts = getQuery().getConflicts(reservation);
getModification().checkReservation(reservation);
// Only show when conflicts are found ?
if (conflicts.length == 0 && showOnlyWhenConflicts) {
try {
saveCommand.execute();
} catch (Exception ex) {
showException(ex,sourceComponent);
}
return;
}
Appointment[] appointments = reservation.getAppointments();
Appointment duplicatedAppointment = null;
for (int i=0;i<appointments.length;i++) {
for (int j=i + 1;j<appointments.length;j++)
if (appointments[i].matches(appointments[j])) {
duplicatedAppointment = appointments[i];
break;
}
}
JComponent infoComponent = getInfoFactory().createInfoComponent(reservation);
JPanel content = new JPanel();
content.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(),getString("confirm.dialog.question")));
content.setLayout(new TableLayout(new double[][] {
{TableLayout.FILL}
,{TableLayout.PREFERRED,TableLayout.PREFERRED,TableLayout.PREFERRED,2,TableLayout.FILL}
}));
if (duplicatedAppointment != null) {
JLabel warningLabel = new JLabel();
warningLabel.setForeground(java.awt.Color.red);
warningLabel.setText
(getI18n().format
(
"warning.duplicated_appointments"
,getAppointmentFormater().getShortSummary(duplicatedAppointment)
)
);
content.add(warningLabel,"0,0");
}
if (conflicts.length > 0) {
JLabel warningLabel = new JLabel();
warningLabel.setText(getString("warning.conflict"));
warningLabel.setForeground(java.awt.Color.red);
content.add(warningLabel,"0,1");
content.add(getConflictPanel(conflicts),"0,2");
}
content.add(infoComponent,"0,4");
DialogUI dialog = DialogUI.create(
getContext()
,sourceComponent
,true
,content
,new String[] {
getString("save")
,getString("back")
}
);
if (conflicts.length > 0)
dialog.setDefault(1);
dialog.getButton(0).setIcon(getIcon("icon.save"));
dialog.getButton(1).setIcon(getIcon("icon.cancel"));
dialog.setTitle(getI18n().format("confirm.dialog.title",getName(reservation)));
dialog.start();
if (dialog.getSelectedIndex() == 0) {
try {
saveCommand.execute();
} catch (Exception ex) {
showException(ex,sourceComponent);
return;
}
}
}
class SaveCommand implements Command {
Reservation reservation;
boolean saved;
public SaveCommand(Reservation reservation) {
this.reservation = reservation;
}
public void execute() throws RaplaException {
getModification().store( reservation );
saved = true;
}
public boolean hasSaved() {
return saved;
}
}
private JComponent getConflictPanel(Conflict[] conflicts) throws RaplaException {
ConflictInfoOldUI panel = new ConflictInfoOldUI();
ConflictTableModel model = new ConflictTableModel(getContext(),conflicts);
panel.getTable().setModel(model);
TableColumn column = panel.getTable().getColumn(getString("conflict.appointment2"));
panel.getTable().removeColumn(column);
column = panel.getTable().getColumn(getString("conflict.reservation1"));
panel.getTable().removeColumn(column);
return panel.getComponent();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -