Search in sources :

Example 41 with Command

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

the class ServerTemplatePresenter method addServerInstance.

private void addServerInstance(final ServerInstanceKey serverInstanceKey) {
    serverInstances.add(serverInstanceKey.getServerInstanceId());
    view.addServerInstance(serverInstanceKey.getServerTemplateId(), serverInstanceKey.getServerInstanceId(), serverInstanceKey.getServerName(), new Command() {

        @Override
        public void execute() {
            serverInstanceSelectedEvent.fire(new ServerInstanceSelected(serverInstanceKey));
        }
    });
}
Also used : ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Command(org.uberfire.mvp.Command) ServerInstanceSelected(org.kie.workbench.common.screens.server.management.client.events.ServerInstanceSelected)

Example 42 with Command

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

the class ServerTemplateView method confirmRemove.

@Override
public void confirmRemove(final Command command) {
    final YesNoCancelPopup result = YesNoCancelPopup.newYesNoCancelPopup(getTemplateRemovePopupTitle(), getTemplateRemovePopupText(), command, new Command() {

        @Override
        public void execute() {
        }
    }, null);
    result.clearScrollHeight();
    result.show();
}
Also used : Command(org.uberfire.mvp.Command) YesNoCancelPopup(org.uberfire.ext.widgets.common.client.common.popups.YesNoCancelPopup)

Example 43 with Command

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

the class ContainerPresenterTest method testRemoveContainer.

@Test
public void testRemoveContainer() {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final Command command = (Command) invocation.getArguments()[0];
            if (command != null) {
                command.execute();
            }
            return null;
        }
    }).when(view).confirmRemove(any(Command.class));
    final String successMessage = "SUCCESS";
    when(view.getRemoveContainerSuccessMessage()).thenReturn(successMessage);
    presenter.loadContainers(containerSpecData);
    presenter.removeContainer();
    verify(specManagementService).deleteContainerSpec(serverTemplateKey.getId(), containerSpec.getId());
    final ArgumentCaptor<NotificationEvent> notificationCaptor = ArgumentCaptor.forClass(NotificationEvent.class);
    verify(notification).fire(notificationCaptor.capture());
    final NotificationEvent event = notificationCaptor.getValue();
    assertEquals(NotificationEvent.NotificationType.SUCCESS, event.getType());
    assertEquals(successMessage, event.getNotification());
    final ArgumentCaptor<ServerTemplateSelected> serverTemplateSelectedCaptor = ArgumentCaptor.forClass(ServerTemplateSelected.class);
    verify(serverTemplateSelectedEvent).fire(serverTemplateSelectedCaptor.capture());
    assertEquals(serverTemplateKey.getId(), serverTemplateSelectedCaptor.getValue().getServerTemplateKey().getId());
    final String errorMessage = "ERROR";
    when(view.getRemoveContainerErrorMessage()).thenReturn(errorMessage);
    doThrow(new RuntimeException()).when(specManagementService).deleteContainerSpec(serverTemplateKey.getId(), containerSpec.getId());
    presenter.removeContainer();
    verify(notification).fire(new NotificationEvent(errorMessage, NotificationEvent.NotificationType.ERROR));
    verify(serverTemplateSelectedEvent, times(2)).fire(new ServerTemplateSelected(containerSpec.getServerTemplateKey()));
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Command(org.uberfire.mvp.Command) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Mockito.anyObject(org.mockito.Mockito.anyObject) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) ServerTemplateSelected(org.kie.workbench.common.screens.server.management.client.events.ServerTemplateSelected) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 44 with Command

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

the class NewWorkspaceProjectHandler method getCommand.

@Override
public Command getCommand(final NewResourcePresenter newResourcePresenter) {
    return new Command() {

        @Override
        public void execute() {
            if (!context.getActiveOrganizationalUnit().isPresent()) {
                ouService.call(new RemoteCallback<OrganizationalUnit>() {

                    @Override
                    public void callback(OrganizationalUnit organizationalUnit) {
                        projectContextChangeEvent.fire(new WorkspaceProjectContextChangeEvent(organizationalUnit));
                        init();
                    }
                }).getOrganizationalUnit(libraryPreferences.getOrganizationalUnitPreferences().getName());
            } else {
                init();
            }
        }
    };
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) Command(org.uberfire.mvp.Command) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback)

Example 45 with Command

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

the class DataModelerScreenPresenter method onValidate.

protected Command onValidate() {
    return new Command() {

        @Override
        public void execute() {
            // at validation time we must do the same calculation as if we were about to save.
            final DataObject[] modifiedDataObject = new DataObject[1];
            if (isDirty()) {
                if (context.isEditorChanged()) {
                    // at save time the source has always priority over the model.
                    // If the source was properly parsed and the editor has changes, we need to send the DataObject
                    // to the server in order to let the source to be updated prior to save.
                    modifiedDataObject[0] = context.getDataObject();
                } else {
                    // if the source has changes, no update form the UI to the source will be performed.
                    // instead the parsed DataObject must be returned from the server.
                    modifiedDataObject[0] = null;
                }
            }
            modelerService.call(new RemoteCallback<List<org.guvnor.common.services.shared.validation.model.ValidationMessage>>() {

                @Override
                public void callback(final List<org.guvnor.common.services.shared.validation.model.ValidationMessage> results) {
                    if (results == null || results.isEmpty()) {
                        notification.fire(new NotificationEvent(org.kie.workbench.common.widgets.client.resources.i18n.CommonConstants.INSTANCE.ItemValidatedSuccessfully(), NotificationEvent.NotificationType.SUCCESS));
                    } else {
                        validationPopup.showMessages(results);
                    }
                }
            }).validate(getSource(), versionRecordManager.getCurrentPath(), modifiedDataObject[0]);
        }
    };
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) DataObject(org.kie.workbench.common.services.datamodeller.core.DataObject) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Command(org.uberfire.mvp.Command) List(java.util.List)

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