Search in sources :

Example 81 with Command

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

the class MainDataObjectFieldEditor method doFieldNameChange.

private void doFieldNameChange(final String oldValue, final String newValue) {
    final Command afterCloseCommand = new Command() {

        @Override
        public void execute() {
            view.setNameOnError(true);
            view.selectAllNameText();
        }
    };
    // In case an invalid name (entered before), was corrected to the original value, don't do anything but reset the label style
    if (oldValue.equalsIgnoreCase(view.getName())) {
        view.setName(oldValue);
        view.setNameOnError(false);
        return;
    }
    validatorService.isValidIdentifier(newValue, new ValidatorCallback() {

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

        @Override
        public void onSuccess() {
            validatorService.isUniqueAttributeName(newValue, getDataObject(), new ValidatorWithReasonCallback() {

                @Override
                public void onFailure() {
                    showFailure(ValidatorService.MANAGED_PROPERTY_EXISTS);
                }

                @Override
                public void onFailure(String reason) {
                    showFailure(reason);
                }

                private void showFailure(String reason) {
                    if (ValidatorService.UN_MANAGED_PROPERTY_EXISTS.equals(reason)) {
                        ObjectProperty unmanagedProperty = getDataObject().getUnManagedProperty(newValue);
                        view.showErrorPopup(Constants.INSTANCE.validation_error_object_un_managed_attribute_already_exists(unmanagedProperty.getName(), unmanagedProperty.getClassName()));
                    } else {
                        view.showErrorPopup(Constants.INSTANCE.validation_error_object_attribute_already_exists(newValue));
                    }
                }

                @Override
                public void onSuccess() {
                    view.setNameOnError(false);
                    objectField.setName(newValue);
                    notifyChange(createFieldChangeEvent(ChangeType.FIELD_NAME_CHANGE).withOldValue(oldValue).withNewValue(newValue));
                }
            });
        }
    });
}
Also used : ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ValidatorCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorCallback) DataModelCommand(org.kie.workbench.common.screens.datamodeller.client.command.DataModelCommand) Command(org.uberfire.mvp.Command) ValidatorWithReasonCallback(org.uberfire.ext.editor.commons.client.validation.ValidatorWithReasonCallback)

Example 82 with Command

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

the class DataModelerScreenViewImpl method showYesNoCancelPopup.

@Override
public void showYesNoCancelPopup(String title, String message, Command yesCommand, String yesButtonText, ButtonType yesButtonType, Command noCommand, String noButtonText, ButtonType noButtonType) {
    YesNoCancelPopup yesNoCancelPopup = YesNoCancelPopup.newYesNoCancelPopup(title, message, yesCommand, yesButtonText, yesButtonType, noCommand, noButtonText, noButtonType, new Command() {

        @Override
        public void execute() {
        // do nothing, but let the cancel button be shown.
        }
    }, 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 83 with Command

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

the class DataModelerScreenViewImpl method showYesNoCancelPopup.

@Override
public void showYesNoCancelPopup(String title, String message, Command yesCommand, Command noCommand) {
    YesNoCancelPopup yesNoCancelPopup = YesNoCancelPopup.newYesNoCancelPopup(title, message, yesCommand, noCommand, new Command() {

        @Override
        public void execute() {
        // do nothing, but let the cancel button be shown.
        }
    });
    yesNoCancelPopup.setClosable(false);
    yesNoCancelPopup.show();
}
Also used : Command(org.uberfire.mvp.Command) YesNoCancelPopup(org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup)

Example 84 with Command

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

the class DefaultNewResourceHandlerTest method testGetCommand.

@Test
public void testGetCommand() {
    final NewResourcePresenter presenter = mock(NewResourcePresenter.class);
    final Command command = handler.getCommand(presenter);
    assertNotNull(command);
    command.execute();
    verify(presenter, times(1)).show(handler);
}
Also used : Command(org.uberfire.mvp.Command) Test(org.junit.Test)

Example 85 with Command

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

the class PackageListBoxTest method setContextTest.

@Test
public void setContextTest() {
    final List<Package> packages = new ArrayList<>();
    packages.add(createPackage("com"));
    packages.add(createPackage("com.myteam"));
    packages.add(createPackage("com.myteam.mymodule"));
    packages.add(createPackage("com.myteam.mymodule.mypackage"));
    final Command packagesLoadedCommand = mock(Command.class);
    doReturn(new HashSet<>(packages)).when(moduleService).resolvePackages(any(Module.class));
    doReturn(packages.get(2)).when(moduleService).resolveDefaultWorkspacePackage(any());
    packageListBox.setUp(true, packagesLoadedCommand);
    verify(packageListBox, times(4)).addPackage(any(), any());
    verify(packageListBox).addPackage(packages.get(0), packages.get(2));
    verify(packageListBox).addPackage(packages.get(1), packages.get(2));
    verify(packageListBox).addPackage(packages.get(2), packages.get(2));
    verify(packageListBox).addPackage(packages.get(3), packages.get(2));
    verify(packagesLoadedCommand).execute();
}
Also used : Command(org.uberfire.mvp.Command) ArrayList(java.util.ArrayList) Package(org.guvnor.common.services.project.model.Package) Module(org.guvnor.common.services.project.model.Module) Test(org.junit.Test)

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