Search in sources :

Example 1 with ShapeSet

use of org.kie.workbench.common.stunner.core.client.ShapeSet in project kie-wb-common by kiegroup.

the class ObserverBuilderControlTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() throws Exception {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            ServiceCallback<Node<View<Object>, Edge>> callback = (ServiceCallback<Node<View<Object>, Edge>>) (invocationOnMock.getArguments()[2]);
            view = new ViewImpl<>(new Object(), new BoundsImpl(new BoundImpl(0.0, 0.0), new BoundImpl(10.0, 20.0)));
            Node<View<Object>, Edge> item = new NodeImpl<>("UUID");
            item.setContent(view);
            callback.onSuccess(item);
            return null;
        }
    }).when(clientFactoryServices).newElement(anyString(), anyString(), any(ServiceCallback.class));
    when(graphBoundsIndexer.setRootUUID(anyString())).thenReturn(graphBoundsIndexer);
    AdapterManager adapters = mock(AdapterManager.class);
    DefinitionAdapter definitionAdapter = mock(DefinitionAdapter.class);
    DefinitionSetRuleAdapter rulesAdapter = mock(DefinitionSetRuleAdapter.class);
    when(definitionAdapter.getId(any())).thenReturn("Object");
    when(rulesAdapter.getRuleSet(any())).thenReturn(mock(RuleSet.class));
    when(adapters.forDefinition()).thenReturn(definitionAdapter);
    when(adapters.forRules()).thenReturn(rulesAdapter);
    when(clientDefinitionManager.adapters()).thenReturn(adapters);
    when(clientDefinitionManager.definitionSets()).thenReturn(mock(TypeDefinitionSetRegistry.class));
    when(canvasCommandFactory.addNode(any(Node.class), anyString())).thenAnswer(new Answer<Command>() {

        @Override
        public Command answer(InvocationOnMock invocationOnMock) {
            Node node = (Node) invocationOnMock.getArguments()[0];
            String uid = (String) invocationOnMock.getArguments()[1];
            return new AddCanvasNodeCommand(node, uid);
        }
    });
    when(canvasCommandFactory.updatePosition(any(Node.class), any(Point2D.class))).thenAnswer(new Answer<Command>() {

        @Override
        public Command answer(InvocationOnMock invocationOnMock) {
            Node node = (Node) invocationOnMock.getArguments()[0];
            Point2D location = (Point2D) invocationOnMock.getArguments()[1];
            return new UpdateElementPositionCommand(node, location);
        }
    });
    when(canvasCommandFactory.draw()).thenReturn(mock(CanvasCommand.class));
    ShapeSet shapeSet = mock(ShapeSet.class);
    ShapeFactory shapeFactory = mock(ShapeFactory.class);
    when(shapeFactory.newShape(any())).thenReturn(mock(ElementShape.class));
    when(shapeSet.getShapeFactory()).thenReturn(shapeFactory);
    when(shapeManager.getShapeSet(anyString())).thenReturn(shapeSet);
    when(shapeManager.getDefaultShapeSet(anyString())).thenReturn(shapeSet);
    tested = new ObserverBuilderControl(clientDefinitionManager, clientFactoryServices, graphUtils, ruleManager, canvasCommandFactory, graphBoundsIndexer, canvasLayoutUtils, mock(Event.class));
    Diagram diagram = mock(Diagram.class);
    Metadata metadata = mock(Metadata.class);
    when(metadata.getCanvasRootUUID()).thenReturn("ID");
    when(diagram.getMetadata()).thenReturn(metadata);
    MutableIndex index = mock(MutableIndex.class);
    Graph graph = mock(Graph.class);
    DefinitionSet graphContent = mock(DefinitionSet.class);
    when(graphContent.getBounds()).thenReturn(new BoundsImpl(new BoundImpl(10d, 10d), new BoundImpl(100d, 100d)));
    when(graph.getContent()).thenReturn(graphContent);
    when(index.getGraph()).thenReturn(graph);
    when(graphIndexBuilder.build(any(Graph.class))).thenReturn(index);
    canvasHandler = new CanvasHandlerImpl(clientDefinitionManager, canvasCommandFactory, clientFactoryServices, ruleManager, graphUtils, graphIndexBuilder, shapeManager, mock(TextPropertyProviderFactory.class), mock(Event.class), null, null, null);
    canvasHandler.handle(mock(AbstractCanvas.class));
    canvasHandler.draw(diagram, mock(ParameterizedCommand.class));
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(Collections.emptyList());
    CanvasCommandManager commandManager = mock(CanvasCommandManager.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            Command command = (Command) invocationOnMock.getArguments()[1];
            command.execute(invocationOnMock.getArguments()[0]);
            return null;
        }
    }).when(commandManager).execute(any(), any(Command.class));
    when(commandManagerProvider.getCommandManager()).thenReturn(commandManager);
    tested.enable(canvasHandler);
    tested.setCommandManagerProvider(commandManagerProvider);
}
Also used : TypeDefinitionSetRegistry(org.kie.workbench.common.stunner.core.registry.definition.TypeDefinitionSetRegistry) Node(org.kie.workbench.common.stunner.core.graph.Node) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) ShapeSet(org.kie.workbench.common.stunner.core.client.ShapeSet) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory) ObserverBuilderControl(org.kie.workbench.common.stunner.core.client.canvas.controls.builder.impl.ObserverBuilderControl) Matchers.anyString(org.mockito.Matchers.anyString) DefinitionAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) RuleSet(org.kie.workbench.common.stunner.core.rule.RuleSet) MutableIndex(org.kie.workbench.common.stunner.core.graph.processing.index.MutableIndex) CanvasHandlerImpl(org.kie.workbench.common.stunner.core.client.canvas.CanvasHandlerImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) Graph(org.kie.workbench.common.stunner.core.graph.Graph) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) AddCanvasNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddCanvasNodeCommand) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Command(org.kie.workbench.common.stunner.core.command.Command) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CanvasCommandManager(org.kie.workbench.common.stunner.core.client.command.CanvasCommandManager) AddCanvasNodeCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AddCanvasNodeCommand) DefinitionSetRuleAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionSetRuleAdapter) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) Edge(org.kie.workbench.common.stunner.core.graph.Edge) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Before(org.junit.Before)

Example 2 with ShapeSet

use of org.kie.workbench.common.stunner.core.client.ShapeSet in project kie-wb-common by kiegroup.

the class ClientDiagramServicesTest method testUpdateClientMetadata.

@Test
@SuppressWarnings("unchecked")
public void testUpdateClientMetadata() {
    String ssid = "shapeSet1";
    ShapeSet shapeSet = mock(ShapeSet.class);
    when(shapeSet.getId()).thenReturn(ssid);
    when(shapeManager.getDefaultShapeSet(anyString())).thenReturn(shapeSet);
    when(metadata.getShapeSetId()).thenReturn(null);
    ServiceCallback<Diagram<Graph, Metadata>> callback = mock(ServiceCallback.class);
    when(diagramService.getDiagramByPath(eq(path))).thenReturn(diagram);
    tested.add(diagram, callback);
    tested.saveOrUpdate(diagram, callback);
    tested.getByPath(path, callback);
    verify(metadata, times(3)).setShapeSetId(eq(ssid));
}
Also used : ShapeSet(org.kie.workbench.common.stunner.core.client.ShapeSet) Matchers.anyString(org.mockito.Matchers.anyString) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 3 with ShapeSet

use of org.kie.workbench.common.stunner.core.client.ShapeSet in project kie-wb-common by kiegroup.

the class ShapeSetsMenuItemsBuilder method build.

public MenuItem build(final String title, final String prefix, final Callback callback) {
    final DropDownMenu menu = new DropDownMenu() {

        {
            addStyleName("pull-right");
        }
    };
    final Collection<ShapeSet<?>> shapeSets = shapeManager.getShapeSets();
    if (null != shapeSets) {
        shapeSets.stream().forEach(shapeSet -> {
            menu.add(new AnchorListItem(prefix + " " + shapeSet.getDescription()) {

                {
                    setTitle(prefix + " " + shapeSet.getDescription());
                    setIcon(IconType.PLUS);
                    addClickHandler(event -> callback.onClick(shapeSet));
                }
            });
        });
    }
    final IsWidget group = new ButtonGroup() {

        {
            add(new Button() {

                {
                    setToggleCaret(false);
                    setDataToggle(Toggle.DROPDOWN);
                    setSize(ButtonSize.SMALL);
                    setText(title);
                    setTitle(title);
                }
            });
            add(menu);
        }
    };
    return MenuUtils.buildItem(group);
}
Also used : AnchorListItem(org.gwtbootstrap3.client.ui.AnchorListItem) IconType(org.gwtbootstrap3.client.ui.constants.IconType) Collection(java.util.Collection) DropDownMenu(org.gwtbootstrap3.client.ui.DropDownMenu) Button(org.gwtbootstrap3.client.ui.Button) Inject(javax.inject.Inject) Toggle(org.gwtbootstrap3.client.ui.constants.Toggle) MenuUtils(org.kie.workbench.common.stunner.client.widgets.menu.MenuUtils) MenuItem(org.uberfire.workbench.model.menu.MenuItem) ShapeManager(org.kie.workbench.common.stunner.core.client.api.ShapeManager) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IsWidget(com.google.gwt.user.client.ui.IsWidget) ButtonSize(org.gwtbootstrap3.client.ui.constants.ButtonSize) ButtonGroup(org.gwtbootstrap3.client.ui.ButtonGroup) ShapeSet(org.kie.workbench.common.stunner.core.client.ShapeSet) IsWidget(com.google.gwt.user.client.ui.IsWidget) AnchorListItem(org.gwtbootstrap3.client.ui.AnchorListItem) ButtonGroup(org.gwtbootstrap3.client.ui.ButtonGroup) Button(org.gwtbootstrap3.client.ui.Button) DropDownMenu(org.gwtbootstrap3.client.ui.DropDownMenu) ShapeSet(org.kie.workbench.common.stunner.core.client.ShapeSet)

Aggregations

ShapeSet (org.kie.workbench.common.stunner.core.client.ShapeSet)3 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)2 Matchers.anyString (org.mockito.Matchers.anyString)2 IsWidget (com.google.gwt.user.client.ui.IsWidget)1 Collection (java.util.Collection)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 AnchorListItem (org.gwtbootstrap3.client.ui.AnchorListItem)1 Button (org.gwtbootstrap3.client.ui.Button)1 ButtonGroup (org.gwtbootstrap3.client.ui.ButtonGroup)1 DropDownMenu (org.gwtbootstrap3.client.ui.DropDownMenu)1 ButtonSize (org.gwtbootstrap3.client.ui.constants.ButtonSize)1 IconType (org.gwtbootstrap3.client.ui.constants.IconType)1 Toggle (org.gwtbootstrap3.client.ui.constants.Toggle)1 Before (org.junit.Before)1 Test (org.junit.Test)1 MenuUtils (org.kie.workbench.common.stunner.client.widgets.menu.MenuUtils)1 ShapeManager (org.kie.workbench.common.stunner.core.client.api.ShapeManager)1 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)1 CanvasHandlerImpl (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandlerImpl)1