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();
}
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);
}
}
}
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);
}
}
}
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;
}
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");
}
}
Aggregations