@Override // Exception squid:S1166 - Hide origin exception // Exception squid:S2221 - This code is trans-coded to JavaScript, hence // Exception semantics changes @SuppressWarnings({ "squid:S1166", "squid:S2221" }) protected boolean accept(VDragEvent drag, UIDL configuration) { try { String component = drag.getTransferable().getDragSource().getWidget().getElement().getId(); int c = configuration.getIntAttribute(COMPONENT_COUNT); String mode = configuration.getStringAttribute(MODE); for (int dragSourceIndex = 0; dragSourceIndex < c; dragSourceIndex++) { String requiredPid = configuration.getStringAttribute(COMPONENT + dragSourceIndex); if ((STRICT_MODE.equals(mode) && component.equals(requiredPid)) || (PREFIX_MODE.equals(mode) && component.startsWith(requiredPid))) { return true; } } } catch (Exception e) { // log and continue LOGGER.log(Level.SEVERE, "Error verifying drop target: " + e.getLocalizedMessage()); } return false; } }
@Override // Exception squid:S1166 - Hide origin exception // Exception squid:S2221 - This code is trans-coded to JavaScript, hence // Exception semantics changes @SuppressWarnings({ "squid:S1166", "squid:S2221" }) protected boolean accept(VDragEvent drag, UIDL configuration) { try { String component = drag.getTransferable().getDragSource().getWidget().getElement().getId(); int c = configuration.getIntAttribute(COMPONENT_COUNT); String mode = configuration.getStringAttribute(MODE); for (int dragSourceIndex = 0; dragSourceIndex < c; dragSourceIndex++) { String requiredPid = configuration.getStringAttribute(COMPONENT + dragSourceIndex); if ((STRICT_MODE.equals(mode) && component.equals(requiredPid)) || (PREFIX_MODE.equals(mode) && component.startsWith(requiredPid))) { return true; } } } catch (Exception e) { // log and continue LOGGER.log(Level.SEVERE, "Error verifying drop target: " + e.getLocalizedMessage()); } return false; } }
/** * Checks if this accept criterion is responsible for the current drag * source. Therefore the current drag source id has to start with the drag * source id-prefix configured for the criterion. * * @param drag * the current drag event holding the context. * @param configuration * for the accept criterion to retrieve the configured drag * source id-prefix. * @return <code>true</code> if the criterion is responsible for the current * drag source, otherwise <code>false</code>. */ // Exception squid:S1166 - Hide origin exception // Exception squid:S2221 - This code is trans-coded to JavaScript, hence // Exception semantics changes @SuppressWarnings({ "squid:S1166", "squid:S2221" }) boolean isValidDragSource(final VDragEvent drag, final UIDL configuration) { try { final String dragSource = drag.getTransferable().getDragSource().getWidget().getElement().getId(); final String dragSourcePrefix = configuration.getStringAttribute(DRAG_SOURCE); if (dragSource.startsWith(dragSourcePrefix)) { return true; } } catch (final Exception e) { // log and continue LOGGER.log(Level.SEVERE, "Error verifying drag source: " + e.getLocalizedMessage()); } return false; }
/** * Determines the active UI theme for a given event. * * @param drag * the event the UI theme is retrieved for. * @return the active theme (e.g. "hawkbit"). */ private static String determineActiveTheme(final VDragEvent drag) { return drag.getTransferable().getDragSource().getConnection().getUIConnector().getActiveTheme(); }
/** * Determines the active UI theme for a given event. * * @param drag * the event the UI theme is retrieved for. * @return the active theme (e.g. "hawkbit"). */ private static String determineActiveTheme(final VDragEvent drag) { return drag.getTransferable().getDragSource().getConnection().getUIConnector().getActiveTheme(); }
/** * Checks if this accept criterion is responsible for the current drag * source. Therefore the current drag source id has to start with the drag * source id-prefix configured for the criterion. * * @param drag * the current drag event holding the context. * @param configuration * for the accept criterion to retrieve the configured drag * source id-prefix. * @return <code>true</code> if the criterion is responsible for the current * drag source, otherwise <code>false</code>. */ // Exception squid:S1166 - Hide origin exception // Exception squid:S2221 - This code is trans-coded to JavaScript, hence // Exception semantics changes @SuppressWarnings({ "squid:S1166", "squid:S2221" }) boolean isValidDragSource(final VDragEvent drag, final UIDL configuration) { try { final String dragSource = drag.getTransferable().getDragSource().getWidget().getElement().getId(); final String dragSourcePrefix = configuration.getStringAttribute(DRAG_SOURCE); if (dragSource.startsWith(dragSourcePrefix)) { return true; } } catch (final Exception e) { // log and continue LOGGER.log(Level.SEVERE, "Error verifying drag source: " + e.getLocalizedMessage()); } return false; }
/** * Displays a message box telling that the action is not allowed. * * @param drag * the current drag event holding the context. */ private void showErrorNotification(final VDragEvent drag) { final VNotification n = VNotification.createNotification(SPUILabelDefinitions.SP_DELAY, drag.getTransferable().getDragSource().getWidget()); n.show(getDraggableTemplate().notificationMsg(errorMessage).asString(), Position.BOTTOM_RIGHT, SPUIStyleDefinitions.SP_NOTIFICATION_ERROR_MESSAGE_STYLE); }
/** * Displays a message box telling that the action is not allowed. * * @param drag * the current drag event holding the context. */ private void showErrorNotification(final VDragEvent drag) { final VNotification n = VNotification.createNotification(SPUILabelDefinitions.SP_DELAY, drag.getTransferable().getDragSource().getWidget()); n.show(getDraggableTemplate().notificationMsg(errorMessage).asString(), Position.BOTTOM_RIGHT, SPUIStyleDefinitions.SP_NOTIFICATION_ERROR_MESSAGE_STYLE); }
@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); };
@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); };
@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); }
@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); }
/** * Styles a multi-row selection with the number of elements. * * @param drag * the current drag event holding the context. */ void setMultiRowDragDecoration(final VDragEvent drag) { final Widget widget = drag.getTransferable().getDragSource().getWidget(); if (widget instanceof VScrollTable) { final VScrollTable table = (VScrollTable) widget; final int rowCount = table.selectedRowKeys.size(); Element dragCountElement = Document.get().getElementById(SP_DRAG_COUNT); if (rowCount > 1 && table.selectedRowKeys.contains(table.focusedRow.getKey())) { if (dragCountElement == null) { dragCountElement = Document.get().createStyleElement(); dragCountElement.setId(SP_DRAG_COUNT); final HeadElement head = HeadElement .as(Document.get().getElementsByTagName(HeadElement.TAG).getItem(0)); head.appendChild(dragCountElement); } final SafeHtml formattedCssStyle = getDraggableTemplate() .multiSelectionStyle(determineActiveTheme(drag), String.valueOf(rowCount)); final StyleElement dragCountStyleElement = StyleElement.as(dragCountElement); dragCountStyleElement.setInnerSafeHtml(formattedCssStyle); } else if (dragCountElement != null) { dragCountElement.removeFromParent(); } } }
/** * Styles a multi-row selection with the number of elements. * * @param drag * the current drag event holding the context. */ void setMultiRowDragDecoration(final VDragEvent drag) { final Widget widget = drag.getTransferable().getDragSource().getWidget(); if (widget instanceof VScrollTable) { final VScrollTable table = (VScrollTable) widget; final int rowCount = table.selectedRowKeys.size(); Element dragCountElement = Document.get().getElementById(SP_DRAG_COUNT); if (rowCount > 1 && table.selectedRowKeys.contains(table.focusedRow.getKey())) { if (dragCountElement == null) { dragCountElement = Document.get().createStyleElement(); dragCountElement.setId(SP_DRAG_COUNT); final HeadElement head = HeadElement .as(Document.get().getElementsByTagName(HeadElement.TAG).getItem(0)); head.appendChild(dragCountElement); } final SafeHtml formattedCssStyle = getDraggableTemplate() .multiSelectionStyle(determineActiveTheme(drag), String.valueOf(rowCount)); final StyleElement dragCountStyleElement = StyleElement.as(dragCountElement); dragCountStyleElement.setInnerSafeHtml(formattedCssStyle); } else if (dragCountElement != null) { dragCountElement.removeFromParent(); } } }
.getTransferable() .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);
.getTransferable() .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);
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); }
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); }
@Override public void onDrop(DropEvent event) { NativeEvent nativeEvent = event.getNativeEvent(); if (validate(nativeEvent) && vaadinDragEvent != null) { nativeEvent.preventDefault(); nativeEvent.stopPropagation(); // event stopped, just notify global handler // Haulmont API if (globalDropHandler != null) { globalDropHandler.onDrop(event); } vaadinDragEvent.setCurrentGwtEvent(nativeEvent); VDragAndDropManager.get().setCurrentDropHandler(dropHandler); // FIXME only text currently supported String data; if (BrowserInfo.get().isIE()) { // IE does not support MIME types // http://www.developerfusion.com/article/144828/the-html5-drag-and-drop-api/ data = event.getData("text"); } else { data = event.getData("text/plain"); } vaadinDragEvent.getTransferable().setData("html5Data", data); VDragAndDropManager.get().endDrag(); vaadinDragEvent = null; } }
@Override public void onDrop(DropEvent event) { NativeEvent nativeEvent = event.getNativeEvent(); if (validate(nativeEvent) && vaadinDragEvent != null) { nativeEvent.preventDefault(); nativeEvent.stopPropagation(); // event stopped, just notify global handler // Haulmont API if (globalDropHandler != null) { globalDropHandler.onDrop(event); } vaadinDragEvent.setCurrentGwtEvent(nativeEvent); VDragAndDropManager.get().setCurrentDropHandler(dropHandler); // FIXME only text currently supported String data; if (BrowserInfo.get().isIE()) { // IE does not support MIME types // http://www.developerfusion.com/article/144828/the-html5-drag-and-drop-api/ data = event.getData("text"); } else { data = event.getData("text/plain"); } vaadinDragEvent.getTransferable().setData("html5Data", data); VDragAndDropManager.get().endDrag(); vaadinDragEvent = null; } }