use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class DecisionServiceMoveDividerControl method register.
@Override
@SuppressWarnings("unchecked")
public void register(final Element element) {
if (checkNotRegistered(element)) {
final Object definition = ((Definition) element.getContent()).getDefinition();
if (!isDecisionServiceDefinition(definition)) {
return;
}
final Canvas<?> canvas = canvasHandler.getCanvas();
final Shape<?> shape = canvas.getShape(element.getUUID());
final ShapeView<?> shapeView = shape.getShapeView();
if (!isDecisionServiceShapeView(shapeView)) {
return;
}
final DecisionServiceSVGShapeView decisionServiceShapeView = (DecisionServiceSVGShapeView) shapeView;
final DragHandler dragHandler = new DragHandler() {
@Override
public void end(final DragEvent event) {
final CommandResult<CanvasViolation> result = doMoveDivider(element, decisionServiceShapeView.getDividerLineY());
if (CommandUtils.isError(result)) {
LOGGER.log(Level.WARNING, "Command failed at resize end [result=" + result + "]");
}
}
};
decisionServiceShapeView.addDividerDragHandler(dragHandler);
registerHandler(element.getUUID(), dragHandler);
}
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class DecisionServiceMoveDividerControl method getMoveDividerCommand.
private Optional<CanvasCommand<AbstractCanvasHandler>> getMoveDividerCommand(final Element<? extends Definition<?>> element, final double dividerY) {
final Definition content = element.getContent();
final Object definition = content.getDefinition();
final DefinitionAdapter<Object> adapter = canvasHandler.getDefinitionManager().adapters().registry().getDefinitionAdapter(definition.getClass());
final Optional<?> dividerYProperty = adapter.getProperty(definition, DIVIDER_Y_PROPERTY_ID);
if (dividerYProperty.isPresent()) {
return Optional.of(canvasCommandFactory.updatePropertyValue(element, DIVIDER_Y_PROPERTY_ID, dividerY));
}
return Optional.empty();
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class ListGridTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() {
when(parent.getGridWidget()).thenReturn(parentGridWidget);
when(parentGridWidget.getModel()).thenReturn(parentGridData);
when(parentGridData.getColumns()).thenReturn(Collections.singletonList(parentGridColumn));
when(sessionManager.getCurrentSession()).thenReturn(session);
when(session.getGridPanel()).thenReturn(gridPanel);
when(session.getGridLayer()).thenReturn(gridLayer);
when(session.getCellEditorControls()).thenReturn(cellEditorControls);
definition = new ListEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, expressionEditorDefinitionsSupplier, headerEditor, readOnlyProvider);
final Decision decision = new Decision();
decision.setName(new Name(NAME));
hasName = Optional.of(decision);
expression = definition.getModelClass();
definition.enrich(Optional.empty(), hasExpression, expression);
final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
expressionEditorDefinitions.add((ExpressionEditorDefinition) definition);
expressionEditorDefinitions.add(literalExpressionEditorDefinition);
expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
when(literalExpressionEditor.getParentInformation()).thenReturn(parent);
when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
when(undefinedExpressionEditor.getParentInformation()).thenReturn(parent);
when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));
when(session.getCanvasHandler()).thenReturn(canvasHandler);
when(canvasHandler.getGraphExecutionContext()).thenReturn(graphCommandExecutionContext);
when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
when(gridLayer.getVisibleBounds()).thenReturn(new BaseBounds(0, 0, 100, 200));
when(gridLayer.getViewport()).thenReturn(viewport);
when(viewport.getTransform()).thenReturn(transform);
when(canvasHandler.getDiagram()).thenReturn(diagram);
when(diagram.getGraph()).thenReturn(graph);
when(graph.nodes()).thenReturn(Collections.singletonList(node));
when(canvasHandler.getGraphIndex()).thenReturn(index);
when(index.get(Mockito.<String>any())).thenReturn(element);
when(element.getContent()).thenReturn(mock(Definition.class));
when(definitionUtils.getNameIdentifier(any())).thenReturn("name");
when(canvasCommandFactory.updatePropertyValue(any(Element.class), Mockito.<String>any(), any())).thenReturn(mock(UpdateElementPropertyCommand.class));
doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).format(Mockito.<String>any());
doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).getTranslation(Mockito.<String>any());
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class DMNIncludedModelHandlerTest method testBuildUpdateCommand.
@Test
public void testBuildUpdateCommand() {
final Decision drgElement = makeDecision("model1.tUUID", "string", true);
final String newName = "model2.tUUID";
final String nameId = "nameId";
final AbstractCanvasHandler context = mock(AbstractCanvasHandler.class);
final Node node = mock(Node.class);
final Definition definition = mock(Definition.class);
final Object definitionObject = mock(Object.class);
when(node.getContent()).thenReturn(definition);
when(definition.getDefinition()).thenReturn(definitionObject);
when(definitionUtils.getNameIdentifier(definitionObject)).thenReturn(nameId);
when(canvasCommandFactory.updatePropertyValue(eq(node), eq(nameId), any(Name.class))).thenReturn(canvasCommand);
doReturn(node).when(handler).getNode(drgElement);
final Command<AbstractCanvasHandler, CanvasViolation> command = handler.buildUpdateCommand(drgElement, newName).getCommands().get(0);
command.execute(context);
assertEquals(canvasCommand, command);
}
use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.
the class DMNElementsSynchronizer method synchronizeFromNode.
public void synchronizeFromNode(final Optional<Node> node) {
node.ifPresent(n -> {
if (n.getContent() instanceof Definition) {
final Definition definition = (Definition) n.getContent();
if (definition.getDefinition() instanceof DRGElement) {
final DRGElement drgElement = (DRGElement) definition.getDefinition();
synchronizeElementsFrom(drgElement);
}
}
});
}
Aggregations