fr.ird.observe.client.form.FormUIModel Maven / Gradle / Ivy
/*
* #%L
* ObServe Toolkit :: Common Client
* %%
* Copyright (C) 2008 - 2017 IRD, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
package fr.ird.observe.client.form;
import fr.ird.observe.client.form.spi.FormUIContext;
import fr.ird.observe.client.tree.navigation.nodes.NavigationTreeNodeSupport;
import javax.swing.Icon;
import org.jdesktop.beans.AbstractBean;
/**
* Le modèle d'un écran d'édition
*
* @author Tony Chemit - [email protected]
* @since 1.4
*/
public abstract class FormUIModel extends AbstractBean {
private static final String PROPERTY_MODE = "mode";
public static final String PROPERTY_MODIFIED = "modified";
public static final String PROPERTY_EDITING = "editing";
public static final String PROPERTY_EDITABLE = "editable";
private static final String PROPERTY_READING_MODE = "readingMode";
private static final String PROPERTY_CREATING_MODE = "creatingMode";
private static final String PROPERTY_UPDATING_MODE = "updatingMode";
private static final String PROPERTY_ENABLED = "enabled";
private static final String PROPERTY_VALID = "valid";
private static final String PROPERTY_CAN_WRITE = "canWrite";
private static final String PROPERTY_TITLE = "title";
private static final String PROPERTY_CONTENT_ICON = "contentIcon";
private static final String PROPERTY_SELECTED_NODE = "selectedNode";
protected FormUIMode mode = FormUIMode.READ;
protected boolean enabled;
protected boolean editing;
protected boolean valid;
protected boolean modified;
protected boolean editable;
private boolean canWrite;
private Icon contentIcon;
private String title;
protected FormUIContext formUIContext;
protected final String prefix;
private NavigationTreeNodeSupport selectedNode;
protected FormUIModel() {
prefix = computePrefix();
}
protected abstract String computePrefix();
public FormUIMode getMode() {
return mode;
}
public void setMode(FormUIMode mode) {
this.mode = mode;
firePropertyChange(PROPERTY_MODE, mode);
firePropertyChange(PROPERTY_READING_MODE, isReadingMode());
firePropertyChange(PROPERTY_CREATING_MODE, isCreatingMode());
firePropertyChange(PROPERTY_UPDATING_MODE, isUpdatingMode());
}
/**
* @return {@code true} si l'écran est en mode creation
* @see FormUIMode#CREATE
*/
public boolean isCreatingMode() {
return FormUIMode.CREATE.equals(getMode());
}
/**
* @return {@code true} si l'écran est en mode mise a jour
* @see FormUIMode#UPDATE
*/
public boolean isUpdatingMode() {
return FormUIMode.UPDATE.equals(getMode());
}
/**
* @return {@code true} si l'écran est en mode lecture
* @see FormUIMode#READ
*/
public boolean isReadingMode() {
return FormUIMode.READ.equals(getMode());
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
Object oldValue = this.enabled;
this.enabled = enabled;
firePropertyChange(PROPERTY_ENABLED, oldValue, enabled);
}
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
Object oldValue = this.editable;
this.editable = editable;
firePropertyChange(PROPERTY_EDITABLE, oldValue, editable);
}
public boolean isEditing() {
return editing;
}
public void setEditing(boolean editing) {
Object oldValue = this.editing;
this.editing = editing;
firePropertyChange(PROPERTY_EDITING, oldValue, editing);
}
public boolean isValid() {
return valid;
}
public void setValid(boolean valid) {
Object oldValue = this.valid;
this.valid = valid;
firePropertyChange(PROPERTY_VALID, oldValue, valid);
}
public boolean isModified() {
return modified;
}
public void setModified(boolean modified) {
Object oldValue = this.modified;
this.modified = modified;
firePropertyChange(PROPERTY_MODIFIED, oldValue, modified);
}
public boolean isCanWrite() {
return canWrite;
}
public void setCanWrite(boolean canWrite) {
boolean oldValue = isCanWrite();
this.canWrite = canWrite;
firePropertyChange(PROPERTY_CAN_WRITE, oldValue, canWrite);
}
protected void firePropertyChange(String propertyName, Object newValue) {
firePropertyChange(propertyName, null, newValue);
}
public void destroy() {
}
public void setContentIcon(Icon contentIcon) {
this.contentIcon = contentIcon;
firePropertyChange(PROPERTY_CONTENT_ICON, contentIcon);
}
Icon getContentIcon() {
return contentIcon;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
firePropertyChange(PROPERTY_TITLE, title);
}
public void setFormUIContext(FormUIContext formUIContext) {
this.formUIContext = formUIContext;
}
public FormUIContext getFormUIContext() {
return formUIContext;
}
public String getPrefix() {
return prefix;
}
public boolean isReferential() {
return false;
}
public NavigationTreeNodeSupport getSelectedNode() {
return selectedNode;
}
public void setSelectedNode(NavigationTreeNodeSupport selectedNode) {
NavigationTreeNodeSupport oldValue = getSelectedNode();
this.selectedNode = selectedNode;
firePropertyChange(PROPERTY_SELECTED_NODE, oldValue, selectedNode);
Icon contentIcon = selectedNode==null?null:selectedNode.getIcon("");
setContentIcon(contentIcon);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy