Java tutorial
/* * $Id$ * * Authors: * Jeff Buchbinder <jeff@freemedsoftware.org> * * FreeMED Electronic Medical Record and Practice Management System * Copyright (C) 1999-2012 FreeMED Software Foundation * * 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 2 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, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ package org.freemedsoftware.gwt.client.screen.patient; import static org.freemedsoftware.gwt.client.i18n.I18nUtil._; import org.freemedsoftware.gwt.client.PatientEntryScreenInterface; import org.freemedsoftware.gwt.client.i18n.AppConstants; import org.freemedsoftware.gwt.client.widget.CustomButton; import org.freemedsoftware.gwt.client.widget.MultiPageImageCompositedForm; import org.freemedsoftware.gwt.client.widget.SupportModuleWidget; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.VerticalPanel; public class FormEntry extends PatientEntryScreenInterface { protected String moduleName = "Form"; protected SupportModuleWidget wForm = new SupportModuleWidget("FormTemplate"); protected MultiPageImageCompositedForm wWidget = new MultiPageImageCompositedForm(); public FormEntry() { final VerticalPanel verticalPanel = new VerticalPanel(); initWidget(verticalPanel); final HorizontalPanel formHeader = new HorizontalPanel(); final Label formLabel = new Label(_("Form")); formHeader.add(formLabel); formHeader.add(wForm); verticalPanel.add(formHeader); wForm.addChangeHandler(new ValueChangeHandler<Integer>() { @Override public void onValueChange(ValueChangeEvent<Integer> event) { // Force load action if (wForm.getValue() > 0) { loadForm(wForm.getValue()); } } }); wWidget.setVisible(false); wWidget.setOnFormLoaded(new Command() { @Override public void execute() { // TODO: populate widget with older data if there is any } }); final HorizontalPanel buttonBar = new HorizontalPanel(); buttonBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); final CustomButton wSubmit = new CustomButton(_("Submit"), AppConstants.ICON_ADD); buttonBar.add(wSubmit); wSubmit.addClickHandler(new ClickHandler() { public void onClick(ClickEvent w) { submitForm(); } }); final CustomButton wReset = new CustomButton(_("Reset"), AppConstants.ICON_CLEAR); buttonBar.add(wReset); wReset.addClickHandler(new ClickHandler() { public void onClick(ClickEvent w) { resetForm(); } }); verticalPanel.add(buttonBar); } protected void loadForm(Integer formId) { wWidget.loadFormFromServer(formId); wWidget.setVisible(true); } public String getModuleName() { return "Form"; } public void resetForm() { wForm.clear(); } }