📄 reservationeditimpl.java
字号:
boolean packFrame = false;
frame.place( true, packFrame);
frame.setVisible( true );
// Insert into open ReservationEditWindows, so that
// we can't edit the same Reservation in different windows
getPrivateReservationController().addReservationEdit(this);
// #TODO this should be done in allocatableEdit
//allocatableEdit.content.setDividerLocation(0.5);
//frame.requestFocus();
reservationInfo.requestFocus();
getLogger().debug("New Reservation-Window created");
}
/*
private void printBlocks( Appointment appointment )
{
AppointmentBlockArray array = new AppointmentBlockArray();
{
Calendar cal = getRaplaLocale().createCalendar();
cal.set( Calendar.YEAR, 2004);
Date start = cal.getTime();
cal.set( Calendar.YEAR, 2007);
Date end = cal.getTime();
appointment.createBlocks(start, end, array);
}
for ( int i=0;i< array.size();i++)
{
Date start = new Date(array.getStartAt( i ));
Date end = new Date(array.getEndAt( i ));
SimpleDateFormat format = new SimpleDateFormat();
format.setTimeZone( getRaplaLocale().getTimeZone());
System.out.println( format.format(start) + " - " + format.format(end));
}
}
*/
/* (non-Javadoc)
* @see org.rapla.gui.edit.reservation.IReservationEdit#getReservation()
*/
public Reservation getReservation() {
return mutableReservation;
}
private void setTitle() {
String title = getI18n().format((bNew) ?
"new_reservation.format" : "edit_reservation.format"
,getName(mutableReservation));
frame.setTitle(title);
}
private void setReservation(Reservation newReservation, Appointment appointment) throws RaplaException {
this.mutableReservation = newReservation;
appointmentEdit.setReservation(mutableReservation, appointment);
allocatableEdit.setReservation(mutableReservation);
reservationInfo.setReservation(mutableReservation);
}
public void closeWindow() {
ContainerUtil.dispose(appointmentEdit);
getPrivateReservationController().removeReservationEdit(this);
frame.dispose();
getLogger().debug("Edit window closed.");
}
class Listener extends AbstractAction implements AppointmentListener,ChangeListener,VetoableChangeListener, ReservationInfoEdit.DetailListener {
private static final long serialVersionUID = 1L;
// Implementation of ReservationListener
public void appointmentRemoved(Appointment appointment) {
setSaved(false);
}
public void appointmentAdded(Appointment appointment) {
setSaved(false);
}
public void appointmentChanged(Appointment appointment) {
setSaved(false);
}
public void stateChanged(ChangeEvent evt) {
if (evt.getSource() == reservationInfo) {
getLogger().debug("ReservationInfo changed");
setSaved(false);
setTitle();
}
if (evt.getSource() == allocatableEdit) {
getLogger().debug("AllocatableEdit changed");
setSaved(false);
}
}
public void detailChanged() {
boolean isMain = reservationInfo.isMainView();
if ( isMain != appointmentEdit.getComponent().isVisible() ) {
appointmentEdit.getComponent().setVisible( isMain );
allocatableEdit.getComponent().setVisible( isMain );
if ( isMain ) {
tableLayout.setRow(0, TableLayout.PREFERRED);
tableLayout.setRow(1, TableLayout.PREFERRED);
tableLayout.setRow(2, TableLayout.FILL);
} else {
tableLayout.setRow(0, TableLayout.FILL);
tableLayout.setRow(1, 0);
tableLayout.setRow(2, 0);
}
mainContent.validate();
}
}
public void actionPerformed(ActionEvent evt) {
try {
if (evt.getSource() == saveButton) {
save();
}
if (evt.getSource() == deleteButton) {
delete();
}
if (evt.getSource() == closeButton) {
if (canClose())
closeWindow();
}
} catch (RaplaException ex) {
showException(ex, null);
}
}
public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
if (!canClose())
throw new PropertyVetoException("Don't close",evt);
closeWindow();
}
};
protected boolean canClose() {
if (!isModifiedSinceLastChange())
return true;
try {
DialogUI dlg = DialogUI.create(
getContext()
,mainContent
,true
,getString("confirm-close.title")
,getString("confirm-close.question")
,new String[] {
getString("confirm-close.ok")
,getString("back")
}
);
dlg.setIcon(getIcon("icon.question"));
dlg.setDefault(1);
dlg.start();
return (dlg.getSelectedIndex() == 0) ;
} catch (RaplaException e) {
return true;
}
}
/* (non-Javadoc)
* @see org.rapla.gui.edit.reservation.IReservationEdit#save()
*/
public void save() throws RaplaException {
save( true );
}
public void save(boolean confirm) throws RaplaException {
if (mutableReservation.getAllocatables().length == 0 ) {
DialogUI dialog = DialogUI.create(
getContext()
,frame
,true
,getString("warning")
,getString("warning.no_allocatables_selected")
,new String[] {
getString("continue")
,getString("back")
}
);
dialog.setIcon(getIcon("icon.warning"));
dialog.setDefault(1);
dialog.start();
if (dialog.getSelectedIndex() != 0)
return;
}
getPrivateReservationController().save(mutableReservation,frame,new SaveCommand(), confirm);
}
/* (non-Javadoc)
* @see org.rapla.gui.edit.reservation.IReservationEdit#delete()
*/
public void delete() throws RaplaException {
try {
DialogUI dlg = getInfoFactory().createDeleteDialog(new Object[] {mutableReservation}
,frame);
dlg.start();
if (dlg.getSelectedIndex() == 0) {
bDeleting = true;
getModification().remove( mutableReservation );
closeWindow();
}
} finally {
bDeleting = false;
}
}
class SaveCommand implements Command {
public void execute() {
frame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
getModification().checkReservation(mutableReservation);
bSaving = true;
getModification().store(mutableReservation);
setSaved(true);
} catch (RaplaException ex) {
showException(ex,frame);
} finally {
frame.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
if (bSaved)
closeWindow();
bSaving = false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -