Results 1 to 1 of 1

Thread: don't show form

  1. #1
    Join Date
    Feb 2007
    Posts
    2

    Default can't show form

    I'm use new Spring RCP ...

    for show calendar form JCalendar ...
    Code:
    package org.rskita.util;
    
    public class JCalendarBinding extends CustomBinding implements PropertyChangeListener {
    	private JDateChooser dateChooser;
    	private Date theDate;
    	private String dateFormat = "dd/MMM/yyyy";
    	
    	public JCalendarBinding(FormModel formModel, String formPropertyPath){
    		super(formModel, formPropertyPath, Date.class);
    		
    		this.theDate = (getValue() == null) ? new Date() : (Date) getValue();
    		dateChooser = new JDateChooser();
    		dateChooser.setDateFormatString(getDateFormat());
    		dateChooser.setDate(this.theDate);
    		dateChooser.addPropertyChangeListener(this);
    	}
    	
    	public JCalendarBinding(FormModel formModel, String formPropertyPath, String customFormat){
    		super(formModel, formPropertyPath, Date.class);
    		
    		this.theDate = (getValue() == null) ? new Date() : (Date) getValue();
    		dateChooser = new JDateChooser();
    		dateChooser.setDateFormatString(getDateFormat());
    		dateChooser.setDate(this.theDate);
    	}
    	
    	public void propertyChange(PropertyChangeEvent e) {
    		controlValueChanged(dateChooser.getDate());
    	}
    
    	@Override
    	protected void valueModelChanged(Object newValue) {
    		if(newValue instanceof Date && newValue != null)
    			dateChooser.setDate((Date) newValue);
    		else
    			dateChooser.setDate(new Date());
    	}
    
    	@Override
    	protected JComponent doBindControl() {
    		return dateChooser;
    	}
    
    	@Override
    	protected void enabledChanged() {
    		dateChooser.setEnabled(isEnabled() && !isReadOnly());
    	}
    
    	@Override
    	protected void readOnlyChanged() {
    		enabledChanged();
    	}
    
    	public String getDateFormat(){
    		return dateFormat;
    	}
    	
    	public void setDateFormat(String dateFormat) {
    		this.dateFormat = dateFormat;
    	}
    }
    create class pasien ...
    Code:
    public class Pasien {
    	private Integer id;
    	private String namaPasien;
    	private String tempatPasien;
    	private Date tglLahirPasien;
    	private String alamat;
    	private String telepon;
    	
    	// getter and setter  .....
    }
    create pasien form ...
    Code:
    public class PasienForm extends AbstractForm {
    	private static final String PASIEN_FORM = "pasienForm";
    	private JComponent nameField;
    	private JComponent tempatField;
    	private JComponent tglField;
    	private JComponent teleponField;
    	
    	public PasienForm(FormModel formModel){
    		super(formModel, PASIEN_FORM);
    	}
    	
    	protected JComponent createFormControl(){
    		final SwingBindingFactory sbf = (SwingBindingFactory) getBindingFactory();
    		TableFormBuilder formBuilder = new TableFormBuilder(sbf);
    
    		formBuilder.setLabelAttributes("colGrId=label colSpec=right:pref");
    		
    		formBuilder.addSeparator("Data Pasien");
    		formBuilder.row();
    		this.nameField = formBuilder.add("namaPasien", "colSpan=3 align=left")[1];
    		((JTextField)this.nameField).setColumns(20);
    		formBuilder.row();
    		this.tempatField = formBuilder.add("tempatPasien")[1];
    		((JTextField) tempatField).setColumns(10);
    		this.tglField = formBuilder.add(new JCalendarBinding(getFormModel(), "tglLahirPasien"))[1];
    		//this.tglField = formBuilder.add("tglLahirPasien")[1];
    		formBuilder.row();
    		formBuilder.addTextArea("alamat", "colSpan=3 align=left");
    		formBuilder.row();
    		this.teleponField = formBuilder.add("telepon", "colSpan=1 align=left")[1];
    		((JTextField) teleponField).setColumns(10);
    		formBuilder.getLayoutBuilder().cell();
    		formBuilder.row();
    		
    		return formBuilder.getForm();
    	}
    	
    	public boolean requestFocusInWindow(){
    		return nameField.requestFocusInWindow();
    	}
    }
    pasien dialog ...
    Code:
    public class NewPasienCommand extends TitledPageApplicationDialog implements ActionCommandExecutor {
    	//private static final Logger _logger = Logger.getLogger(NewPasienCommand.class);
    	private static final String NEW_PASIEN_PROPERTIES = "pasienProperties";
    	
    	private ValidatingFormModel formModel;
    	private PasienForm newPasienForm;
    	private Pasien pasien;
    	private PasienDataStored pasienDataStored;
    	private Form form;
    	
    	private boolean creatingNew = false;
    	
    	public NewPasienCommand() {
    		setCloseAction(CloseAction.DISPOSE);
    		
    		setPasien(null);
    		formModel = FormModelHelper.createFormModel(pasien);
    		form = new PasienForm(formModel);
    		FormBackedDialogPage page = new FormBackedDialogPage(form);
    		setDialogPage(page);
    	}
    	
    	private void initFormObject(){
    		form.setFormObject(pasien);
    		
    		if(creatingNew){
    			getMessage("pasienProperties.new.title");
    			setTitle(getMessage("pasienProperties.new.title"));
    		} else {
    			getMessage("pasienProperties.edit.title");
    			setTitle(getMessage("pasienProperties.edit.title"));
    		}
    	}
    	
    	public void setPasien(Pasien pasien){
    		if(pasien == null){
    			creatingNew = true;
    			this.pasien = new Pasien();
    		} else {
    			creatingNew = false;
    			this.pasien = pasien;
    		}
    	}
    	
    	@Override
    	protected void onCancel() {
    		if(formModel.isDirty()){
    			String title = getMessage(NEW_PASIEN_PROPERTIES + ".dirtyCancelTitle");
    			String msg = getMessage(NEW_PASIEN_PROPERTIES + ".dirtyCancelMessage");
    			ConfirmationDialog dlg = new ConfirmationDialog(title, msg){
    				protected void onConfirm(){
    					NewPasienCommand.super.onCancel();
    				}
    			};
    			dlg.showDialog();
    		} else {
    			super.onCancel();
    		}
    	}
    
    	@Override
    	protected boolean onFinish() {
    		formModel.commit();
    		
    		Pasien pasien = (Pasien) formModel.getFormObject();
                    System.out.println("Tgl lahir pasien : " + pasien.getTglLahirPasien());
    
    		String eventType;
    		if(creatingNew){
    			eventType = LifecycleApplicationEvent.CREATED;			
    			System.out.println("Created ... ");
    			getPasienDataStored().add("Created success ... !!");
    		} else {
    			eventType = LifecycleApplicationEvent.MODIFIED;
    			System.out.println("Modified ...");
    		}
    		
    		getApplicationContext().publishEvent(new LifecycleApplicationEvent(eventType, pasien));
    		
    		return true;
    	}
    	
    	public void execute(){
    		setParent(getActiveWindow().getControl());
    		initFormObject();
    		showDialog();
    		setPasien(null);
    	}
    
    	public PasienDataStored getPasienDataStored() {
    		return pasienDataStored;
    	}
    
    	public void setPasienDataStored(PasienDataStored pasienDataStored) {
    		this.pasienDataStored = pasienDataStored;
    	}
    }
    create rules with DefaultRulesSource ...
    Code:
    private Rules createPasienRules(){
    		return new Rules(Pasien.class){
    			protected void initRules(){
    				add("namaPasien", getNameValueConstraint(20));
    				add("tempatPasien", getNameValueConstraint(15));
    				//add("tglLahirPasien", required());
    				
    				add("tglLahirPasien", lt(new Date()));
    				add("alamat", required());
    				add("telepon", PHONE_CONSTRAINT);
    			}
    		};
    	}
    in command-context.xml ...
    Code:
    <bean id="masterPasienCommand" 
         	class="org.springframework.richclient.command.TargetableActionCommand">
         	<property name="commandExecutor">
         		<ref bean="newPasienCommand"/>
        	</property>
        </bean>
    in application-context.xml ...
    Code:
    <bean id="newPasienCommand" class="org.rskita.master.command.NewPasienCommand" />
    i have problem with error ...
    Code:
    org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'newPasienCommand' must be of type [org.springframework.richclient.security.SecurityController], but was actually of type [org.rskita.master.command.NewPasienCommand] at ...
    i have question ...
    why have couldn't show to the pasien form ??
    i wanna get to date form dateChooser after onFinish in the class NewPasienCommand but couldn't, why ? except if use extends ApplicationWindowAwareCommand in the class NewPasienCommand, it's no problem ...

    Do you know to my mean or no ??

    sorry if my english is bad ...

    Thanks
    Paulus
    Last edited by paganekoso; Feb 7th, 2007 at 10:47 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •