Search in sources :

Example 46 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class DefaultTabSheetDropHandler method handleComponentReordering.

@Override
protected void handleComponentReordering(DragAndDropEvent event) {
    LayoutBoundTransferable transferable = (LayoutBoundTransferable) event.getTransferable();
    TabSheetTargetDetails details = (TabSheetTargetDetails) event.getTargetDetails();
    DDTabSheet tabSheet = (DDTabSheet) details.getTarget();
    Component c = transferable.getComponent();
    Tab tab = tabSheet.getTab(c);
    HorizontalDropLocation location = details.getDropLocation();
    int idx = details.getOverIndex();
    if (location == HorizontalDropLocation.LEFT) {
        // Left of previous tab
        int originalIndex = tabSheet.getTabPosition(tab);
        if (originalIndex > idx) {
            tabSheet.setTabPosition(tab, idx);
        } else if (idx - 1 >= 0) {
            tabSheet.setTabPosition(tab, idx - 1);
        }
    } else if (location == HorizontalDropLocation.RIGHT) {
        // Right of previous tab
        int originalIndex = tabSheet.getTabPosition(tab);
        if (originalIndex > idx) {
            tabSheet.setTabPosition(tab, idx + 1);
        } else {
            tabSheet.setTabPosition(tab, idx);
        }
    }
}
Also used : TabSheetTargetDetails(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet.TabSheetTargetDetails) Tab(com.vaadin.ui.TabSheet.Tab) DDTabSheet(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDTabSheet) LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) HorizontalDropLocation(com.vaadin.shared.ui.dd.HorizontalDropLocation) Component(com.vaadin.ui.Component)

Example 47 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class CubaTreeTable method iterator.

@Override
@Nonnull
public Iterator<Component> iterator() {
    List<Component> additionalConnectors = null;
    CubaTreeTableState tableState = getState(false);
    if (tableState.presentations != null) {
        additionalConnectors = new LinkedList<>();
        additionalConnectors.add((Component) tableState.presentations);
    }
    if (tableState.contextMenu != null) {
        if (additionalConnectors == null) {
            additionalConnectors = new LinkedList<>();
        }
        additionalConnectors.add((Component) tableState.contextMenu);
    }
    if (tableState.customPopup != null) {
        if (additionalConnectors == null) {
            additionalConnectors = new LinkedList<>();
        }
        additionalConnectors.add((Component) tableState.customPopup);
    }
    if (additionalConnectors == null) {
        return super.iterator();
    } else if (_visibleComponents() != null) {
        return Iterables.concat(_visibleComponents(), additionalConnectors).iterator();
    } else {
        return additionalConnectors.iterator();
    }
}
Also used : CubaTreeTableState(com.haulmont.cuba.web.widgets.client.treetable.CubaTreeTableState) AbstractComponent(com.vaadin.ui.AbstractComponent) Component(com.vaadin.ui.Component) Nonnull(javax.annotation.Nonnull)

Example 48 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class DDAccordion method getTransferable.

/**
 * {@inheritDoc}
 */
public Transferable getTransferable(Map<String, Object> rawVariables) {
    if (rawVariables.get("index") != null) {
        int index = Integer.parseInt(rawVariables.get("index").toString());
        Iterator<Component> iter = getComponentIterator();
        int counter = 0;
        Component c = null;
        while (iter.hasNext()) {
            c = iter.next();
            if (counter == index) {
                break;
            }
            counter++;
        }
        rawVariables.put("component", c);
    } else if (rawVariables.get("component") == null) {
        rawVariables.put("component", DDAccordion.this);
    }
    return new LayoutBoundTransferable(this, rawVariables);
}
Also used : LayoutBoundTransferable(com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable) LegacyComponent(com.vaadin.ui.LegacyComponent) Component(com.vaadin.ui.Component)

Example 49 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class CubaMainTabSheet method silentCloseTabAndSelectPrevious.

public void silentCloseTabAndSelectPrevious(Component tab) {
    while (openedComponents.removeElement(tab)) {
        openedComponents.removeElement(tab);
    }
    if ((!openedComponents.empty()) && (_selected().equals(tab))) {
        Component c = openedComponents.pop();
        while (!_components().contains(c) && !openedComponents.isEmpty()) {
            c = openedComponents.pop();
        }
        setSelectedTab(c);
    }
}
Also used : Component(com.vaadin.ui.Component)

Example 50 with Component

use of com.vaadin.ui.Component in project cuba by cuba-platform.

the class CubaUI method isAccessibleForUser.

/**
 * Check if users can interact with the component - there are no modal windows that prevent user action.
 *
 * @param component component
 * @return whether it accessible or not
 */
public boolean isAccessibleForUser(Component component) {
    Collection<Window> windows = this.getWindows();
    if (windows.isEmpty()) {
        // there are no windows - all components are accessible
        return true;
    }
    boolean hasModalWindows = windows.stream().anyMatch(Window::isModal);
    if (!hasModalWindows) {
        // there are no modal windows - all components are accessible
        return true;
    }
    Component windowOrUI = CubaUIUtils.getWindowOrUI(component);
    if (windowOrUI == null) {
        // something went wrong
        return false;
    }
    if (windowOrUI instanceof UI) {
        // there are modal windows, component belongs to UI
        return false;
    }
    if (windowOrUI instanceof Window) {
        Window currentWindow = (Window) windowOrUI;
        if (!currentWindow.isModal()) {
            // there are modal windows, component belongs to non-modal window
            return false;
        }
    // CAUTION we cannot sort windows in UI, because they are ordered only on client side
    }
    // we cannot reliably check if access is permitted
    return true;
}
Also used : Window(com.vaadin.ui.Window) UI(com.vaadin.ui.UI) Component(com.vaadin.ui.Component)

Aggregations

Component (com.vaadin.ui.Component)146 LayoutBoundTransferable (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.events.LayoutBoundTransferable)23 VerticalDropLocation (com.vaadin.shared.ui.dd.VerticalDropLocation)13 ComponentContainer (com.vaadin.ui.ComponentContainer)12 SingleComponentContainer (com.vaadin.ui.SingleComponentContainer)12 WebAbstractComponent (com.haulmont.cuba.web.gui.components.WebAbstractComponent)11 HorizontalLayout (com.vaadin.ui.HorizontalLayout)11 VerticalLayout (com.vaadin.ui.VerticalLayout)11 Button (com.vaadin.ui.Button)9 Window (com.haulmont.cuba.gui.components.Window)8 Label (com.vaadin.ui.Label)8 Test (org.junit.Test)8 WebWindow (com.haulmont.cuba.web.gui.WebWindow)7 AbstractOrderedLayout (com.vaadin.ui.AbstractOrderedLayout)6 CssLayout (com.vaadin.ui.CssLayout)6 List (java.util.List)6 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)5 CubaUI (com.haulmont.cuba.web.widgets.CubaUI)5 DDAbsoluteLayout (com.haulmont.cuba.web.widgets.addons.dragdroplayouts.DDAbsoluteLayout)5 Item (com.vaadin.data.Item)5