public static CubaImageObjectFitPolyfillExtension get(UI ui) { CubaImageObjectFitPolyfillExtension extension = null; // Search singleton extension for (Extension uiExtension : ui.getExtensions()) { if (uiExtension instanceof CubaImageObjectFitPolyfillExtension) { extension = (CubaImageObjectFitPolyfillExtension) uiExtension; break; } } // Create new extension if not found if (extension == null) { extension = new CubaImageObjectFitPolyfillExtension(); extension.extend(ui); } return extension; }
/** * Refreshes the grid preserving its current cell focus. * * @return the decorator for method chaining */ public ComponentGridDecorator<T> refresh() { focusPreserveExtension.saveFocus(); // inspired by the awesome viritin extension // https://github.com/viritin/viritin/blob/viritin-1.44/src/main/java/org/vaadin/viritin/grid/MGrid.java#L218 for (Extension extension : grid.getExtensions()) { if (extension instanceof RpcDataProviderExtension) { ((RpcDataProviderExtension) extension).refreshCache(); break; } } focusPreserveExtension.restoreFocus(); return this; }
/** * Removes IdleAlarm extension from given UI content * @param ui UI from where extension is unloaded */ public static void unload(UI ui) { if(ui == null) { throw new IllegalArgumentException("UI can not be null"); } IdleAlarm idleAlarm = null; for(Extension extension : ui.getExtensions()) { if(extension instanceof IdleAlarm) { idleAlarm = (IdleAlarm)extension; break; } } if(idleAlarm != null) { ui.removeExtension(idleAlarm); } }
/** * Manually forces refresh of the row that represents given entity. * ListContainer backing MGrid/MTable don't support property change * listeners (to save memory and CPU cycles). In some case with Grid, if you * know only certain row(s) are changed, you can make a smaller client side * change by refreshing rows with this method, instead of refreshing the * whole Grid (e.g. by re-assigning the bean list). * <p> * This method is automatically called if you use "editor row". * * @param bean the bean whose row should be refreshed. */ public void refreshRow(T bean) { Collection<Extension> extensions = getExtensions(); for (Extension extension : extensions) { // Calling with reflection for 7.6-7.5 compatibility if (extension.getClass().getName().contains( "RpcDataProviderExtension")) { try { Method method = extension.getClass().getMethod( "updateRowData", Object.class); method.invoke(extension, bean); break; } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { Logger.getLogger(MGrid.class.getName()). log(Level.SEVERE, null, ex); } } } }
/** * Manually forces refresh of all visible rows. ListContainer backing * MGrid/MTable don't support property change listeners (to save memory and * CPU cycles). This method explicitly forces Grid's row cache invalidation. */ public void refreshVisibleRows() { Collection<Extension> extensions = getExtensions(); for (Extension extension : extensions) { // Calling with reflection for 7.6-7.5 compatibility if (extension.getClass().getName().contains( "RpcDataProviderExtension")) { try { Method method = extension.getClass().getMethod( "refreshCache"); method.invoke(extension); break; } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { Logger.getLogger(MGrid.class.getName()). log(Level.SEVERE, null, ex); } } } }
/** * Detects the current geographic location of the client. The detection * happens asynchronously and the position is reported to the callback given * in the callback argument. Note that this only checks the position once, * you need to call this method multiple times if you want to update the * location as the client moves. * * @param callback * The {@link PositionCallback} instance that is called when the * position is available. */ public static void detect(PositionCallback callback) { Geolocator locator = null; // Do we already have a Geolocator attached? for (Extension e : UI.getCurrent().getExtensions()) { if (e instanceof Geolocator) { locator = (Geolocator) e; } } // Attach a Geolocator if none found. if (locator == null) { locator = new Geolocator(); locator.extend(UI.getCurrent()); } locator.detectCurrentPosition(callback); }
/** * Returns a local storage proxy bound to the given UI. * * @param ui * the UI to bind to. * @return A LocalStorage extension bound to the given UI. If an extension * is not yet applied, a new one is created and applied to the UI. */ public static LocalStorage get(UI ui) { if (ui == null) { throw new IllegalArgumentException("A UI must be provided"); } LocalStorage locator = null; // Do we already have an extension attached? for (Extension e : ui.getExtensions()) { if (e instanceof LocalStorage) { locator = (LocalStorage) e; } } // Attach if none found. if (locator == null) { locator = new LocalStorage(); locator.extend(UI.getCurrent()); } return locator; }
protected Renderer<?> getRenderer(final String propId) { // Grid.Column (as of 8.0.3) does not expose its renderer, we have to get it from extensions final Column<T, ?> column = getColumn(propId); if (column != null) { for (Extension each : column.getExtensions()) { if (each instanceof Renderer<?>) { return (Renderer<?>) each; } } } return null; }
public List<CubaTimer> getTimers() { AbstractComponent timersHolder = getTopLevelWindowComposition(); List<CubaTimer> timers = new ArrayList<>(); for (Extension extension : timersHolder.getExtensions()) { if (extension instanceof CubaTimer) { timers.add((CubaTimer) extension); } } return timers; }
private Object extractExtension(Grid grid, Class extensionClass) { for (Extension extension : grid.getExtensions()) { if (extension.getClass().isAssignableFrom(extensionClass)) { return extension; } } return null; }
private boolean containsComponentCellKeyExtension(Grid grid) { for (Extension extension : grid.getExtensions()) { if (extension instanceof ComponentCellKeyExtension) { return true; } } return false; }
private boolean containsDetailsGridExtension(Grid grid) { for (Extension extension : grid.getExtensions()) { if (extension instanceof DetailsKeysExtension) { return true; } } return false; }
private boolean containsFocusPreserveExtension(Grid grid) { for (Extension extension : grid.getExtensions()) { if (extension instanceof FocusPreserveExtension) { return true; } } return false; }
/** * Get LabelButtonExtension of given label. * @param label Label with extension * @param createIfMissing If true extension will be added if not found. * @return LabelButtonExtension of given label, or null if no extension. */ public static LabelButtonExtension get(Label label, boolean createIfMissing) { for(Extension extension : label.getExtensions()) { if(extension instanceof LabelButtonExtension) { return (LabelButtonExtension)extension; } } if(createIfMissing) { return new LabelButtonExtension(label); } else { return null; } }
public static Root getRoot(AbstractComponent target) { Optional<Extension> existing = target.getExtensions().stream() .filter(e -> e.getClass() == ElementIntegration.class) .findFirst(); ElementIntegration integration = existing.isPresent() ? (ElementIntegration) existing .get() : new ElementIntegration(target); return integration.root; }
/** * Get instance of IdleAlarm. I * @param ui UI that is extended * @return Instance of IdleAlarm * @throws IllegalArgumentException If invalid UI given * @throws IllegalStateException If given UI does not have valid max inactive interval defined */ public static IdleAlarm get(UI ui) throws IllegalArgumentException, IllegalStateException { if(ui == null) { throw new IllegalArgumentException("UI can not be null"); } for(Extension extension : ui.getExtensions()) { if(extension instanceof IdleAlarm) { return (IdleAlarm)extension; } } return new IdleAlarm(ui); }
/** * Optionally get current existing instance of BeforeUnload * @return empty if not found */ protected static Optional<BeforeUnload> optionalGet(UI currentUI) { if(currentUI == null) { return Optional.empty(); } for(Extension extension : currentUI.getExtensions()) { if(extension instanceof BeforeUnload) { return Optional.of((BeforeUnload)extension); } } return Optional.empty(); }
/** * Get current "singleton" instance of BeforeUnload * @param currentUI UI used to resolve instance * @return BeforeUnload instance */ protected static BeforeUnload get(UI currentUI) throws IllegalStateException { if(currentUI == null) { throw new IllegalStateException("Current UI not defined"); } for(Extension extension : currentUI.getExtensions()) { if(extension instanceof BeforeUnload) { return (BeforeUnload)extension; } } BeforeUnload beforeUnload = new BeforeUnload(); beforeUnload.extend(currentUI); return beforeUnload; }
private void addAnimatorListener() { UI ui = UI.getCurrent(); for (Extension ex : ui.getExtensions()) { if (ex instanceof Animator) { animator = (Animator) ex; } } if (animator != null) { animator.addListener(animationEndListener); } }
/** * Gets or creates the {@link LocalStorage} instance of the given parent {@link UI}. * @param parent Parent {@link UI} * @return {@link LocalStorage} instance of the given parent {@link UI}. */ public static LocalStorage getCurrent(UI parent) { if (parent == null) { throw new NullPointerException(); } for (Extension extension : parent.getExtensions()) { if (extension instanceof LocalStorage) { return (LocalStorage) extension; } } return new LocalStorage(parent); }
public void addExtension (Extension extension) { super.addExtension(extension); }
@Override public void addKeyAction(Extension keyAction) { if (keyAction != null && keyAction instanceof KeyAction) { keyActions.add((KeyAction) keyAction); } }
void addKeyAction(Extension keyAction);