<?xml version="1.0" encoding="UTF-8"?>

<!--
/*
 * Copyright (C) 2018-2020 Andrew Gegg
 *
 *	This file is part of the Garden Notebook application
 *
 * The Garden Notebook application 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/gpl.html>.
 */

/*
    Change log
    2.1.0   Properly display products
            Remove support for Detail_2
    2.4.0   Display products as a tree by ProductCategory
    2.7.0   Add copy context menu
    2.8.0   Add tooltips
            Allow in-line creation/edit of items
 */

-->

<?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TreeTableColumn?>
<?import javafx.scene.control.TreeTableView?>
<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.control.Tooltip?>

<fx:root type="javafx.scene.layout.GridPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="404.0" prefWidth="600.0"
         xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1">
    <stylesheets>
        <URL value="@notebook.css"/>
    </stylesheets>

    <columnConstraints>
        <ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0"/>
    </columnConstraints>

    <rowConstraints>
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS"/>
        <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER"/>
    </rowConstraints>

    <SplitPane dividerPositions="0.5" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="20" minWidth="-10"
               orientation="VERTICAL" GridPane.rowIndex="0">
        <TableView id="tblCatalogue" fx:id="tblCatalogue" editable="true" minHeight="10"
                   onDragDropped="#tbvItemsOnDragDropped" onDragOver="#tbvItemsOnDragOver"
                   maxHeight="1.7976931348623157E308" prefHeight="515.0" prefWidth="600.0">
            <columns>
                <TableColumn text="%col.product">
                    <columns>
                        <TableColumn id="tbvShopProductCategory" fx:id="tbvShopProductCategory" editable="true" prefWidth="75.0"
                                     text="%col.product.category"/>
                        <TableColumn id="tbvShopProductName" fx:id="tbvShopProductName" editable="true" prefWidth="75.0" text="%col.product.name"/>
                        <TableColumn id="tbvShopProductDetail" fx:id="tbvShopProductDetail" editable="true" prefWidth="75.0" text="%col.product.detail_1"/>
                        <TableColumn id="tbvShopProductBrand" fx:id="tbvShopProductBrand" editable="true" prefWidth="75.0" text="%col.product.brand"/>
                    </columns>
                </TableColumn>
                <TableColumn id="tbvShopNonSpecific" fx:id="tbvShopNonSpecific" editable="true" prefWidth="75.0" text="%col.shop.nonspecific"/>
                <TableColumn id="tbvShopComment" fx:id="tbvShopComment" editable="true" prefWidth="75.0" text="%col.comment"/>
            </columns>
            <contextMenu>
                <ContextMenu onShowing="#ctxmnuOnShowing">
                    <items>
                        <MenuItem id="ctxmnuAdd" onAction="#ctxmnuAddOnAction" text="%menu.add"/>
                        <MenuItem id="ctxmnuChange" onAction="#ctxmnuChangeOnAction" text="%menu.change"/>
                        <MenuItem id="ctxmnuDelete" fx:id="ctxmnuDelete" onAction="#ctxmnuDeleteOnAction" text="%menu.delete"/>
                    </items>
                </ContextMenu>
            </contextMenu>
        </TableView>
        <GridPane>
            <columnConstraints>
                <ColumnConstraints hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="10.0"/>
            </columnConstraints>
            <rowConstraints>
                <RowConstraints minHeight="10.0" vgrow="NEVER"/>
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS"/>
            </rowConstraints>
            <padding>
                <Insets top="5.0"/>
            </padding>
            <Label text="%lbl.products" GridPane.halignment="LEFT" GridPane.rowIndex="0" GridPane.valignment="TOP"/>
            <!-- The Products table is essentially NOT editable, only the description and comment columns -->
            <TreeTableView id="tbvProducts" fx:id="tbvProducts" editable="true" showRoot="false" prefHeight="200.0" prefWidth="200.0" minHeight="10"
                           GridPane.rowIndex="1">
                <columns>
                    <!--                                <TableColumn id="tbvProdProductCategory" fx:id="tbvProdProductCategory" editable="false" prefWidth="75.0" text="%col.product.category" />   -->
                    <TreeTableColumn id="tbvProdProductName" fx:id="tbvProdProductName" editable="false" prefWidth="75.0" text="%col.product.name"/>
                    <TreeTableColumn id="tbvProdProductDetail_1" fx:id="tbvProdProductDetail_1" editable="false" prefWidth="75.0"
                                     text="%col.product.detail_1"/>
                    <!--                                <TableColumn id="tbvProdProductDetail_2" fx:id="tbvProdProductDetail_2" editable="false" prefWidth="75.0" text="%col.product.detail_2" />   -->
                    <TreeTableColumn id="tbvProdProductBrand" fx:id="tbvProdProductBrand" editable="false" prefWidth="75.0" text="%col.product.brand"/>
                    <TreeTableColumn id="tbvProdProductDescription" fx:id="tbvProdProductDescription" editable="true" prefWidth="75.0"
                                     text="%col.product.description"/>
                    <TreeTableColumn id="tbvProdComment" fx:id="tbvProdComment" editable="true" prefWidth="75.0" text="%col.comment"/>
                </columns>
                <contextMenu>
                    <ContextMenu onShowing="#ctxmnuProdOnShowing">
                        <items>
                            <MenuItem id="ctxmnuProdCopyToSL" fx:id="ctxmnuProdCopyToSL" onAction="#ctxmnuProdCopyToSLOnAction"
                                      text="%menu.purchase.copyprod"/>
                        </items>
                    </ContextMenu>
                </contextMenu>
            </TreeTableView>
        </GridPane>
    </SplitPane>

    <ButtonBar prefHeight="40.0" prefWidth="200.0" GridPane.rowIndex="1">
        <buttons>
            <Button id="btnAdd" fx:id="btnAdd" mnemonicParsing="false" text="%btn.add" onAction="#btnAddOnAction" styleClass="notebook-cmd-button">
                <tooltip>
                    <Tooltip text="%tip.shoppinglist.button.add"/>
                </tooltip>
            </Button>
            <Button id="btnChange" fx:id="btnChange" mnemonicParsing="false" text="%btn.change" onAction="#btnChangeOnAction" styleClass="notebook-cmd-button">
                <tooltip>
                    <Tooltip text="%tip.shoppinglist.button.change"/>
                </tooltip>
            </Button>
            <Button id="btnDelete" fx:id="btnDelete" mnemonicParsing="false" text="%btn.delete" onAction="#btnDeleteOnAction" styleClass="notebook-cmd-button">
                <tooltip>
                    <Tooltip text="%tip.shoppinglist.button.delete"/>
                </tooltip>
            </Button>
        </buttons>
    </ButtonBar>

</fx:root>
