mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-02 19:27:57 +08:00
Double click mode for Tree #PL-3097
This commit is contained in:
parent
bfa86e5a3c
commit
353aa33dea
@ -60,7 +60,7 @@ def webToolkitLegacyModule = project(':cuba-web6-toolkit')
|
||||
def webModuleThemes = project(':cuba-web-themes')
|
||||
def webLegacyModuleThemes = project(':cuba-web6-themes')
|
||||
|
||||
def vaadinVersion = '7.1.8.cuba.2'
|
||||
def vaadinVersion = '7.1.8.cuba.3'
|
||||
def vaadinLegacyVersion = '6.6.1.140'
|
||||
def springVersion = '3.1.3.RELEASE'
|
||||
|
||||
|
@ -8,6 +8,7 @@ package com.haulmont.cuba.web.toolkit.ui.client.tree;
|
||||
import com.haulmont.cuba.web.toolkit.ui.CubaTree;
|
||||
import com.vaadin.client.ApplicationConnection;
|
||||
import com.vaadin.client.UIDL;
|
||||
import com.vaadin.client.communication.StateChangeEvent;
|
||||
import com.vaadin.client.ui.ShortcutActionHandler;
|
||||
import com.vaadin.client.ui.VTree;
|
||||
import com.vaadin.client.ui.tree.TreeConnector;
|
||||
@ -25,11 +26,19 @@ public class CubaTreeConnector extends TreeConnector {
|
||||
return (CubaTreeWidget) super.getWidget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CubaTreeState getState() {
|
||||
return (CubaTreeState) super.getState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
|
||||
super.updateFromUIDL(uidl, client);
|
||||
|
||||
getWidget().setContextMenuHandling(false);
|
||||
// We may have actions attached to this panel
|
||||
getWidget().setDoubleClickHandling(false);
|
||||
|
||||
// We may have actions attached to this tree
|
||||
if (uidl.getChildCount() > 1) {
|
||||
final int cnt = uidl.getChildCount();
|
||||
for (int i = 1; i < cnt; i++) {
|
||||
@ -44,6 +53,15 @@ public class CubaTreeConnector extends TreeConnector {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateChanged(StateChangeEvent stateChangeEvent) {
|
||||
super.onStateChanged(stateChangeEvent);
|
||||
|
||||
if (stateChangeEvent.hasPropertyChanged("doubleClickMode")) {
|
||||
getWidget().doubleClickMode = getState().doubleClickMode;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPopupSelection(UIDL uidl) {
|
||||
return Boolean.TRUE.equals(uidl.getBooleanAttribute("popupSelection"));
|
||||
@ -53,4 +71,4 @@ public class CubaTreeConnector extends TreeConnector {
|
||||
protected VTree.TreeNode createNode(UIDL childUidl) {
|
||||
return getWidget().new CubaTreeNode();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
|
||||
package com.haulmont.cuba.web.toolkit.ui.client.tree;
|
||||
|
||||
import com.google.gwt.core.client.Scheduler;
|
||||
import com.google.gwt.user.client.DOM;
|
||||
import com.google.gwt.user.client.Event;
|
||||
import com.vaadin.client.ui.ShortcutActionHandler;
|
||||
@ -20,6 +21,12 @@ public class CubaTreeWidget extends VTree implements ShortcutActionHandler.Short
|
||||
|
||||
protected boolean contextMenuHandling = false;
|
||||
|
||||
protected boolean doubleClickHandling = false;
|
||||
|
||||
protected long lastDoubleClickHandled = 0;
|
||||
|
||||
protected boolean doubleClickMode = false;
|
||||
|
||||
@Override
|
||||
public ShortcutActionHandler getShortcutActionHandler() {
|
||||
return shortcutHandler;
|
||||
@ -53,6 +60,89 @@ public class CubaTreeWidget extends VTree implements ShortcutActionHandler.Short
|
||||
contextMenuHandling = true;
|
||||
handleClickSelection(false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toggleSelection() {
|
||||
if (!doubleClickMode) {
|
||||
super.toggleSelection();
|
||||
} else {
|
||||
if (selectable) {
|
||||
CubaTreeWidget.this.setSelected(this, doubleClickHandling || !isSelected());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fireClick(Event evt) {
|
||||
doubleClickHandling = doubleClickMode && DOM.eventGetType(evt) == Event.ONDBLCLICK;
|
||||
|
||||
super.fireClick(evt);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isNeedToHandleClick() {
|
||||
if (!doubleClickMode) {
|
||||
return super.isNeedToHandleClick();
|
||||
} else {
|
||||
return !doubleClickHandling;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeEventCommand(final Scheduler.ScheduledCommand command) {
|
||||
if (!doubleClickMode || doubleClickHandling) {
|
||||
super.executeEventCommand(command);
|
||||
} else {
|
||||
Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {
|
||||
|
||||
private long scheduledTimestamp = System.currentTimeMillis();
|
||||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
if (!doubleClickHandling && lastDoubleClickHandled < scheduledTimestamp) {
|
||||
command.execute();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}, 250);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareToFireClick(int eventType) {
|
||||
if (eventType == Event.ONDBLCLICK && doubleClickHandling) {
|
||||
if (selectable) {
|
||||
CubaTreeWidget.this.deselectAll();
|
||||
|
||||
TreeNode targetNode = getNodeByKey(key);
|
||||
targetNode.setFocused(true);
|
||||
|
||||
targetNode.setSelected(true);
|
||||
selectedIds.add(targetNode.key);
|
||||
|
||||
client.updateVariable(paintableId, "selected",
|
||||
selectedIds.toArray(new String[selectedIds.size()]),
|
||||
false);
|
||||
selectionHasChanged = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isNeedToSendDoubleClick(int eventType, boolean sendClickEventNow) {
|
||||
if (eventType != Event.ONDBLCLICK || !doubleClickMode) {
|
||||
return super.isNeedToSendDoubleClick(eventType, sendClickEventNow);
|
||||
} else {
|
||||
return doubleClickHandling;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setDoubleClickHandling(boolean doubleClickHandling) {
|
||||
this.doubleClickHandling = doubleClickHandling;
|
||||
|
||||
lastDoubleClickHandled = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void setContextMenuHandling(boolean contextMenuHandling) {
|
||||
@ -62,4 +152,4 @@ public class CubaTreeWidget extends VTree implements ShortcutActionHandler.Short
|
||||
public boolean isSelected(TreeNode treeNode) {
|
||||
return selectedIds.contains(treeNode.key) && !contextMenuHandling;
|
||||
}
|
||||
}
|
||||
}
|
@ -29,6 +29,7 @@ import com.haulmont.cuba.web.gui.components.WebComponentsHelper;
|
||||
import com.haulmont.cuba.web.gui.components.WebFrameActionsHolder;
|
||||
import com.haulmont.cuba.web.toolkit.VersionedThemeResource;
|
||||
import com.haulmont.cuba.web.toolkit.ui.CubaTimer;
|
||||
import com.haulmont.cuba.web.toolkit.ui.CubaTree;
|
||||
import com.haulmont.cuba.web.toolkit.ui.CubaVerticalActionsLayout;
|
||||
import com.vaadin.event.ItemClickEvent;
|
||||
import com.vaadin.server.Sizeable;
|
||||
@ -1062,7 +1063,8 @@ public class WebWindow implements Window, Component.Wrapper,
|
||||
});
|
||||
} else if (lookupComponent instanceof Tree) {
|
||||
final Tree tree = (Tree) lookupComponent;
|
||||
final com.vaadin.ui.Tree treeComponent = (com.vaadin.ui.Tree) WebComponentsHelper.unwrap(tree);
|
||||
final CubaTree treeComponent = (CubaTree) WebComponentsHelper.unwrap(tree);
|
||||
treeComponent.setDoubleClickMode(true);
|
||||
treeComponent.addItemClickListener(new ItemClickEvent.ItemClickListener() {
|
||||
@Override
|
||||
public void itemClick(ItemClickEvent event) {
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
package com.haulmont.cuba.web.toolkit.ui;
|
||||
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.tree.CubaTreeState;
|
||||
import com.vaadin.event.Action;
|
||||
import com.vaadin.event.ActionManager;
|
||||
import com.vaadin.event.ShortcutListener;
|
||||
@ -21,12 +22,32 @@ import java.util.Set;
|
||||
*/
|
||||
public class CubaTree extends Tree {
|
||||
|
||||
private static final String POPUP_SELECTION = "popupSelection";
|
||||
protected static final String POPUP_SELECTION = "popupSelection";
|
||||
|
||||
private boolean popupSelection = false;
|
||||
protected boolean popupSelection = false;
|
||||
|
||||
protected ActionManager shortcutsManager = new ActionManager();
|
||||
|
||||
@Override
|
||||
protected CubaTreeState getState() {
|
||||
return (CubaTreeState) super.getState();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CubaTreeState getState(boolean markAsDirty) {
|
||||
return (CubaTreeState) super.getState(markAsDirty);
|
||||
}
|
||||
|
||||
public void setDoubleClickMode(boolean doubleClickMode) {
|
||||
if (getState(false).doubleClickMode != doubleClickMode) {
|
||||
getState().doubleClickMode = doubleClickMode;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDoubleClickMode() {
|
||||
return getState(false).doubleClickMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeVariables(Object source, Map<String, Object> variables) {
|
||||
super.changeVariables(source, variables);
|
||||
@ -58,5 +79,4 @@ public class CubaTree extends Tree {
|
||||
super.removeShortcutListener(listener);
|
||||
shortcutsManager.removeAction(listener);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2013 Haulmont. All rights reserved.
|
||||
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
|
||||
*/
|
||||
|
||||
package com.haulmont.cuba.web.toolkit.ui.client.tree;
|
||||
|
||||
import com.vaadin.shared.ui.tree.TreeState;
|
||||
|
||||
/**
|
||||
* @author artamonov
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CubaTreeState extends TreeState {
|
||||
|
||||
public boolean doubleClickMode = false;
|
||||
}
|
Loading…
Reference in New Issue
Block a user