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; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.ui.Label; import com.vaadin.ui.NativeSelect; import de.decidr.model.annotations.Reviewed; import de.decidr.model.annotations.Reviewed.State; import de.decidr.model.exceptions.TransactionException; import de.decidr.ui.controller.MarkWorkItemAsDoneAction; import de.decidr.ui.controller.show.ShowWorkItemWindowAction; import de.decidr.ui.data.WorkItemContainer; import de.decidr.ui.main.DecidrUI; import de.decidr.ui.main.ModelFacades; import de.decidr.ui.view.tables.WorkItemTable; /** * This component represents the work items in a table. The user can choose if * he wants to see the work items of all tenants or just from the current * tenant. * * @author AT */ @Reviewed(reviewers = { "TK", "JS" }, lastRevision = "0", currentReviewState = State.NeedsReview) public class WorkItemComponent extends AbstractListComponent { private static final long serialVersionUID = -2110748321898265548L; private WorkItemContainer workItemContainer = null; private Label showWorkItemLabel = null; private WorkItemContainer filteredWorkItemContainer; private NativeSelect filterSelect; private WorkItemTable filteredWorkItemsTable; private WorkItemTable allWorkItemsTable; private static final String[] FILTERS = new String[] { "Current Tenant", "All Tenants" }; /** * Default constructor. * */ public WorkItemComponent() { super(); init(); } /** * Returns the work item table. * * @return workItemTable */ public WorkItemTable getWorkItemTable() { return (WorkItemTable) contentTable; } protected boolean isMemberOfMultipleTenants() { try { return (ModelFacades.getUserFacade() .getJoinedTenants(DecidrUI.getCurrent().getCurrentUser().getActorId()).size() > 1); } catch (TransactionException e) { return false; } } /** * Set up the select box for showing all workitems or only those of the current tenant. */ protected void initFilterSelect() { showWorkItemLabel = new Label("Show Work Items from: "); filterSelect = new NativeSelect(""); for (String item : FILTERS) { filterSelect.addItem(item); } filterSelect.setNullSelectionAllowed(false); filterSelect.select(FILTERS[0]); filterSelect.setImmediate(true); filterSelect.addListener(new Property.ValueChangeListener() { private static final long serialVersionUID = 1L; @Override public void valueChange(ValueChangeEvent event) { if (filterSelect.getValue() == FILTERS[0]) { replaceContentTable(filteredWorkItemsTable); } else { replaceContentTable(allWorkItemsTable); } } }); searchPanel.getSearchHorizontalLayout().addComponent(showWorkItemLabel); searchPanel.getSearchHorizontalLayout().addComponent(filterSelect); } /** * This method initializes the components of the work item component. * */ protected void init() { workItemContainer = new WorkItemContainer(); filteredWorkItemContainer = new WorkItemContainer(true); label = new Label("<h2>My Work Items</h2>"); label.setContentMode(Label.CONTENT_XHTML); allWorkItemsTable = new WorkItemTable(workItemContainer); filteredWorkItemsTable = new WorkItemTable(filteredWorkItemContainer); contentTable = filteredWorkItemsTable; addButton("Edit Work Item", new ShowWorkItemWindowAction(contentTable), ButtonPolicy.ONE_SELECTED, true); addButton("Mark as done", new MarkWorkItemAsDoneAction(contentTable)); super.init(); if (isMemberOfMultipleTenants()) { initFilterSelect(); } } }