use of com.google.gwt.user.client.ui.Widget in project gwt-material by GwtMaterialDesign.
the class MaterialCollection method setActive.
@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.");
}
}
}
}
use of com.google.gwt.user.client.ui.Widget in project gwt-material by GwtMaterialDesign.
the class MaterialCollectionItem method onLoad.
@Override
protected void onLoad() {
super.onLoad();
HandlerRegistration handlerRegistration = addClickHandler(event -> {
// been clicked to avoid duplicate events.
if (Element.as(event.getNativeEvent().getEventTarget()) != getElement()) {
if (getType() == CollectionType.CHECKBOX) {
event.stopPropagation();
event.preventDefault();
}
}
for (Widget w : MaterialCollectionItem.this) {
if (w instanceof MaterialCollectionSecondary) {
for (Widget a : (MaterialCollectionSecondary) w) {
if (a instanceof HasValue) {
try {
@SuppressWarnings("unchecked") HasValue<Boolean> cb = (HasValue<Boolean>) a;
if (cb.getValue()) {
cb.setValue(false);
} else {
cb.setValue(true);
}
} catch (ClassCastException ex) {
// Ignore non-boolean has value handlers.
}
}
}
}
}
});
registerHandler(handlerRegistration);
JsMaterialElement.initDismissableCollection();
}
use of com.google.gwt.user.client.ui.Widget in project gwt-material by GwtMaterialDesign.
the class MaterialDropDown method registerDropdownItemHandlers.
protected void registerDropdownItemHandlers() {
getChildren().forEach(widget -> {
if (widget instanceof ListItem) {
ListItem item = (ListItem) widget;
if (item.getWidgetCount() > 0) {
if (item.getWidget(0) instanceof MaterialWidget) {
MaterialWidget child = (MaterialWidget) item.getWidget(0);
registerHandler(child.addDomHandler(event -> {
SelectionEvent.fire(MaterialDropDown.this, child);
}, ClickEvent.getType()));
}
}
}
});
}
use of com.google.gwt.user.client.ui.Widget in project gwt-material by GwtMaterialDesign.
the class MaterialDropDown method load.
@Override
public void load() {
Widget parent = getParent();
if (parent instanceof HasActivates) {
String uid = DOM.createUniqueId();
((HasActivates) parent).setActivates(uid);
setId(uid);
activatorElement = parent.getElement();
} else if (activatorElement == null) {
activatorElement = DOMHelper.getElementByAttribute("data-activates", activator);
if (activatorElement == null) {
GWT.log("There is no activator element with id: '" + activator + "' in the DOM, " + "cannot instantiate MaterialDropDown without a data-activates.", new IllegalStateException());
}
}
$(activatorElement).dropdown(options);
}
use of com.google.gwt.user.client.ui.Widget in project gwt-material by GwtMaterialDesign.
the class MaterialCollapsibleBody method add.
@Override
public void add(final Widget child) {
if (child instanceof UnorderedList) {
for (Widget w : (UnorderedList) child) {
if (w instanceof ListItem) {
w.getElement().getStyle().setDisplay(Style.Display.BLOCK);
provideActiveClickHandler(w);
}
}
} else if (child instanceof ListItem) {
child.getElement().getStyle().setDisplay(Style.Display.BLOCK);
provideActiveClickHandler(child);
}
super.add(child);
}
Aggregations