Skip to content

Instantly share code, notes, and snippets.

@BenDol
Last active September 24, 2017 13:35
Show Gist options
  • Save BenDol/65ef029034e61281430b76f676928b96 to your computer and use it in GitHub Desktop.
Save BenDol/65ef029034e61281430b76f676928b96 to your computer and use it in GitHub Desktop.
public class MaterialDropDown extends UnorderedList implements HasSelectionHandlers<Widget>, HasInOutDurationTransition, Loader, HasConfigure {
...
JsDropdownOptions options = new JsDropdownOptions();
@Override
protected void onLoad() {
super.onLoad();
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());
}
}
configure();
load();
}
@Override
public void configure() {
options.constrain_width = constrainWidth;
options.inDuration = inDuration;
options.outDuration = outDuration;
options.hover = hover;
options.gutter = gutter;
options.belowOrigin = belowOrigin;
options.alignment = alignment.getCssName();
}
@Override
public void load() {
$(activatorElement).dropdown(options);
setupActivator();
}
@Override
public void reload() {
remove(activatorElement);
configure();
load();
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment