de.invation.code.toval.graphic.dialog.AbstractEditCreateDialog Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of TOVAL Show documentation
Show all versions of TOVAL Show documentation
TOVAL comprises a set of java classes for common programming issues. It includes utils for arrays, lists, sets and collections for convenient handling and modification, but also support for mathematic definitions concerning logic (clauses + resolution) together with some algorithms for permutations, powersets and resolution. Additionally it contains a number of types for multisets, matrices with object keys and much more.
The newest version!
package de.invation.code.toval.graphic.dialog;
import java.awt.Window;
import de.invation.code.toval.validate.Validate;
public abstract class AbstractEditCreateDialog extends AbstractDialog {
private static final long serialVersionUID = 5737860895484822620L;
private boolean editMode;
private DialogObject originalObject;
protected AbstractEditCreateDialog(Window owner, DialogObject originalObject) {
super(owner);
this.editMode = true;
Validate.notNull(originalObject);
this.originalObject = originalObject;
setDialogObject(originalObject.clone());
}
protected AbstractEditCreateDialog(Window owner, String title, DialogObject originalObject) {
this(owner, originalObject);
Validate.notNull(title);
setTitle(title);
}
protected AbstractEditCreateDialog(Window owner, Object... parameters) {
super(owner);
this.editMode = false;
setDialogObject(newDialogObject(parameters));
}
protected AbstractEditCreateDialog(Window owner, String title, Object... parameters) {
super(owner, title);
this.editMode = false;
setDialogObject(newDialogObject(parameters));
}
protected AbstractEditCreateDialog(Window owner, ButtonPanelLayout buttonLayout, Object... parameters) {
super(owner, buttonLayout);
this.editMode = false;
setDialogObject(newDialogObject(parameters));
}
protected boolean editMode() {
return editMode;
}
protected abstract O newDialogObject(Object... parameters);
/**
* Validates field values and sets properties of the dialog object according
* to them.
* Note: Properties of the original object are not changed.
* They are set on basis of the dialog object using the method
* {@link DialogObject#takeoverValues(Object)} afterwards.
*/
protected abstract boolean validateAndSetFieldValues() throws Exception;
@Override
protected void initializeContent() throws Exception {
if (editMode) {
prepareEditing();
}
}
@Override
protected void okProcedure() {
try {
if(!validateAndSetFieldValues())
return;
} catch (Exception e) {
invalidFieldContentException(e);
return;
}
if (editMode) {
try {
originalObject.takeoverValues(getDialogObject());
} catch (Exception e) {
exception("Cannot save changes.", e);
}
}
super.okProcedure();
}
protected abstract void prepareEditing() throws Exception;
@Override
protected void cancelProcedure() {
if (!editMode) {
setDialogObject(null);
}
super.cancelProcedure();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy