Search in sources :

Example 76 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class NewPackagePopupTest method showAndCreateValidPackageTest.

@Test
public void showAndCreateValidPackageTest() {
    NewPackagePopup newPackagePopup = new NewPackagePopup(view, validatorService);
    final boolean[] commandExecuted = { false };
    newPackagePopup.show(new Command() {

        @Override
        public void execute() {
            commandExecuted[0] = true;
        }
    });
    Map<String, Boolean> validationResult = new HashMap<String, Boolean>();
    validationResult.put("somePackageName", true);
    when(validationService.evaluateJavaIdentifiers(any(String[].class))).thenReturn(validationResult);
    when(view.getPackageName()).thenReturn("somePackageName");
    newPackagePopup.onCreatePackage();
    // the command is executed only when a valid package name was provided.
    verify(view, times(1)).hide();
    assertEquals(true, commandExecuted[0]);
}
Also used : Command(org.uberfire.mvp.Command) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 77 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class DefEditorBaseViewImpl method init.

protected void init(DefEditorActionsPanelView.Presenter presenter) {
    actionsPanel.setSaveCommand(new Command() {

        @Override
        public void execute() {
            presenter.onSave();
        }
    });
    actionsPanel.setCancelCommand(new Command() {

        @Override
        public void execute() {
            presenter.onCancel();
        }
    });
    actionsPanel.setDeleteCommand(new Command() {

        @Override
        public void execute() {
            presenter.onDelete();
        }
    });
}
Also used : Command(org.uberfire.mvp.Command)

Example 78 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class PopupsUtil method showOkButtonPopup.

private static void showOkButtonPopup(final String title, final String message) {
    YesNoCancelPopup yesNoCancelPopup = YesNoCancelPopup.newYesNoCancelPopup(title, message, new Command() {

        @Override
        public void execute() {
        }
    }, CommonConstants.INSTANCE.OK(), null, null, null, null);
    yesNoCancelPopup.setClosable(false);
    yesNoCancelPopup.show();
}
Also used : Command(org.uberfire.mvp.Command) YesNoCancelPopup(org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup)

Example 79 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class DroolsDataObjectEditor method onExpiresChange.

@Override
public void onExpiresChange() {
    if (getDataObject() != null) {
        view.setExpiresOnError(false);
        final Command afterCloseCommand = new Command() {

            @Override
            public void execute() {
                view.setExpiresOnError(true);
                view.selectAllExpiresText();
            }
        };
        final String newValue = view.getExpires();
        // Otherwise validate
        validatorService.isValidTimerInterval(newValue, new ValidatorCallback() {

            @Override
            public void onFailure() {
                view.showErrorPopup(Constants.INSTANCE.validation_error_invalid_timer_expression(newValue), null, afterCloseCommand);
            }

            @Override
            public void onSuccess() {
                commandBuilder.buildDataObjectAnnotationValueChangeCommand(getContext(), getName(), getDataObject(), DroolsDomainAnnotations.EXPIRES_ANNOTATION, DroolsDomainAnnotations.VALUE_PARAM, DataModelerUtils.nullTrim(newValue), true).execute();
            }
        });
    }
}
Also used : ValidatorCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorCallback) Command(org.uberfire.mvp.Command)

Example 80 with Command

use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.

the class DroolsDataObjectFieldEditor method onPositionChange.

@Override
public void onPositionChange() {
    if (getDataObject() != null) {
        view.setPositionOnError(false);
        final Command afterCloseCommand = new Command() {

            @Override
            public void execute() {
                view.setPositionOnError(true);
                view.selectAllPositionText();
            }
        };
        final String newValue = DataModelerUtils.nullTrim(view.getPosition());
        if (newValue != null && !"".equals(newValue)) {
            // validate that entered value is a valid position.
            int newPosition;
            String error = null;
            try {
                newPosition = Integer.parseInt(newValue);
            } catch (NumberFormatException e) {
                newPosition = -1;
            }
            if (newPosition < 0 || newPosition >= MAX_CLASS_FIELDS) {
                error = Constants.INSTANCE.validation_error_position_greater_or_equal_than_and_lower_than(newValue, "0", MAX_CLASS_FIELDS + "");
            } else {
                List<ObjectProperty> fieldsUsingPosition = getFieldsUsingPosition(newPosition);
                if (fieldsUsingPosition.size() > 0) {
                    String fieldsUsingPositionNames = listNames(fieldsUsingPosition);
                    error = Constants.INSTANCE.validation_error_position_already_used_by_fields(newPosition + "", fieldsUsingPositionNames);
                }
            }
            if (error != null) {
                view.showErrorPopup(error, null, afterCloseCommand);
            } else {
                // just proceed to change the position
                commandBuilder.buildFieldAnnotationValueChangeCommand(getContext(), getName(), getDataObject(), getObjectField(), DroolsDomainAnnotations.POSITION_ANNOTATION, DroolsDomainAnnotations.VALUE_PARAM, newPosition, false).execute();
                view.setPosition(newPosition + "");
            }
        } else {
            commandBuilder.buildFieldAnnotationRemoveCommand(getContext(), getName(), getDataObject(), getObjectField(), DroolsDomainAnnotations.POSITION_ANNOTATION).execute();
            view.setPosition(null);
        }
    }
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) Command(org.uberfire.mvp.Command)

Aggregations

Command (org.uberfire.mvp.Command)117 Test (org.junit.Test)66 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)15 ClientSessionCommand (org.kie.workbench.common.stunner.core.client.session.command.ClientSessionCommand)11 Group (com.ait.lienzo.client.core.shape.Group)9 YesNoCancelPopup (org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup)9 Before (org.junit.Before)8 HasListSelectorControl (org.kie.workbench.common.dmn.client.widgets.grid.controls.list.HasListSelectorControl)7 Path (org.uberfire.backend.vfs.Path)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)6 PlaceRequest (org.uberfire.mvp.PlaceRequest)5 MenuItem (org.uberfire.workbench.model.menu.MenuItem)5 IsWidget (com.google.gwt.user.client.ui.IsWidget)4 Inject (javax.inject.Inject)4 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)4 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)4 DeleteHeaderValueCommand (org.kie.workbench.common.dmn.client.commands.general.DeleteHeaderValueCommand)4 SetCellValueCommand (org.kie.workbench.common.dmn.client.commands.general.SetCellValueCommand)4 SetHeaderValueCommand (org.kie.workbench.common.dmn.client.commands.general.SetHeaderValueCommand)4