private boolean supportsControlPoints(Shape<?> shape) { return shape.getShapeView() instanceof HasControlPoints; }
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()); } }
@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(); }
@SuppressWarnings("unchecked") public Canvas addShapeIntoView(final Shape shape) { if (shape.getUUID() == null) { shape.setUUID(UUID.uuid()); } getView().add(shape.getShapeView()); return this; }
public S getChild(final String uuid) { return children.stream() .filter(c -> c.getUUID().equals(uuid)) .findFirst() .orElse(null); } }
/** * 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); }
public CanvasHighlight unhighLight() { if (!uuids.isEmpty()) { uuids.forEach(uuid -> { final Shape shape = getShape(uuid); if (null != shape) { shape.applyState(ShapeState.NONE); } }); uuids.clear(); } setValidCursor(); return this; }
@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 animate(final int index, final Command callback) { if (index < shapes.size()) { final Shape shape = shapes.get(index); shape.applyState(ShapeState.HIGHLIGHT); final Timer t = new Timer() { @Override public void run() { animate(index + 1, callback); } }; t.schedule(TIMER_DELAY); } else { callback.execute(); } }
private boolean isConnector(Shape<?> shape) { return shape.getShapeView() instanceof IsConnector; }
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); } } }
@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; }
private boolean applyViolation(final H canvasHandler, final RuleViolation violation) { if (hasViolations(violation)) { final Shape shape = getShape(canvasHandler, violation.getUUID()); if (null != shape) { shape.applyState(ShapeState.INVALID); } return true; } return false; }
@SuppressWarnings("unchecked") public Canvas addChild(final Shape parent, final Shape child) { getView().addChild(parent.getShapeView(), child.getShapeView()); return this; }
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 deleteShape(final Shape shape) { deleteShapeFromView(shape); fireCanvasShapeRemoved(shape); shapes.remove(shape.getUUID()); canvasShapeRemovedEvent.fire(new CanvasShapeRemovedEvent(this, shape)); return this; }
private void applyStateToShape(final String uuid, final ShapeState state) { final Shape shape = getShape(uuid); if (null != shape) { uuids.add(uuid); shape.applyState(state); } if (ShapeState.INVALID.equals(state)) { setInvalidCursor(); } else { setValidCursor(); } }
@SuppressWarnings("unchecked") public Canvas dock(final Shape parent, final Shape child) { getView().dock(parent.getShapeView(), child.getShapeView()); return this; }
final Shape<?> shape = getShape(element.getUUID()); if (null != shape) { final ShapeView shapeView = shape.getShapeView(); if (shapeView instanceof HasEventHandlers) { final HasEventHandlers hasEventHandlers = (HasEventHandlers) shapeView; 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);
@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()))); }