public S getChild(final String uuid) { return children.stream() .filter(c -> c.getUUID().equals(uuid)) .findFirst() .orElse(null); } }
@Override public void start(DragEvent event) { if (Objects.nonNull(selectionEvent)) { //select the moving shape, if not selectionEvent.fire(new CanvasSelectionEvent(canvasHandler, shape.getUUID())); } }
private void doDeregisterHandler(final Shape shape, final ViewHandler<?> handler) { if (null != shape && null != handler) { final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView(); hasEventHandlers.removeHandler(handler); disabledHandlers.putIfAbsent(shape.getUUID(), new HashSet<>()); disabledHandlers.get(shape.getUUID()).add(handler); } } }
private void doDeregisterHandler(final Shape shape, final ViewHandler<?> handler) { if (null != shape && null != handler) { final HasEventHandlers hasEventHandlers = (HasEventHandlers) shape.getShapeView(); hasEventHandlers.removeHandler(handler); handlers.remove(shape.getUUID()); } }
private void enableAllHandlers() { if (!handlers.isEmpty() && Objects.nonNull(canvasHandler)) { handlers.keySet().stream() .filter(this::isRegistered) .map(uuid -> canvasHandler.getCanvas().getShape(uuid)) .filter(Objects::nonNull) .filter(shape -> shape.getShapeView() instanceof HasEventHandlers) .forEach(shape -> disabledHandlers.get(shape.getUUID()) .stream() .forEach(eventHandler -> { ((HasEventHandlers) shape.getShapeView()).addHandler(eventHandler.getType(), eventHandler); handlers.get(shape.getUUID()).add(eventHandler); }) ); disabledHandlers.values().stream().forEach(Set::clear); disabledHandlers.clear(); } }
@Override public Canvas addShape(final Shape shape) { shapes.computeIfAbsent(shape.getUUID(), (v) -> { addShapeIntoView(shape); fireCanvasShapeAdded(shape); canvasShapeAddedEvent.fire(new CanvasShapeAddedEvent(this, shape)); return shape; }); return this; }
@Override public Canvas deleteShape(final Shape shape) { deleteShapeFromView(shape); fireCanvasShapeRemoved(shape); shapes.remove(shape.getUUID()); canvasShapeRemovedEvent.fire(new CanvasShapeRemovedEvent(this, shape)); return this; }
@Override @SuppressWarnings("unchecked") public Optional<Element> getElementAt(final double x, final double y) { final Optional<Shape> shape = getCanvas().getShapeAt(x, y); return shape.flatMap(s -> Optional.of(getGraphExecutionContext().getGraphIndex().getNode(s.getUUID()))); }
public void onShapeRemoved(final CanvasShapeRemovedEvent shapeRemovedEvent) { checkNotNull("shapeRemovedEvent", shapeRemovedEvent); if (null == canvasHandler) { return; } if (getCanvas().equals(shapeRemovedEvent.getCanvas())) { items.remove(shapeRemovedEvent.getShape().getUUID()); } }
private boolean checkEventContext(final AbstractCanvasShapeEvent canvasShapeEvent) { return toolboxControl.getCanvasHandler() != null && toolboxControl.getCanvasHandler().getCanvas().equals(canvasShapeEvent.getCanvas()) && toolboxControl.isActive(canvasShapeEvent.getShape().getUUID()); } }
@SuppressWarnings("unchecked") private void updateViewShapesState(Collection<String> uuids) { uuids.stream() .map(uuid -> getCanvas().getShape(uuid)) .filter(Objects::nonNull) .forEach(shape -> { final boolean isSelected = isSelected(shape.getUUID()); if (isSelected && isReadonly()) { shape.applyState(ShapeState.HIGHLIGHT); } else if (isSelected) { shape.applyState(ShapeState.SELECTED); } else { shape.applyState(ShapeState.NONE); } }); getCanvas().focus(); }
@Override @SuppressWarnings("unchecked") public Node<View<?>, Edge> getAt(final double x, final double y) { final WiresCanvas canvas = (WiresCanvas) canvasHandler.getAbstractCanvas(); final LienzoLayer lienzoLayer = canvas.getView().getLayer(); final String viewUUID = LienzoLayerUtils.getUUID_At(lienzoLayer, x, y); if (null != viewUUID && viewUUID.trim().length() > 0) { final Shape<?> shape = canvas.getShape(viewUUID); if (null != shape) { return canvasHandler.getGraphIndex().getNode(shape.getUUID()); } } return null; }
@SuppressWarnings("unchecked") public Canvas addShapeIntoView(final Shape shape) { if (shape.getUUID() == null) { shape.setUUID(UUID.uuid()); } getView().add(shape.getShapeView()); return this; }
node = canvasHandler.getGraphIndex().getNode(shape.getUUID()); if (node != parentNode) { return node; final Shape<?> shape = canvas.getShape(viewUUID_UR); if (null != shape) { node = canvasHandler.getGraphIndex().getNode(shape.getUUID()); if (node != parentNode) { return node; final Shape<?> shape = canvas.getShape(viewUUID_CC); if (null != shape) { node = canvasHandler.getGraphIndex().getNode(shape.getUUID()); if (node != parentNode) { return node; final Shape<?> shape = canvas.getShape(viewUUID_LL); if (null != shape) { node = canvasHandler.getGraphIndex().getNode(shape.getUUID()); if (node != parentNode) { return node; final Shape<?> shape = canvas.getShape(viewUUID_LR); if (null != shape) { node = canvasHandler.getGraphIndex().getNode(shape.getUUID()); if (node != parentNode) { return node;
hasEventHandlers.addHandler(ViewEventType.TEXT_DBL_CLICK, clickHandler); registerHandler(shape.getUUID(), clickHandler); hasEventHandlers.addHandler(ViewEventType.TEXT_ENTER, enterHandler); registerHandler(shape.getUUID(), enterHandler); hasEventHandlers.addHandler(ViewEventType.TEXT_EXIT, exitHandler); registerHandler(shape.getUUID(), exitHandler);
/** * It does: * - Registers a new graph element into the structure * - Creates the shape for the element to register, using the given shape factory. * @param factory The shape factory to use. * @param candidate The graph element to register. * @param fireEvents If canvas and canvas handled registration events must be fired. */ @SuppressWarnings("unchecked") public void register(final ShapeFactory<Object, Shape> factory, final Element<View<?>> candidate, final boolean fireEvents) { assert factory != null && candidate != null; final Shape shape = factory.newShape(candidate.getContent().getDefinition()); // Set the same identifier as the graph element's one. if (null == shape.getUUID()) { shape.setUUID(candidate.getUUID()); } register(shape, candidate, fireEvents); }
hasEventHandlers.addHandler(ViewEventType.MOUSE_ENTER, overHandler); registerHandler(shape.getUUID(), overHandler); final MouseExitHandler outHandler = new MouseExitHandler() { hasEventHandlers.addHandler(ViewEventType.MOUSE_EXIT, outHandler); registerHandler(shape.getUUID(), outHandler); registerHandler(shape.getUUID(), dragHandler);
@Override protected void onRegister(final Element element) { super.onRegister(element); final Shape<?> shape = getSelectionControl().getCanvas().getShape(element.getUUID()); if (null != shape) { final ShapeView shapeView = shape.getShapeView(); if (shapeView instanceof HasEventHandlers) { final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView; if (hasEventHandlers.supports(ViewEventType.MOUSE_CLICK)) { final MouseClickHandler clickHandler = new MouseClickHandler() { @Override public void handle(final MouseClickEvent event) { if (event.isButtonLeft() || event.isButtonRight()) { singleSelect(element); } } }; hasEventHandlers.addHandler(ViewEventType.MOUSE_CLICK, clickHandler); registerHandler(shape.getUUID(), clickHandler); } } } }