Search in sources :

Example 1 with TabPaneListener

use of org.apache.pivot.wtk.TabPaneListener in project pivot by apache.

the class TabPanes method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    confirmCloseTabPrompt = (Prompt) namespace.get("confirmCloseTabPrompt");
    tabPane = (TabPane) namespace.get("tabPane");
    closeableCheckbox = (Checkbox) namespace.get("closeableCheckbox");
    collapsibleCheckbox = (Checkbox) namespace.get("collapsibleCheckbox");
    horizontalRadioButton = (RadioButton) namespace.get("horizontalRadioButton");
    verticalRadioButton = (RadioButton) namespace.get("verticalRadioButton");
    cornerBoxPane = (BoxPane) namespace.get("cornerBoxPane");
    tabPane.getTabPaneListeners().add(new TabPaneListener() {

        @Override
        public Vote previewRemoveTabs(final TabPane tabPaneArgument, final int index, final int count) {
            Vote vote;
            if (confirmCloseTab) {
                confirmCloseTabPrompt.open(TabPanes.this, new SheetCloseListener() {

                    @Override
                    public void sheetClosed(Sheet sheet) {
                        if (confirmCloseTabPrompt.getResult() && confirmCloseTabPrompt.getSelectedOptionIndex() == 1) {
                            confirmCloseTab = false;
                            int n = tabPaneArgument.getTabs().getLength();
                            if (index < n - 1) {
                                tabPaneArgument.setSelectedIndex(index + 1);
                            } else {
                                tabPaneArgument.setSelectedIndex(index - 1);
                            }
                            tabPaneArgument.getTabs().remove(index, count);
                            confirmCloseTab = true;
                        }
                    }
                });
                vote = Vote.DENY;
            } else {
                vote = Vote.APPROVE;
            }
            return vote;
        }
    });
    ButtonStateListener checkboxStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            updateTabPane();
        }
    };
    closeableCheckbox.getButtonStateListeners().add(checkboxStateListener);
    collapsibleCheckbox.getButtonStateListeners().add(checkboxStateListener);
    ButtonStateListener radioButtonStateListener = new ButtonStateListener() {

        @Override
        public void stateChanged(Button button, Button.State previousState) {
            if (button.isSelected()) {
                updateTabPane();
            }
        }
    };
    horizontalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    verticalRadioButton.getButtonStateListeners().add(radioButtonStateListener);
    updateTabPane();
}
Also used : TabPaneListener(org.apache.pivot.wtk.TabPaneListener) TabPane(org.apache.pivot.wtk.TabPane) Vote(org.apache.pivot.util.Vote) RadioButton(org.apache.pivot.wtk.RadioButton) Button(org.apache.pivot.wtk.Button) ButtonStateListener(org.apache.pivot.wtk.ButtonStateListener) SheetCloseListener(org.apache.pivot.wtk.SheetCloseListener) Sheet(org.apache.pivot.wtk.Sheet)

Aggregations

Vote (org.apache.pivot.util.Vote)1 Button (org.apache.pivot.wtk.Button)1 ButtonStateListener (org.apache.pivot.wtk.ButtonStateListener)1 RadioButton (org.apache.pivot.wtk.RadioButton)1 Sheet (org.apache.pivot.wtk.Sheet)1 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)1 TabPane (org.apache.pivot.wtk.TabPane)1 TabPaneListener (org.apache.pivot.wtk.TabPaneListener)1