Search in sources :

Example 1 with ButtonTabComponent

use of com.haulmont.cuba.desktop.sys.ButtonTabComponent in project cuba by cuba-platform.

the class DesktopTabSheet method detachTab.

protected void detachTab(final int tabIndex) {
    final JComponent tabContent = (JComponent) impl.getComponentAt(tabIndex);
    TabImpl tabAtIndex = null;
    for (TabImpl tab : tabs) {
        if (DesktopComponentsHelper.getComposition(tab.getComponent()) == tabContent) {
            tabAtIndex = tab;
            if (tab.isLazy() && !tab.isLazyInitialized()) {
                initLazyTab(tabContent);
            }
            break;
        }
    }
    if (tabAtIndex == null) {
        throw new IllegalStateException("Unable to find tab to detach");
    }
    final TabImpl tabToDetach = tabAtIndex;
    final ButtonTabComponent tabComponent = tabToDetach.getButtonTabComponent();
    final JFrame frame = new DetachedFrame(tabComponent.getCaption(), impl);
    frame.setLocationRelativeTo(DesktopComponentsHelper.getTopLevelFrame(this));
    impl.remove(tabContent);
    updateTabsEnabledState();
    frame.setSize(impl.getSize());
    frame.add(tabContent);
    final HierarchyListener listener = new HierarchyListener() {

        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) == HierarchyEvent.DISPLAYABILITY_CHANGED && !impl.isDisplayable()) {
                attachTab(frame, tabToDetach);
                impl.removeHierarchyListener(this);
            }
        }
    };
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            attachTab(frame, tabToDetach);
            impl.removeHierarchyListener(listener);
        }
    });
    impl.addHierarchyListener(listener);
    frame.setVisible(true);
}
Also used : ButtonTabComponent(com.haulmont.cuba.desktop.sys.ButtonTabComponent) HierarchyEvent(java.awt.event.HierarchyEvent) WindowEvent(java.awt.event.WindowEvent) DetachedFrame(com.haulmont.cuba.desktop.DetachedFrame) WindowAdapter(java.awt.event.WindowAdapter) HierarchyListener(java.awt.event.HierarchyListener)

Example 2 with ButtonTabComponent

use of com.haulmont.cuba.desktop.sys.ButtonTabComponent in project cuba by cuba-platform.

the class DesktopTabSheet method setTabComponent.

protected void setTabComponent(TabImpl tab, int componentIndex) {
    ButtonTabComponent.CloseListener closeListener = new ButtonTabComponent.CloseListener() {

        @Override
        public void onTabClose(int tabIndex) {
            if (tab.getCloseHandler() != null) {
                tab.getCloseHandler().onTabClose(tab);
            } else {
                removeTab(tab.getName());
            }
        }
    };
    ButtonTabComponent.DetachListener detachListener = new ButtonTabComponent.DetachListener() {

        @Override
        public void onDetach(int tabIndex) {
            detachTab(tabIndex);
        }
    };
    ButtonTabComponent btnTabComponent = new ButtonTabComponent(impl, false, false, closeListener, detachListener);
    tab.setButtonTabComponent(btnTabComponent);
    impl.setTabComponentAt(componentIndex, btnTabComponent);
}
Also used : ButtonTabComponent(com.haulmont.cuba.desktop.sys.ButtonTabComponent)

Example 3 with ButtonTabComponent

use of com.haulmont.cuba.desktop.sys.ButtonTabComponent in project cuba by cuba-platform.

the class DesktopTabSheet method attachTab.

protected void attachTab(JFrame frame, TabImpl tab) {
    int tabIndex = 0;
    int attachedBeforeCount = 0;
    JComponent tabContent = DesktopComponentsHelper.getComposition(tab.getComponent());
    String caption = tab.getCaption();
    ButtonTabComponent tabComponent = tab.getButtonTabComponent();
    for (Map.Entry<JComponent, TabImpl> entry : tabContents.entrySet()) {
        if (entry.getKey() == tabContent) {
            tabIndex = attachedBeforeCount;
            break;
        } else if (entry.getKey().getParent() == impl) {
            attachedBeforeCount++;
        }
    }
    impl.add(tabContent, tabIndex);
    if (!tab.isEnabled()) {
        impl.setComponentAt(tabIndex, null);
    }
    impl.setTitleAt(tabIndex, caption);
    impl.setTabComponentAt(tabIndex, tabComponent);
    updateTabsEnabledState();
    tabComponent.revalidate();
    tabComponent.repaint();
    frame.dispose();
}
Also used : ButtonTabComponent(com.haulmont.cuba.desktop.sys.ButtonTabComponent)

Aggregations

ButtonTabComponent (com.haulmont.cuba.desktop.sys.ButtonTabComponent)3 DetachedFrame (com.haulmont.cuba.desktop.DetachedFrame)1 HierarchyEvent (java.awt.event.HierarchyEvent)1 HierarchyListener (java.awt.event.HierarchyListener)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1