Search in sources :

Example 46 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DMNDiagramEditor method newDiagram.

private void newDiagram(final String uuid, final String title, final String definitionSetId, final String shapeSetId, final Command callback) {
    BusyPopup.showMessage("Loading");
    final Metadata metadata = buildMetadata(definitionSetId, shapeSetId, title);
    clientFactoryServices.newDiagram(uuid, definitionSetId, metadata, new ServiceCallback<Diagram>() {

        @Override
        public void onSuccess(final Diagram diagram) {
            marshallerService.setOnDiagramLoad(onDiagramLoadCallback(callback));
            marshallerService.registerDiagramInstance(diagram, title, shapeSetId);
            open(diagram, callback);
        }

        @Override
        public void onError(final ClientRuntimeError error) {
            showError(error);
            callback.execute();
        }
    });
}
Also used : Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram)

Example 47 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DMNDiagramEditorTest method testGetHashcodeSupplier.

@Test
public void testGetHashcodeSupplier() {
    final Diagram diagram = new DiagramImpl("something", null);
    final Integer expectedHashcode = diagram.hashCode();
    doReturn(diagram).when(editor).getDiagram();
    final Integer actualHashcode = editor.getHashcodeSupplier().get();
    assertEquals(expectedHashcode, actualHashcode);
}
Also used : DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Test(org.junit.Test)

Example 48 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DMNDiagramEditorTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    when(searchBarComponent.getView()).thenReturn(searchBarComponentView);
    when(searchBarComponentView.getElement()).thenReturn(searchBarComponentViewElement);
    when(presenter.getView()).thenReturn(sessionPresenterView);
    when(drdNameChanger.getElement()).thenReturn(drdNameChangerElement);
    doReturn(presenter).when(presenter).withToolbar(anyBoolean());
    doReturn(presenter).when(presenter).withPalette(anyBoolean());
    doReturn(presenter).when(presenter).displayNotifications(any());
    doReturn(session).when(presenter).getInstance();
    doReturn(session).when(sessionManager).getCurrentSession();
    doReturn(expressionEditor).when(session).getExpressionEditor();
    doAnswer((invocation) -> {
        Diagram diagram = (Diagram) invocation.getArguments()[0];
        SessionPresenter.SessionPresenterCallback callback = (SessionPresenter.SessionPresenterCallback) invocation.getArguments()[1];
        callback.onOpen(diagram);
        callback.afterCanvasInitialized();
        callback.afterSessionOpened();
        callback.onSuccess();
        return null;
    }).when(presenter).open(any(Diagram.class), any(SessionPresenter.SessionPresenterCallback.class));
    editor = spy(new DMNDiagramEditor(sessionManager, null, presenter, refreshFormPropertiesEvent, null, null, decisionNavigatorDock, diagramPropertiesDock, diagramPreviewAndExplorerDock, layoutHelper, layoutExecutor, dataTypesPage, includedModelsPage, documentationView, editorSearchIndex, searchBarComponent, null, null, null, null, screenPanelView, null, kieView, feelInitializer, dmnDiagramsSession, marshallerService, drdNameChanger, lazyCanvasFocusUtils));
    doReturn(searchBarComponentWidget).when(editor).getWidget(searchBarComponentViewElement);
    doReturn(drdNameWidget).when(editor).getWidget(drdNameChangerElement);
}
Also used : SessionPresenter(org.kie.workbench.common.stunner.client.widgets.presenters.session.SessionPresenter) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Before(org.junit.Before)

Example 49 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DMNClientProjectDiagramServiceTest method testGetMarshallerCallback.

@Test
public void testGetMarshallerCallback() {
    final DMNContentResource resource = mock(DMNContentResource.class);
    final Diagram diagram = mock(Diagram.class);
    final Graph graph = mock(Graph.class);
    final ProjectMetadata projectMetadata = mock(ProjectMetadata.class);
    final String name = "name";
    when(diagram.getName()).thenReturn(name);
    when(diagram.getGraph()).thenReturn(graph);
    when(resource.getMetadata()).thenReturn(projectMetadata);
    service.getMarshallerCallback(resource, projectDiagramCallback).onSuccess(diagram);
    verify(projectDiagramCallback).onSuccess(projectDiagramArgumentCaptor.capture());
    final ProjectDiagramImpl projectDiagram = projectDiagramArgumentCaptor.getValue();
    assertEquals(name, projectDiagram.getName());
    assertEquals(graph, projectDiagram.getGraph());
    assertEquals(projectMetadata, projectDiagram.getMetadata());
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) ProjectMetadata(org.kie.workbench.common.stunner.project.diagram.ProjectMetadata) DMNContentResource(org.kie.workbench.common.dmn.api.DMNContentResource) ProjectDiagram(org.kie.workbench.common.stunner.project.diagram.ProjectDiagram) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) ProjectDiagramImpl(org.kie.workbench.common.stunner.project.diagram.impl.ProjectDiagramImpl) Test(org.junit.Test)

Example 50 with Diagram

use of org.kie.workbench.common.stunner.core.diagram.Diagram in project kie-wb-common by kiegroup.

the class DMNClientProjectDiagramServiceTest method testAsProjectDiagramImpl.

@Test
public void testAsProjectDiagramImpl() {
    final Graph graph = mock(Graph.class);
    final Diagram diagram = mock(Diagram.class);
    final DMNContentResource resource = mock(DMNContentResource.class);
    final ProjectMetadata metadata = mock(ProjectMetadata.class);
    when(diagram.getName()).thenReturn("Traffic Violation.dmn");
    when(diagram.getGraph()).thenReturn(graph);
    when(resource.getMetadata()).thenReturn(metadata);
    final ProjectDiagramImpl projectDiagram = service.asProjectDiagramImpl(diagram, resource);
    assertEquals("Traffic Violation", projectDiagram.getName());
    assertEquals(graph, projectDiagram.getGraph());
    assertEquals(metadata, projectDiagram.getMetadata());
}
Also used : Graph(org.kie.workbench.common.stunner.core.graph.Graph) ProjectMetadata(org.kie.workbench.common.stunner.project.diagram.ProjectMetadata) ProjectDiagram(org.kie.workbench.common.stunner.project.diagram.ProjectDiagram) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNContentResource(org.kie.workbench.common.dmn.api.DMNContentResource) ProjectDiagramImpl(org.kie.workbench.common.stunner.project.diagram.impl.ProjectDiagramImpl) Test(org.junit.Test)

Aggregations

Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)128 Test (org.junit.Test)64 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)48 Node (org.kie.workbench.common.stunner.core.graph.Node)38 Graph (org.kie.workbench.common.stunner.core.graph.Graph)31 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)24 View (org.kie.workbench.common.stunner.core.graph.content.view.View)23 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)22 ArrayList (java.util.ArrayList)20 List (java.util.List)20 Edge (org.kie.workbench.common.stunner.core.graph.Edge)20 Inject (javax.inject.Inject)15 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)15 Before (org.junit.Before)14 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)14 Map (java.util.Map)13 Optional (java.util.Optional)13 Collectors (java.util.stream.Collectors)13 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)13 Collection (java.util.Collection)12