/** * Internal method called to hide a presenter. * See {@link PresenterWidget} for ways to hide a presenter. */ void internalHide() { if (!isVisible()) { return; } for (PresenterWidget<?> child : children) { child.internalHide(); } if (isPopup()) { ((PopupView) this.getView()).setCloseHandler(null); ((PopupView) this.getView()).hide(); } unregisterVisibleHandlers(); visible = false; onHide(); }
/** * Internal method called to reveal a presenter. * See {@link PresenterWidget} and {@link Presenter} for ways to reveal a * presenter. */ @SuppressWarnings("unchecked") void internalReveal() { if (isVisible()) { return; } onReveal(); visible = true; // use new set to prevent concurrent modification for (PresenterWidget<?> child: new HashSet<>(children)) { child.internalReveal(); } if (isPopup()) { monitorCloseEvent((PresenterWidget<? extends PopupView>) this); ((PopupView) getView()).showAndReposition(); } registerVisibleHandlers(); }
@Override public void addToPopupSlot(PresenterWidget<? extends PopupView> child) { addToSlot(POPUP_SLOT, child); }
/** * This method sets some content in a specific slot of the {@link Presenter}. The attached {@link View} should * manage this slot when its {@link View#setInSlot(Object, IsWidget)} is called. It should also clear the slot when * called with {@code null} as a parameter. * <p/> * For more details on slots, see {@link HasSlots}. * * @param slot The slot for which the content is being set. * @param child The content, a {@link PresenterWidget}. Passing {@code null} will clear the slot. * @param performReset Pass {@code true} if you want a {@link ResetPresentersEvent} to be fired after the content * has been added and this presenter is visible, pass {@code false} otherwise. */ @Override public <T extends PresenterWidget<?>> void setInSlot(IsSlot<T> slot, T child, boolean performReset) { if (child == null) { clearSlot((RemovableSlot<?>) slot); return; } adoptChild(slot, child); internalClearSlot(slot, child); if (!child.isPopup()) { getView().setInSlot(slot.getRawSlot(), child); } if (isVisible()) { child.internalReveal(); if (performReset) { ResetPresentersEvent.fire(this); } } }
/** * This method adds some content in a specific slot of the {@link Presenter}. The attached {@link View} should * manage this slot when its {@link View#addToSlot(Object, IsWidget)} is called. * <p/> * Contrary to the {@link #setInSlot(IsSlot, PresenterWidget)} method, no {@link ResetPresentersEvent} is fired, so * {@link PresenterWidget#onReset()} is not invoked. * <p/> * For more details on slots, see {@link HasSlots}. * * @param slot The slot into which the content is being added. * @param child The content, a {@link PresenterWidget}. Passing {@code null} will not add anything. */ @Override public <T extends PresenterWidget<?>> void addToSlot(MultiSlot<T> slot, T child) { assert child != null : "cannot add null to a slot"; if (child.slot == slot && child.parent == this) { return; } adoptChild(slot, child); if (!child.isPopup()) { getView().addToSlot(slot.getRawSlot(), child); } if (isVisible()) { child.internalReveal(); } }
@Override protected void onBind() { super.onBind(); M listModel = getModel(); listModel.getSelectedItemChangedEvent().addListener((ev, sender, args) -> updateSelectedRows()); listModel.getSelectedItemsChangedEvent().addListener((ev, sender, args) -> updateSelectedRows()); }
@Override protected void onReveal() { super.onReveal(); activePopups++; }
/** * Registers an event handler towards the {@link EventBus} and registers it to be automatically removed when {@link * #unbind()} is called. This is usually the desired behavior, but if you want to unregister handlers manually use * {@link EventBus#addHandler} instead. * * @param <H> The handler type. * @param type See {@link Type}. * @param handler The handler to register. * * @see #addVisibleHandler(Type, EventHandler) */ protected <H extends EventHandler> void addRegisteredHandler(Type<H> type, H handler) { registerHandler(getEventBus().addHandler(type, handler)); }
@Override protected void onHide() { super.onHide(); activePopups--; if (activePopups == 0) { // No popups active, reap tooltips attached to popup content. Scheduler.get().scheduleDeferred(() -> ElementTooltipUtils.reapPopupContentTooltips()); } }
private <H extends EventHandler> void registerVisibleHandler(HandlerInformation<H> handlerInformation) { HandlerRegistration handlerRegistration = getEventBus().addHandler(handlerInformation.type, handlerInformation.eventHandler); visibleHandlerRegistrations.add(handlerRegistration); }
@Override public void fireEvent(GwtEvent<?> event) { fireEvent((Event<?>) event); }
@Override public final void bind() { super.bind(); if (getProxy() instanceof HasHandlerContainer) { ((HasHandlerContainer) getProxy()).getHandlerContainer().bind(); } }
@Override public void onBind() { super.onBind(); registerHandler(getView().getButton().addClickHandler(event -> { if (toggled) { getView().switchToDefault(); } else { getView().switchToSecondary(); } toggled = !toggled; hasToggle.onToggle(toggled); })); } }
/** * Fires the given event to the handlers listening to the event's type. * <p> * Any exceptions thrown by handlers will be bundled into a * {@link com.google.gwt.event.shared.UmbrellaException UmbrellaException} and then re-thrown after all handlers have * completed. An exception thrown by a handler will not prevent other handlers * from executing. * * @param event the event */ public void fireEvent(Event<?> event) { getEventBus().fireEventFromSource(event, this); }
@Override protected void onBind() { super.onBind(); addRegisteredHandler(ResetPresentersEvent.getType(), this); addRegisteredHandler(RevealRootContentEvent.getType(), this); addRegisteredHandler(RevealRootLayoutContentEvent.getType(), this); addRegisteredHandler(RevealRootPopupContentEvent.getType(), this); addRegisteredHandler(LockInteractionEvent.getType(), this); } }
@Override protected void onBind() { super.onBind(); HasClickHandlers closeButton = getView().getCloseButton(); if (closeButton != null) { registerHandler(closeButton.addClickHandler(event -> AbstractPopupPresenterWidget.this.onClose())); } HasClickHandlers closeIconButton = getView().getCloseIconButton(); if (closeIconButton != null) { registerHandler(closeIconButton.addClickHandler(event -> AbstractPopupPresenterWidget.this.onClose())); } registerHandler(getView().setPopupKeyPressHandler(event -> AbstractPopupPresenterWidget.this.onKeyPress(event))); registerHandler(getEventBus().addHandler(UserLoginChangeEvent.getType(), event -> { if (isVisible()) { getView().hide(); } })); registerHandler(getView().getRepositionOnWindowResizeHandler()); }