private static void clearSelection(final EditorSession session) { if (null != session.getSelectionControl()) { session.getSelectionControl().clearSelection(); } } }
public String selectedNodeId() { if (editorSession != null && editorSession.getSelectionControl().getSelectedItems().size() == 1) { return editorSession.getSelectionControl().getSelectedItems().iterator().next(); } else { return null; } }
protected String getSelectedElementUUID(ClientSession clientSession) { if (clientSession instanceof EditorSession) { final SelectionControl selectionControl = ((EditorSession) clientSession).getSelectionControl(); if (null != selectionControl) { final Collection<String> selectedItems = selectionControl.getSelectedItems(); if (null != selectedItems && !selectedItems.isEmpty()) { return selectedItems.iterator().next(); } } } return null; }
@Override public SelectionControl getSelectionControl(final EditorSession session) { return cast(session).getSelectionControl(); }
protected String getSelectedElementUUID(ClientSession clientSession) { if (clientSession instanceof EditorSession) { final SelectionControl selectionControl = ((EditorSession) clientSession).getSelectionControl(); if (null != selectionControl) { final Collection<String> selectedItems = selectionControl.getSelectedItems(); if (null != selectedItems && !selectedItems.isEmpty()) { return selectedItems.iterator().next(); } } } return null; }
private Optional<Element> getSelectedParentElement(String nodeUUID) { if (null != getSession().getSelectionControl()) { Collection<String> selectedItems = getSession().getSelectionControl().getSelectedItems(); if (Objects.nonNull(selectedItems) && !selectedItems.isEmpty()) { Optional<String> selectedParent = selectedItems.stream() .filter(Objects::nonNull) .filter(item -> Objects.equals(item, nodeUUID)) .findFirst(); return (selectedParent.isPresent() ? selectedParent : selectedItems.stream().filter(Objects::nonNull).findFirst()) .map(this::getElement); } } return Optional.empty(); }
public static String getSelectedElementUUID(ClientSession clientSession) { Optional<Collection<String>> selectedItems = Optional.empty(); if (clientSession instanceof EditorSession) { selectedItems = Optional.ofNullable(((EditorSession) clientSession).getSelectionControl().getSelectedItems()); } else if (clientSession instanceof ViewerSession) { selectedItems = Optional.ofNullable(((ViewerSession) clientSession).getSelectionControl().getSelectedItems()); } return selectedItems.map(strings -> strings.stream().findFirst().orElse(null)).orElse(null); }
@SuppressWarnings("unchecked") private Collection<String> getSelectedItems() { return getSession().getSelectionControl().getSelectedItems(); } }
@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"); } }
@Override public <V> void execute(final Callback<V> callback) { if (null != getSession().getSelectionControl()) { try { //for now just copy Nodes not Edges final SelectionControl<AbstractCanvasHandler, Element> selectionControl = getSession().getSelectionControl(); //for now just copy Nodes not Edges clipboardControl.set(selectionControl.getSelectedItems().stream() .map(this::getElement) .toArray(Element[]::new)); commandExecutedEvent.fire(new CopySelectionSessionCommandExecutedEvent(this, getSession())); callback.onSuccess(); } catch (Exception e) { LOGGER.severe("Error on copy selection." + e.getMessage()); return; } } }
@Before public void setup() throws Exception { super.init(); when(canvasHandler.getDiagram()).thenReturn(diagram); when(session.getCanvasHandler()).thenReturn(canvasHandler); when(session.getCanvas()).thenReturn(canvas); when(session.getZoomControl()).thenReturn(zoomControl); when(session.getSelectionControl()).thenReturn(selectionControl); when(session.getConnectionAcceptorControl()).thenReturn(connectionAcceptorControl); when(session.getContainmentAcceptorControl()).thenReturn(containmentAcceptorControl); when(session.getDockingAcceptorControl()).thenReturn(dockingAcceptorControl); when(metadata.getDefinitionSetId()).thenReturn(DEFINITION_SET_ID); when(preferencesRegistries.get(DEFINITION_SET_ID, StunnerPreferences.class)).thenReturn(stunnerPreferences); this.tested = new SessionEditorImpl<>(view, canvasPanel, preferencesRegistries); }
checkNotNull("callback", callback); if (null != getSession().getSelectionControl()) { final AbstractCanvasHandler canvasHandler = getSession().getCanvasHandler(); final SelectionControl<AbstractCanvasHandler, Element> selectionControl = getSession().getSelectionControl(); final Collection<String> selectedItems = selectionControl.getSelectedItems();
@Override @SuppressWarnings("unchecked") public <V> void execute(final Callback<V> callback) { checkNotNull("callback", callback); final SessionCommandManager<AbstractCanvasHandler> scm = getSessionCommandManager(); if (null != scm) { final CommandResult<CanvasViolation> result = getSessionCommandManager().undo((AbstractCanvasHandler) getSession().getCanvasHandler()); checkState(); if (CommandUtils.isError(result)) { callback.onError((V) result); } else { callback.onSuccess(); } getSession().getSelectionControl().clearSelection(); } }
@Override @SuppressWarnings("unchecked") public <V> void execute(final Callback<V> callback) { checkNotNull("callback", callback); if (!redoCommandHandler.isEnabled()) { callback.onSuccess(); } final CommandResult<?> result = redoCommandHandler.execute(getSession().getCanvasHandler(), sessionCommandManager); checkState(); if (CommandUtils.isError(result)) { callback.onError((V) result); } else { callback.onSuccess(); } getSession().getSelectionControl().clearSelection(); }