List of usage examples for com.vaadin.client BrowserInfo get
public static BrowserInfo get()
From source file:com.haulmont.cuba.web.toolkit.ui.client.Tools.java
License:Apache License
public static void fixFlashTitleIE() { // if url has '#' then title changed in ie8 after flash loaded. This fix changed set normal title if (BrowserInfo.get().isIE()) { impl.fixFlashTitleIEJS();/*w w w. j a v a 2s . co m*/ } }
From source file:com.haulmont.cuba.web.toolkit.ui.client.Tools.java
License:Apache License
public static boolean isUseSimpleMultiselectForTouchDevice() { return BrowserInfo.get().isAndroid() || BrowserInfo.get().isIOS(); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.tooltip.CubaTooltip.java
License:Apache License
@Override public void connectHandlersToWidget(Widget widget) { Profiler.enter("VTooltip.connectHandlersToWidget"); widget.addDomHandler(tooltipEventHandler, MouseOutEvent.getType()); widget.addDomHandler(tooltipEventHandler, MouseDownEvent.getType()); widget.addDomHandler(tooltipEventHandler, KeyDownEvent.getType()); if (!BrowserInfo.get().isIOS()) { widget.addDomHandler(tooltipEventHandler, MouseMoveEvent.getType()); widget.addDomHandler(tooltipEventHandler, FocusEvent.getType()); widget.addDomHandler(tooltipEventHandler, BlurEvent.getType()); }//from w w w . jav a 2s . com Profiler.leave("VTooltip.connectHandlersToWidget"); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.verticalmenu.CubaSideMenuWidget.java
License:Apache License
public CubaSideMenuWidget() { setStylePrimaryName(CLASS_NAME);/* ww w . j av a 2 s . c o m*/ sinkEvents(Event.ONMOUSEOVER | Event.ONMOUSEOUT); // Navigation is only handled by the root bar addFocusHandler(this); addBlurHandler(this); /* * Firefox auto-repeat works correctly only if we use a key press * handler, other browsers handle it correctly when using a key down handler */ if (BrowserInfo.get().isGecko()) { addKeyPressHandler(this); } else { addKeyDownHandler(this); } }
From source file:com.haulmont.cuba.web.widgets.client.addons.dragdroplayouts.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 * * 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//ww w.j a v a 2s .c o m */ 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 */ boolean hasDragCaption = false; com.google.gwt.dom.client.Element dragImageElement = null; if (root instanceof VHasDragCaptionProvider) { VDragCaptionProvider dragCaptionProvider = ((VHasDragCaptionProvider) root).getDragCaptionProvider(); if (dragCaptionProvider != null) { hasDragCaption = true; dragImageElement = dragCaptionProvider.getDragCaptionElement(currentDraggedWidget); } } if (!hasDragCaption && dragImageProvider != null) { dragImageElement = dragImageProvider.getDragImageElement(w); } if (dragImageElement != null) { // Set stylename to proxy component as well if (hasDragCaption) { dragImageElement.addClassName(ACTIVE_DRAG_CUSTOM_IMAGE_STYLENAME); } else { 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(); } Element clone; if (hasDragCaption) { currentDragEvent.setDragImage(dragImageElement); clone = dragImageElement; } else { currentDragEvent.createDragImage(dragImageElement, true); clone = currentDragEvent.getDragImage(); } assert (clone != null); // Lock drag image dimensions if (!hasDragCaption) { clone.getStyle().setWidth(dragImageElement.getOffsetWidth(), Style.Unit.PX); clone.getStyle().setHeight(dragImageElement.getOffsetHeight(), Style.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:com.haulmont.cuba.web.widgets.client.jqueryfileupload.CubaFileUploadWidget.java
License:Apache License
public CubaFileUploadWidget() { submitButton = new VButton(); submitButton.addClickHandler(new ClickHandler() { @Override/*w ww . j av a 2s .c o m*/ public void onClick(ClickEvent event) { fireNativeClick(getFileInputElement()); } }); add(submitButton); submitButton.setTabIndex(-1); setStyleName(DEFAULT_CLASSNAME); Element inputElement = Document.get().createFileInputElement(); inputElement.setAttribute("name", "files[]"); if (!BrowserInfo.get().isIE() && !BrowserInfo.get().isEdge()) { inputElement.setAttribute("title", " "); } listenToFocusEvents(inputElement); getElement().appendChild(inputElement); fileUpload = new JQueryFileUploadOverlay(this) { protected boolean canceled = false; @Override protected boolean isValidFile(String name, double size) { if (fileSizeLimit > 0 && size > fileSizeLimit) { if (filePermissionsHandler != null) { filePermissionsHandler.fileSizeLimitExceeded(name); } return false; } if (hasInvalidExtension(name)) { if (filePermissionsHandler != null) { filePermissionsHandler.fileExtensionNotAllowed(name); } return false; } return true; } protected boolean hasInvalidExtension(String name) { if (permittedExtensions != null && !permittedExtensions.isEmpty()) { if (name.lastIndexOf(".") > 0) { String fileExtension = name.substring(name.lastIndexOf("."), name.length()); return !permittedExtensions.contains(fileExtension.toLowerCase()); } return true; } return false; } @Override protected void queueUploadStart() { // listen to events of new input element listenToFocusEvents(getFileInputElement()); progressWindow = new CubaFileUploadProgressWindow(); progressWindow.setOwner(CubaFileUploadWidget.this); progressWindow.addStyleName(getStylePrimaryName() + "-progresswindow"); progressWindow.setVaadinModality(true); progressWindow.setDraggable(true); progressWindow.setResizable(false); progressWindow.setClosable(true); progressWindow.setCaption(progressWindowCaption); progressWindow.setCancelButtonCaption(cancelButtonCaption); progressWindow.closeListener = new CubaFileUploadProgressWindow.CloseListener() { @Override public void onClose() { canceled = true; // null progress to prevent repeated hide() call inside cancelUploading progressWindow = null; cancelUploading(); if (queueUploadListener != null) { queueUploadListener.uploadFinished(); } } }; progressWindow.setVisible(false); progressWindow.show(); progressWindow.center(); progressWindow.setVisible(true); canceled = false; } @Override protected void fileUploadStart(String fileName) { if (progressWindow != null) { progressWindow.setCurrentFileName(fileName); } } @Override protected void fileUploadSucceed(String fileName) { if (fileUploadedListener != null) { fileUploadedListener.fileUploaded(fileName); } } @Override protected void uploadProgress(double loaded, double total) { if (progressWindow != null) { float ratio = (float) (loaded / total); progressWindow.setProgress(ratio); } } @Override protected void queueUploadStop() { if (progressWindow != null) { progressWindow.hide(); progressWindow = null; } getFileInputElement().focus(); if (queueUploadListener != null) { queueUploadListener.uploadFinished(); } } @Override protected void uploadFailed(String textStatus, String errorThrown) { if (ignoreExceptions) { if (progressWindow != null) progressWindow.hide(); return; } if (!canceled) { if (unableToUploadFileMessage != null) { // show notification without server round trip, server may be unreachable VNotification notification = VNotification.createNotification(-1, CubaFileUploadWidget.this); String fileName = ""; if (progressWindow != null) { fileName = progressWindow.getCurrentFileName(); } String message = "<h1>" + WidgetUtil.escapeHTML(unableToUploadFileMessage.replace("%s", fileName)) + "</h1>"; notification.show(message, Position.MIDDLE_CENTER, "error"); } canceled = true; cancelUploading(); } } }; }
From source file:com.haulmont.cuba.web.widgets.client.orderedactionslayout.CubaOrderedLayoutSlot.java
License:Apache License
public void setCaption(String captionText, boolean contextHelpIconEnabled, Icon icon, List<String> styles, String error, boolean showError, boolean required, boolean enabled, boolean captionAsHtml) { // CAUTION copied from super // Caption wrappers Widget widget = getWidget();/*from w ww .j a v a2 s. com*/ final Element focusedElement = WidgetUtil.getFocusedElement(); // By default focus will not be lost boolean focusLost = false; if (captionText != null || icon != null || error != null || required || contextHelpIconEnabled) { if (caption == null) { caption = DOM.createDiv(); captionWrap = DOM.createDiv(); captionWrap.addClassName(StyleConstants.UI_WIDGET); captionWrap.addClassName("v-has-caption"); getElement().appendChild(captionWrap); orphan(widget); captionWrap.appendChild(widget.getElement()); adopt(widget); // Made changes to DOM. Focus can be lost if it was in the // widget. focusLost = (focusedElement == null ? false : widget.getElement().isOrHasChild(focusedElement)); } } else if (caption != null) { orphan(widget); getElement().appendChild(widget.getElement()); adopt(widget); captionWrap.removeFromParent(); caption = null; captionWrap = null; // Made changes to DOM. Focus can be lost if it was in the widget. focusLost = (focusedElement == null ? false : widget.getElement().isOrHasChild(focusedElement)); } // Caption text if (captionText != null) { if (this.captionText == null) { this.captionText = DOM.createSpan(); this.captionText.addClassName("v-captiontext"); if (caption != null) { caption.appendChild(this.captionText); } } if (captionText.trim().equals("")) { this.captionText.setInnerHTML(" "); } else { if (captionAsHtml) { this.captionText.setInnerHTML(captionText); } else { this.captionText.setInnerText(captionText); } } } else if (this.captionText != null) { this.captionText.removeFromParent(); this.captionText = null; } // Icon if (this.icon != null) { this.icon.getElement().removeFromParent(); } if (icon != null) { if (caption != null) { caption.insertFirst(icon.getElement()); } } this.icon = icon; // Required if (required) { if (requiredIcon == null) { requiredIcon = DOM.createSpan(); // TODO decide something better (e.g. use CSS to insert the // character) requiredIcon.setInnerHTML("*"); requiredIcon.setClassName("v-required-field-indicator"); // The star should not be read by the screen reader, as it is // purely visual. Required state is set at the element level for // the screen reader. Roles.getTextboxRole().setAriaHiddenState(requiredIcon, true); } if (caption != null) { caption.appendChild(requiredIcon); } } else if (requiredIcon != null) { requiredIcon.removeFromParent(); requiredIcon = null; } // Context Help // Haulmont API if (contextHelpIconEnabled) { if (contextHelpIcon == null) { contextHelpIcon = DOM.createSpan(); // TODO decide something better (e.g. use CSS to insert the character) contextHelpIcon.setInnerHTML("?"); contextHelpIcon.setClassName(CONTEXT_HELP_CLASSNAME); ComponentConnector componentConnector = Util.findConnectorFor(widget); if (hasContextHelpIconListeners(componentConnector.getState())) { contextHelpIcon.addClassName(CONTEXT_HELP_CLICKABLE_CLASSNAME); } // The question mark should not be read by the screen reader, as it is // purely visual. Required state is set at the element level for // the screen reader. Roles.getTextboxRole().setAriaHiddenState(contextHelpIcon, true); } if (caption != null) { caption.appendChild(contextHelpIcon); if (clickHandlerRegistration == null) { clickHandlerRegistration = addDomHandler(this, ClickEvent.getType()); } } } else { if (this.contextHelpIcon != null) { this.contextHelpIcon.removeFromParent(); this.contextHelpIcon = null; } if (clickHandlerRegistration != null) { clickHandlerRegistration.removeHandler(); clickHandlerRegistration = null; } } // Error if (error != null && showError) { if (errorIcon == null) { errorIcon = DOM.createSpan(); errorIcon.setClassName("v-errorindicator"); } if (caption != null) { caption.appendChild(errorIcon); } } else if (errorIcon != null) { errorIcon.removeFromParent(); errorIcon = null; } if (caption != null) { // Styles caption.setClassName("v-caption"); if (styles != null) { for (String style : styles) { caption.addClassName("v-caption-" + style); } } if (enabled) { caption.removeClassName("v-disabled"); } else { caption.addClassName("v-disabled"); } // Caption position if (captionText != null || icon != null) { setCaptionPosition(CaptionPosition.TOP); } else { setCaptionPosition(CaptionPosition.RIGHT); } } if (focusLost) { // Find out what element is currently focused. Element currentFocus = WidgetUtil.getFocusedElement(); if (currentFocus != null && currentFocus.equals(Document.get().getBody())) { // Focus has moved to BodyElement and should be moved back to // original location. This happened because of adding or // removing the captionWrap focusedElement.focus(); } else if (currentFocus != focusedElement) { // Focus is either moved somewhere else on purpose or IE has // lost it. Investigate further. Timer focusTimer = new Timer() { @Override public void run() { if (WidgetUtil.getFocusedElement() == null) { // This should never become an infinite loop and // even if it does it will be stopped once something // is done with the browser. schedule(25); } else if (WidgetUtil.getFocusedElement().equals(Document.get().getBody())) { // Focus found it's way to BodyElement. Now it can // be restored focusedElement.focus(); } } }; if (BrowserInfo.get().isIE8()) { // IE8 can't fix the focus immediately. It will fail. focusTimer.schedule(25); } else { // Newer IE versions can handle things immediately. focusTimer.run(); } } } }
From source file:de.bonprix.gridstacklayout.client.GridStackLayoutWidget.java
License:Open Source License
public GridStackLayoutWidget() { this.gridstackId = DOM.createUniqueId(); this.gridstackDiv = DOM.createDiv(); this.gridstackDiv.addClassName("grid-stack"); this.gridstackDiv.setId(this.gridstackId); setElement(this.gridstackDiv); // Clear any unwanted styling final Style style = getElement().getStyle(); style.setBorderStyle(BorderStyle.NONE); style.setMargin(0, Unit.PX);/* w w w. j av a2s .c o m*/ style.setPadding(0, Unit.PX); if (BrowserInfo.get().isIE()) { style.setPosition(Position.RELATIVE); } setStyleName(CLASSNAME); addAttachHandler(new Handler() { @Override public void onAttachOrDetach(final AttachEvent event) { checkInit(); } }); setStackedModeWidth(60 * DEFAULT_COLUMNS); }
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 * // w w w . j ava 2 s . co m * 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.magnoliashell.shell.ShellAppLauncher.java
License:Open Source License
private void construct() { divetWrapper.setId("divet"); logoImg.setId("logo"); String baseUrl = GWT.getModuleBaseURL().replace("widgetsets/" + GWT.getModuleName() + "/", ""); String logoPath = baseUrl + "themes/admincentraltheme/img/"; boolean isIE8 = BrowserInfo.get().isIE8(); logoImg.setAttribute("src", logoPath + (isIE8 ? "logo-magnolia.png" : "logo-magnolia.svg")); logo.getElement().appendChild(logoImg); add(logo);/* w ww. j a v a 2s.co m*/ userMenu.setClassName(USER_MENU_CLASS_NAME); getElement().appendChild(userMenu); getElement().appendChild(divetWrapper); for (final ShellAppType appType : ShellAppType.values()) { final NavigatorButton w = new NavigatorButton(appType); w.addTouchEndHandler(new TouchEndHandler() { @Override public void onTouchEnd(TouchEndEvent event) { toggleShellApp(appType); } }); controlsMap.put(appType, w); add(w); } divetWrapper.getStyle().setDisplay(Display.NONE); }