Java 类com.vaadin.server.Extension 实例源码

项目:cuba    文件:CubaImageObjectFitPolyfillExtension.java   
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;
}
项目:cuba    文件:ComponentGridDecorator.java   
/**
 * 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;
}
项目:componentrenderer    文件:ComponentGridDecorator.java   
/**
 * 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;
}
项目:IdleAlarm    文件:IdleAlarm.java   
/**
 * 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);
    }
}
项目:viritin    文件:MGrid.java   
/**
 * 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);
            }
        }
    }
}
项目:viritin    文件:MGrid.java   
/**
 * 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);
            }
        }
    }
}
项目:touchkit    文件:Geolocator.java   
/**
 * 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);
}
项目:touchkit    文件:LocalStorage.java   
/**
 * 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;

}
项目:vaadin-gridexport    文件:DefaultGridHolder.java   
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;
}
项目:cuba    文件:AppUI.java   
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;
}
项目:componentrenderer    文件:ComponentGridTest.java   
private Object extractExtension(Grid grid, Class extensionClass) {
    for (Extension extension : grid.getExtensions()) {
        if (extension.getClass().isAssignableFrom(extensionClass)) {
            return extension;
        }
    }
    return null;
}
项目:componentrenderer    文件:ComponentGridDecoratorTest.java   
private Object extractExtension(Grid grid, Class extensionClass) {
    for (Extension extension : grid.getExtensions()) {
        if (extension.getClass().isAssignableFrom(extensionClass)) {
            return extension;
        }
    }
    return null;
}
项目:componentrenderer    文件:ComponentCellKeyExtensionTest.java   
private boolean containsComponentCellKeyExtension(Grid grid) {
    for (Extension extension : grid.getExtensions()) {
        if (extension instanceof ComponentCellKeyExtension) {
            return true;
        }
    }
    return false;
}
项目:componentrenderer    文件:DetailsKeysExtensionTest.java   
private boolean containsDetailsGridExtension(Grid grid) {
    for (Extension extension : grid.getExtensions()) {
        if (extension instanceof DetailsKeysExtension) {
            return true;
        }
    }
    return false;
}
项目:componentrenderer    文件:FocusPreserveExtensionTest.java   
private boolean containsFocusPreserveExtension(Grid grid) {
    for (Extension extension : grid.getExtensions()) {
        if (extension instanceof FocusPreserveExtension) {
            return true;
        }
    }
    return false;
}
项目:LabelButton    文件:LabelButtonExtension.java   
/**
 * 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;
    }
}
项目:serverside-elements    文件:ElementIntegration.java   
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;
}
项目:IdleAlarm    文件:IdleAlarm.java   
/**
 * 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);
}
项目:BeforeUnload    文件:BeforeUnload.java   
/**
 * 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();
}
项目:BeforeUnload    文件:BeforeUnload.java   
/**
 * 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;
}
项目:Notifique    文件:Notifique.java   
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);
    }

}
项目:Vaadin-LocalStorage    文件:LocalStorage.java   
/**
 * 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);
}
项目:GlycanBuilderVaadin7Version    文件:GlycanBuilderWindow.java   
public void addExtension (Extension extension)
{
    super.addExtension(extension);
}
项目:hypothesis    文件:SlideContainerPresenter.java   
@Override
public void addKeyAction(Extension keyAction) {
    if (keyAction != null && keyAction instanceof KeyAction) {
        keyActions.add((KeyAction) keyAction);
    }
}
项目:hypothesis    文件:SlidePresenter.java   
void addKeyAction(Extension keyAction);