@Override public HandlerRegistration addDragStartHandler(DragStartHandler handler) { return handlers.addHandler(DragStartEvent.getType(), handler); }
private DocTab( ImageResource icon, String docId, String title, String tooltip, TabCloseObserver closeHandler) { docId_ = docId; final HorizontalPanel layoutPanel = new HorizontalPanel(); layoutPanel.setStylePrimaryName(styles_.tabLayout()); layoutPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM); layoutPanel.getElement().setDraggable("true"); layoutPanel.addDomHandler( new DragStartHandler() { @Override public void onDragStart(DragStartEvent evt) { evt.getDataTransfer() .setData( getDataTransferFormat(), docId_ + "|" + SourceWindowManager.getSourceWindowId()); JsObject dt = evt.getDataTransfer().cast(); dt.setString("effectAllowed", "move"); // figure out where the cursor is inside the element; because the // drag shows an image of the tab, knowing where the cursor is // inside that image is necessary for us to know the screen // location of the dragged image int evtX = evt.getNativeEvent().getClientX(); ElementEx ele = getElement().cast(); events_.fireEvent( new DocTabDragInitiatedEvent( docId_, getElement().getClientWidth(), evtX - ele.getBoundingClientRect().getLeft())); } }, DragStartEvent.getType()); HTML left = new HTML(); left.setStylePrimaryName(styles_.tabLayoutLeft()); layoutPanel.add(left); contentPanel_ = new HorizontalPanel(); contentPanel_.setTitle(tooltip); contentPanel_.setStylePrimaryName(styles_.tabLayoutCenter()); contentPanel_.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); if (icon != null) contentPanel_.add(imageForIcon(icon)); label_ = new Label(title, false); label_.addStyleName(styles_.docTabLabel()); contentPanel_.add(label_); appendDirtyMarker(); Image img = new Image(ThemeResources.INSTANCE.closeTab()); img.setStylePrimaryName(styles_.closeTabButton()); img.addStyleName(ThemeStyles.INSTANCE.handCursor()); contentPanel_.add(img); layoutPanel.add(contentPanel_); HTML right = new HTML(); right.setStylePrimaryName(styles_.tabLayoutRight()); layoutPanel.add(right); initWidget(layoutPanel); this.sinkEvents(Event.ONCLICK); closeHandler_ = closeHandler; closeElement_ = img.getElement(); }