Add a shortcut modifier util class to handle cross platform
functionality. Signed-off-by: SirWayne <dennis.melzer@bosch-si.com>
This commit is contained in:
@@ -9,12 +9,11 @@
|
||||
package org.eclipse.hawkbit.ui.common.table;
|
||||
|
||||
import org.eclipse.hawkbit.ui.common.detailslayout.AbstractTableDetailsLayout;
|
||||
import org.eclipse.hawkbit.ui.utils.ShortCutModifierUtils;
|
||||
|
||||
import com.vaadin.event.Action;
|
||||
import com.vaadin.event.Action.Handler;
|
||||
import com.vaadin.event.ShortcutAction;
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.server.WebBrowser;
|
||||
import com.vaadin.ui.Alignment;
|
||||
import com.vaadin.ui.Panel;
|
||||
import com.vaadin.ui.VerticalLayout;
|
||||
@@ -109,34 +108,21 @@ public abstract class AbstractTableLayout extends VerticalLayout {
|
||||
|
||||
private static final String SELECT_ALL_TEXT = "Select All";
|
||||
private final ShortcutAction selectAllAction = new ShortcutAction(SELECT_ALL_TEXT, ShortcutAction.KeyCode.A,
|
||||
new int[] { ShortcutAction.ModifierKey.CTRL });
|
||||
|
||||
private final ShortcutAction selectAllMacAction = new ShortcutAction(SELECT_ALL_TEXT, ShortcutAction.KeyCode.A,
|
||||
new int[] { ShortcutAction.ModifierKey.META });
|
||||
new int[] { ShortCutModifierUtils.getCtrlOrMetaModifier() });
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void handleAction(final Action action, final Object sender, final Object target) {
|
||||
if (!isSelecAllAction(action)) {
|
||||
if (!selectAllAction.equals(action)) {
|
||||
return;
|
||||
}
|
||||
table.selectAll();
|
||||
publishEvent();
|
||||
}
|
||||
|
||||
private boolean isSelecAllAction(final Action action) {
|
||||
return selectAllAction.equals(action) || selectAllMacAction.equals(action);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action[] getActions(final Object target, final Object sender) {
|
||||
|
||||
final WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
|
||||
if (webBrowser.isMacOSX()) {
|
||||
return new Action[] { selectAllMacAction };
|
||||
}
|
||||
|
||||
return new Action[] { selectAllAction };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.ui.utils;
|
||||
|
||||
import com.vaadin.event.ShortcutAction;
|
||||
import com.vaadin.server.Page;
|
||||
import com.vaadin.server.WebBrowser;
|
||||
|
||||
/**
|
||||
* On different systems there are different modifier for short cuts. This
|
||||
* utility class handles the cross-platform functionality.
|
||||
*/
|
||||
public final class ShortCutModifierUtils {
|
||||
|
||||
private ShortCutModifierUtils() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ctrl or meta modifier depending on the platform.
|
||||
*
|
||||
* @return on mac return
|
||||
* {@link com.vaadin.event.ShortcutAction.ModifierKey#META} other
|
||||
* platform return
|
||||
* {@link com.vaadin.event.ShortcutAction.ModifierKey#CTRL}
|
||||
*/
|
||||
public static int getCtrlOrMetaModifier() {
|
||||
final WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
|
||||
if (webBrowser.isMacOSX()) {
|
||||
return ShortcutAction.ModifierKey.META;
|
||||
}
|
||||
|
||||
return ShortcutAction.ModifierKey.CTRL;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user