/ESSSetup/src/za/co/accsys/ess/FXMLDocumentController.java
Java | 1128 lines | 728 code | 105 blank | 295 comment | 84 complexity | 04e7a9c05617d2bd9d13415c9981f351 MD5 | raw file
- /*
- * This is the Controller part of the MVC used to set up the PeopleWare organograms,
- * rules, and attributes.
- */
- package za.co.accsys.ess;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Iterator;
- import java.util.LinkedList;
- import java.util.ResourceBundle;
- import java.util.StringTokenizer;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.application.Platform;
- import javafx.beans.property.DoubleProperty;
- import javafx.beans.property.SimpleDoubleProperty;
- import javafx.beans.value.ChangeListener;
- import javafx.beans.value.ObservableValue;
- import javafx.collections.FXCollections;
- import javafx.collections.ListChangeListener;
- import javafx.collections.ObservableList;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.geometry.Insets;
- import javafx.scene.Node;
- import javafx.scene.control.Button;
- import javafx.scene.control.CheckBox;
- import javafx.scene.control.ChoiceBox;
- import javafx.scene.control.Dialogs;
- import javafx.scene.control.Dialogs.DialogResponse;
- import javafx.scene.control.Label;
- import javafx.scene.control.ListView;
- import javafx.scene.control.MenuItem;
- import javafx.scene.control.ProgressBar;
- import javafx.scene.control.SelectionMode;
- import javafx.scene.control.Tab;
- import javafx.scene.control.TabPane;
- import javafx.scene.control.TextField;
- import javafx.scene.control.Tooltip;
- import javafx.scene.control.TreeCell;
- import javafx.scene.control.TreeItem;
- import javafx.scene.control.TreeView;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.input.ClipboardContent;
- import javafx.scene.input.DataFormat;
- import javafx.scene.input.DragEvent;
- import javafx.scene.input.Dragboard;
- import javafx.scene.input.KeyCode;
- import javafx.scene.input.KeyEvent;
- import javafx.scene.input.MouseEvent;
- import javafx.scene.input.TransferMode;
- import javafx.scene.layout.Pane;
- import javafx.scene.layout.StackPane;
- import javafx.scene.paint.Color;
- import javafx.scene.text.Font;
- import javafx.scene.text.Text;
- import javafx.scene.web.HTMLEditor;
- import javafx.stage.FileChooser;
- import javafx.stage.Stage;
- import javafx.util.Callback;
- import static za.co.accsys.ess.ESSSetup.stage;
- import za.co.ucs.accsys.webmodule.ESSVersion;
- import za.co.ucs.accsys.webmodule.EmployeeSelection;
- import za.co.ucs.accsys.webmodule.EmployeeSelectionRule;
- import za.co.ucs.accsys.webmodule.FileContainer;
- import za.co.ucs.accsys.webmodule.ReportingStructure;
- import za.co.ucs.accsys.webmodule.SelectionInterpreter;
- import za.co.ucs.accsys.webmodule.SelectionLink;
- import za.co.ucs.accsys.webmodule.WebProcessDefinition;
- import za.co.ucs.lwt.initools.OutputFile;
- /**
- *
- * @author lterblanche
- */
- public class FXMLDocumentController implements Initializable {
- // Private members
- FileContainer fileContainer = FileContainer.getInstance();
- LinkedList<EmployeeSelection> localEmployeeSelections = new LinkedList<>();
- LinkedList<EmployeeSelection> llES_filteredEmployeeSelections = new LinkedList<>();
- LinkedList<EmployeeSelection> llRS_filteredAndUnusedEmployeeSelections = new LinkedList<>();
- LinkedList<ReportingStructure> llRS_ReportingStructures = new LinkedList<>();
- LinkedList<ReportingStructure> localReportingStructures = new LinkedList<>();
- LinkedList<WebProcessDefinition> localWebProcessDefinitions = new LinkedList<>();
- // Now add observability by wrapping it with ObservableList
- // ObservableList<ReportingStructure> observableReportingStructures = FXCollections.observableList(localReportingStructures);
- ObservableList<ReportingStructure> observableReportingStructures;
- // ObservableList<WebProcessDefinition> observableWebProcessDefinitions = FXCollections.observableList(localWebProcessDefinitions);
- ObservableList<WebProcessDefinition> observableWebProcessDefinitions;
- EmployeeSelection clipboardEmployeeSelection;
- SelectionLink clipboardSelectionLink;
- static boolean contentsChanged = false;
- static String appTitle = "ESS Configuration";
- // Used an observable value to bind to the progress bar (pbProgress)
- private final DoubleProperty progressBarPosition = new SimpleDoubleProperty(0);
- // <editor-fold defaultstate="collapsed" desc=" ${Scene Builder Setup} ">
- @FXML
- private TabPane tpTabPane;
- @FXML
- private Tab tabWebProcesses;
- @FXML
- private ListView<WebProcessDefinition> lvAvailableWebProcesses;
- @FXML
- private Label lblWebProcess_ProcessName;
- @FXML
- private TextField tfWebProcess_ProcessName;
- @FXML
- private Label lblWebProcess_ReportingStructure;
- @FXML
- private Label lblWebProcess_MaxProcAge;
- @FXML
- private Label lblWebProcess_MaxStageAge;
- @FXML
- private TextField tfWebProcess_MaxDurationPerProcess;
- @FXML
- private TextField tfWebProcess_MaxDurationPerStage;
- @FXML
- private CheckBox cbWebProcess_IsSupervisor;
- @FXML
- private Tab tabReportingStructures;
- @FXML
- private Tab tabSelectionFormulas;
- @FXML
- private TextField tfWebProcess_ActivateOn;
- @FXML
- private TextField tfWebProcess_DeactivateOn;
- @FXML
- private Button btnWebProcess_Apply;
- @FXML
- private CheckBox cbWebProcess_NotifyStaffOfActivation;
- @FXML
- private ChoiceBox<ReportingStructure> cbWebProcess_ReportingStructure;
- @FXML
- private CheckBox cbWebProcess_NotifyStaffOfDeActivation;
- @FXML
- private MenuItem mnuSaveConfiguration;
- @FXML
- private ListView<ReportingStructure> lvRS_ExistingReportingStructures;
- @FXML
- private ListView<EmployeeSelection> lvRS_ExistingEmployeeSelections;
- @FXML
- private Insets x1;
- @FXML
- private Button btnRS_ClearFilter;
- @FXML
- private TreeView<EmployeeSelection> tvRS_ReportingStructureTreeView;
- @FXML
- private TextField tfRS_FilterEmployeeSelections;
- private ListView<ReportingStructure> lvRS_FilteredEmployeeSelections;
- @FXML
- private TextField tfRS_FindEmployeeSelection;
- @FXML
- private Button btnRS_ClearLocate;
- @FXML
- private Insets x2;
- @FXML
- private Button btnRS_NewRS;
- @FXML
- private Button btnRS_RenameRS;
- @FXML
- private Button btnRS_CopyRS;
- @FXML
- private Button btnRS_DeleteRS;
- @FXML
- private MenuItem mnuClose;
- @FXML
- private TextField tfES_FilterEmployeeSelections;
- @FXML
- private Button btnES_ClearFilter;
- @FXML
- private Font x4;
- @FXML
- private HTMLEditor htmlSF_Editor;
- @FXML
- private ListView<EmployeeSelection> lvES_ExistingEmployeeSelections;
- @FXML
- private Button btnES_NewES;
- @FXML
- private Button btnES_DeleteES;
- @FXML
- private Button btnES_CopyES;
- @FXML
- private Button btnES_TestFormula;
- @FXML
- private Label lblRS_ReportingStructureHierarchy;
- @FXML
- private TextField tfES_ProcessName;
- @FXML
- private ChoiceBox<String> cbES_Filter;
- @FXML
- private ChoiceBox<String> cbES_Compare;
- @FXML
- private Button btnES_AddToFormula;
- @FXML
- private Button btnES_ApplyChanges;
- @FXML
- private ListView<String> lvES_TestResult;
- @FXML
- private MenuItem mnuValidateConfiguration;
- @FXML
- private Text txtStatus;
- @FXML
- private StackPane root;
- @FXML
- private MenuItem mnuExportConfiguration;
- @FXML
- private Color x3;
- @FXML
- private Font x5;
- @FXML
- private MenuItem mnuAbout;
- @FXML
- private Insets x11;
- @FXML
- private Insets x12;
- @FXML
- private Insets x13;
- @FXML
- private Insets x14;
- @FXML
- private Insets x15;
- @FXML
- private Insets x16;
- @FXML
- private Insets x17;
- @FXML
- private Insets x18;
- @FXML
- private ProgressBar pbProgress;
- // </editor-fold>
- //
- // <editor-fold defaultstate="collapsed" desc=" ${WebProcessDefinition Tab} ">
- /**
- * Setup the components used in the Web Process Definitions
- */
- private void initWebProcessDefinitionsTab() {
- // Populate existing WebProcessDefinitions
- lvAvailableWebProcesses.setItems(observableWebProcessDefinitions);
- //
- // EVENT LISTENER: Click on Web Proccesses Structure
- //
- lvAvailableWebProcesses.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<WebProcessDefinition>() {
- @Override
- public void changed(ObservableValue<? extends WebProcessDefinition> observable, WebProcessDefinition oldValue, WebProcessDefinition newValue) {
- // Update the display
- if (newValue != null) {
- tfWebProcess_ProcessName.setText(newValue.getName());
- tfWebProcess_MaxDurationPerProcess.setText(String.valueOf(newValue.getMaxProcessAge()));
- tfWebProcess_MaxDurationPerStage.setText(String.valueOf(newValue.getMaxStageAge()));
- tfWebProcess_ActivateOn.setText(String.valueOf(newValue.getActiveFromDayOfMonth()));
- tfWebProcess_DeactivateOn.setText(String.valueOf(newValue.getActiveToDayOfMonth()));
- cbWebProcess_NotifyStaffOfActivation.setSelected(newValue.isNotifyOfPendingActivation());
- cbWebProcess_NotifyStaffOfDeActivation.setSelected(newValue.isNotifyOfPendingDeactivation());
- cbWebProcess_IsSupervisor.setSelected(newValue.getCannotInstantiateSelf());
- // Populate the ChoiceBox with the list of available ReportingStructures
- cbWebProcess_ReportingStructure.setItems(observableReportingStructures);
- // Highlight the correct one
- cbWebProcess_ReportingStructure.getSelectionModel().clearSelection();
- if (newValue.getReportingStructure() != null) {
- cbWebProcess_ReportingStructure.getSelectionModel().select(newValue.getReportingStructure());
- }
- }
- }
- });
- //
- // EVENT LISTENER: Web Process Definition attributes changed
- //
- observableWebProcessDefinitions.addListener(new ListChangeListener() {
- @Override
- public void onChanged(ListChangeListener.Change change) {
- System.out.println("Web Process Definition - Detected a change! ");
- setContentsChanged(true);
- }
- });
- //
- // EVENT LISTENER: Click on Apply button
- //
- btnWebProcess_Apply.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- int index = lvAvailableWebProcesses.getSelectionModel().getSelectedIndex();
- WebProcessDefinition toChange = localWebProcessDefinitions.get(index);
- saveWebProcessDefinition(toChange);
- observableWebProcessDefinitions.remove(toChange);
- observableWebProcessDefinitions.add(index, toChange);
- setContentsChanged(true);
- // Reselect in the listView
- lvAvailableWebProcesses.getSelectionModel().clearAndSelect(index);
- }
- });
- //
- // TOOL TIPS
- //
- Tooltip t1 = new Tooltip("This list contains all the possible processes that can be used in the ESS");
- Tooltip.install(lvAvailableWebProcesses, t1);
- Tooltip t2 = new Tooltip("When checked, the employee will not have access to this process.\n"
- + "Only a manager can use this process.\nAnd he/she can only use it on employees reporting to him/her.");
- Tooltip.install(cbWebProcess_IsSupervisor, t2);
- Tooltip t3a = new Tooltip("Should an employee be notified via email if this process is being activated?");
- Tooltip t3d = new Tooltip("Should an employee be notified via email if this process is being deactivated?");
- Tooltip.install(cbWebProcess_NotifyStaffOfActivation, t3a);
- Tooltip.install(cbWebProcess_NotifyStaffOfDeActivation, t3d);
- Tooltip t4 = new Tooltip("How many hours (8 hours per day) should a process stay alive before being cancelled?");
- Tooltip.install(tfWebProcess_MaxDurationPerProcess, t4);
- Tooltip t5 = new Tooltip("How long should a process wait for authorisation before escalating to the next person?");
- Tooltip.install(tfWebProcess_MaxDurationPerStage, t5);
- //
- // Select the first item
- //
- if (lvAvailableWebProcesses.getItems().size() > 0) {
- lvAvailableWebProcesses.getSelectionModel().select(0);
- }
- //
- // Bind the Progress Bar to the ProgressPosition variable
- //
- pbProgress.progressProperty().bind(progressBarPosition);
- }
- // </editor-fold>
- //
- // <editor-fold defaultstate="collapsed" desc=" ${ReportingStructure Tab} ">
- /**
- * Setup the components used in the Reporting Structures
- */
- private void initReportingStructuresTab() {
- // ----------------------------------------------
- // SETUP LISTVIEW : REPORTING STRUCTURES
- // Populate existing ReportingStructures
- lvRS_ExistingReportingStructures.setItems(observableReportingStructures);
- // Order the list
- orderReportingStructureList(lvRS_ExistingReportingStructures);
- // Disable the Delete button
- btnRS_DeleteRS.setDisable(true);
- // Disable the Rename button
- btnRS_RenameRS.setDisable(true);
- // Disable the Copy button
- btnRS_CopyRS.setDisable(true);
- //
- // EVENT LISTENER: Click Reporting Structure
- //
- lvRS_ExistingReportingStructures.setOnMouseClicked(new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent event) {
- ReportingStructure newValue = lvRS_ExistingReportingStructures.getSelectionModel().getSelectedItem();
- if (newValue != null) {
- System.out.println("Selected item: " + newValue);
- // Enable the Delete button
- btnRS_DeleteRS.setDisable(false);
- // Enable the Rename button
- btnRS_RenameRS.setDisable(false);
- // Enable the Copy button
- btnRS_CopyRS.setDisable(false);
- // Clear the filters
- tfRS_FindEmployeeSelection.setText("");
- tfRS_FilterEmployeeSelections.setText("");
- buildReportingStructureInTreeView(newValue, tvRS_ReportingStructureTreeView);
- // For this reporting structure, list the
- // Employee Selections that has not yet been used, and
- // apply the filter (if any)
- rebuildEmployeeSelectionLists();
- }
- }
- });
- //
- // EVENT LISTENER: Reporting Structure List changed
- //
- observableReportingStructures.addListener(new ListChangeListener() {
- @Override
- public void onChanged(ListChangeListener.Change change) {
- System.out.println("Reporting Structures - Detected a change! " + change.toString());
- setContentsChanged(true);
- }
- });
- // ---------------------------------------------
- // SETUP LISTVIEW :EMPLOYEE SELECTIONS
- // FILTER Employee Selections
- //
- // Initiate the filtered list of EmployeeSelections
- llRS_filteredAndUnusedEmployeeSelections.addAll(localEmployeeSelections);
- lvRS_ExistingEmployeeSelections.setItems(FXCollections.observableList(llRS_filteredAndUnusedEmployeeSelections));
- // Order the list
- orderEmployeeSelectionList(lvRS_ExistingEmployeeSelections);
- //
- // EVENT LISTENER: Filter on TextField
- //
- tfRS_FilterEmployeeSelections.setOnKeyReleased(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent ke) {
- // Filter
- rebuildEmployeeSelectionLists();
- }
- });
- //
- // EVENT LISTENER: Click on Clear button
- //
- btnRS_ClearFilter.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- tfRS_FilterEmployeeSelections.setText("");
- // Filter
- rebuildEmployeeSelectionLists();
- }
- });
- //
- // EVENT LISTENER: Click Employee Selection
- //
- lvRS_ExistingEmployeeSelections.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<EmployeeSelection>() {
- @Override
- public void changed(ObservableValue<? extends EmployeeSelection> observable, EmployeeSelection oldValue, EmployeeSelection newValue) {
- // This is where we build the reporting structure for the TreeView
- //System.out.println("Selected item: " + newValue);
- }
- });
- //
- // DRAG n DROP: On Drag Detected
- //
- lvRS_ExistingEmployeeSelections.setOnDragDetected(
- new EventHandler<MouseEvent>() {
- @Override
- public void handle(MouseEvent event
- ) {
- // Can't Drag if no Employee Selection is selected
- if (lvRS_ExistingEmployeeSelections.getSelectionModel().getSelectedItem() == null) {
- event.consume();
- return;
- }
- // Can't Drag if no Reporting Structure is selected
- if (lvRS_ExistingReportingStructures.getSelectionModel().getSelectedItem() == null) {
- event.consume();
- return;
- }
- /* drag was detected, start a drag-and-drop gesture*/
- /* allow any transfer mode */
- Dragboard db = lvRS_ExistingEmployeeSelections.startDragAndDrop(TransferMode.MOVE);
- /* Put a string on a dragboard */
- ClipboardContent content = new ClipboardContent();
- content.put(DataFormat.PLAIN_TEXT, lvRS_ExistingEmployeeSelections.getSelectionModel().getSelectedItem().toString());
- db.setContent(content);
- event.consume();
- }
- }
- );
- //
- // EVENT LISTENER: Delete Reporting Structure
- //
- btnRS_DeleteRS.setOnAction(
- new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- ReportingStructure selected = lvRS_ExistingReportingStructures.getSelectionModel().getSelectedItem();
- if (selected != null) {
- DialogResponse response = Dialogs.showConfirmDialog(null,
- "Do you wish to delete this reporting structure?", "Confirm Deletion", "Delete '" + selected + "'", Dialogs.DialogOptions.YES_NO);
- if (response == DialogResponse.YES) {
- // Clear this Reporting Structure
- //lvRS_ExistingReportingStructures.getItems().remove(selected);
- observableReportingStructures.remove(selected);
- // Unselect reporting structures
- //lvRS_ExistingReportingStructures.getSelectionModel().clearSelection();
- // Clear TreeView
- tvRS_ReportingStructureTreeView.setRoot(null);
- //TODO: Still clear up the WebProcessDefinition screen if the reporting structure is gone
- //rebuildReportingStructureLists();
- setContentsChanged(true);
- }
- }
- }
- }
- );
- //
- // EVENT LISTENER: Rename Reporting Structure
- //
- btnRS_RenameRS.setOnAction(
- new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- ReportingStructure selected = lvRS_ExistingReportingStructures.getSelectionModel().getSelectedItem();
- if (selected != null) {
- String newName = Dialogs.showInputDialog(null, "New name:", "Rename Reporting Structure", "Rename '" + selected + "'", selected.getName());
- if (newName != null) {
- if (newName.trim().length() > 0) {
- // Rename Reporting Structure
- int index = lvRS_ExistingReportingStructures.getSelectionModel().getSelectedIndex();
- ReportingStructure toChange = localReportingStructures.get(index);
- String originalName = toChange.toString();
- observableReportingStructures.remove(toChange);
- toChange.setName(newName);
- //
- // Validate new name
- //
- while (!isRSNameUnique(toChange)) {
- String nameOfCurrentStructure = toChange.getName();
- String message = "Please rename:\n\n\t" + nameOfCurrentStructure + "\n\nto avoid errors in the reporting structure.";
- String newStructureName = Dialogs.showInputDialog(getMainStage(), message, "The name already exists!", "Duplicate name", nameOfCurrentStructure);
- // If the suer makes it blank keep the old name
- if (newStructureName == null || newStructureName.trim().length() == 0) {
- newStructureName = originalName;
- }
- toChange.setName(newStructureName);
- setContentsChanged(true);
- }
- showStatus(null, 0, 0);
- if (toChange.getName() != null) {
- observableReportingStructures.add(index, toChange);
- }
- // Order the list
- orderReportingStructureList(lvRS_ExistingReportingStructures);
- orderEmployeeSelectionList(lvRS_ExistingEmployeeSelections);
- // Once created and added, select it
- lvRS_ExistingReportingStructures.getSelectionModel().select(toChange);
- lvRS_ExistingReportingStructures.scrollTo(lvRS_ExistingReportingStructures.getSelectionModel().getSelectedIndex());
- }
- }
- }
- }
- }
- );
- //
- // EVENT LISTENER: New Reporting Structure
- //
- btnRS_NewRS.setOnAction(
- new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- String newName = Dialogs.showInputDialog(null, "Name:", "Create a new Reporting Structure", "New Reporting Structure");
- if (newName != null) {
- if (newName.trim().length() > 0) {
- // New Reporting Structure
- ReportingStructure newStructure = new ReportingStructure(newName, newName);
- setContentsChanged(true);
- //
- // Validate new name
- //
- int i = 1;
- while (!isRSNameUnique(newStructure)) {
- String nameOfCurrentStructure = newStructure.getName();
- String message = "Please rename:\n\n\t" + nameOfCurrentStructure + "\n\nto avoid errors in the reporting structure.\n*Failure to choose a unique name will result in an automatic rename.";
- String newStructureName = Dialogs.showInputDialog(getMainStage(), message, "The name already exists!", "Duplicate name", nameOfCurrentStructure);
- // If the user cancels exit the loop
- if (newStructureName == null) {
- return;
- }
- // If the user makes it blank rename
- if (newStructureName.trim().length() == 0) {
- newStructureName = i++ + "_renamed_" + nameOfCurrentStructure;
- }
- newStructure.setName(newStructureName);
- setContentsChanged(true);
- }
- showStatus(null, 0, 0);
- if (newStructure.getName() != null) {
- observableReportingStructures.add(newStructure);
- }
- // Order the list
- orderReportingStructureList(lvRS_ExistingReportingStructures);
- orderEmployeeSelectionList(lvRS_ExistingEmployeeSelections);
- // Once created and added, select it
- lvRS_ExistingReportingStructures.getSelectionModel().select(newStructure);
- lvRS_ExistingReportingStructures.scrollTo(lvRS_ExistingReportingStructures.getSelectionModel().getSelectedIndex());
- }
- }
- }
- }
- );
- //
- // EVENT LISTENER: Copy Reporting Structure
- //
- btnRS_CopyRS.setOnAction(
- new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- ReportingStructure toCopy = lvRS_ExistingReportingStructures.getSelectionModel().getSelectedItem();
- if (toCopy != null) {
- String newName = Dialogs.showInputDialog(null, "Name for new Reporting Structure", "Copy", "Copy existing Reporting Structure", toCopy.getName() + "(copy)");
- if (newName != null) {
- if (newName.trim().length() > 0) {
- // Rename Reporting Structure
- ReportingStructure newStructure = new ReportingStructure(newName, newName);
- LinkedList<SelectionLink> links = new LinkedList(toCopy.selectionLinks);
- for (SelectionLink sl : links) {
- newStructure.addSelectionLink(sl);
- }
- //
- // Validate new name
- //
- int nbReportingStructures = localReportingStructures.size();
- if (nbReportingStructures > 0) {
- int i = 1;
- showStatus("Testing Reporting Structure: " + newStructure.toString(), i + 1, nbReportingStructures);
- //
- // Check that names differ
- //
- LinkedList<ReportingStructure> localStructures = new LinkedList(localReportingStructures);
- // localStructures.remove(newStructure);
- for (ReportingStructure structureInList : localStructures) {
- // If hashCodes are the same rename the current reporting structure
- if (newStructure.getName().equals(structureInList.getName())) {
- // Ask user to change name
- // Edit a Reporting Structure
- // Edit dialog
- String nameOfCurrentStructure = newStructure.getName();
- String message = "Please rename:\n\n\t" + nameOfCurrentStructure + "\n\nto avoid errors in the reporting structure.\n\n*If you do not rename the reporting structure it will be renamed automatically.";
- String newStructureName = Dialogs.showInputDialog(getMainStage(), message, "The name already exists!", "Duplicate name");
- // Rename Structure
- if ((newStructureName == null) || (newStructureName.trim().length() == 0)) {
- newStructureName = i - 1 + "_renamed_" + nameOfCurrentStructure;
- }
- newStructure.setName(newStructureName);
- setContentsChanged(true);
- }
- i++;
- }
- showStatus(null, 0, 0);
- }
- // Add to existing list
- observableReportingStructures.add(newStructure);
- // Order the list
- orderReportingStructureList(lvRS_ExistingReportingStructures);
- orderEmployeeSelectionList(lvRS_ExistingEmployeeSelections);
- rebuildEmployeeSelectionLists();
- // Once created and added, select it
- lvRS_ExistingReportingStructures.getSelectionModel().select(newStructure);
- lvRS_ExistingReportingStructures.scrollTo(lvRS_ExistingReportingStructures.getSelectionModel().getSelectedIndex());
- setContentsChanged(true);
- }
- }
- } else {
- Dialogs.showErrorDialog(null, "Please select an existing Reporting Structure before trying to copy it.");
- }
- }
- }
- );
- // --------------------------------------
- // SETUP TREEVIEW: Reporting Structures
- // CELL FACTORY for TreeView
- //
- tvRS_ReportingStructureTreeView.setCellFactory(
- new Callback<TreeView<EmployeeSelection>, TreeCell<EmployeeSelection>>() {
- @Override
- public TreeCell call(TreeView<EmployeeSelection> param
- ) {
- return new DnDCell(param, lvRS_ExistingReportingStructures.getSelectionModel().getSelectedItem());
- }
- }
- );
- //
- // EVENT LISTENER: Person typed in search terms
- //
- tfRS_FindEmployeeSelection.setOnKeyReleased(
- new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent ke
- ) {
- // Only SEARCH if we have selected a Reporting Structure
- if (tvRS_ReportingStructureTreeView.getRoot() != null) {
- TreeItem rootItem = tvRS_ReportingStructureTreeView.getRoot();
- TreeItem selectedItem = rootItem;
- // GET FILTER String
- String strFind = tfRS_FindEmployeeSelection.getText();
- if (strFind.trim().length() > 0) {
- //Locate strFind in the TreeView
- selectedItem = searchInTreeView(rootItem, strFind);
- }
- // Only highlight found item if we did, in fact, find an item
- if (selectedItem != null) {
- tvRS_ReportingStructureTreeView.getSelectionModel().select(selectedItem);
- tvRS_ReportingStructureTreeView.scrollTo(tvRS_ReportingStructureTreeView.getRow(selectedItem));
- }
- }
- }
- /**
- * Iteratively steps through the tree view, looking for the first
- * occurrence of 'searchString' in the given TreeItem
- *
- * @param currentNode
- * @param valueToSearch
- * @return TreeItem - the item that matches the search string
- */
- private TreeItem<EmployeeSelection> searchInTreeView(final TreeItem<EmployeeSelection> currentNode, final String valueToSearch) {
- TreeItem<EmployeeSelection> result = null;
- if (matchesFilter(currentNode.toString(), valueToSearch)) {
- result = currentNode;
- } else if (!currentNode.isLeaf()) {
- for (TreeItem<EmployeeSelection> child : currentNode.getChildren()) {
- result = searchInTreeView(child, valueToSearch);
- if (result != null) {
- break;
- }
- }
- }
- return result;
- }
- }
- );
- //
- // EVENT LISTENER: Person pressed a KEY
- //
- tvRS_ReportingStructureTreeView.setOnKeyPressed(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent t) {
- System.out.println("KeyCode :" + t.getCode());
- //
- // KEY = DELETE
- //
- if (t.getCode() == KeyCode.DELETE) {
- // Which item was deleted?
- TreeItem<EmployeeSelection> ti = tvRS_ReportingStructureTreeView.getSelectionModel().getSelectedItem();
- EmployeeSelection es = ti.getValue();
- ReportingStructure rs = lvRS_ExistingReportingStructures.getSelectionModel().getSelectedItem();
- deleteEmployeeSelectionFromReportingStructure(es, rs);
- buildReportingStructureInTreeView(rs, tvRS_ReportingStructureTreeView);
- // For this reporting structure, list the
- // Employee Selections that has not yet been used, and
- // apply the filter (if any)
- rebuildEmployeeSelectionLists();
- tvRS_ReportingStructureTreeView.getSelectionModel().clearSelection();
- setContentsChanged(true);
- t.consume();
- }
- //
- // KEY = CTRL+X (Cut)
- //
- if (t.getCode().equals(KeyCode.X) && t.isControlDown()) {
- System.out.println("Cut :" + t.getCode());
- // Which EmployeeSelection was cut?
- TreeItem<EmployeeSelection> ti = tvRS_ReportingStructureTreeView.getSelectionModel().getSelectedItem();
- int selectionIndex = tvRS_ReportingStructureTreeView.getSelectionModel().getSelectedIndex();
- EmployeeSelection es = ti.getValue();
- clipboardEmployeeSelection = es;
- // Which SelectionLink should be cut?
- ReportingStructure rs = lvRS_ExistingReportingStructures.getSelectionModel().getSelectedItem();
- EmployeeSelection parentSelection = rs.getParentSelection(clipboardEmployeeSelection);
- clipboardSelectionLink = rs.getSelectionLink(clipboardEmployeeSelection, parentSelection);
- buildReportingStructureInTreeView(rs, tvRS_ReportingStructureTreeView);
- tvRS_ReportingStructureTreeView.getSelectionModel().select(selectionIndex);
- tvRS_ReportingStructureTreeView.scrollTo(selectionIndex);
- t.consume();
- }
- //
- // KEY = CTRL+V (Paste)
- //
- if (t.getCode().equals(KeyCode.V) && t.isControlDown()) {
- System.out.println("Paste :" + t.getCode());
- // Which item was selected?
- ReportingStructure rs = lvRS_ExistingReportingStructures.getSelectionModel().getSelectedItem();
- TreeItem<EmployeeSelection> ti = tvRS_ReportingStructureTreeView.getSelectionModel().getSelectedItem();
- EmployeeSelection newParentSelection = ti.getValue();
- //
- // ONLY PASTE IF ITS NOT RECURSIVE!
- //
- if (isDecendentOf(tvRS_ReportingStructureTreeView, clipboardEmployeeSelection.toString(), newParentSelection.toString())) // We accept the transfer!!!!!
- {
- Dialogs.showErrorDialog(null, "You cannot paste an Employee Selection under a Selection that reports to it.");
- // Reset the 'clipboardEmployeeSelection'
- clipboardEmployeeSelection = null;
- buildReportingStructureInTreeView(rs, tvRS_ReportingStructureTreeView);
- t.consume();
- } else {
- // Delete the CUT selection link
- rs.getSelectionLinks().remove(clipboardSelectionLink);
- // Create the PASTE selection link
- SelectionLink pasteLink = new SelectionLink(clipboardEmployeeSelection, newParentSelection);
- int selectionIndex = tvRS_ReportingStructureTreeView.getSelectionModel().getSelectedIndex();
- rs.getSelectionLinks().add(pasteLink);
- // Reset the 'clipboardEmployeeSelection'
- clipboardEmployeeSelection = null;
- buildReportingStructureInTreeView(rs, tvRS_ReportingStructureTreeView);
- tvRS_ReportingStructureTreeView.getSelectionModel().select(selectionIndex);
- tvRS_ReportingStructureTreeView.scrollTo(selectionIndex);
- setContentsChanged(true);
- t.consume();
- }
- }
- }
- });
- //
- // EVENT LISTENER: Select an item in the TreeView
- //
- tvRS_ReportingStructureTreeView.getSelectionModel()
- .selectedItemProperty().addListener(new ChangeListener() {
- @Override
- public void changed(ObservableValue observable, Object oldValue,
- Object newValue
- ) {
- TreeItem<EmployeeSelection> selectedItem = (TreeItem<EmployeeSelection>) newValue;
- if (selectedItem != null) {
- System.out.println("Selected Text : " + selectedItem.getValue());
- //Display the hierarchy from this selection to the top
- lblRS_ReportingStructureHierarchy.setText(getHierarchyOfReportingStructure(lvRS_ExistingReportingStructures.getSelectionModel().getSelectedItem(), selectedItem.getValue()));
- }
- }
- }
- );
- }
- // </editor-fold>
- //
- // <editor-fold defaultstate="collapsed" desc=" ${EmployeeSelections Tab} ">
- /**
- * Setup the components used in the Web Process Definitions
- */
- private void initEmployeeSelectionsTab() {
- // ---------------------------------------------
- // SETUP LISTVIEW :EMPLOYEE SELECTIONS
- // FILTER Employee Selections
- //
- // Initiate the filtered list of EmployeeSelections
- llES_filteredEmployeeSelections.addAll(localEmployeeSelections);
- lvES_ExistingEmployeeSelections.setItems(FXCollections.observableList(llES_filteredEmployeeSelections));
- // Order the list
- orderEmployeeSelectionList(lvES_ExistingEmployeeSelections);
- lvES_ExistingEmployeeSelections.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
- // ---------------------------------------------
- // SETUP HTML Editor
- // HIDE Controls
- //
- // for (Node toolBar = htmlSF_Editor.lookup(".tool-bar"); toolBar != null; toolBar = htmlSF_Editor.lookup(".tool-bar")) {
- // ((Pane) toolBar.getParent()).getChildren().remove(toolBar);
- // }
- //
- // SETUP CHOICEBOX: Filter
- //
- // Populate the ChoiceBox with the list of available Filters
- ArrayList<String> keyWords = new ArrayList<>();
- keyWords.addAll(Arrays.asList(EmployeeSelectionRule.getKeyWords()));
- cbES_Filter.setItems(FXCollections.observableList(keyWords));
- //
- // SETUP CHOICEBOX: Comparitors
- //
- // Populate the ChoiceBox with the list of available Filters
- ArrayList<String> comparitors = new ArrayList<>();
- comparitors.addAll(Arrays.asList(getSelectionComparators()));
- cbES_Compare.setItems(FXCollections.observableList(comparitors));
- //
- // Disable all the buttons
- //
- // <editor-fold defaultstate="collapsed" desc=" $Disable all the buttons ">
- {
- // Disable the Delete button
- btnES_DeleteES.setDisable(true);
- // Disable the Copy button
- btnES_CopyES.setDisable(true);
- // Disable Test Formula Button
- btnES_TestFormula.setDisable(true);
- // Disable the AddToFormula button
- btnES_AddToFormula.setDisable(true);
- // Disable dropdown choicebox for Filter
- cbES_Filter.setDisable(true);
- // Disable dropdown choicebox for Compare
- cbES_Compare.setDisable(true);
- // Disable Apply Changes
- btnES_ApplyChanges.setDisable(true);
- }
- // </editor-fold>
- //
- // EVENT LISTENER: On Test Formula
- //
- btnES_TestFormula.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- // Get the text in the HTMLEditor
- String htmlText = htmlSF_Editor.getHtmlText();
- String plainText = stripHTML(htmlText);
- plainText = plainText.replaceAll(" ", " ");
- plainText = plainText.replaceAll("&NBSP;", " ");
- // Display the formula
- htmlSF_Editor.setHtmlText(convertStringToHTML(plainText));
- //-------------------
- // Evaluate the rule
- //-------------------
- // Create a new Rule and Execute it to test the results
- EmployeeSelectionRule rule = new EmployeeSelectionRule("Test", "Test");
- // Extract Text from editor and execute rule
- rule.setRule(plainText);
- String testResult = rule.listResult();
- StringTokenizer token = new StringTokenizer(testResult, "\n");
- ObservableList<String> items = FXCollections.observableArrayList();
- while (token.hasMoreTokens()) {
- String resultEmp = token.nextToken();
- items.add(resultEmp);
- }
- lvES_TestResult.setItems(items);
- // Enable the Apply button
- btnES_ApplyChanges.setDisable(false);
- }
- });
- //
- // EVENT LISTENER: On AddToFormula
- //
- btnES_AddToFormula.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- // Add a default formula into the Rules Editor
- String comparator = cbES_Compare.getSelectionModel().getSelectedItem();
- String formula = " [" + cbES_Filter.getSelectionModel().getSelectedItem() + " " + comparator + " '...'] ";
- String htmlText = htmlSF_Editor.getHtmlText();
- String text = htmlText.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", " ");
- text = text.replaceAll(" ", " ");
- text = text + formula;
- // Display the formula
- htmlSF_Editor.setHtmlText(convertStringToHTML(text));
- }
- });
- //
- // EVENT LISTENER: Filter on TextField
- //
- tfES_FilterEmployeeSelections.setOnKeyReleased(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent ke) {
- // Filter
- rebuildEmployeeSelectionLists();
- }
- });
- //
- // EVENT LISTENER: Change on Selection's name
- //
- tfES_ProcessName.setOnKeyReleased(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent ke) {
- // Enable the Apply button
- btnES_ApplyChanges.setDisable(false);
- }
- });
- //
- // EVENT LISTENER: Click on Clear button
- //
- btnES_ClearFilter.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- tfES_FilterEmployeeSelections.setText("");
- // Filter
- rebuildEmployeeSelectionLists();
- }
- });
- //
- // EVENT LISTENER: Click Employee Selection
- //
- lvES_ExistingEmployeeSelections.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<EmployeeSelection>() {
- @Override
- public void changed(ObservableValue<? extends EmployeeSelection> observable, EmployeeSelection oldValue, EmployeeSelection newValue) {
- if (newValue != null) {
- // This is where we build the reporting structure for the TreeView
- System.out.println("Selected EmployeeSelection item: " + newValue);
- // Enable the Delete button
- btnES_DeleteES.setDisable(false);
- // Enable the Copy button
- btnES_CopyES.setDisable(false);
- // Enable Test Formula Button
- btnES_TestFormula.setDisable(false);
- // Enable the AddToFormula button
- btnES_AddToFormula.setDisable(false);
- // Enable dropdown choicebox for Filter
- cbES_Filter.setDisable(false);
- // Enable dropdown choicebox for Compare
- cbES_Compare.setDisable(false);
- // Display the formula
- htmlSF_Editor.setHtmlText(convertStringToHTML(((EmployeeSelectionRule) newValue).getRule()));
- // Display the name
- tfES_ProcessName.setText(((EmployeeSelection) newValue).getName());
- }
- }
- });
- //
- // EVENT LISTENER: Delete Employee Selection
- //
- btnES_DeleteES.setOnAction(
- new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- // Did we select multiple items?
- EmployeeSelection selected = lvES_ExistingEmployeeSelections.getSelectionModel().getSelectedItem();
- deleteEmployeeSelectionFromCollection(lvES_ExistingEmployeeSelections.getSelectionModel().getSelectedItems());
- }
- }
- );
- //
- // EVENT LISTENER: Person pressed the DELETE button
- //
- lvES_ExistingEmployeeSelections.setOnKeyPressed(new EventHandler<KeyEvent>() {
- @Override
- public void handle(KeyEvent t) {
- if (t.getCode() == KeyCode.DELETE) {
- EmployeeSelection selected = lvES_ExistingEmployeeSelections.getSelectionModel().getSelectedItem();
- deleteEmployeeSelectionFromCollection(lvES_ExistingEmployeeSelections.getSelectionModel().getSelectedItems());
- t.consume();
- }
- }
- });
- //
- // EVENT LISTENER: Click on NEW (New Employee Selection)
- //
- btnES_NewES.setOnAction(
- new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent e) {
- String newName = Dialogs.showInputDialog(null, "Name:", "Create a new Employee Selection", "New Employee Selection");
- if (newName != null) {
- if (newName.trim().length() > 0) {
- // New employee Selection
- EmployeeSelection newSelection = new EmployeeSelectionRule(newName, newName);
- //
- // Validate new name
- //
- int nbEmployeeSelections = localEmployeeSelections.size();
- if (nbEmployeeSelections > 0) {
- int i = 1;
- showStatus("Testing Employee Selection: " + newSelection.toString(), i + 1, nbEmployeeSelections);
- //
- // Check that names differ
- //
- LinkedList<EmployeeSelection> localSelections = new LinkedList(localEmployeeSelections);
- for (EmployeeSelection selectionInList : localSelections) {
- // If hashCodes are the same rename the current reporting structure
- if (newSelection.hashCode() == selectionInList.hashCode()) {
- // Ask user to change name
- // Edit a Reporting Structure
- // Edit dialog
-