本文整理汇总了Java中com.vaadin.ui.JavaScript类的典型用法代码示例。如果您正苦于以下问题:Java JavaScript类的具体用法?Java JavaScript怎么用?Java JavaScript使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JavaScript类属于com.vaadin.ui包,在下文中一共展示了JavaScript类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: callBlind
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
void callBlind(final JavaScriptCallback<Void> javaScriptCallback)
{
final Stopwatch timer = Stopwatch.createStarted();
final ScheduledFuture<?> future = createTimeoutHook();
JavaScript.getCurrent().addFunction(hookName, new JavaScriptFunction()
{
boolean done = false;
private static final long serialVersionUID = 1L;
@Override
public void call(JsonArray arguments)
{
logger.debug("Handling response for " + hookName);
if (!done)
{
done = true;
javaScriptCallback.callback(null);
}
else
{
logger.warn("This appears to have been a duplicate callback, ignoring it!");
}
future.cancel(false);
removeHooks(hookName, errorHookName);
if (timer.elapsed(TimeUnit.MILLISECONDS) > EXPECTED_RESPONSE_TIME_MS)
{
logger.warn(jsToExecute + "\n\nResponded after {}ms", timer.elapsed(TimeUnit.MILLISECONDS));
}
}
});
setupErrorHook(future);
JavaScript.getCurrent().execute(wrapJSInTryCatchBlind(jsToExecute));
}
示例2: FileExample
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
public FileExample() {
setCaption("Interactive SVG");
addComponent(new MLabel(
"A simple example from an svg file using Embedded component. Unlike with Image component, the SVGs JS etc are active. The example also demonstrates how to provide a trivial server side integration API for the SVG."));
Embedded svg = new Embedded();
svg.setWidth("400px");
svg.setHeight("400px");
svg.setSource(new ClassResource("/pull.svg"));
// Expose a JS hook that pull.svg file calls when clicked
JavaScript.getCurrent().addFunction("callMyVaadinFunction", (JsonArray arguments) -> {
Notification.show("Message from SVG:" + arguments.getString(0));
});
addComponent(svg);
}
示例3: registerJavaScriptFunctionsIfNeeded
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
@SuppressWarnings("serial")
private final void registerJavaScriptFunctionsIfNeeded()
{
if (jsFunctionsRegistered.getAndSet(true))
{
return; // already registered
}
final JavaScript javaScript = JavaScript.getCurrent();
javaScript.addFunction(JS_FUNC_OnSwipe, new JavaScriptFunction()
{
@Override
public void call(final JsonArray arguments)
{
invokeOnSwipe(arguments);
}
});
}
示例4: getCookieValue
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
public static void getCookieValue(String key, final Callback callback) {
final String callbackid = "hybridbpmcookie"+UUID.randomUUID().toString().substring(0,8);
JavaScript.getCurrent().addFunction(callbackid, new JavaScriptFunction() {
@Override
public void call(JsonArray arguments) {
JavaScript.getCurrent().removeFunction(callbackid);
if(arguments.length() == 0) {
callback.onValue(null);
} else {
callback.onValue(arguments.getString(0));
}
}
});
JavaScript.getCurrent().execute(String.format(
"var nameEQ = \"%2$s=\";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++) {var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) {%1$s( c.substring(nameEQ.length,c.length)); return;};} %1$s();",
callbackid,key
));
}
示例5: detectCookieValue
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
public static void detectCookieValue(String key, final Callback callback) {
final String callbackid = "viritincookiecb"+UUID.randomUUID().toString().substring(0,8);
JavaScript.getCurrent().addFunction(callbackid, new JavaScriptFunction() {
private static final long serialVersionUID = -3426072590182105863L;
@Override
public void call(JsonArray arguments) {
JavaScript.getCurrent().removeFunction(callbackid);
if(arguments.length() == 0) {
callback.onValueDetected(null);
} else {
callback.onValueDetected(arguments.getString(0));
}
}
});
JavaScript.getCurrent().execute(String.format(
"var nameEQ = \"%2$s=\";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++) {var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) {%1$s( c.substring(nameEQ.length,c.length)); return;};} %1$s();",
callbackid,key
));
}
示例6: requestClose
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
/**
* Do on test closing
*
* @param event
*/
public void requestClose(@Observes final CloseTestEvent event) {
log.debug("close requested");
if (requestBack) {
log.debug("closing ProcessUI with history back");
JavaScript javaScript = ui.getPage().getJavaScript();
javaScript.execute("window.history.back();");
ui.requestClose();
} else {
String path = VaadinServlet.getCurrent().getServletContext().getContextPath();
ui.getPage().setLocation(path + CLOSE_URL);
// this is also possible way but not for SWT browser
// Page.getCurrent().getJavaScript().execute("window.setTimeout(function(){/*window.open('','_self','');*/window.close();},10);")
log.debug("closing ProcessUI");
ui.requestClose();
}
}
示例7: showHelpBrowserWindow
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
public static void showHelpBrowserWindow(String guid) {
JavaScript javaScript = MainUI.getCurrent().getPage().getJavaScript();
if (!useFirstName) {
javaScript.execute(closeNativeWindow(HELP_WINDOW_NAME_1));
} else {
javaScript.execute(closeNativeWindow(HELP_WINDOW_NAME_2));
}
MainUI.getCurrent().getPage().open("/WebHelp/" + guid,
useFirstName ? HELP_WINDOW_NAME_1 : HELP_WINDOW_NAME_2);
useFirstName = !useFirstName;
}
示例8: setBeforePageUnloadMessage
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
public static void setBeforePageUnloadMessage(final String message)
{
final JavaScript javaScript = Page.getCurrent().getJavaScript();
if (message == null || message.trim().isEmpty())
{
javaScript.execute("$(window).off('beforeunload');");
}
else
{
// TODO: escape the message
javaScript.execute("$(window).on('beforeunload', function() { return \"" + message + "\"; });");
}
}
示例9: enable
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
public synchronized void enable(final Component component, final SwipeHandler handler)
{
Preconditions.checkNotNull(component, "component is null");
final String componentId = component.getId();
Preconditions.checkNotNull(componentId, "componentId is null");
final ComponentSwipe swipe = new ComponentSwipe(componentId, handler);
component2swipe.put(component, swipe);
componentId2swipe.put(componentId, swipe);
registerJavaScriptFunctionsIfNeeded();
final JavaScript javaScript = JavaScript.getCurrent();
javaScript.execute(""
+ "if (!window.swipesMap) { window.swipesMap={}; }"
//
+ "window.swipesMap['" + componentId + "'] = Swiped.init({"
+ "query: '#" + componentId + "'"
+ ", left: 300"
+ ", right: 300"
+ ", tolerance: 200"
+ ", onOpen: function() { " + JS_FUNC_OnSwipe + "('" + componentId + "'); }"
+ "});"
//
+ "\n console.log('Enabled swiping for element: " + componentId + "');"
);
}
示例10: destroy
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
public void destroy()
{
JavaScript.getCurrent().execute("window.swipesMap['" + componentId + "'].destroy(false);"); // isRemoveNode=false
}
示例11: setCookie
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
public static void setCookie(String key, String value, String path) {
JavaScript.getCurrent().execute(String.format(
"document.cookie = \"%s=%s; path=%s\";", key, value, path
));
}
示例12: addTypeStyle
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
private static void addTypeStyle(final Long tagId, final String color) {
final JavaScript javaScript = UI.getCurrent().getPage().getJavaScript();
UI.getCurrent()
.access(() -> javaScript.execute(
HawkbitCommonUtil.getScriptSMHighlightWithColor(".v-table-row-distribution-upload-type-" + tagId
+ "{background-color:" + color + " !important;background-image:none !important }")));
}
示例13: _jsSetTimeStep
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
private void _jsSetTimeStep(TimeStep timeStep) {
JavaScript.getCurrent()
.execute("document.getElementById('" + LIVE_CHART_ID
+ "').firstElementChild.contentDocument.getElementsByClassName('stepli')["
+ timeStep.ordinal() + "].click();");
}
示例14: setCookie
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
public static void setCookie(String key, String value, LocalDateTime expirationTime) {
String expires = toCookieGMTDate(expirationTime);
JavaScript.getCurrent().execute(String.format(
"document.cookie = \"%s=%s; Expires=%s\";", key, value, expires
));
}
示例15: removeHooks
import com.vaadin.ui.JavaScript; //导入依赖的package包/类
void removeHooks(final String hook1, final String hook2)
{
final JavaScript js = JavaScript.getCurrent();
js.removeFunction(hook1);
js.removeFunction(hook2);
}