下面列出了怎么用com.vaadin.server.Extension的API类实例代码及写法,或者点击链接到github查看源代码。
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;
}
/**
* 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);
}
}
}
}
public static HtmlAttributesExtension get(Component component) {
for (Extension e : component.getExtensions()) {
if (e instanceof HtmlAttributesExtension) {
return (HtmlAttributesExtension) e;
}
}
return new HtmlAttributesExtension((AbstractClientConnector) component);
}
protected void workaroundForFirefoxIssue(boolean initial) {
if (initial && Page.getCurrent().getWebBrowser().getBrowserApplication().
contains("Firefox")) {
// Responsive, FF, cross site is currently broken :-(
Extension r = null;
for (Extension ext : getExtensions()) {
if (ext instanceof Responsive) {
r = ext;
}
}
removeExtension(r);
}
}
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;
}
@Override
protected void addExtension(Extension extension) {
ContextMenu.this.addExtension(extension);
}
@Override
protected void addExtension(Extension extension) {
ContextMenu.this.addExtension(extension);
}