Example usage for com.google.gwt.event.logical.shared ValueChangeEvent fire

List of usage examples for com.google.gwt.event.logical.shared ValueChangeEvent fire

Introduction

In this page you can find the example usage for com.google.gwt.event.logical.shared ValueChangeEvent fire.

Prototype

public static <T> void fire(HasValueChangeHandlers<T> source, T value) 

Source Link

Document

Fires a value change event on all registered handlers in the handler manager.

Usage

From source file:org.kie.workbench.common.forms.jbpm.client.document.DocumentFieldRendererViewImpl.java

License:Apache License

@Override
public void setValue(DocumentData value, boolean fireEvents) {
    if (this.value == value) {
        return;//from  w  w w  .  ja va 2 s  .c  o m
    }
    if (value == null || value.getStatus().equals(DocumentStatus.NEW) || !value.equals(this.value)) {

        this.value = value;

        linkContainer.clear();
        if (this.value != null) {

            Anchor link = new Anchor();
            link.setText(value.getFileName() + " (" + calculateSize() + ")");

            if (value.getLink() == null) {
                link.setEnabled(false);
                link.setHref("#");
                link.addClickHandler(event -> {
                    return;
                });
            } else {
                link.setHref(value.getLink());
                link.setTarget("_blank");
            }
            linkContainer.add(link);
        }

        if (fireEvents) {
            ValueChangeEvent.fire(this, this.value);
        }
    }
}

From source file:org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.DocumentUpload.java

License:Apache License

@Override
public void doUpload(final Document document, File file) {
    if (!enabled) {
        return;//from   w  w  w  . j  a v  a 2  s .c  o m
    }

    DocumentData documentData = new DocumentData(document.getId(), document.getName(), document.getSize(),
            document.getUrl(), (long) document.getLastModified());

    DocumentPreview preview = render(documentData);

    DocumentPreviewStateActionsHandlerImpl handler = new DocumentPreviewStateActionsHandlerImpl(
            DocumentPreviewState.PENDING);

    DocumentPreviewStateAction abortAction = new DocumentPreviewStateAction(
            translationService.getTranslation(Constants.DocumentUploadViewImplAbort),
            () -> uploader.remove(document.getId(), () -> doRemove(preview)));

    handler.addStateActions(DocumentPreviewState.UPLOADING, Collections.singletonList(abortAction));

    DocumentPreviewStateAction removeAction = new DocumentPreviewStateAction(
            translationService.getTranslation(Constants.DocumentUploadViewImplRemove),
            () -> uploader.remove(document.getId(), () -> doRemove(preview)));

    handler.addStateActions(DocumentPreviewState.PENDING, Collections.singletonList(removeAction));
    handler.addStateActions(DocumentPreviewState.UPLOADED, Collections.singletonList(removeAction));

    final Command startUploadCallback = () -> handler.notifyStateChange(DocumentPreviewState.UPLOADING);
    final ParameterizedCommand<Boolean> onFinishUpload = success -> {
        if (success) {
            handler.notifyStateChange(DocumentPreviewState.UPLOADED);
        } else {
            handler.notifyStateChange(DocumentPreviewState.ERROR);
        }
    };

    DocumentPreviewStateAction retryAction = new DocumentPreviewStateAction(
            translationService.getTranslation(Constants.DocumentUploadViewImplRetry), () -> {
                uploader.remove(document.getId(),
                        () -> uploader.upload(document.getId(), file, startUploadCallback, onFinishUpload));
            });

    handler.addStateActions(DocumentPreviewState.ERROR, Arrays.asList(removeAction, retryAction));

    preview.setStateHandler(handler);

    uploader.upload(document.getId(), file, startUploadCallback, onFinishUpload);

    ValueChangeEvent.fire(DocumentUpload.this, getValue());
}

From source file:org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.DocumentUpload.java

License:Apache License

protected void doRemove(DocumentPreview preview) {
    previews.remove(preview);/*from w w  w  . j  a v a 2s. c  o m*/
    view.removeDocument(preview);
    instance.destroy(preview);

    ValueChangeEvent.fire(DocumentUpload.this, getValue());
}

From source file:org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.DocumentUpload.java

License:Apache License

@Override
public void setValue(List<DocumentData> value, boolean fireEvents) {

    if (value == null) {
        value = new ArrayList<>();
    }/*w  ww .ja va 2 s.  c o  m*/

    if (getValue().containsAll(value)) {
        return;
    }

    this.clear();

    value.forEach(documentData -> {
        DocumentPreview preview = render(documentData);

        DocumentPreviewStateActionsHandlerImpl handler = new DocumentPreviewStateActionsHandlerImpl(
                DocumentPreviewState.STORED);

        DocumentPreviewStateAction action = new DocumentPreviewStateAction(
                translationService.getTranslation(Constants.DocumentUploadViewImplRemove),
                () -> doRemove(preview));

        handler.addStateActions(DocumentPreviewState.STORED, Collections.singletonList(action));
        preview.setStateHandler(handler);
    });

    if (fireEvents) {
        ValueChangeEvent.fire(this, value);
    }
}

From source file:org.kie.workbench.common.screens.examples.client.wizard.pages.project.ProjectItemViewImpl.java

License:Apache License

@EventHandler("project-selected")
public void onSelectProject(final ClickEvent event) {
    ValueChangeEvent.fire(this, projectSelected.isChecked());
}

From source file:org.kie.workbench.common.stunner.bpmn.client.forms.fields.assignmentsEditor.AssignmentListItemWidgetViewImpl.java

License:Apache License

@PostConstruct
public void init() {
    // Configure dataType and customDataType controls
    dataTypeComboBox.init(this, false, dataType, customDataType, false, true, CUSTOM_PROMPT, ENTER_TYPE_PROMPT);
    // Configure processVar and constant controls
    processVarComboBox.init(this, false, processVar, constant, true, true, CONSTANT_PROMPT,
            ENTER_CONSTANT_PROMPT);/*from   w w w .  j a  va2 s.c  om*/
    name.setRegExp(StringUtils.ALPHA_NUM_REGEXP,
            StunnerFormsClientFieldsConstants.INSTANCE.Removed_invalid_characters_from_name(),
            StunnerFormsClientFieldsConstants.INSTANCE.Invalid_character_in_name());
    customDataType.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            int iChar = event.getNativeKeyCode();
            if (iChar == ' ') {
                event.preventDefault();
            }
        }
    });
    name.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            if (!allowDuplicateNames) {
                String value = name.getText();
                if (isDuplicateName(value)) {
                    notification.fire(new NotificationEvent(duplicateNameErrorMessage,
                            NotificationEvent.NotificationType.ERROR));
                    name.setValue("");
                    ValueChangeEvent.fire(name, "");
                }
            }
        }
    });
}

From source file:org.kie.workbench.common.stunner.bpmn.client.forms.fields.variablesEditor.VariableListItemWidgetViewImpl.java

License:Apache License

@PostConstruct
public void init() {
    // Configure dataType and customDataType controls
    dataTypeComboBox.init(this, true, dataType, customDataType, false, true, CUSTOM_PROMPT, ENTER_TYPE_PROMPT);
    name.setRegExp(StringUtils.ALPHA_NUM_REGEXP, "Removed invalid characters from name",
            "Invalid character in name");
    customDataType.addKeyDownHandler(new KeyDownHandler() {
        @Override//from  w w w .jav  a2s.co  m
        public void onKeyDown(final KeyDownEvent event) {
            int iChar = event.getNativeKeyCode();
            if (iChar == ' ') {
                event.preventDefault();
            }
        }
    });
    name.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(final BlurEvent event) {
            if (!allowDuplicateNames) {
                String value = name.getText();
                if (isDuplicateName(value)) {
                    notification.fire(new NotificationEvent(duplicateNameErrorMessage,
                            NotificationEvent.NotificationType.ERROR));
                    name.setValue("");
                    ValueChangeEvent.fire(name, "");
                }
            }
            notifyModelChanged();
        }
    });
}

From source file:org.kie.workbench.common.stunner.bpmn.client.forms.widgets.AbstractValidatingTextBox.java

License:Apache License

protected void setup() {
    final TextBox me = this;
    //Validate value as it is entered
    this.addKeyPressHandler(new KeyPressHandler() {

        public void onKeyPress(final KeyPressEvent event) {
            // Permit navigation
            int keyCode = getKeyCodeFromKeyPressEvent(event);
            if (event.isControlKeyDown()) {
                return;
            }/*from w ww  .j a  va 2  s . co  m*/
            if (!event.isShiftKeyDown()) {
                if (keyCode == KeyCodes.KEY_BACKSPACE || keyCode == KeyCodes.KEY_DELETE
                        || keyCode == KeyCodes.KEY_LEFT || keyCode == KeyCodes.KEY_RIGHT
                        || keyCode == KeyCodes.KEY_TAB || keyCode == KeyCodes.KEY_HOME
                        || keyCode == KeyCodes.KEY_END) {
                    return;
                }
            }
            // Get new value and validate
            int charCode = event.getCharCode();
            String oldValue = me.getValue();
            String newValue = oldValue.substring(0, me.getCursorPos());
            newValue = newValue + ((char) charCode);
            newValue = newValue + oldValue.substring(me.getCursorPos() + me.getSelectionLength());
            String validationError = isValidValue(newValue, false);
            if (validationError != null) {
                event.preventDefault();
                fireValidationError(validationError);
            }
        }
    });
    //Add validation when loses focus (for when values are pasted in by user)
    this.addBlurHandler(new BlurHandler() {

        @Override
        public void onBlur(final BlurEvent event) {
            String value = me.getText();
            String validationError = isValidValue(value, true);
            if (validationError != null) {
                fireValidationError(validationError);
                String validValue = makeValidValue(value);
                me.setValue(validValue);
                ValueChangeEvent.fire(AbstractValidatingTextBox.this, validValue);
            }
        }
    });
}

From source file:org.kie.workbench.common.stunner.forms.client.fields.assignmentsEditor.AssignmentListItemWidgetViewImpl.java

License:Apache License

@PostConstruct
public void init() {
    // Configure dataType and customDataType controls
    dataTypeComboBox.init(this, false, dataType, customDataType, false, true, CUSTOM_PROMPT, ENTER_TYPE_PROMPT);

    // Configure processVar and constant controls
    processVarComboBox.init(this, false, processVar, constant, true, true, CONSTANT_PROMPT,
            ENTER_CONSTANT_PROMPT);//w  ww .  j  ava2s .  co  m

    name.setRegExp("^[a-zA-Z0-9\\-\\.\\_]*$",
            StunnerFormsClientFieldsConstants.INSTANCE.Removed_invalid_characters_from_name(),
            StunnerFormsClientFieldsConstants.INSTANCE.Invalid_character_in_name());

    customDataType.addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            int iChar = event.getNativeKeyCode();
            if (iChar == ' ') {
                event.preventDefault();
            }
        }
    });

    name.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            if (!allowDuplicateNames) {
                String value = name.getText();
                if (isDuplicateName(value)) {
                    notification.fire(new NotificationEvent(duplicateNameErrorMessage,
                            NotificationEvent.NotificationType.ERROR));
                    name.setValue("");
                    ValueChangeEvent.fire(name, "");
                }
            }
        }
    });

}

From source file:org.kie.workbench.common.stunner.forms.client.fields.variablesEditor.VariableListItemWidgetViewImpl.java

License:Apache License

@PostConstruct
public void init() {
    // Configure dataType and customDataType controls
    dataTypeComboBox.init(this, true, dataType, customDataType, false, true, CUSTOM_PROMPT, ENTER_TYPE_PROMPT);

    name.setRegExp("^[a-zA-Z0-9\\-\\.\\_]*$", "Removed invalid characters from name",
            "Invalid character in name");

    customDataType.addKeyDownHandler(new KeyDownHandler() {
        @Override//from  w ww  .  java 2  s  .c  o m
        public void onKeyDown(KeyDownEvent event) {
            int iChar = event.getNativeKeyCode();
            if (iChar == ' ') {
                event.preventDefault();
            }
        }
    });

    name.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            if (!allowDuplicateNames) {
                String value = name.getText();
                if (isDuplicateName(value)) {
                    notification.fire(new NotificationEvent(duplicateNameErrorMessage,
                            NotificationEvent.NotificationType.ERROR));
                    name.setValue("");
                    ValueChangeEvent.fire(name, "");
                }
            }
            notifyModelChanged();
        }
    });

}