Search in sources :

Example 1 with EditorSession

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

the class DMNDiagramsSessionTest method testLoadHistoryForTheCurrentDiagram.

@Test
public void testLoadHistoryForTheCurrentDiagram() {
    final Map<String, List<Command<AbstractCanvasHandler, CanvasViolation>>> storedRedoHistory = mock(Map.class);
    final Map<String, List<Command<AbstractCanvasHandler, CanvasViolation>>> storedUndoHistory = mock(Map.class);
    final String diagramId = "diagramId";
    final EditorSession editorSession = mock(EditorSession.class);
    final Optional<EditorSession> optionalEditorSession = Optional.of(editorSession);
    final Registry<Command<AbstractCanvasHandler, CanvasViolation>> undoCommandRegistry = mock(Registry.class);
    final Registry<Command<AbstractCanvasHandler, CanvasViolation>> redoCommandRegistry = mock(Registry.class);
    final List<Command<AbstractCanvasHandler, CanvasViolation>> redoHistory = mock(List.class);
    final List<Command<AbstractCanvasHandler, CanvasViolation>> undoHistory = mock(List.class);
    doReturn(storedRedoHistory).when(dmnDiagramsSession).getStoredRedoHistories();
    doReturn(storedUndoHistory).when(dmnDiagramsSession).getStoredUndoHistories();
    doReturn(diagramId).when(dmnDiagramsSession).getCurrentDiagramId();
    doReturn(optionalEditorSession).when(dmnDiagramsSession).getCurrentSession();
    when(storedRedoHistory.containsKey(diagramId)).thenReturn(true);
    when(storedUndoHistory.containsKey(diagramId)).thenReturn(true);
    when(editorSession.getCommandRegistry()).thenReturn(undoCommandRegistry);
    when(editorSession.getRedoCommandRegistry()).thenReturn(redoCommandRegistry);
    when(storedRedoHistory.get(diagramId)).thenReturn(redoHistory);
    when(storedUndoHistory.get(diagramId)).thenReturn(undoHistory);
    doNothing().when(dmnDiagramsSession).loadHistoryToTheRegistry(redoHistory, redoCommandRegistry);
    doNothing().when(dmnDiagramsSession).loadHistoryToTheRegistry(undoHistory, undoCommandRegistry);
    dmnDiagramsSession.loadHistoryForTheCurrentDiagram();
    verify(dmnDiagramsSession).loadHistoryToTheRegistry(redoHistory, redoCommandRegistry);
    verify(dmnDiagramsSession).loadHistoryToTheRegistry(undoHistory, undoCommandRegistry);
    verify(dmnDiagramsSession).notifyRegistryChanged();
    verify(undoCommandRegistry, never()).clear();
    verify(redoCommandRegistry, never()).clear();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Command(org.kie.workbench.common.stunner.core.command.Command) Arrays.asList(java.util.Arrays.asList) List(java.util.List) EditorSession(org.kie.workbench.common.stunner.core.client.session.impl.EditorSession) Test(org.junit.Test)

Example 2 with EditorSession

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

the class FormPropertiesWidget method show.

private void show(final String graphUuid, final Element<? extends Definition<?>> element, final Command callback) {
    if (element != null) {
        if (isNode(element) && !isFiltered(element) && lastElement != null && lastElement.getUUID().equals(element.getUUID())) {
            lastPosition = GraphUtils.getComputedPosition((Node<?, ? extends Edge>) element);
            return;
        }
        final String elementUUID = element.getUUID();
        final Diagram<?, ?> diagram = formSessionHandler.getDiagram();
        if (Objects.isNull(diagram)) {
            return;
        }
        final Metadata metadata = diagram.getMetadata();
        if (Objects.isNull(metadata)) {
            return;
        }
        final Path diagramPath = metadata.getPath();
        final Definition content = element.getContent();
        if (Objects.isNull(content)) {
            return;
        }
        final Object definition = content.getDefinition();
        final RenderMode renderMode = formSessionHandler.getSession() instanceof EditorSession ? RenderMode.EDIT_MODE : RenderMode.READ_ONLY_MODE;
        formsContainer.render(graphUuid, elementUUID, definition, diagramPath, (fieldName, newValue) -> {
            try {
                formSessionHandler.executeUpdateProperty(element, fieldName, newValue);
            } catch (final Exception ex) {
                log(Level.SEVERE, "Something wrong happened refreshing the canvas for " + "field '" + fieldName + "': " + ex.getCause());
            } finally {
                if (null != callback) {
                    callback.execute();
                }
            }
        }, renderMode);
        final String elementName = definitionUtils.getName(definition);
        fireFormsPropertiesOpenedEvent(elementUUID, elementName);
        lastElement = element;
        if (isNode(element)) {
            lastPosition = GraphUtils.getComputedPosition((Node<?, ? extends Edge>) element);
        }
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) RenderMode(org.kie.workbench.common.forms.dynamic.service.shared.RenderMode) Node(org.kie.workbench.common.stunner.core.graph.Node) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) DomainObject(org.kie.workbench.common.stunner.core.domainobject.DomainObject) EditorSession(org.kie.workbench.common.stunner.core.client.session.impl.EditorSession) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 3 with EditorSession

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

the class BPMNProjectSessionDiagramOpenedHandler method onSessionDiagramOpened.

@Override
public void onSessionDiagramOpened(final ClientSession clientSession) {
    if (clientSession instanceof EditorSession) {
        final EditorSession editorSession = (EditorSession) clientSession;
        final AbstractCanvasHandler canvasHandler = editorSession.getCanvasHandler();
        final ProjectMetadata metadata = (ProjectMetadata) canvasHandler.getDiagram().getMetadata();
        if (metadata.getDiagramSVGPath() == null || metadata.getDiagramSVGGenerator() == ProjectMetadata.SVGGenerator.JBPM_DESIGNER) {
            super.saveOrUpdateDiagram(editorSession);
        }
    }
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) ProjectMetadata(org.kie.workbench.common.stunner.project.diagram.ProjectMetadata) EditorSession(org.kie.workbench.common.stunner.core.client.session.impl.EditorSession)

Example 4 with EditorSession

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

the class AbstractCanvasShortcutsControlImplTest method mockSelectedElements.

private List<Element> mockSelectedElements(final String... selectedIds) {
    final Index index = mock(Index.class);
    doReturn(index).when(canvasHandlerMock).getGraphIndex();
    final EditorSession session = mock(EditorSession.class);
    final SelectionControl selectionControl = mock(SelectionControl.class);
    final KeyboardControl keyboardControl = mock(KeyboardControl.class);
    doReturn(selectionControl).when(session).getSelectionControl();
    doReturn(keyboardControl).when(session).getKeyboardControl();
    doReturn(Arrays.asList(selectedIds)).when(selectionControl).getSelectedItems();
    canvasShortcutsControl.bind(session);
    final List<Element> selectedElements = new ArrayList<>();
    for (final String id : selectedIds) {
        final Element element = mock(Element.class);
        doReturn(element).when(index).get(id);
        selectedElements.add(element);
    }
    return selectedElements;
}
Also used : Element(org.kie.workbench.common.stunner.core.graph.Element) ArrayList(java.util.ArrayList) Index(org.kie.workbench.common.stunner.core.graph.processing.index.Index) EditorSession(org.kie.workbench.common.stunner.core.client.session.impl.EditorSession) SelectionControl(org.kie.workbench.common.stunner.core.client.canvas.controls.SelectionControl)

Example 5 with EditorSession

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

the class AbstractSelectionDevCommand method execute.

@Override
@SuppressWarnings("unchecked")
public void execute() {
    try {
        boolean found = false;
        final EditorSession session = (EditorSession) getSession();
        final Collection<String> selectedItems = session.getSelectionControl().getSelectedItems();
        if (null != selectedItems) {
            final String uuid = selectedItems.stream().findFirst().orElse(null);
            if (null != uuid) {
                execute(selectedItems.stream().map(this::getViewElement).collect(Collectors.toList()));
                found = true;
            }
        }
        if (!found) {
            LOGGER.log(Level.WARNING, "No items selected.");
        }
    } catch (final ClassCastException e) {
        LOGGER.log(Level.WARNING, "Session is not an instance of ClientFullSession");
    }
}
Also used : EditorSession(org.kie.workbench.common.stunner.core.client.session.impl.EditorSession)

Aggregations

EditorSession (org.kie.workbench.common.stunner.core.client.session.impl.EditorSession)13 Test (org.junit.Test)6 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)6 Arrays.asList (java.util.Arrays.asList)3 List (java.util.List)3 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)3 Command (org.kie.workbench.common.stunner.core.command.Command)3 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)3 RenderMode (org.kie.workbench.common.forms.dynamic.service.shared.RenderMode)2 Element (org.kie.workbench.common.stunner.core.graph.Element)2 Path (org.uberfire.backend.vfs.Path)2 ArrayList (java.util.ArrayList)1 DMNEditorSession (org.kie.workbench.common.dmn.client.session.DMNEditorSession)1 SessionFocusedEvent (org.kie.workbench.common.stunner.client.widgets.event.SessionFocusedEvent)1 CanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.CanvasHandler)1 SelectionControl (org.kie.workbench.common.stunner.core.client.canvas.controls.SelectionControl)1 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)1 DomainObject (org.kie.workbench.common.stunner.core.domainobject.DomainObject)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1