0

I have a component in a panel, with DragSourceExtension, I can pass any data by DragData, but I can not get relativeX and Y with DragStartEvent.

  • I can get relativeX and Y of end position with DropEvent.

In vaadin 7, with DragAndDropWrapper.WrapperTransferable (transferable), we can get relativeX and Y when start draging:

transferable.getMouseDownEvent().getClientX()
transferable.getMouseDownEvent().getClientY()

UPDATE: this is some part of code:

DropTargetExtension<AbsoluteLayout> absoluteLayoutDropTargetExtension = new DropTargetExtension<>(sceneLayout);
...
absoluteLayoutDropTargetExtension.addDropListener(event -> {
Optional<Object> source = event.getDragData();
int x = event.getMouseEventDetails().getRelativeX();
int y = event.getMouseEventDetails().getRelativeY();

with x and y is current mouse position, but I have not start position to calculate diff

UPDATE 2: by this doc Component and UI Extension, I test extension example.

public class CapsLockWarning extends AbstractExtension {
// You could pass it in the constructor
public CapsLockWarning(PasswordField field) {
    super.extend(field);
    System.out.println("CapsLockWarning");
}

// Or in an extend() method
public void extend(PasswordField field) {
    super.extend(field);
}

// Or with a static helper
public static void addTo(PasswordField field) {
    new CapsLockWarning(field);
}

}

@Connect(CapsLockWarning.class)
public class CapsLockWarningConnector extends AbstractExtensionConnector {

public CapsLockWarningConnector() {
    super();
    System.out.println("CapsLockWarningConnector");
}

@Override
protected void extend(ServerConnector target) {
    // Get the extended widget
    final Widget pw = ((ComponentConnector) target).getWidget();

    // Preparations for the added feature
    final VOverlay warning = new VOverlay();
    warning.setOwner(pw);
    warning.add(new HTML("Caps Lock is enabled!"));
    Window.alert("ssss");

    // Add an event handler
    pw.addDomHandler(new KeyPressHandler() {
        public void onKeyPress(KeyPressEvent event) {
            if (isEnabled() && isCapsLockOn(event)) {
                warning.showRelativeTo(pw);
                UiUtilities.showMessage("oh");
            } else {
                warning.hide();
            }
        }
    }, KeyPressEvent.getType());
}

private boolean isCapsLockOn(KeyPressEvent e) {
    return e.isShiftKeyDown() ^
            Character.isUpperCase(e.getCharCode());
}

}

UI:

    txtPassword = new PasswordField(bundle.getString("common.password"));
    txtPassword.setRequiredIndicatorVisible(true);
    binder.forField(txtPassword).asRequired(MessageFormat.format(bundle.getString("common.error.isRequiredFor"), bundle.getString("common.password")))
            .bind(HostEntity::getPassword, HostEntity::setPassword);
    txtPassword.addStyleName("inline-label");
    new CapsLockWarning(txtPassword);
    form.addComponent(txtPassword);

but, CapsLockWarningConnector's constructor did'nt run and no action happen in UI

Alireza
  • 126
  • 1
  • 14
  • I think you need to create some sort of an extension for that. But what for do you need X,Y? What is the actual problem? – pirho Feb 28 '18 at 11:33
  • @pirho I need to create a map and make a json to save an load it. for this reason, i need x and y of all objects. – Alireza Feb 28 '18 at 12:45
  • Just some custom implementation or OL / Leaflet map? – pirho Feb 28 '18 at 13:02
  • @pirho lets I ask another question: how move an image (for example) that added to an absolutepanel from a position to another? do I need to reset top and left of image on addDropListener method of DropTargetExtension? – Alireza Feb 28 '18 at 13:30
  • I can try to answer but it would be better if you updated your question and added some code what you are currently trying - like in the above comments example - and where you are stuck. I am not sure what you mean by _resetting_? – pirho Feb 28 '18 at 13:46
  • @pirho some part of code was added – Alireza Mar 03 '18 at 08:45
  • Ok, I was guessing the same. It seems that you need the MouseDown event. [This](https://stackoverflow.com/q/45056632/6413377) might help you. – pirho Mar 03 '18 at 09:17
  • @pirho: please see the Updte – Alireza Mar 05 '18 at 06:58

0 Answers0