net.sourceforge.msscodefactory.cfbam.v2_7.CFBamJavaFX.CFBamJavaFXClearSubDep1PickerPane.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfbam.v2_7.CFBamJavaFX.CFBamJavaFXClearSubDep1PickerPane.java

Source

// Description: Java 8 JavaFX Picker of Obj Pane implementation for ClearSubDep1.

/*
 *   CFBam
 *
 *   Copyright (c) 2014-2016 Mark Sobkow
 *   
 *   This program is available as free software under the GNU GPL v3, or
 *   under a commercial license from Mark Sobkow.  For commercial licensing
 *   details, please contact msobkow@sasktel.net.
 *   
 *   Under the terms of the GPL:
 *   
 *      This program is free software: you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation, either version 3 of the License, or
 *      (at your option) any later version.
 *     
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *     
 *      You should have received a copy of the GNU General Public License
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *   
 */

package net.sourceforge.msscodefactory.cfbam.v2_7.CFBamJavaFX;

import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.util.List;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Parent;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellDataFeatures;
import javafx.scene.control.TableView;
import javafx.util.Callback;
import net.sourceforge.msscodefactory.cflib.v2_7.CFLib.*;
import net.sourceforge.msscodefactory.cflib.v2_7.CFLib.JavaFX.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cfsecurity.v2_7.CFSecurity.*;
import net.sourceforge.msscodefactory.cfinternet.v2_7.CFInternet.*;
import net.sourceforge.msscodefactory.cfbam.v2_7.CFBam.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_7.CFSecurityObj.*;
import net.sourceforge.msscodefactory.cfinternet.v2_7.CFInternetObj.*;
import net.sourceforge.msscodefactory.cfbam.v2_7.CFBamObj.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_7.CFSecurityJavaFX.*;
import net.sourceforge.msscodefactory.cfinternet.v2_7.CFInternetJavaFX.*;

/**
 *   CFBamJavaFXClearSubDep1PickerPane JavaFX Pick Obj Pane implementation
 *   for ClearSubDep1.
 */
public class CFBamJavaFXClearSubDep1PickerPane extends CFBorderPane implements ICFBamJavaFXClearSubDep1PaneList {
    public static String S_FormName = "Choose ClearSubDep1";
    protected ICFBamJavaFXSchema javafxSchema = null;
    protected Collection<ICFBamClearSubDep1Obj> javafxDataCollection = null;
    protected ObservableList<ICFBamClearSubDep1Obj> observableListOfClearSubDep1 = null;
    protected TableColumn<ICFBamClearSubDep1Obj, Long> tableColumnId = null;
    protected TableColumn<ICFBamClearSubDep1Obj, String> tableColumnName = null;
    protected TableColumn<ICFBamClearSubDep1Obj, ICFBamRelationObj> tableColumnLookupRelation = null;
    protected TableColumn<ICFBamClearSubDep1Obj, ICFBamSchemaDefObj> tableColumnLookupDefSchema = null;
    protected TableView<ICFBamClearSubDep1Obj> dataTable = null;
    protected CFHBox hboxMenu = null;
    public final String S_ColumnNames[] = { "Name" };
    protected ICFFormManager cfFormManager = null;
    protected ICFBamJavaFXClearSubDep1Chosen invokeWhenChosen = null;
    protected ICFBamClearTopDepObj javafxContainer = null;
    protected CFButton buttonCancel = null;
    protected CFButton buttonChooseNone = null;
    protected CFButton buttonChooseSelected = null;

    public CFBamJavaFXClearSubDep1PickerPane(ICFFormManager formManager, ICFBamJavaFXSchema argSchema,
            ICFBamClearSubDep1Obj argFocus, ICFBamClearTopDepObj argContainer,
            Collection<ICFBamClearSubDep1Obj> argDataCollection, ICFBamJavaFXClearSubDep1Chosen whenChosen) {
        super();
        final String S_ProcName = "construct-schema-focus";
        if (formManager == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                    "formManager");
        }
        cfFormManager = formManager;
        if (argSchema == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 2,
                    "argSchema");
        }
        if (whenChosen == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 6,
                    "whenChosen");
        }
        invokeWhenChosen = whenChosen;
        // argFocus is optional; focus may be set later during execution as
        // conditions of the runtime change.
        javafxSchema = argSchema;
        javaFXFocus = argFocus;
        javafxContainer = argContainer;
        setJavaFXDataCollection(argDataCollection);
        dataTable = new TableView<ICFBamClearSubDep1Obj>();
        tableColumnId = new TableColumn<ICFBamClearSubDep1Obj, Long>("Id");
        tableColumnId.setCellValueFactory(
                new Callback<CellDataFeatures<ICFBamClearSubDep1Obj, Long>, ObservableValue<Long>>() {
                    public ObservableValue<Long> call(CellDataFeatures<ICFBamClearSubDep1Obj, Long> p) {
                        ICFBamScopeObj obj = p.getValue();
                        if (obj == null) {
                            return (null);
                        } else {
                            long value = obj.getRequiredId();
                            Long wrapped = new Long(value);
                            ReadOnlyObjectWrapper<Long> observable = new ReadOnlyObjectWrapper<Long>();
                            observable.setValue(wrapped);
                            return (observable);
                        }
                    }
                });
        tableColumnId.setCellFactory(
                new Callback<TableColumn<ICFBamClearSubDep1Obj, Long>, TableCell<ICFBamClearSubDep1Obj, Long>>() {
                    @Override
                    public TableCell<ICFBamClearSubDep1Obj, Long> call(
                            TableColumn<ICFBamClearSubDep1Obj, Long> arg) {
                        return new CFInt64TableCell<ICFBamClearSubDep1Obj>();
                    }
                });
        dataTable.getColumns().add(tableColumnId);
        tableColumnName = new TableColumn<ICFBamClearSubDep1Obj, String>("Name");
        tableColumnName.setCellValueFactory(
                new Callback<CellDataFeatures<ICFBamClearSubDep1Obj, String>, ObservableValue<String>>() {
                    public ObservableValue<String> call(CellDataFeatures<ICFBamClearSubDep1Obj, String> p) {
                        ICFBamClearSubDep1Obj obj = p.getValue();
                        if (obj == null) {
                            return (null);
                        } else {
                            String value = obj.getRequiredName();
                            ReadOnlyObjectWrapper<String> observable = new ReadOnlyObjectWrapper<String>();
                            observable.setValue(value);
                            return (observable);
                        }
                    }
                });
        tableColumnName.setCellFactory(
                new Callback<TableColumn<ICFBamClearSubDep1Obj, String>, TableCell<ICFBamClearSubDep1Obj, String>>() {
                    @Override
                    public TableCell<ICFBamClearSubDep1Obj, String> call(
                            TableColumn<ICFBamClearSubDep1Obj, String> arg) {
                        return new CFStringTableCell<ICFBamClearSubDep1Obj>();
                    }
                });
        dataTable.getColumns().add(tableColumnName);
        tableColumnLookupRelation = new TableColumn<ICFBamClearSubDep1Obj, ICFBamRelationObj>("Relation");
        tableColumnLookupRelation.setCellValueFactory(
                new Callback<CellDataFeatures<ICFBamClearSubDep1Obj, ICFBamRelationObj>, ObservableValue<ICFBamRelationObj>>() {
                    public ObservableValue<ICFBamRelationObj> call(
                            CellDataFeatures<ICFBamClearSubDep1Obj, ICFBamRelationObj> p) {
                        ICFBamClearSubDep1Obj obj = p.getValue();
                        if (obj == null) {
                            return (null);
                        } else {
                            ICFBamRelationObj ref = obj.getRequiredLookupRelation();
                            ReadOnlyObjectWrapper<ICFBamRelationObj> observable = new ReadOnlyObjectWrapper<ICFBamRelationObj>();
                            observable.setValue(ref);
                            return (observable);
                        }
                    }
                });
        tableColumnLookupRelation.setCellFactory(
                new Callback<TableColumn<ICFBamClearSubDep1Obj, ICFBamRelationObj>, TableCell<ICFBamClearSubDep1Obj, ICFBamRelationObj>>() {
                    @Override
                    public TableCell<ICFBamClearSubDep1Obj, ICFBamRelationObj> call(
                            TableColumn<ICFBamClearSubDep1Obj, ICFBamRelationObj> arg) {
                        return new CFReferenceTableCell<ICFBamClearSubDep1Obj, ICFBamRelationObj>();
                    }
                });
        dataTable.getColumns().add(tableColumnLookupRelation);
        tableColumnLookupDefSchema = new TableColumn<ICFBamClearSubDep1Obj, ICFBamSchemaDefObj>(
                "Defining Schema Definition");
        tableColumnLookupDefSchema.setCellValueFactory(
                new Callback<CellDataFeatures<ICFBamClearSubDep1Obj, ICFBamSchemaDefObj>, ObservableValue<ICFBamSchemaDefObj>>() {
                    public ObservableValue<ICFBamSchemaDefObj> call(
                            CellDataFeatures<ICFBamClearSubDep1Obj, ICFBamSchemaDefObj> p) {
                        ICFBamClearSubDep1Obj obj = p.getValue();
                        if (obj == null) {
                            return (null);
                        } else {
                            ICFBamSchemaDefObj ref = obj.getOptionalLookupDefSchema();
                            ReadOnlyObjectWrapper<ICFBamSchemaDefObj> observable = new ReadOnlyObjectWrapper<ICFBamSchemaDefObj>();
                            observable.setValue(ref);
                            return (observable);
                        }
                    }
                });
        tableColumnLookupDefSchema.setCellFactory(
                new Callback<TableColumn<ICFBamClearSubDep1Obj, ICFBamSchemaDefObj>, TableCell<ICFBamClearSubDep1Obj, ICFBamSchemaDefObj>>() {
                    @Override
                    public TableCell<ICFBamClearSubDep1Obj, ICFBamSchemaDefObj> call(
                            TableColumn<ICFBamClearSubDep1Obj, ICFBamSchemaDefObj> arg) {
                        return new CFReferenceTableCell<ICFBamClearSubDep1Obj, ICFBamSchemaDefObj>();
                    }
                });
        dataTable.getColumns().add(tableColumnLookupDefSchema);
        dataTable.getSelectionModel().selectedItemProperty()
                .addListener(new ChangeListener<ICFBamClearSubDep1Obj>() {
                    @Override
                    public void changed(ObservableValue<? extends ICFBamClearSubDep1Obj> observable,
                            ICFBamClearSubDep1Obj oldValue, ICFBamClearSubDep1Obj newValue) {
                        setJavaFXFocus(newValue);
                        if (buttonChooseSelected != null) {
                            if (newValue != null) {
                                buttonChooseSelected.setDisable(false);
                            } else {
                                buttonChooseSelected.setDisable(true);
                            }
                        }
                    }
                });
        hboxMenu = new CFHBox(10);
        buttonCancel = new CFButton();
        buttonCancel.setMinWidth(200);
        buttonCancel.setText("Cancel");
        buttonCancel.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent e) {
                final String S_ProcName = "handle";
                try {
                    cfFormManager.closeCurrentForm();
                } catch (Throwable t) {
                    CFConsole.formException(S_FormName, ((CFButton) e.getSource()).getText(), t);
                }
            }
        });
        hboxMenu.getChildren().add(buttonCancel);
        buttonChooseNone = new CFButton();
        buttonChooseNone.setMinWidth(200);
        buttonChooseNone.setText("ChooseNone");
        buttonChooseNone.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent e) {
                final String S_ProcName = "handle";
                try {
                    ICFBamSchemaObj schemaObj = (ICFBamSchemaObj) javafxSchema.getSchema();
                    if (schemaObj == null) {
                        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                                "schemaObj");
                    }
                    invokeWhenChosen.choseClearSubDep1(null);
                    cfFormManager.closeCurrentForm();
                } catch (Throwable t) {
                    CFConsole.formException(S_FormName, ((CFButton) e.getSource()).getText(), t);
                }
            }
        });
        hboxMenu.getChildren().add(buttonChooseNone);
        buttonChooseSelected = new CFButton();
        buttonChooseSelected.setMinWidth(200);
        buttonChooseSelected.setText("ChooseSelected");
        buttonChooseSelected.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent e) {
                final String S_ProcName = "handle";
                try {
                    ICFBamSchemaObj schemaObj = (ICFBamSchemaObj) javafxSchema.getSchema();
                    if (schemaObj == null) {
                        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                                "schemaObj");
                    }
                    ICFBamClearSubDep1Obj selectedInstance = getJavaFXFocusAsClearSubDep1();
                    invokeWhenChosen.choseClearSubDep1(selectedInstance);
                    cfFormManager.closeCurrentForm();
                } catch (Throwable t) {
                    CFConsole.formException(S_FormName, ((CFButton) e.getSource()).getText(), t);
                }
            }
        });
        hboxMenu.getChildren().add(buttonChooseSelected);
        if (argFocus != null) {
            dataTable.getSelectionModel().select(argFocus);
        }
        setTop(hboxMenu);
        setCenter(dataTable);
    }

    public ICFFormManager getCFFormManager() {
        return (cfFormManager);
    }

    public void setCFFormManager(ICFFormManager value) {
        final String S_ProcName = "setCFFormManager";
        if (value == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "value");
        }
        cfFormManager = value;
    }

    public ICFBamJavaFXSchema getJavaFXSchema() {
        return (javafxSchema);
    }

    public void setJavaFXFocus(ICFLibAnyObj value) {
        final String S_ProcName = "setJavaFXFocus";
        if ((value == null) || (value instanceof ICFBamClearSubDep1Obj)) {
            super.setJavaFXFocus(value);
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "value",
                    value, "ICFBamClearSubDep1Obj");
        }
        if (dataTable == null) {
            return;
        }
    }

    public ICFBamClearSubDep1Obj getJavaFXFocusAsClearSubDep1() {
        return ((ICFBamClearSubDep1Obj) getJavaFXFocus());
    }

    public void setJavaFXFocusAsClearSubDep1(ICFBamClearSubDep1Obj value) {
        setJavaFXFocus(value);
    }

    public class ClearSubDep1ByQualNameComparator implements Comparator<ICFBamClearSubDep1Obj> {
        public ClearSubDep1ByQualNameComparator() {
        }

        public int compare(ICFBamClearSubDep1Obj lhs, ICFBamClearSubDep1Obj rhs) {
            if (lhs == null) {
                if (rhs == null) {
                    return (0);
                } else {
                    return (-1);
                }
            } else if (rhs == null) {
                return (1);
            } else {
                String lhsValue = lhs.getObjQualifiedName();
                String rhsValue = rhs.getObjQualifiedName();
                if (lhsValue == null) {
                    if (rhsValue == null) {
                        return (0);
                    } else {
                        return (-1);
                    }
                } else if (rhsValue == null) {
                    return (1);
                } else {
                    return (lhsValue.compareTo(rhsValue));
                }
            }
        }
    }

    protected ClearSubDep1ByQualNameComparator compareClearSubDep1ByQualName = new ClearSubDep1ByQualNameComparator();

    public Collection<ICFBamClearSubDep1Obj> getJavaFXDataCollection() {
        return (javafxDataCollection);
    }

    public void setJavaFXDataCollection(Collection<ICFBamClearSubDep1Obj> value) {
        final String S_ProcName = "setJavaFXDataCollection";
        javafxDataCollection = value;
        observableListOfClearSubDep1 = null;
        if (javafxDataCollection != null) {
            observableListOfClearSubDep1 = FXCollections.observableArrayList(javafxDataCollection);
            observableListOfClearSubDep1.sort(compareClearSubDep1ByQualName);
        } else {
            observableListOfClearSubDep1 = FXCollections.observableArrayList();
        }
        if (dataTable != null) {
            dataTable.setItems(observableListOfClearSubDep1);
            // Hack from stackoverflow to fix JavaFX TableView refresh issue
            ((TableColumn) dataTable.getColumns().get(0)).setVisible(false);
            ((TableColumn) dataTable.getColumns().get(0)).setVisible(true);
        }
    }

    public ICFBamClearTopDepObj getJavaFXContainer() {
        return (javafxContainer);
    }

    public void setJavaFXContainer(ICFBamClearTopDepObj value) {
        javafxContainer = value;
    }
}