Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

Advanced Web Application Topics

return allowed;

}

};

return criterion;

}

Accept Indicators

When a dragged object hovers on a drop target, an accept indicator is displayed to show whether or not the location is accepted. For MIDDLE location, the indicator is a box around the target (tree node, table row, or component). For vertical drop locations, the accepted locations are shown as horizontal lines, and for horizontal drop locations as vertical lines.

For DragAndDropWrapper drop targets, you can disable the accept indicators or drag hints with the no-vertical-drag-hints, no-horizontal-drag-hints, and no-box-drag-hints styles.You need to add the styles to the layout that contains the wrapper, not to the wrapper itself.

// Have a wrapper

DragAndDropWrapper wrapper = new DragAndDropWrapper(c); layout.addComponent(wrapper);

// Disable the hints layout.addStyleName("no-vertical-drag-hints"); layout.addStyleName("no-horizontal-drag-hints"); layout.addStyleName("no-box-drag-hints");

11.11.5. Dragging Components

Dragging a component requires wrapping the source component within a DragAndDropWrapper. You can then allow dragging by putting the wrapper (and the component) in drag mode with setDragStartMode(). The method supports two drag modes: DragStartMode.WRAPPER and DragStartMode.COMPONENT, which defines whether the entire wrapper is shown as the drag image while dragging or just the wrapped component.

// Have a component to drag

final Button button = new Button("An Absolute Button");

// Put the component in a D&D wrapper and allow dragging it

final DragAndDropWrapper buttonWrap = new DragAndDropWrapper(button); buttonWrap.setDragStartMode(DragStartMode.COMPONENT);

//Set the wrapper to wrap tightly around the component buttonWrap.setSizeUndefined();

//Add the wrapper, not the component, to the layout layout.addComponent(buttonWrap, "left: 50px; top: 50px;");

The default height of DragAndDropWrapper is undefined, but the default width is 100%. If you want to ensure that the wrapper fits tightly around the wrapped component, you should call setSizeUndefined() for the wrapper. Doing so, you should make sure that the wrapped component does not have a relative size, which would cause a paradox.

Dragged components are referenced in the WrapperTransferable. You can get the reference to the dragged component with getDraggedComponent(). The method will return null if the transferable is not a component. Also HTML 5 drags (see later) are held in wrapper transferables.

310

Dragging Components

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]