Java tutorial
/* * Copyright 2014 JBoss Inc * * Licensed 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 io.apiman.manager.ui.client.local.pages.common; import io.apiman.manager.api.beans.summary.ApplicationSummaryBean; import io.apiman.manager.ui.client.local.services.NavigationHelperService; import java.util.List; import javax.inject.Inject; import org.jboss.errai.ui.client.local.spi.TranslationService; import com.google.gwt.event.logical.shared.ValueChangeEvent; import com.google.gwt.event.logical.shared.ValueChangeHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.ui.FlowPanel; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.HasValue; import com.google.gwt.user.client.ui.InlineLabel; import com.google.gwt.user.client.ui.Widget; /** * UI component to display the user's list of applications. * * @author eric.wittmann@redhat.com */ public abstract class AbstractApplicationList extends FlowPanel implements HasValue<List<ApplicationSummaryBean>> { @Inject protected NavigationHelperService navHelper; @Inject protected TranslationService i18n; private List<ApplicationSummaryBean> apps; private boolean filtered; /** * Constructor. */ public AbstractApplicationList() { getElement().setClassName("apiman-applications"); //$NON-NLS-1$ } /** * @see com.google.gwt.event.logical.shared.HasValueChangeHandlers#addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) */ @Override public HandlerRegistration addValueChangeHandler(ValueChangeHandler<List<ApplicationSummaryBean>> handler) { return super.addHandler(handler, ValueChangeEvent.getType()); } /** * @see com.google.gwt.user.client.ui.HasValue#getValue() */ @Override public List<ApplicationSummaryBean> getValue() { return apps; } /** * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object) */ public void setFilteredValue(List<ApplicationSummaryBean> value) { filtered = true; setValue(value, false); } /** * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object) */ @Override public void setValue(List<ApplicationSummaryBean> value) { filtered = false; setValue(value, false); } /** * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object, boolean) */ @Override public void setValue(List<ApplicationSummaryBean> value, boolean fireEvents) { apps = value; clear(); refresh(); } /** * Refresh the display with the current value. */ public void refresh() { if (apps != null && !apps.isEmpty()) { for (ApplicationSummaryBean bean : apps) { Widget row = createAppRow(bean); add(row); } } else { add(createNoEntitiesWidget()); } } /** * @return a no-entities widget to be shown when no aps are found */ protected abstract NoEntitiesWidget createNoEntitiesWidget(); /** * Creates a single application row. * @param bean */ private Widget createAppRow(ApplicationSummaryBean bean) { FlowPanel container = new FlowPanel(); container.getElement().setClassName("container-fluid"); //$NON-NLS-1$ container.getElement().addClassName("apiman-summaryrow"); //$NON-NLS-1$ FlowPanel row1 = new FlowPanel(); container.add(row1); row1.getElement().setClassName("row"); //$NON-NLS-1$ createTitleRow(bean, row1); FlowPanel row2 = new FlowPanel(); container.add(row2); row2.getElement().setClassName("row"); //$NON-NLS-1$ InlineLabel description = new InlineLabel(bean.getDescription()); row2.add(description); description.getElement().setClassName("description"); //$NON-NLS-1$ container.add(new HTMLPanel("<hr/>")); //$NON-NLS-1$ return container; } /** * Creates the title row for a single app in the list. * @param bean * @param row1 */ protected abstract void createTitleRow(ApplicationSummaryBean bean, FlowPanel row1); /** * @return the filtered */ protected boolean isFiltered() { return filtered; } }