com.vaadin.client.ComponentConnector Java Examples

The following examples show how to use com.vaadin.client.ComponentConnector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VDDVerticalSplitPanelDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void dragOver(VDragEvent drag) {

    getLayout().deEmphasis();

    getLayout().updateDragDetails(drag);

    getLayout().postOverHook(drag);

    ComponentConnector widgetConnector = (ComponentConnector) drag
            .getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);

    if (widgetConnector != null
            && getLayout().equals(widgetConnector.getWidget())) {
        return;
    }

    // Validate the drop
    validate(new VAcceptCallback() {
        public void accepted(VDragEvent event) {
            getLayout().emphasis(event.getElementOver());
        }
    }, drag);
}
 
Example #2
Source File: CubaPasswordFieldConnector.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    super.onStateChanged(stateChangeEvent);

    getWidget().setAutocomplete(getState().autocomplete);

    if (stateChangeEvent.hasPropertyChanged("capsLockIndicator")) {
        ComponentConnector capsLockIndicator = (ComponentConnector) getState().capsLockIndicator;

        getWidget().setIndicateCapsLock(capsLockIndicator == null ? null : capsLockIndicator.getWidget());
    }

    if (stateChangeEvent.hasPropertyChanged("htmlName")) {
        getWidget().setHtmlName(getState().htmlName);
    }
}
 
Example #3
Source File: VDDHorizontalSplitPanelDropHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void dragOver(VDragEvent drag) {

    getLayout().deEmphasis();

    getLayout().updateDragDetails(drag);

    getLayout().postOverHook(drag);

    ComponentConnector widgetConnector = (ComponentConnector) drag
            .getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);

    if (widgetConnector != null
            && getLayout().equals(widgetConnector.getWidget())) {
        return;
    }

    // Validate the drop
    validate(new VAcceptCallback() {
        public void accepted(VDragEvent event) {
            getLayout().emphasis(event.getElementOver());
        }
    }, drag);
}
 
Example #4
Source File: VGrabFilter.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected boolean canBeGrabbedRecursive(Widget root, Widget widget) {
    if (widget == root) {
        return true;
    }

    ComponentConnector connector;
    if (!isCaptionForAccordion(widget)) {
        connector = Util.findConnectorFor(widget);
    } else {
        connector = findConnectorForAccordionCaption(widget);
    }

    if (connector != null && state.nonGrabbable.contains(connector)) {
        return false;
    }

    Widget parent = widget.getParent();
    if (parent == null || parent == root) {
        return true;
    }

    return canBeGrabbedRecursive(root, parent);
}
 
Example #5
Source File: HTML5Support.java    From cuba with Apache License 2.0 6 votes vote down vote up
public static HTML5Support enable(final ComponentConnector connector,
        final VDDAbstractDropHandler<? extends Widget> handler) {
    if (handler == null) {
        return null;
    }

    Widget w = connector.getWidget();
    final HTML5Support support = GWT.create(HTML5Support.class);
    final HTML5DragHandler dragHandler = new HTML5DragHandler(connector,
            handler);

    support.handlers
            .add(w.addDomHandler(dragHandler, DragEnterEvent.getType()));
    support.handlers
            .add(w.addDomHandler(dragHandler, DragOverEvent.getType()));
    support.handlers.add(w.addDomHandler(dragHandler, DropEvent.getType()));

    return support;
}
 
Example #6
Source File: VPopupButton.java    From cuba with Apache License 2.0 6 votes vote down vote up
private void checkForRTE(Widget popupComponentWidget2) {
    if (popupComponentWidget2 instanceof VRichTextArea) {
        ComponentConnector rtaConnector = Util
                .findConnectorFor(popupComponentWidget2);
        if (rtaConnector != null) {
            rtaConnector.flush();
        }
    } else if (popupComponentWidget2 instanceof Grid) {
        // Grid implements HasWidgets but iterator() throws
        // UnsupportedOperationException so don't do anything
        // in case of Grid.
    } else if (popupComponentWidget2 instanceof HasWidgets) {
        HasWidgets hw = (HasWidgets) popupComponentWidget2;
        Iterator<Widget> iterator = hw.iterator();
        while (iterator.hasNext()) {
            checkForRTE(iterator.next());
        }
    }
}
 
Example #7
Source File: AutoCompleteTextFieldConnector.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void extend(final ServerConnector target) {
    textFieldWidget = (VTextField) ((ComponentConnector) target).getWidget();
    textFieldWidget.setImmediate(true);
    textFieldWidget.textChangeEventMode = "EAGER";
    panel.setWidget(select);
    panel.setStyleName("suggestion-popup");
    panel.setOwner(textFieldWidget);

    textFieldWidget.addKeyUpHandler(new KeyUpHandler() {
        @Override
        public void onKeyUp(final KeyUpEvent event) {
            if (panel.isAttached()) {
                handlePanelEventDelegation(event);
            } else if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
                rpc.executeQuery(textFieldWidget.getValue(), textFieldWidget.getCursorPos());
            } else {
                doAskForSuggestion();
            }
        }
    });
}
 
Example #8
Source File: VDDGridLayout.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Emphasizes a component container when user is hovering a dragged
 * component over the container.
 * 
 * @param cell
 *            The container
 * @param event
 */
protected void emphasis(CellDetails cell, VDragEvent event) {

    Style shadowStyle = dragShadow.getElement().getStyle();
    shadowStyle.setPosition(Position.ABSOLUTE);
    shadowStyle.setWidth(cell.width, Unit.PX);
    shadowStyle.setHeight(cell.height, Unit.PX);
    shadowStyle.setLeft(cell.x, Unit.PX);
    shadowStyle.setTop(cell.y, Unit.PX);

    // Remove any existing empasis
    deEmphasis();

    // Ensure we are not dragging ourself into ourself
    ComponentConnector draggedConnector = (ComponentConnector) event
            .getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);

    if (draggedConnector != null
            && draggedConnector.getWidget() == VDDGridLayout.this) {
        return;
    }

    HorizontalDropLocation hl = getHorizontalDropLocation(cell, event);
    VerticalDropLocation vl = getVerticalDropLocation(cell, event);

    // Apply over style
    setStyleName(dragShadow.getElement(), OVER, true);

    // Add vertical location dependent style
    setStyleName(dragShadow.getElement(),
            OVER + "-" + vl.toString().toLowerCase(), true);

    // Add horizontal location dependent style
    setStyleName(dragShadow.getElement(),
            OVER + "-" + hl.toString().toLowerCase(), true);

}
 
Example #9
Source File: VDDLayoutStateDragImageProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Element getDragImageElement(Widget w) {
    ComponentConnector component = Util.findConnectorFor(w);
    Connector dragImage = state.referenceImageComponents.get(component);

    if (dragImage != null) {
        return ConnectorMap.get(component.getConnection())
                .getElement(dragImage.getConnectorId());
    }

    return null;
}
 
Example #10
Source File: VDragCaptionProvider.java    From cuba with Apache License 2.0 5 votes vote down vote up
public Element getDragCaptionElement(Widget w) {
    ComponentConnector component = Util.findConnectorFor(w);
    DDLayoutState state = ((DragAndDropAwareState) root.getState()).getDragAndDropState();
    DragCaptionInfo dci = state.dragCaptions.get(component);

    Document document = Document.get();

    Element dragCaptionImage = document.createDivElement();
    Element dragCaption = document.createSpanElement();

    String dragCaptionText = dci.caption;
    if (dragCaptionText != null) {
        if (dci.contentMode == ContentMode.TEXT) {
            dragCaption.setInnerText(dragCaptionText);
        } else if (dci.contentMode == ContentMode.HTML) {
            dragCaption.setInnerHTML(dragCaptionText);
        } else if (dci.contentMode == ContentMode.PREFORMATTED) {
            PreElement preElement = document.createPreElement();
            preElement.setInnerText(dragCaptionText);
            dragCaption.appendChild(preElement);
        }
    }

    String dragIconKey = state.dragCaptions.get(component).iconKey;
    if (dragIconKey != null) {
        String resourceUrl = root.getResourceUrl(dragIconKey);
        Icon icon = component.getConnection().getIcon(resourceUrl);
        dragCaptionImage.appendChild(icon.getElement());
    }

    dragCaptionImage.appendChild(dragCaption);

    return dragCaptionImage;
}
 
Example #11
Source File: GwtUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Contract("null -> null")
public static Widget connector2Widget(@Nullable Connector connector) {
  if (connector == null) {
    return null;
  }
  ComponentConnector componentConnector = (ComponentConnector)connector;
  return componentConnector.getWidget();
}
 
Example #12
Source File: VDragFilter.java    From cuba with Apache License 2.0 5 votes vote down vote up
private ComponentConnector findConnectorFor(Widget widget) {
    if (!isCaptionForAccordion(widget)) {
        return Util.findConnectorFor(widget);
    } else {
        return findConnectorForAccordionCaption(widget);
    }
}
 
Example #13
Source File: CubaCopyButtonExtensionConnector.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void extend(ServerConnector target) {
    VButton button = (VButton) ((ComponentConnector) target).getWidget();

    button.addClickHandler(event -> {
        if (getState().copyTargetSelector != null) {
            boolean success = copyToClipboard(getState().copyTargetSelector.startsWith(".")
                    ? getState().copyTargetSelector
                    : "." + getState().copyTargetSelector);
            getRpcProxy(CubaCopyButtonExtensionServerRpc.class).copied(success);
        }
    });
}
 
Example #14
Source File: CubaOrderedLayoutSlot.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(ClickEvent event) {
    Element target = Element.as(event.getNativeEvent().getEventTarget());
    ComponentConnector componentConnector = Util.findConnectorFor(getWidget());

    if (target == contextHelpIcon
            && componentConnector instanceof HasContextHelpConnector) {
        HasContextHelpConnector connector = (HasContextHelpConnector) componentConnector;
        if (hasContextHelpIconListeners(componentConnector.getState())) {
            connector.contextHelpIconClick(event);
        }
    }
}
 
Example #15
Source File: CubaFieldGroupLayoutWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected ComponentConnectorLayoutSlot createComponentConnectorLayoutSlot(ComponentConnector component) {
    CubaFieldGroupLayoutComponentSlot slot =
            new CubaFieldGroupLayoutComponentSlot(CubaFieldGroupLayoutWidget.CLASSNAME, component, getConnector());
    slot.setCaptionInline(useInlineCaption);
    return slot;
}
 
Example #16
Source File: CubaFieldGroupLayoutComponentSlot.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    if (DOM.eventGetType(event) == Event.ONCLICK) {
        Element target = Element.as(event.getEventTarget());
        ComponentConnector componentConnector = Util.findConnectorFor(getWidget());
        if (target == contextHelpIndicatorElement
                && componentConnector instanceof HasContextHelpConnector) {
            HasContextHelpConnector connector = (HasContextHelpConnector) componentConnector;
            if (hasContextHelpIconListeners(componentConnector.getState())) {
                connector.contextHelpIconClick(event);
            }
        }
    }
}
 
Example #17
Source File: CubaFieldGroupLayoutConnector.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void updateCaption(ComponentConnector childConnector) {
    super.updateCaption(childConnector);

    if (getState().useInlineCaption && initialStateChangePerformed) {
        updateCaptionSizes();
        updateCaptionAlignments();

        // always relayout after caption changes
        getLayoutManager().setNeedsLayout(this);
    }
}
 
Example #18
Source File: GwtUIUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static List<Widget> remapWidgets(AbstractComponentContainerConnector abstractLayout) {
  List<Widget> widgets = new ArrayList<>();
  for (ComponentConnector connector : abstractLayout.getChildComponents()) {
    widgets.add(connector.getWidget());
  }

  return widgets;
}
 
Example #19
Source File: HTML5Support.java    From cuba with Apache License 2.0 5 votes vote down vote up
private boolean validate(NativeEvent event) {
    if (!Element.is(event.getEventTarget())) {
        return false;
    }

    Element target = Element.as(event.getEventTarget());
    Widget widget = Util.findWidget(target, null);
    if (widget == null) {
        return false;
    }

    ComponentConnector connector = Util.findConnectorFor(widget);
    while (connector == null && widget != null) {
        widget = widget.getParent();
        connector = Util.findConnectorFor(widget);
    }

    if (this.connector == connector) {
        return true;
    } else if (connector == null) {
        return false;
    } else if (connector.getWidget() instanceof VDDHasDropHandler) {
        // Child connector handles its own drops
        return false;
    }

    // Over non droppable child
    return true;
}
 
Example #20
Source File: VDDAccordion.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public int getTabContentPosition(Widget w) {
    for (int i = 0; i < getTabCount(); i++) {
        ComponentConnector tabContent = getTab(i);
        if (tabContent.getWidget() == w) {
            return i;
        }
    }
    return -1;
}
 
Example #21
Source File: CubaCollapsibleMenuLayoutExtensionConnector.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void extend(ServerConnector target) {
    ComponentConnector connector = ((ComponentConnector) target);
    LayoutManager layoutManager = connector.getLayoutManager();

    Scheduler.get().scheduleFinally(() -> layoutManager.addElementResizeListener(
            connector.getWidget().getElement(),
            e -> layoutManager.setNeedsMeasureRecursively(connector)));
}
 
Example #22
Source File: CriterionTestHelper.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
static VDropHandler createMockedVDropHandler(String dropTargetId) {
    com.google.gwt.user.client.Element element = Mockito.mock(com.google.gwt.user.client.Element.class);
    when(element.getId()).thenReturn(dropTargetId);
    Widget widget = Mockito.mock(Widget.class);
    when(widget.getElement()).thenReturn(element);
    ComponentConnector connector = Mockito.mock(ComponentConnector.class);
    when(connector.getWidget()).thenReturn(widget);
    VDropHandler dropHandler = Mockito.mock(VDropHandler.class);
    when(dropHandler.getConnector()).thenReturn(connector);

    return dropHandler;
}
 
Example #23
Source File: CriterionTestHelper.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
static VDragEvent createMockedVDragEvent(String dragSourceId, Widget widget) {
    com.google.gwt.user.client.Element element = Mockito.mock(com.google.gwt.user.client.Element.class);
    when(element.getId()).thenReturn(dragSourceId);
    when(widget.getElement()).thenReturn(element);
    ComponentConnector dragSource = Mockito.mock(ComponentConnector.class);
    when(dragSource.getWidget()).thenReturn(widget);
    VTransferable transferable = Mockito.mock(VTransferable.class);
    when(transferable.getDragSource()).thenReturn(dragSource);
    VDragEvent dragEvent = Mockito.mock(VDragEvent.class);
    when(dragEvent.getTransferable()).thenReturn(transferable);

    return dragEvent;
}
 
Example #24
Source File: WrappingGridConnector.java    From GridExtensionPack with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void extend(ServerConnector target) {
	grid = (Grid<?>) ((ComponentConnector) target).getWidget();

	wrappingEnabled = false;
	WrappingClientRPC rpc = new WrappingClientRPC() {
		@Override
		public void setWrapping(boolean enable, int defaultRowHeight) {
			if (wrappingEnabled != enable) {
				wrappingEnabled = enable;
				DEFAULT_HEIGHT = defaultRowHeight;
				if (enable) {
					// Figure out default header height
					applyStyle.execute(0);
				} else {
					disableWrapping();
				}
			}
		}
	};

	registerRpc(WrappingClientRPC.class, rpc);

	resizeHandler = grid.addColumnResizeHandler(new ColumnResizeHandler() {
		@Override
		public void onColumnResize(ColumnResizeEvent event) {
			Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() {
				@Override
				public void execute() {
					AnimationScheduler.get().requestAnimationFrame(applyStyle);						
				}
			});
		}
	});
}
 
Example #25
Source File: GanttConnector.java    From gantt with Apache License 2.0 5 votes vote down vote up
private void updateScrollDelegateScrollContainerHeight() {
    boolean tableHorScrollbarVisible = GanttUtil
            .isHorizontalScrollbarVisible(delegateScrollGridTarget.getEscalator());
    int headerHeight = getWidget().getTimelineHeight();
    // Adjust table's scroll container height to match the Gantt widget's
    // scroll container height.
    int newTableScrollContainerHeight = getWidget().getScrollContainerHeight();
    if (getWidget().isContentOverflowingHorizontally()) {
        getWidget().hideHorizontalScrollbarSpacer();
        if (tableHorScrollbarVisible) {
            newTableScrollContainerHeight += WidgetUtil.getNativeScrollbarSize();
        }
    } else {
        if (tableHorScrollbarVisible) {
            getWidget().showHorizontalScrollbarSpacer();
        } else {
            getWidget().hideHorizontalScrollbarSpacer();
        }
    }

    GanttUtil.getTableWrapper(delegateScrollGridTarget.getEscalator()).getStyle().setProperty("height",
            Math.max(0, headerHeight + newTableScrollContainerHeight) + "px");
    delegateScrollGridTarget.getEscalator().getBody().getElement().getStyle().setProperty("height",
            Math.max(0, newTableScrollContainerHeight) + "px");
    delegateScrollGridTarget.getEscalator()
            .setHeight(Math.max(0, headerHeight + newTableScrollContainerHeight) + "px");

    getLayoutManager().setNeedsMeasure((ComponentConnector) getState().verticalScrollDelegateTarget);
}
 
Example #26
Source File: GanttConnector.java    From gantt with Apache License 2.0 5 votes vote down vote up
/** Updates all steps predecessor visualizations. */
public void updateAllStepsPredecessors() {
    for (ComponentConnector c : getChildComponents()) {
        StepWidget stepWidget = ((StepConnector) c).getWidget();
        stepWidget.updatePredecessor();
    }
}
 
Example #27
Source File: GanttConnector.java    From gantt with Apache License 2.0 5 votes vote down vote up
/**
 * Return {@link StepWidget} objects that are related to the given
 * StepWidget. Via {@link Step#getPredecessor()} for example.
 */
public Set<StepWidget> findRelatedSteps(Step targetStep, List<ComponentConnector> stepConnectors) {
    Set<StepWidget> widgets = new HashSet<StepWidget>();
    for (ComponentConnector con : stepConnectors) {
        StepWidget stepWidget = ((StepConnector) con).getWidget();
        if (targetStep.equals(stepWidget.getStep().getPredecessor())) {
            widgets.add(stepWidget);
        }
    }
    return widgets;
}
 
Example #28
Source File: GwtDockLayoutImplConnector.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {
  GwtDockLayoutImpl dockLayout = getWidget();
  dockLayout.clear();

  boolean noCenterElement = true;
  List<ComponentConnector> childComponents = getChildComponents();
  for (int i = 0; i < childComponents.size(); i++) {
    ComponentConnector connector = childComponents.get(i);
    DockLayoutState.Constraint constraint = getState().myConstraints.get(i);

    Widget widget = GwtUIUtil.fillAndReturn(connector.getWidget());
    switch (constraint) {
      case TOP:
        dockLayout.add(widget, GwtDockLayoutImpl.NORTH);
        break;
      case BOTTOM:
        dockLayout.add(widget, GwtDockLayoutImpl.SOUTH);
        break;
      case LEFT:
        dockLayout.add(widget, GwtDockLayoutImpl.WEST);
        break;
      case RIGHT:
        dockLayout.add(widget, GwtDockLayoutImpl.EAST);
        break;
      case CENTER:
        setCenterWidget(dockLayout, widget);
        noCenterElement = false;
        break;
    }
  }

  if (noCenterElement) {
    setCenterWidget(dockLayout, new SimplePanel());
  }
}
 
Example #29
Source File: VDDCssLayout.java    From cuba with Apache License 2.0 5 votes vote down vote up
private void updatePlaceHolderStyleProperties(VDragEvent drag) {
    int width = 0;
    int height = 0;
    String className = "";

    placeHolderElement.setClassName(DRAG_SHADOW_STYLE_NAME);

    ComponentConnector draggedConnector = (ComponentConnector) drag
            .getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);
    if (draggedConnector != null) {
        height = Util.getRequiredHeight(draggedConnector.getWidget());
        width = Util.getRequiredWidth(draggedConnector.getWidget());
        className = draggedConnector.getWidget().getElement()
                .getClassName();
        className = className.replaceAll(
                VLayoutDragDropMouseHandler.ACTIVE_DRAG_SOURCE_STYLENAME,
                "");
        placeHolderElement.addClassName(className);
    } else if (drag.getElementOver() != getElement()) {
        width = 3;
        height = drag.getElementOver().getOffsetHeight();
    }

    placeHolderElement.getStyle().setWidth(width, Unit.PX);
    placeHolderElement.getStyle().setHeight(height, Unit.PX);
}
 
Example #30
Source File: VDDAbsoluteLayoutDropHandler.java    From cuba with Apache License 2.0 4 votes vote down vote up
public VDDAbsoluteLayoutDropHandler(ComponentConnector connector) {
    super(connector);
}