Java tutorial
/* * The DecidR Development Team licenses this file to you under * the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package de.decidr.ui.view.windows; import com.vaadin.ui.Button; import com.vaadin.ui.Form; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; import de.decidr.model.annotations.Reviewed; import de.decidr.model.annotations.Reviewed.State; import de.decidr.model.schema.decidrtypes.THumanTaskData; import de.decidr.model.schema.decidrtypes.TInformation; import de.decidr.model.schema.decidrtypes.TTaskItem; import de.decidr.ui.controller.HideWindowAndDeleteFileAction; import de.decidr.ui.controller.SaveWorkItemAction; import de.decidr.ui.view.uibuilder.FormBuilder; /** * This window represents a form where the work items of the user are displayed. * Here he can enter his data into the provided fields and save them. * * @author AT */ @Reviewed(reviewers = { "unknown" }, lastRevision = "0", currentReviewState = State.NeedsReview) public class WorkItemWindow extends Window { private static final long serialVersionUID = 1L; private VerticalLayout verticalLayout = null; private HorizontalLayout horizontalLayout = null; private Label label = null; private Form itemForm = null; private Button okButton = null; private Button cancelButton = null; private Button markAsDoneButton = null; /** * Constructor with a given {@link THumanTaskData} object which calls the * init method. */ public WorkItemWindow(THumanTaskData tHumanTaskData, Long workItemId) { init(tHumanTaskData, workItemId); } /** * Fills the form with the specific settings from the {@link THumanTaskData} * . For every simple type another Field is added to the form and if * necessary a validator is added, so that the user can't enter invalid * data. A tooltip shows the user some information on what to enter into the * fields. If a value already exists, this value is shown. * * @param tHumanTaskData * - An object representing the work item xml file as a java * object */ private void fillForm(THumanTaskData tHumanTaskData) { FormBuilder builder = new FormBuilder(); for (Object listItem : tHumanTaskData.getTaskItemOrInformation()) { if (listItem instanceof TTaskItem) { builder.addControl(getItemForm(), (TTaskItem) listItem); } else { builder.addControl(getItemForm(), (TInformation) listItem); } } } /** * Returns the item {@link Form}. * * @return itemForm - The form where the date from the work item are showed */ public Form getItemForm() { return itemForm; } /** * Initializes the components for the window and fills the form with the * information from the {@link THumanTaskData}. * * @param tHumanTaskData * - An object representing the work item xml file as a java * object */ private void init(THumanTaskData tHumanTaskData, Long workItemId) { verticalLayout = new VerticalLayout(); verticalLayout.setMargin(true); horizontalLayout = new HorizontalLayout(); label = new Label(); itemForm = new Form(); fillForm(tHumanTaskData); okButton = new Button("OK", new SaveWorkItemAction(itemForm, tHumanTaskData, workItemId)); okButton.focus(); cancelButton = new Button("Cancel", new HideWindowAndDeleteFileAction()); markAsDoneButton = new Button("Mark as done", new SaveWorkItemAction(itemForm, tHumanTaskData, workItemId)); this.setContent(verticalLayout); this.setModal(true); this.setHeight("650px"); this.setWidth("370px"); this.center(); this.setResizable(true); this.setCaption("Work item"); verticalLayout.addComponent(label); verticalLayout.addComponent(itemForm); horizontalLayout.addComponent(okButton); horizontalLayout.addComponent(markAsDoneButton); horizontalLayout.addComponent(cancelButton); verticalLayout.addComponent(horizontalLayout); } }