Search in sources :

Example 1 with DetachedFrame

use of com.haulmont.cuba.desktop.DetachedFrame 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 DetachedFrame

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

the class DesktopFrame method detachFrame.

@Override
public void detachFrame(String caption) {
    if (isDetached()) {
        throw new RuntimeException("Frame already detached");
    }
    final java.awt.Container parent = impl.getParent();
    detachedFrame = new DetachedFrame(caption, parent);
    for (int i = 0; i < parent.getComponentCount(); i++) {
        if (impl == parent.getComponent(i)) {
            componentPosition = i;
            break;
        }
    }
    hierarchyListener = new HierarchyListener() {

        @Override
        public void hierarchyChanged(HierarchyEvent e) {
            if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) == HierarchyEvent.DISPLAYABILITY_CHANGED && !parent.isDisplayable()) {
                parent.removeHierarchyListener(this);
                attachFrame();
            }
        }
    };
    detachedFrame.setLocationRelativeTo(DesktopComponentsHelper.getTopLevelFrame(impl));
    detachedFrame.setSize(impl.getSize());
    detachedFrame.add(impl);
    detachedFrame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            parent.removeHierarchyListener(hierarchyListener);
            attachFrame();
        }
    });
    parent.revalidate();
    parent.repaint();
    parent.addHierarchyListener(hierarchyListener);
    detachedFrame.setVisible(true);
    detached = true;
    for (DetachListener listener : detachListeners) {
        listener.frameDetached(this);
    }
}
Also used : 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 3 with DetachedFrame

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

the class DesktopTabSheet method updateTabVisibility.

protected void updateTabVisibility(TabImpl tab) {
    // find insert/remove index by visibility of existing tabs
    int currentIndex = tab.getTabIndex();
    int idx = 0;
    for (TabImpl t : tabs) {
        if (t.equals(tab))
            break;
        if (t.isVisible())
            idx++;
    }
    JComponent comp = DesktopComponentsHelper.getComposition(tab.getComponent());
    if (currentIndex >= 0 || tab.isVisible()) {
        if (tab.isVisible()) {
            impl.insertTab(tab.getCaption(), null, comp, null, idx);
            impl.setTabComponentAt(idx, tab.getButtonTabComponent());
        } else {
            impl.removeTabAt(idx);
        }
    } else {
        // tab is detached
        DetachedFrame detachedFrame = (DetachedFrame) SwingUtilities.getWindowAncestor(comp);
        detachedFrame.dispose();
    }
    // if we just detach component, it will return isVisible() == true
    if (!tab.isVisible())
        comp.setVisible(false);
}
Also used : DetachedFrame(com.haulmont.cuba.desktop.DetachedFrame)

Aggregations

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