use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.
the class ItemImplTest method testFocusExecutorDoingUnFocus.
@Test
public void testFocusExecutorDoingUnFocus() {
final AbstractDecoratorItem decorator = mock(AbstractDecoratorItem.class);
final Group decPrimitive = mock(Group.class);
when(decorator.asPrimitive()).thenReturn(decPrimitive);
final TooltipItem<?> tooltip = mock(TooltipItem.class);
tested = new ItemImpl(groupItem, shape).setFocusDelay(0).setUnFocusDelay(0).decorate(decorator).tooltip(tooltip);
final AbstractFocusableGroupItem<ItemImpl>.FocusGroupExecutor focusExecutor = spy(tested.getFocusGroupExecutor());
doAnswer(invocationOnMock -> {
((Command) invocationOnMock.getArguments()[1]).execute();
return null;
}).when(focusExecutor).accept(any(Group.class), any(Command.class));
focusExecutor.unFocus();
verify(focusExecutor, times(1)).setAlpha(AbstractFocusableGroupItem.ALPHA_UNFOCUSED);
verify(decorator, times(3)).hide();
verify(tooltip, times(2)).hide();
}
use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.
the class ToolboxImplTest method testShow.
@Test
public void testShow() {
final Command before = mock(Command.class);
final Command after = mock(Command.class);
tested.show(before, after);
verify(wrapped, times(1)).show(any(Command.class), any(Command.class));
verify(wrapped, never()).hide(any(Command.class), any(Command.class));
verify(before, times(1)).execute();
verify(after, times(1)).execute();
ArgumentCaptor<Point2D> pc = ArgumentCaptor.forClass(Point2D.class);
verify(group, times(1)).setLocation(pc.capture());
Point2D point = pc.getValue();
assertEquals(33d, point.getX(), 0);
assertEquals(0d, point.getY(), 0);
}
use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.
the class WiresShapeToolboxTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() {
when(toolbox.getBoundingBox()).thenReturn(() -> boundingBox);
when(toolbox.asPrimitive()).thenReturn(group);
when(toolbox.setGridSize(anyDouble(), anyDouble())).thenReturn(toolbox);
when(toolbox.refresh()).thenReturn(toolbox);
when(group.getComputedLocation()).thenReturn(new Point2D(5d, 10d));
when(group.getComputedBoundingPoints()).thenReturn(boundingPoints);
when(group.getBoundingBox()).thenReturn(boundingBox);
when(boundingPoints.getBoundingBox()).thenReturn(boundingBox);
when(shape.getGroup()).thenReturn(group);
when(shape.addWiresMoveHandler(any(WiresMoveHandler.class))).thenReturn(moveRegistration);
when(shape.addWiresDragStartHandler(any(WiresDragStartHandler.class))).thenReturn(dragStartRegistration);
when(shape.addWiresDragMoveHandler(any(WiresDragMoveHandler.class))).thenReturn(dragMoveRegistration);
when(shape.addWiresDragEndHandler(any(WiresDragEndHandler.class))).thenReturn(dragEndRegistration);
when(shape.addWiresResizeStartHandler(any(WiresResizeStartHandler.class))).thenReturn(resizeStartRegistration);
when(shape.addWiresResizeStepHandler(any(WiresResizeStepHandler.class))).thenReturn(resizeStepRegistration);
when(shape.addWiresResizeEndHandler(any(WiresResizeEndHandler.class))).thenReturn(resizeEndRegistration);
doAnswer(invocationOnMock -> {
((Command) invocationOnMock.getArguments()[0]).execute();
((Command) invocationOnMock.getArguments()[1]).execute();
return toolbox;
}).when(toolbox).show(any(Command.class), any(Command.class));
doAnswer(invocationOnMock -> {
((Command) invocationOnMock.getArguments()[0]).execute();
((Command) invocationOnMock.getArguments()[1]).execute();
return toolbox;
}).when(toolbox).hide(any(Command.class), any(Command.class));
tested = new WiresShapeToolbox(shape, toolbox, registrations).useHideExecutor(hideExecutor).useShowExecutor(showExecutor);
}
use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.
the class AbstractProjectDiagramEditor method save.
/**
* This method is called just once clicking on save.
* Before starting the save process, let's perform a diagram validation
* to check all it's valid.
* It's allowed to continue with the save process event if warnings found,
* but cannot save if any error is present in order to
* guarantee the diagram's consistency.
*/
@Override
protected void save() {
final Command continueSaveOnceValid = () -> super.save();
getCommand(ValidateSessionCommand.class).execute(new ClientSessionCommand.Callback<Collection<DiagramElementViolation<RuleViolation>>>() {
@Override
public void onSuccess() {
continueSaveOnceValid.execute();
}
@Override
public void onError(final Collection<DiagramElementViolation<RuleViolation>> violations) {
final Violation.Type maxSeverity = ValidationUtils.getMaxSeverity(violations);
if (maxSeverity.equals(Violation.Type.ERROR)) {
onValidationFailed(violations);
} else {
// Allow saving when only warnings founds.
continueSaveOnceValid.execute();
}
}
});
}
use of org.uberfire.mvp.Command in project kie-wb-common by kiegroup.
the class AbstractPaletteDefinitionBuilder method build.
private void build(final Metadata metadata, final Consumer<DefaultPaletteDefinition> paletteDefinitionConsumer) {
final String definitionSetId = metadata.getDefinitionSetId();
final Object definitionSet = getDefinitionManager().definitionSets().getDefinitionSetById(definitionSetId);
final Set<String> definitions = getDefinitionManager().adapters().forDefinitionSet().getDefinitions(definitionSet);
if (null != definitions) {
final Map<String, DefaultPaletteItem> items = new LinkedHashMap<>();
final Set<String> consumed = new HashSet<>(definitions);
// Once all item definitions consumed, build the resulting palette definition
// and let the consumer do its job.
final Command checkConsumedAndComplete = () -> {
if (consumed.isEmpty()) {
paletteDefinitionConsumer.accept(new DefaultPaletteDefinition(getSortedItems(items.values(), getDefaultComparator()), definitionSetId));
}
};
for (final String defId : definitions) {
consumed.remove(defId);
// Check if this concrete definition is excluded from the palette model.
if (itemFilter.test(defId)) {
clientFactoryServices.newDefinition(defId, new ServiceCallback<Object>() {
@Override
public void onSuccess(final Object definition) {
buildItem(definition, metadata, items);
checkConsumedAndComplete.execute();
}
@Override
public void onError(final ClientRuntimeError error) {
LOGGER.severe("Error while building the palette definition. " + "[Message=" + error.getMessage() + "]");
}
});
} else {
checkConsumedAndComplete.execute();
}
}
}
}
Aggregations