diff --git a/enhanced-window-opener-addon/pom.xml b/enhanced-window-opener-addon/pom.xml index d84ec32..e328ead 100644 --- a/enhanced-window-opener-addon/pom.xml +++ b/enhanced-window-opener-addon/pom.xml @@ -5,7 +5,7 @@ org.vaadin.addon enhanced-window-opener-root - 0.1.1 + 0.1.2 ../ enhanced-window-opener diff --git a/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/EnhancedBrowserWindowOpener.java b/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/EnhancedBrowserWindowOpener.java index 2f4aa83..fd538eb 100644 --- a/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/EnhancedBrowserWindowOpener.java +++ b/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/EnhancedBrowserWindowOpener.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Marco Collovati (mcollovati@gmail.com) + * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import java.time.Instant; import java.util.Objects; +import com.vaadin.event.ShortcutListener; import com.vaadin.server.AbstractClientConnector; import com.vaadin.server.BrowserWindowOpener; import com.vaadin.server.Resource; @@ -142,6 +143,19 @@ public EnhancedBrowserWindowOpener popupBlockerWorkaround(boolean active) { return this; } + public EnhancedBrowserWindowOpener withShortcut(int keyCode, int... modifiers) { + getState().shortcut = new EnhancedBrowserWindowOpenerState.Shortcut(keyCode, modifiers); + return this; + } + public EnhancedBrowserWindowOpener withShortcut(ShortcutListener shortcutListener) { + return withShortcut(shortcutListener.getKeyCode(), shortcutListener.getModifiers()); + } + + public EnhancedBrowserWindowOpener withoutShortcut() { + getState().shortcut = null; + return this; + } + /** * Sets a {@code resource} for this instance whose content will be generated * when the window will be opened. diff --git a/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/StreamResourceCustomizer.java b/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/StreamResourceCustomizer.java index 0a561be..5582df2 100644 --- a/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/StreamResourceCustomizer.java +++ b/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/StreamResourceCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Marco Collovati (mcollovati@gmail.com) + * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/client/EnhancedBrowserWindowOpenerConnector.java b/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/client/EnhancedBrowserWindowOpenerConnector.java index 15c5847..1c6ceb2 100644 --- a/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/client/EnhancedBrowserWindowOpenerConnector.java +++ b/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/client/EnhancedBrowserWindowOpenerConnector.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Marco Collovati (mcollovati@gmail.com) + * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,14 +18,27 @@ import java.util.Map; import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.KeyDownEvent; +import com.google.gwt.event.dom.client.KeyDownHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.http.client.URL; +import com.google.gwt.user.client.DOM; +import com.google.gwt.user.client.Event; +import com.google.gwt.user.client.ui.KeyboardListener; +import com.google.gwt.user.client.ui.KeyboardListenerCollection; +import com.google.gwt.user.client.ui.RootPanel; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; import com.vaadin.client.VConsole; +import com.vaadin.client.WidgetUtil; import com.vaadin.client.annotations.OnStateChange; import com.vaadin.client.extensions.BrowserWindowOpenerConnector; import com.vaadin.client.ui.VMenuBar; +import com.vaadin.client.ui.VUI; import com.vaadin.client.ui.menubar.MenuBarConnector; import com.vaadin.shared.ui.BrowserWindowOpenerState; import com.vaadin.shared.ui.Connect; @@ -42,6 +55,8 @@ public class EnhancedBrowserWindowOpenerConnector extends BrowserWindowOpenerCon private JavaScriptObject window; private HandlerRegistration menuClickHandlerReg; + private HandlerRegistration shortcutHandler; + private ShortcutKeyCombination shortcutKeyCombination; @Override public void onClick(ClickEvent event) { @@ -54,6 +69,8 @@ public void onClick(ClickEvent event) { @Override public void onUnregister() { + removeShortcutHandler(); + shortcutKeyCombination = null; window = null; super.onUnregister(); if (menuClickHandlerReg != null) { @@ -93,6 +110,79 @@ public void onMenuItemSelected(ServerSideIdAwareMenuItem.MenuItemSelectedEvent e }, ServerSideIdAwareMenuItem.MenuItemSelectedEvent.getType()); } + @OnStateChange("shortcut") + private void onShortcutChanged() { + VConsole.log("=============== Shortcut changed " + getState().shortcut); + + + ShortcutKeyCombination newShortcutKeyCombination; + + if (getState().shortcut == null) { + removeShortcutHandler(); + shortcutKeyCombination = null; + } else { + shortcutKeyCombination = new ShortcutKeyCombination( + getState().shortcut.keyCode, getState().shortcut.modifiers + ); + if (shortcutHandler == null) { + final VUI ui = findUI(); + Widget shortcutContextWidget = ui; + if (getConnection().getConfiguration().isStandalone()) { + // Listen to body for standalone apps (#19392) + shortcutContextWidget = RootPanel.get(); // document body + } + + if (shortcutContextWidget != null) { + // Only react to body and elements inside the UI + shortcutHandler = shortcutContextWidget.addDomHandler(new KeyDownHandler() { + @Override + public void onKeyDown(KeyDownEvent event) { + Element target = Element.as(event.getNativeEvent().getEventTarget()); + if (target == Document.get().getBody() + || ui.getElement().isOrHasChild(target)) { + // Only react to body and elements inside the UI + Event castedEvent = event.getNativeEvent().cast(); + EnhancedBrowserWindowOpenerConnector.this.handleKeyboardEvent(castedEvent); + } + } + }, KeyDownEvent.getType()); + } else { + // TODO: log + } + } + } + } + + + + private void removeShortcutHandler() { + if (shortcutHandler != null) { + shortcutHandler.removeHandler(); + } + } + + private void handleKeyboardEvent(final Event event) { + final char keyCode = (char) DOM.eventGetKeyCode(event); + if (keyCode == 0 || shortcutKeyCombination == null) { + return; + } + final int modifiers = KeyboardListenerCollection + .getKeyboardModifiers(event); + final ShortcutKeyCombination kc = new ShortcutKeyCombination(keyCode, modifiers); + + if (shortcutKeyCombination.equals(kc)) { + onClick(null); + } + } + + private VUI findUI() { + if (getParent() instanceof ComponentConnector) { + Element element = ((ComponentConnector) getParent()).getWidget().getElement(); + return WidgetUtil.findWidget(element, VUI.class); + } + return null; + } + @OnStateChange("lastUpdated") private void onLastUpdateChanged() { if (!getState().clientSide && getState().lastUpdated > 0) { @@ -143,6 +233,7 @@ private String addParametersAndFragment(String url) { return url; } + private static native JavaScriptObject openWindow(String name, String features) /*-{ return $wnd.open(undefined, name, features); }-*/; @@ -164,3 +255,78 @@ private static native void wrapMenu(VMenuBar hostReference) /*-{ } }-*/; } + +/** + * Code taken from {@link com.vaadin.client.ui.ShortcutActionHandler} + * + * + * Copyright 2000-2018 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +class ShortcutKeyCombination { + + public static final int SHIFT = 16; + public static final int CTRL = 17; + public static final int ALT = 18; + public static final int META = 91; + + char keyCode = 0; + private int modifiersMask; + + public ShortcutKeyCombination() { + } + + ShortcutKeyCombination(char kc, int modifierMask) { + keyCode = kc; + modifiersMask = modifierMask; + } + + ShortcutKeyCombination(int kc, int[] modifiers) { + keyCode = (char) kc; + + modifiersMask = 0; + if (modifiers != null) { + for (int modifier : modifiers) { + switch (modifier) { + case ALT: + modifiersMask = modifiersMask + | KeyboardListener.MODIFIER_ALT; + break; + case CTRL: + modifiersMask = modifiersMask + | KeyboardListener.MODIFIER_CTRL; + break; + case SHIFT: + modifiersMask = modifiersMask + | KeyboardListener.MODIFIER_SHIFT; + break; + case META: + modifiersMask = modifiersMask + | KeyboardListener.MODIFIER_META; + break; + default: + break; + } + } + } + } + + public boolean equals(ShortcutKeyCombination other) { + if (keyCode == other.keyCode && modifiersMask == other.modifiersMask) { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/client/ServerSideIdAwareMenuItem.java b/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/client/ServerSideIdAwareMenuItem.java index ea7af8e..4fb40d9 100644 --- a/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/client/ServerSideIdAwareMenuItem.java +++ b/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/client/ServerSideIdAwareMenuItem.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016-2017 Marco Collovati (mcollovati@gmail.com) + * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/shared/EnhancedBrowserWindowOpenerState.java b/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/shared/EnhancedBrowserWindowOpenerState.java index 6a3f5e3..a5052f6 100644 --- a/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/shared/EnhancedBrowserWindowOpenerState.java +++ b/enhanced-window-opener-addon/src/main/java/org/vaadin/addon/ewopener/shared/EnhancedBrowserWindowOpenerState.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Marco Collovati (mcollovati@gmail.com) + * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,9 @@ */ package org.vaadin.addon.ewopener.shared; +import java.io.Serializable; +import java.util.Arrays; + import com.vaadin.shared.ui.BrowserWindowOpenerState; public class EnhancedBrowserWindowOpenerState extends BrowserWindowOpenerState { @@ -26,4 +29,24 @@ public class EnhancedBrowserWindowOpenerState extends BrowserWindowOpenerState { public boolean popupBlockerWorkaround = false; public int menuItem = 0; + public Shortcut shortcut; + + public static class Shortcut implements Serializable { + public int keyCode; + + public int[] modifiers; + + public Shortcut() { + } + + public Shortcut(int keyCode, int[] modifiers) { + this.keyCode = keyCode; + this.modifiers = modifiers; + } + + @Override + public String toString() { + return "KeyCode: " + keyCode + " - modifiers: [" + Arrays.toString(modifiers) + "]"; + } + } } diff --git a/enhanced-window-opener-addon/src/test/java/org/vaadin/addon/ewopener/EnhancedBrowserWindowOpenerTest.java b/enhanced-window-opener-addon/src/test/java/org/vaadin/addon/ewopener/EnhancedBrowserWindowOpenerTest.java index 71fe29c..ea4436f 100644 --- a/enhanced-window-opener-addon/src/test/java/org/vaadin/addon/ewopener/EnhancedBrowserWindowOpenerTest.java +++ b/enhanced-window-opener-addon/src/test/java/org/vaadin/addon/ewopener/EnhancedBrowserWindowOpenerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Marco Collovati (mcollovati@gmail.com) + * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/enhanced-window-opener-demo/pom.xml b/enhanced-window-opener-demo/pom.xml index 191fccd..08d2d05 100644 --- a/enhanced-window-opener-demo/pom.xml +++ b/enhanced-window-opener-demo/pom.xml @@ -4,7 +4,7 @@ org.vaadin.addon enhanced-window-opener-root - 0.1.1 + 0.1.2 ../ enhanced-window-opener-demo diff --git a/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/AboutUI.java b/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/AboutUI.java new file mode 100644 index 0000000..47f10c9 --- /dev/null +++ b/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/AboutUI.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.vaadin.addon.ewopener.demo; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Label; +import com.vaadin.ui.UI; + +@Theme("demo") +public class AboutUI extends UI { + @Override + protected void init(VaadinRequest request) { + setContent(new Label("EnhancedWindowOpener")); + } +} diff --git a/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/DemoUI.java b/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/DemoUI.java index c9d2edd..9df53bc 100644 --- a/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/DemoUI.java +++ b/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/DemoUI.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Marco Collovati (mcollovati@gmail.com) + * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,8 @@ import com.vaadin.annotations.VaadinServletConfiguration; import com.vaadin.annotations.Viewport; import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.event.ShortcutAction; +import com.vaadin.event.ShortcutListener; import com.vaadin.server.ClassResource; import com.vaadin.server.Resource; import com.vaadin.server.Sizeable; @@ -42,6 +44,7 @@ import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Label; import com.vaadin.ui.Layout; import com.vaadin.ui.Link; import com.vaadin.ui.MenuBar; @@ -69,16 +72,37 @@ public class DemoUI extends UI { private final AtomicInteger downloadCounter = new AtomicInteger(0); private Table table; + + private ShortcutListener createShortcutListener(Runnable action, int keyCode, int... modifiers) { + return new ShortcutListener("", keyCode, modifiers) { + + @Override + public void handleAction(Object sender, Object target) { + action.run(); + } + }; + } + @Override protected void init(VaadinRequest request) { - EnhancedBrowserWindowOpener opener1 = new EnhancedBrowserWindowOpener() - .popupBlockerWorkaround(true); + Button button1 = new Button("Click me"); + ShortcutListener shortcutListener = createShortcutListener( + () -> button1.click(), + ShortcutAction.KeyCode.NUM1, ShortcutAction.ModifierKey.CTRL, ShortcutAction.ModifierKey.ALT + ); + getActionManager().addAction(shortcutListener); + + EnhancedBrowserWindowOpener opener1 = new EnhancedBrowserWindowOpener() + .popupBlockerWorkaround(true) + .withShortcut(shortcutListener); button1.addClickListener(e -> { opener1.open(generateResource()); }); opener1.extend(button1); + Label shortcut1Label = new Label("Or press CTRL+ALT+1"); + EnhancedBrowserWindowOpener opener4 = new EnhancedBrowserWindowOpener() .popupBlockerWorkaround(true); @@ -106,7 +130,9 @@ protected void init(VaadinRequest request) { new EnhancedBrowserWindowOpener() .clientSide(true) .withGeneratedContent("myFileName.txt", this::generateContent) + .withShortcut(ShortcutAction.KeyCode.NUM2, ShortcutAction.ModifierKey.CTRL, ShortcutAction.ModifierKey.ALT) .doExtend(link); + Label shortcut2Label = new Label("Or press CTRL+ALT+2"); Link link2 = new Link("Click me", null); new EnhancedBrowserWindowOpener() @@ -125,6 +151,7 @@ protected void init(VaadinRequest request) { CompletableFuture.runAsync(this::doSomeLongProcessing) .thenRun(() -> getUI().access(opener5::open)); + table = new Table("Select items to download", new BeanItemContainer<>(DummyService.Person.class, DummyService.data())); table.setImmediate(true); table.setVisibleColumns("name", "age"); @@ -135,7 +162,6 @@ protected void init(VaadinRequest request) { table.setMultiSelect(true); table.setSelectable(true); - final MyPopupContent popupContent = new MyPopupContent(); Button popupButton = new Button("Open modal", event -> { Window window = new Window("Test", popupContent); @@ -175,6 +201,26 @@ protected void init(VaadinRequest request) { opener8.doExtend(menuBar, subItem); + Button button9 = new Button("Open another UI (client side)"); + EnhancedBrowserWindowOpener opener9 = new EnhancedBrowserWindowOpener(AboutUI.class) + .clientSide(true) + .withShortcut(ShortcutAction.KeyCode.NUM3, ShortcutAction.ModifierKey.CTRL, ShortcutAction.ModifierKey.ALT) + .doExtend(button9); + Label shortcutLabel9 = new Label("Or press CTRL+ALT+3"); + + Button button10 = new Button("Open another UI (popup workaround)"); + ShortcutListener shortcutListener2 = createShortcutListener( + () -> button10.click(), + ShortcutAction.KeyCode.NUM4, ShortcutAction.ModifierKey.CTRL, ShortcutAction.ModifierKey.ALT + ); + getActionManager().addAction(shortcutListener2); + EnhancedBrowserWindowOpener opener10 = new EnhancedBrowserWindowOpener(AboutUI.class) + .popupBlockerWorkaround(true) + .withShortcut(shortcutListener2) + .doExtend(button10); + button10.addClickListener(ev -> opener10.open()); + Label shortcutLabel10 = new Label("Or press CTRL+ALT+4"); + // Show it in the middle of the screen final Layout layout = new MVerticalLayout( new MLabel("Enhanced Window Opener Demo") @@ -182,14 +228,14 @@ protected void init(VaadinRequest request) { new MHorizontalLayout().add(table, 1).add( new MCssLayout( menuBar, readMarkdown("code_menu.md"), - new MVerticalLayout(readMarkdown("code1.md"), button1) + new MVerticalLayout(readMarkdown("code1.md"), button1, shortcut1Label) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined() .withMargin(false), new MVerticalLayout(readMarkdown("code2.md"), button2) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), new MVerticalLayout(readMarkdown("code7.md"), button3) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), - new MVerticalLayout(readMarkdown("code5.md"), link) + new MVerticalLayout(readMarkdown("code5.md"), link, shortcut2Label) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), new MVerticalLayout(readMarkdown("code6.md"), link2) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), @@ -198,6 +244,10 @@ menuBar, readMarkdown("code_menu.md"), new MVerticalLayout(readMarkdown("code8.md"), popupButton) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), new MVerticalLayout(readMarkdown("code4.md"), hiddenComponent) + .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), + new MVerticalLayout(readMarkdown("code_ui_client.md"), button9, shortcutLabel9) + .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false), + new MVerticalLayout(readMarkdown("code_ui_popupblocker.md"), button10, shortcutLabel10) .alignAll(Alignment.MIDDLE_CENTER).withWidthUndefined().withMargin(false) ).withFullWidth().withStyleName("demo-samples") , 5).withFullWidth() diff --git a/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/DummyService.java b/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/DummyService.java index 632dd38..b4c3439 100644 --- a/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/DummyService.java +++ b/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/DummyService.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Marco Collovati (mcollovati@gmail.com) + * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/HighlightJS.java b/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/HighlightJS.java index 86841e0..0a4d7a9 100644 --- a/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/HighlightJS.java +++ b/enhanced-window-opener-demo/src/main/java/org/vaadin/addon/ewopener/demo/HighlightJS.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Marco Collovati (mcollovati@gmail.com) + * Copyright (C) 2016-2018 Marco Collovati (mcollovati@gmail.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/enhanced-window-opener-demo/src/main/resources/org/vaadin/addon/ewopener/demo/code_ui_client.md b/enhanced-window-opener-demo/src/main/resources/org/vaadin/addon/ewopener/demo/code_ui_client.md new file mode 100644 index 0000000..e626c71 --- /dev/null +++ b/enhanced-window-opener-demo/src/main/resources/org/vaadin/addon/ewopener/demo/code_ui_client.md @@ -0,0 +1,12 @@ +## Open UI with shortcut + +Open window for another UI handling shortcut directly on client side (no need to register a shortcut listenere into the UI) + + +```java +Button button = new Button("Open another UI (client side)"); +EnhancedBrowserWindowOpener opener = new EnhancedBrowserWindowOpener(AboutUI.class) + .clientSide(true) + .withShortcut(ShortcutAction.KeyCode.NUM3, ShortcutAction.ModifierKey.CTRL, ShortcutAction.ModifierKey.ALT) + .doExtend(button); +``` \ No newline at end of file diff --git a/enhanced-window-opener-demo/src/main/resources/org/vaadin/addon/ewopener/demo/code_ui_popupblocker.md b/enhanced-window-opener-demo/src/main/resources/org/vaadin/addon/ewopener/demo/code_ui_popupblocker.md new file mode 100644 index 0000000..0decfa0 --- /dev/null +++ b/enhanced-window-opener-demo/src/main/resources/org/vaadin/addon/ewopener/demo/code_ui_popupblocker.md @@ -0,0 +1,28 @@ +## Open UI with shortcut + +Open window for another UI; popup blocker workaround activated. +Open action could also be triggered with a shortcut. + +```java +Button button = new Button("Open another UI (popup workaround)"); + + +// Shortcut action will run on server side +ShortcutListener shortcutListener = new ShortcutListener("", + ShortcutAction.KeyCode.NUM1, new int[]{ + ShortcutAction.ModifierKey.CTRL, ShortcutAction.ModifierKey.ALT +}) { + + @Override + public void handleAction(Object sender, Object target) { + button10.click() + } +}; +getActionManager().addAction(shortcutListener); + +EnhancedBrowserWindowOpener opener = new EnhancedBrowserWindowOpener(AboutUI.class) + .popupBlockerWorkaround(true) + .withShortcut(shortcutListener2) + .doExtend(button); +button.addClickListener(ev -> opener7.open()); +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index b8f722e..894059d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.vaadin.addon enhanced-window-opener-root pom - 0.1.1 + 0.1.2 Enhanced Window Opener Add-on Root Project @@ -18,7 +18,7 @@ Marco Collovati https://github.com/mcollovati - 2016 + 2016-2018 GitHub https://github.com/mcollovati/enhanced-window-opener/issues