All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.cedarsoft.utils.springrcp.beanlist.AbstractBeanDialog Maven / Gradle / Ivy

package com.cedarsoft.utils.springrcp.beanlist;

import com.cedarsoft.utils.springrcp.form.FormManager;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.richclient.application.ApplicationServicesLocator;
import org.springframework.richclient.dialog.CloseAction;
import org.springframework.richclient.dialog.FormBackedDialogPage;
import org.springframework.richclient.dialog.TitledPageApplicationDialog;
import org.springframework.richclient.form.Form;

/**
 * This is a basic implementation of BeanDialog.
 * 

* Date: 21.08.2006
* Time: 15:45:22
* * @author Johannes Schneider - * Xore Systems */ public abstract class AbstractBeanDialog extends TitledPageApplicationDialog implements BeanDialog { @NotNull @NonNls public static final String DIALOG_SUFFIX = ".dialog"; protected T bean; protected Form form; protected boolean isNew; protected AbstractBeanDialog() { setCloseAction( CloseAction.DISPOSE ); } public boolean isNew() { return isNew; } public void setIsNew( boolean isNew ) { this.isNew = isNew; } @NotNull public T getBean() { if ( bean == null ) { throw new IllegalStateException( "No bean has been set" ); } return bean; } public void setBean( @NotNull T bean ) { this.bean = bean; form = createForm(); setDialogPage( new FormBackedDialogPage( form ) ); MessageSourceAccessor messageSourceAccessor = ( MessageSourceAccessor ) ApplicationServicesLocator.services().getService( MessageSourceAccessor.class ); setTitle( messageSourceAccessor.getMessage( form.getClass().getName() + DIALOG_SUFFIX ) ); } @Override protected final boolean onFinish() { form.commit(); if ( isNew ) { beanAdded(); } saveBean(); activateBean(); return true; } /** * Add the new bean ({@link #saveBean()} will be called later. */ protected abstract void beanAdded(); /** * Save the bean. {@link #beanAdded()} has been called before (if it is a new bean) */ protected abstract void saveBean(); /** * Create a new form for the given form model * * @return the created form */ protected Form createForm() { return FormManager.getInstance().createForm( bean ); } /** * This method is called when the dialog is closed. The implementation may select * the active bean within the component this dialog has been opened from (e.g. the table) */ protected abstract void activateBean(); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy