All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gwt.material.design.client.ui.MaterialCollection Maven / Gradle / Ivy

There is a newer version: 2.8.3
Show newest version
/*
 * #%L
 * GwtMaterial
 * %%
 * Copyright (C) 2015 - 2017 GwtMaterialDesign
 * %%
 * 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.
 * #L%
 */
package gwt.material.design.client.ui;

import com.google.gwt.dom.client.Document;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
import com.google.gwt.user.client.ui.Widget;
import gwt.material.design.client.base.HasActiveParent;
import gwt.material.design.client.base.HasClearActiveHandler;
import gwt.material.design.client.base.MaterialWidget;
import gwt.material.design.client.base.helper.UiHelper;
import gwt.material.design.client.constants.CssName;
import gwt.material.design.client.constants.HeadingSize;
import gwt.material.design.client.events.ClearActiveEvent;
import gwt.material.design.client.ui.html.Heading;
import gwt.material.design.client.ui.html.ListItem;

//@formatter:off

/**
 * Collections allow you to group list objects together.
 * 

*

*

UiBinder Usage:

*
 * {@code
 * Simple
 * 
 * 
 * 
 * 
 * 
 * 
 *
 * Links
 * 
 * 
 * 
 * 
 * 
 * 
 *
 * Header
 * 
 * 
 * 
 * 
 * 
 * 
 *
 * Secondary Content
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * }
 * 
*

* * @author kevzlou7979 * @author Ben Dol * @see Material Collections * @see Material Design Specification */ //@formatter:on public class MaterialCollection extends MaterialWidget implements HasActiveParent, HasClearActiveHandler { private int index; private Heading headerLabel = new Heading(HeadingSize.H4); /** * Creates an empty collection component. */ public MaterialCollection() { super(Document.get().createULElement(), CssName.COLLECTION); } @Override public void clearActive() { clearActiveClass(this); } /** * Sets the header of the collection component. */ public void setHeader(String header) { headerLabel.getElement().setInnerSafeHtml(SafeHtmlUtils.fromString(header)); addStyleName(CssName.WITH_HEADER); ListItem item = new ListItem(headerLabel); UiHelper.addMousePressedHandlers(item); item.setStyleName(CssName.COLLECTION_HEADER); insert(item, 0); } @Override public void setActive(int index) { setActive(index, true); } @Override public void setActive(int index, boolean value) { this.index = index; Widget activeWidget = getActive(); if (activeWidget != null) { if (index <= getWidgetCount()) { if (index != 0) { clearActiveClass(this); if (activeWidget instanceof MaterialCollectionItem) { ((MaterialCollectionItem) activeWidget).setActive(value); } } else { throw new IllegalArgumentException("The active index must be a one-base index to mark as active."); } } } } @Override public Widget getActive() { try { return getWidget(index - 1); } catch (IndexOutOfBoundsException ex) { return null; } } public Heading getHeaderLabel() { return headerLabel; } @Override public HandlerRegistration addClearActiveHandler(final ClearActiveEvent.ClearActiveHandler handler) { return addHandler(handler, ClearActiveEvent.TYPE); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy