List of usage examples for com.vaadin.client Util findConnectorFor
public static ComponentConnector findConnectorFor(Widget widget)
From source file:fi.jasoft.dragdroplayouts.client.ui.VLayoutDragDropMouseHandler.java
License:Apache License
/** * Called when the dragging a component should be initiated by both a mouse * down event as well as a touch start event * // www . j a v a 2s . c om * FIXME This method is a BIG hack to circumvent Vaadin's very poor client * side API's. This will break often. Refactor once Vaadin gets a grip. * * @param event */ protected void initiateDrag(NativeEvent event) { // Check that dragging is enabled if (dragMode == LayoutDragMode.NONE) { return; } // Dragging can only be done with left mouse button and no modifier keys if (!isMouseDragEvent(event) && !Util.isTouchEvent(event)) { return; } // Get target widget EventTarget eventTarget = event.getEventTarget(); Element targetElement = Element.as(eventTarget); Widget target = WidgetUtil.findWidget(targetElement, null); if (isEventOnScrollBar(event)) { return; } // do not drag close button of TabSheet tab if (isElementNotDraggable(targetElement)) { VDragAndDropManager.get().interruptDrag(); return; } // Abort if drag mode is caption mode and widget is not a caption boolean isPanelCaption = target instanceof VPanel && targetElement.getParentElement().getClassName().contains("v-panel-caption"); boolean isCaption = isPanelCaption || VDragDropUtil.isCaptionOrCaptionless(target); if (dragMode == LayoutDragMode.CAPTION && !isCaption) { /* * Ensure target is a caption in caption mode */ return; } if (dragMode == LayoutDragMode.CAPTION && isCaption) { /* * Ensure that captions in nested layouts don't get accepted if in * caption mode */ Widget w = VDragDropUtil.getTransferableWidget(target); ComponentConnector c = Util.findConnectorFor(w); ComponentConnector parent = (ComponentConnector) c.getParent(); if (parent.getWidget() != root) { return; } } // Create the transfarable VTransferable transferable = VDragDropUtil.createLayoutTransferableFromMouseDown(event, root, target); // Are we trying to drag the root layout if (transferable == null) { VConsole.log("Creating transferable on mouse down returned null"); return; } // Resolve the component final Widget w; ComponentConnector c = null, parent = null; if (target instanceof TabCaption) { TabCaption tabCaption = (TabCaption) target; Tab tab = tabCaption.getTab(); int tabIndex = ((ComplexPanel) tab.getParent()).getWidgetIndex(tab); VTabsheet tabsheet = tab.getTabsheet(); w = tab; c = tabsheet.getTab(tabIndex); parent = Util.findConnectorFor(tabsheet); } else if (root instanceof VDDAccordion) { w = target; parent = Util.findConnectorFor(root); StackItem tab = WidgetUtil.findWidget(targetElement, StackItem.class); if (tab != null && root.getElement().isOrHasChild(tab.getElement())) { c = ((VDDAccordion) root).getTab(((VDDAccordion) root).getTabPosition(tab)); } } else if (transferable.getData(Constants.TRANSFERABLE_DETAIL_COMPONENT) != null) { ComponentConnector connector = (ComponentConnector) transferable .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT); w = connector.getWidget(); c = Util.findConnectorFor(w); parent = (ComponentConnector) c.getParent(); } else { // Failsafe if no widget was found w = root; c = Util.findConnectorFor(w); parent = (ComponentConnector) c.getParent(); VConsole.log("Could not resolve component, using root as component"); } VConsole.log("Dragging widget: " + w); VConsole.log(" in parent: " + parent); // Ensure component is draggable if (!VDragDropUtil.isDraggingEnabled(parent, w)) { VConsole.log("Dragging disabled for " + w.getClass().getName() + " in " + parent.getWidget().getClass().getName()); VDragAndDropManager.get().interruptDrag(); return; } // Announce drag start to listeners for (DragStartListener dl : dragStartListeners) { if (!dl.dragStart(w, dragMode)) { VDragAndDropManager.get().interruptDrag(); return; } } currentDraggedWidget = w; // Announce to handler that we are starting a drag operation VDragEvent currentDragEvent = VDragAndDropManager.get().startDrag(transferable, event, true); /* * Create the drag image */ com.google.gwt.dom.client.Element dragImageElement = dragImageProvider == null ? null : dragImageProvider.getDragImageElement(w); if (dragImageElement != null) { // Set stylename to proxy component as well dragImageElement.addClassName(ACTIVE_DRAG_SOURCE_STYLENAME); } else if (root instanceof VCssLayout) { /* * CSS Layout does not have an enclosing div so we just use the * component div */ dragImageElement = w.getElement(); } else if (root instanceof VTabsheet) { /* * Tabsheet should use the dragged tab as a drag image */ dragImageElement = targetElement; } else if (root instanceof VAccordion) { /* * Accordion should use the dragged tab as a drag image */ dragImageElement = targetElement; } else if (root instanceof VFormLayout) { /* * Dragging a component in a form layout should include the caption * and error indicator as well */ Element rowElement = (Element) VDDFormLayout .getRowFromChildElement((com.google.gwt.dom.client.Element) w.getElement().cast(), (com.google.gwt.dom.client.Element) root.getElement().cast()) .cast(); dragImageElement = rowElement; } else { /* * For other layouts we just use the target element; */ dragImageElement = w.getElement(); } currentDragEvent.createDragImage(dragImageElement, true); Element clone = currentDragEvent.getDragImage(); assert (clone != null); // Lock drag image dimensions clone.getStyle().setWidth(dragImageElement.getOffsetWidth(), Unit.PX); clone.getStyle().setHeight(dragImageElement.getOffsetHeight(), Unit.PX); if (c != null && c.delegateCaptionHandling() && !(root instanceof VTabsheet) && !(root instanceof VAccordion)) { /* * Captions are not being dragged with the widget since they are * separate. Manually add a clone of the caption to the drag image. */ if (target instanceof VCaption) { clone.insertFirst(targetElement.cloneNode(true)); } } if (BrowserInfo.get().isIE()) { // Fix IE not aligning the drag image correctly when dragging // layouts clone.getStyle().setPosition(Position.ABSOLUTE); } currentDraggedWidget.addStyleName(ACTIVE_DRAG_SOURCE_STYLENAME); // Listen to mouse up for cleanup mouseUpHandlerReg = Event.addNativePreviewHandler(new Event.NativePreviewHandler() { @Override public void onPreviewNativeEvent(NativePreviewEvent event) { if (event.getTypeInt() == Event.ONMOUSEUP || event.getTypeInt() == Event.ONTOUCHEND || event.getTypeInt() == Event.ONTOUCHCANCEL) { if (mouseUpHandlerReg != null) { mouseUpHandlerReg.removeHandler(); if (currentDraggedWidget != null) { currentDraggedWidget.removeStyleName(ACTIVE_DRAG_SOURCE_STYLENAME); if (dragImageProvider != null) { com.google.gwt.dom.client.Element dragImageElement = dragImageProvider .getDragImageElement(currentDraggedWidget); if (dragImageElement != null) { dragImageElement.removeClassName(ACTIVE_DRAG_SOURCE_STYLENAME); } } currentDraggedWidget = null; } } // Ensure capturing is turned off at mouse up Event.releaseCapture(RootPanel.getBodyElement()); } } }); }
From source file:info.magnolia.ui.vaadin.gwt.client.applauncher.widget.AppLauncherUtil.java
License:Open Source License
public static AppLauncherConnector getConnector() { return (AppLauncherConnector) Util.findConnectorFor(getView().asWidget()); }
From source file:info.magnolia.ui.vaadin.gwt.client.form.connector.FormConnector.java
License:Open Source License
@Override public void jumpToNextError(FormFieldWrapper fieldWrapper) { ComponentConnector cc = fieldWrapper == null ? null : Util.findConnectorFor(fieldWrapper.getField()); focusRpc.focusNextProblematicField(cc); }
From source file:info.magnolia.ui.vaadin.gwt.client.magnoliashell.shell.MagnoliaShellConnector.java
License:Open Source License
@Override public void updateViewportLayout(ViewportWidget activeViewport) { getLayoutManager().setNeedsMeasure(Util.findConnectorFor(activeViewport)); getLayoutManager().layoutNow(); }
From source file:info.magnolia.ui.vaadin.gwt.client.magnoliashell.viewport.AppsTransitionDelegate.java
License:Open Source License
public AppsTransitionDelegate(final AppsViewportWidget viewport) { this.viewport = viewport; curtainFadeOutAnimation.addCallback(new JQueryCallback() { @Override/*from w w w .j a v a2 s . co m*/ public void execute(JQueryWrapper jq) { setCurtainAttached(false); } }); Util.findConnectorFor(viewport).getConnection() .addHandler(ApplicationConnection.ResponseHandlingStartedEvent.TYPE, communicationHandler); Util.findConnectorFor(viewport).getConnection() .addHandler(ApplicationConnection.ResponseHandlingEndedEvent.TYPE, communicationHandler); }
From source file:info.magnolia.ui.vaadin.gwt.client.magnoliashell.viewport.AppsTransitionDelegate.java
License:Open Source License
/** * Zoom-in if switching to a different running app, from apps-launcher only * closing an app doesn't zoom-in the next app, running apps are all hidden explicitly except current one. */// www .j a v a 2s .c o m @Override public void setVisibleChild(final ViewportWidget viewport, final Widget app) { if (!((AppsViewportWidget) viewport).isAppClosing() && isWidgetVisibilityHidden(app)) { viewport.showChildNoTransition(app); pendingAppZoomCommand = new Command() { @Override public void execute() { Util.findConnectorFor(viewport).getLayoutManager().layoutNow(); zoomInAnimation.run(ZOOM_DURATION, app.getElement()); } }; if (!isResponseProcessingInProgress) { pendingAppZoomCommand.execute(); this.pendingAppZoomCommand = null; } } else { viewport.showChildNoTransition(app); ShellState.get().setAppStarted(); log.warning("Switching to 'APP STARTED' state without app transition"); } }
From source file:info.magnolia.ui.vaadin.gwt.client.magnoliashell.viewport.connector.AppsViewportConnector.java
License:Open Source License
private String resolveAppNameHack(Widget appWidget) { return ((MagnoliaTabSheetConnector) Util.findConnectorFor(appWidget)).getState().name; }
From source file:info.magnolia.ui.vaadin.gwt.client.magnoliashell.viewport.connector.AppsViewportConnector.java
License:Open Source License
private Widget resolveAppWidgetHack(String appName) { final Iterator<Widget> it = getWidget().iterator(); while (it.hasNext()) { final Widget widget = it.next(); if (appName.equals(((MagnoliaTabSheetConnector) Util.findConnectorFor(widget)).getState().name)) { return widget; }// w ww . j a v a 2s. c o m } return null; }
From source file:info.magnolia.ui.vaadin.gwt.client.magnoliashell.viewport.connector.ShellAppsViewportConnector.java
License:Open Source License
@Override public void onShellAppLoaded(Widget shellAppWidget) { ComponentConnector shellAppConnector = Util.findConnectorFor(shellAppWidget); eventBus.fireEvent(new ShellAppStartedEvent(getState().getShellAppType(shellAppConnector))); }
From source file:info.magnolia.ui.vaadin.gwt.client.richtext.TextAreaStretcherConnector.java
License:Open Source License
private void registerSizeChangeListeners() { final LayoutManager lm = getParent().getLayoutManager(); final UIConnector ui = getConnection().getUIConnector(); getParent().addStateChangeHandler(textAreaSizeHandler); lm.addElementResizeListener(ui.getWidget().getElement(), windowResizeListener); final ComponentConnector formConnector = Util.findConnectorFor(this.form); if (formConnector != null) { formConnector.getLayoutManager().addElementResizeListener(this.form.getElement(), formResizeListener); }/*from ww w. j a v a 2 s . c o m*/ }