tableName.setRowFactory(
new Callback<TableView<CounselorDetailsBEAN>, TableRow<CounselorDetailsBEAN>>() {
@Override
public TableRow<CounselorDetailsBEAN> call(TableView<CounselorDetailsBEAN> param
) {
final ContextMenu contextMenu = new ContextMenu();
final MenuItem itemOpenEnquiry = new MenuItem("Open Assesment Form");
final MenuItem itemOpenRegistration = new MenuItem("Open Registration Form");
final MenuItem itemForwardEnquiry = new MenuItem("Forward Enquiries");
final MenuItem itemLockEnquiry = new MenuItem("Lock Enquiry");
final TableRow<CounselorDetailsBEAN> row = new TableRow<CounselorDetailsBEAN>() {
@Override
protected void updateItem(CounselorDetailsBEAN detailsBEAN, boolean empty) {
super.updateItem(detailsBEAN, empty);
if (!empty) {
if (detailsBEAN.getReadflag() != null) {
setTooltip(new Tooltip("Double click a cell to edit \n Press 'Enter key' to finish editing"));
if (detailsBEAN.getReadflag().equals("0")) {
getStyleClass().remove("highlightOldEnquiryRow");
getStyleClass().add("highlighNewEnquiryRow");
} else {
getStyleClass().remove("highlighNewEnquiryRow");
getStyleClass().add("highlightOldEnquiryRow");
}
} else {
getStyleClass().remove("highlightOldEnquiryRow");
getStyleClass().add("highlighNewEnquiryRow");
}
} else {
getStyleClass().remove("highlighNewEnquiryRow");
getStyleClass().add("highlightOldEnquiryRow");
setText(null);
setGraphic(null);
}
}
};
itemOpenEnquiry.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
/* ======================== set which assessment category ==================== */
switch (tabName) {
case "study":
Context.getInstance().currentProfile().setCurrentTab("study");
break;
case "work":
Context.getInstance().currentProfile().setCurrentTab("work");
break;
case "migration":
Context.getInstance().currentProfile().setCurrentTab("migration");
break;
case "training":
Context.getInstance().currentProfile().setCurrentTab("training");
break;
default:
System.out.println("Something went wrong !");
}
/* ======================== End set which assessment category ==================== */
Context.getInstance().currentProfile().setCounselorDetailsBEAN(row.getItem());
StackPane secondaryLayout = new StackPane();
Pane myPane = null;
FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/zs/ina/assesment/FXMLAssesmentForm.fxml"));
Parent root = (Parent) loader.load();
secondaryLayout.getChildren().add(root);
Scene secondScene = new Scene(secondaryLayout);
Stage secondStage = new Stage();
secondStage.setTitle("Assessment form of " + row.getItem().getContactName());
secondStage.getIcons().add(new Image(INALoginForm.class.getResourceAsStream("images/ia_logo.png")));
secondStage.setScene(secondScene);
secondStage.getIcons().add(new Image(INALoginForm.class.getResourceAsStream("images/ia_logo.png")));
secondStage.setOnHidden(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
DBPool.getInstance().CloseConnections();
resetAll();
}
});
// stageAppointment.initStyle(StageStyle.UNDECORATED);
secondStage.setMaximized(true);
secondStage.initModality(Modality.APPLICATION_MODAL);
secondStage.initOwner(btnSearchSubmit.getScene().getWindow());
secondStage.show();
} catch (IOException ex) {
ex.printStackTrace();
logger.error(ex.toString());
}
}
});
/* ======================== Open Registration Form ==================== */
itemOpenRegistration.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
try {
/* ======================== set which assessment category ==================== */
switch (tabName) {
case "study":
Context.getInstance().currentProfile().setCurrentTab("study");
break;
case "work":
Context.getInstance().currentProfile().setCurrentTab("work");
break;
case "migration":
Context.getInstance().currentProfile().setCurrentTab("migration");
break;
case "training":
Context.getInstance().currentProfile().setCurrentTab("training");
break;
default:
System.out.println("Something went wrong !");
}
/* ======================== End set which assessment category ==================== */
Context.getInstance().currentProfile().setCounselorDetailsBEAN(row.getItem());
StackPane secondaryLayout = new StackPane();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/zs/ina/registration/FXMLRegistrationForm.fxml"));
Parent root = (Parent) loader.load();
secondaryLayout.getChildren().add(root);
Scene secondScene = new Scene(secondaryLayout);
Stage secondStage = new Stage();
secondStage.setTitle("Registration form of " + row.getItem().getContactName());
secondStage.getIcons().add(new Image(INALoginForm.class.getResourceAsStream("images/ia_logo.png")));
secondStage.setScene(secondScene);
secondStage.getIcons().add(new Image(INALoginForm.class.getResourceAsStream("images/ia_logo.png")));
secondStage.setOnHidden(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
DBPool.getInstance().CloseConnections();
resetAll();
}
});
// stageAppointment.initStyle(StageStyle.UNDECORATED);
secondStage.setMaximized(true);
secondStage.initModality(Modality.APPLICATION_MODAL);
secondStage.initOwner(btnSearchSubmit.getScene().getWindow());
secondStage.show();
} catch (IOException ex) {
ex.printStackTrace();
logger.error(ex.toString());
}
}
});
/* ======================== Forward Enquiry ==================== */
itemForwardEnquiry.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Pane myPane = new Pane();
FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/zs/ina/admin/inbox/forward/FXMLForward.fxml"));
try {
Parent root = (Parent) loader.load();
// System.out.println(loader.getController());
FXMLForwardController controller = (FXMLForwardController) loader.getController();
if (listCheckedEnquiries.size() > 0) {
controller.forwardMultipleEnquiries(listCheckedEnquiries, popForward, tableName, CUR_ROLE);
} else {
controller.initData(row.getItem(), popForward);
}
myPane.getChildren().add(root);
popForward.setContentNode(myPane);
popForward.setArrowLocation(PopOver.ArrowLocation.RIGHT_TOP);
popForward.setAnchorLocation(PopupWindow.AnchorLocation.WINDOW_TOP_LEFT);
popForward.setArrowSize(12.0);
popForward.setHideOnEscape(true);
popForward.setAutoFix(true);
popForward.setAutoHide(true);
popForward.setTitle("Forward Enquiry Of " + row.getItem().getContactName());
// popForward.setOnAutoHide(new EventHandler<Event>() {
//
// @Override
// public void handle(Event event) {
// tableName.getColumns().get(0).setVisible(false);
// tableName.getColumns().get(0).setVisible(true);
// refreshPriorityCell(clmTabPriority);
//// Event.fireEvent(lblMonth, new MouseEvent(MouseEvent.MOUSE_CLICKED, 0,
//// 0, 0, 0, MouseButton.PRIMARY, 1, true, true, true, true,
//// true, true, true, true, true, true, null));
// }
// });
popForward.setOnHidden(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
reloadTableWithProgress(Context.getInstance().currentProfile().getInboxCountsBEAN());
int c = 0;
for (TableColumn column : tableName.getColumns()) {
c++;
if (c == 2) {
refreshPriorityCell(column);
}
if (c == 3) {
refreshFlagyCell(column);
}
}
if (serviceHyperLinkCounts != null) {
if (!serviceHyperLinkCounts.isRunning()) {
serviceHyperLinkCounts.reset();
serviceHyperLinkCounts.restart();
}
} else {
serviceHyperLinkCounts.start();
}
/* ======================== Refresh All Data To Common Pool ==================== */
/* ======================== Fires MousEvent Of lblToday ==================== */
// Event.fireEvent(hyperCommonPool, new MouseEvent(MouseEvent.MOUSE_CLICKED, 0,
// 0, 0, 0, MouseButton.PRIMARY, 1, true, true, true, true,
// true, true, true, true, true, true, null));
listCheckedEnquiries.clear();
}
});
} catch (IOException exception) {
exception.printStackTrace();
logger.error(exception.toString());
}
if (popForward.isShowing()) {
popForward.hide();
popForward.show(row, row.localToScreen(0, 0).getX() - 6, row.localToScreen(0, 0).getY() + 30, Duration.millis(100));
} else {
popForward.show(row, row.localToScreen(0, 0).getX() - 6, row.localToScreen(0, 0).getY() + 30, Duration.millis(500));
}
}
});
/* ======================== Add To Commom Pool ==================== */
itemLockEnquiry.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Map<String, String> mapCommonPoolConfig = CommonPoolService.retrieveCommonPoolConfig(CUR_USERNAME, CUR_BRANCH, CUR_ROLE);
Map<String, String> mapFlagEnquiryStatus = CommonPoolService.checkFlagEnquiryStatus(CUR_USERNAME, CUR_BRANCH, CUR_ROLE);
long flagLimitConfig = Long.parseLong(mapCommonPoolConfig.get("flag_limit"));
long flagLimitStatus = Long.parseLong(mapFlagEnquiryStatus.get("flag_limit"));
long enquiryLimitConfig = Long.parseLong(mapCommonPoolConfig.get("enquiry_limit"));
long enquiryLimitStatus = Long.parseLong(mapFlagEnquiryStatus.get("enquiry_limit"));
// if (flagLimitConfig == 0 || flagLimitConfig < enquiryLimitConfig) {
// System.out.println("User can flag");
// }
if (enquiryLimitConfig == 0 || enquiryLimitStatus < enquiryLimitConfig) {
if (CommonPoolService.verifyEnquiryLocking(CUR_USERNAME, CUR_BRANCH, row.getItem().getEnquiryID())) {
int done = CommonPoolService.lockEnquiry(CUR_USERNAME, CUR_BRANCH, CUR_ROLE, row.getItem());
if (done > 0) {
/* ======================== Add History Row For Self Assign ==================== */
ForwardHistoryPOJO historyPOJO = new ForwardHistoryPOJO();
historyPOJO.setHid("his_" + UiiDGenerator.getUIID8());
historyPOJO.setAssigned_branch(CUR_BRANCH);
historyPOJO.setAssigned_by("Self Assigned");
historyPOJO.setAssigned_date(new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()).toString());
historyPOJO.setEnquiry_id(row.getItem().getEnquiryID());
historyPOJO.setAssigned_to(CUR_USERNAME);
// row.getItem().setEnquiryAssignedTo(CUR_USERNAME);
historyPOJO.setAssigned_to_branch(CUR_BRANCH);
historyPOJO.setHolded_by(row.getItem().getEnquiryAssignedTo());
historyPOJO.setPurpose(row.getItem().getReference());
historyPOJO.setRemarks(row.getItem().getRemarks());
if (row.getItem().getStatus() != null) {
historyPOJO.setCurrent_status(row.getItem().getStatus());
} else {
historyPOJO.setCurrent_status("Assessment Pending");
}
historyPOJO.setCompletionFlag(row.getItem().getCompletionflag());
historyPOJO.setStudy_required(row.getItem().getStudyRequired());
historyPOJO.setWork_required(row.getItem().getWorkRequired());
historyPOJO.setMigration_required(row.getItem().getMigrationRequired());
historyPOJO.setTraining_required(row.getItem().getTrainingRequired());
forwardHistoryDAO.forwardEnquiry(historyPOJO);
}
int index = row.indexProperty().get();
row.getStyleClass().remove("highlighNewEnquiryRow");
row.getStyleClass().add("highlightOldEnquiryRow");
row.setGraphic(new Label("This enquiry has been moved to your inbox"));
EffectsClass.blinkingAndFading(row);
PauseTransition delay = new PauseTransition(Duration.seconds(3.5));
delay.setOnFinished((ActionEvent event1) -> {
/* ======================== Refresh Table ==================== */
tableName.getItems().remove(index);
int c = 0;
for (TableColumn column : tableName.getColumns()) {
c++;
if (c == 2) {
refreshPriorityCell(column);
}
if (c == 3) {
// refreshFlagyCell(column);
}
}
});
delay.play();
if (serviceHyperLinkCounts != null) {
if (!serviceHyperLinkCounts.isRunning()) {
serviceHyperLinkCounts.reset();
serviceHyperLinkCounts.restart();
}
} else {
serviceHyperLinkCounts.start();
}
} else {
/* ======================== Remove Already Locked Enquiry ==================== */
int index = row.indexProperty().get();
tableName.getItems().remove(index);
int c = 0;
for (TableColumn column : tableName.getColumns()) {
c++;
if (c == 2) {
refreshPriorityCell(column);
}
if (c == 3) {
// refreshFlagyCell(column);
}
}
Notification notification = Notifications.WARNING;
TrayNotification tray = new TrayNotification("Already locked !", "This enquiry locked! Please refresh to see latest enquiries !", notification);
tray.setAnimation(Animations.POPUP);
tray.showAndDismiss(Duration.seconds(3), btnSearchSubmit);
tray.setOnDismiss(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
int c = 0;
for (TableColumn column : tableName.getColumns()) {
c++;
if (c == 2) {
refreshPriorityCell(column);
}
if (c == 3) {
// refreshFlagyCell(column);
}
}
}
});
}/* ======================== End verify locking ==================== */
} else {
showPopupMessages.showWarning("Your pending enquiry limit reached !", "Please complete all pending enquiries !", row);
}
/* ======================== Refresh All Columns ==================== */
// int c = 0;
// for (TableColumn column : tableName.getColumns()) {
// c++;
// if (c == 2) {
// refreshPriorityCell(column);
// }
// if (c == 3) {
// refreshFlagyCell(column);
// }
// }
}
});
if (IS_COMMON_POOL) {
contextMenu.getItems().addAll(itemLockEnquiry);
row.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (event.getButton().equals(MouseButton.PRIMARY)) {
if (event.getClickCount() == 2) {
Map<String, String> mapCommonPoolConfig = CommonPoolService.retrieveCommonPoolConfig(CUR_USERNAME, CUR_BRANCH, CUR_ROLE);
Map<String, String> mapFlagEnquiryStatus = CommonPoolService.checkFlagEnquiryStatus(CUR_USERNAME, CUR_BRANCH, CUR_ROLE);
long flagLimitConfig = Long.parseLong(mapCommonPoolConfig.get("flag_limit"));
long flagLimitStatus = Long.parseLong(mapFlagEnquiryStatus.get("flag_limit"));
long enquiryLimitConfig = Long.parseLong(mapCommonPoolConfig.get("enquiry_limit"));
long enquiryLimitStatus = Long.parseLong(mapFlagEnquiryStatus.get("enquiry_limit"));
// if (flagLimitConfig == 0 || flagLimitConfig < enquiryLimitConfig) {
// System.out.println("User can flag");
// }
if (enquiryLimitConfig == 0 || enquiryLimitStatus < enquiryLimitConfig) {
if (CommonPoolService.verifyEnquiryLocking(CUR_USERNAME, CUR_BRANCH, row.getItem().getEnquiryID())) {
int done = CommonPoolService.lockEnquiry(CUR_USERNAME, CUR_BRANCH, CUR_ROLE, row.getItem());
if (done > 0) {
/* ======================== Add History Row For Self Assign ==================== */
ForwardHistoryPOJO historyPOJO = new ForwardHistoryPOJO();
historyPOJO.setHid("his_" + UiiDGenerator.getUIID8());
historyPOJO.setAssigned_branch(CUR_BRANCH);
historyPOJO.setAssigned_by("Self Assigned");
historyPOJO.setAssigned_date(new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()).toString());
historyPOJO.setEnquiry_id(row.getItem().getEnquiryID());
historyPOJO.setAssigned_to(CUR_USERNAME);
// row.getItem().setEnquiryAssignedTo(CUR_USERNAME);
historyPOJO.setAssigned_to_branch(CUR_BRANCH);
historyPOJO.setHolded_by(row.getItem().getEnquiryAssignedTo());
historyPOJO.setPurpose(row.getItem().getReference());
historyPOJO.setRemarks(row.getItem().getRemarks());
if (row.getItem().getStatus() != null) {
historyPOJO.setCurrent_status(row.getItem().getStatus());
} else {
historyPOJO.setCurrent_status("Assessment Pending");
}
historyPOJO.setCompletionFlag(row.getItem().getCompletionflag());
historyPOJO.setStudy_required(row.getItem().getStudyRequired());
historyPOJO.setWork_required(row.getItem().getWorkRequired());
historyPOJO.setMigration_required(row.getItem().getMigrationRequired());
historyPOJO.setTraining_required(row.getItem().getTrainingRequired());
forwardHistoryDAO.forwardEnquiry(historyPOJO);
}
int index = row.indexProperty().get();
row.getStyleClass().remove("highlighNewEnquiryRow");
row.getStyleClass().add("highlightOldEnquiryRow");
row.setGraphic(new Label("This enquiry has been moved to your inbox"));
EffectsClass.blinkingAndFading(row);
PauseTransition delay = new PauseTransition(Duration.seconds(3.5));
delay.setOnFinished((ActionEvent event1) -> {
/* ======================== Refresh Table ==================== */
try {
tableName.getItems().remove(index);
} catch (IndexOutOfBoundsException e) {
System.out.println("Exception Occured While removing row !!!!!!!!!!!!!!!");
}
int c = 0;
for (TableColumn column : tableName.getColumns()) {
c++;
if (c == 2) {
refreshPriorityCell(column);
}
if (c == 3) {
// refreshFlagyCell(column);
}
}
});
delay.play();
if (serviceHyperLinkCounts != null) {
if (!serviceHyperLinkCounts.isRunning()) {
serviceHyperLinkCounts.reset();
serviceHyperLinkCounts.restart();
}
} else {
serviceHyperLinkCounts.start();
}
} else {
/* ======================== Remove Already Locked Enquiry ==================== */
int index = row.indexProperty().get();
tableName.getItems().remove(index);
int c = 0;
for (TableColumn column : tableName.getColumns()) {
c++;
if (c == 2) {
refreshPriorityCell(column);
}
if (c == 3) {
// refreshFlagyCell(column);
}
}
Notification notification = Notifications.WARNING;
TrayNotification tray = new TrayNotification("Already locked !", "This enquiry locked! Please refresh to see latest enquiries !", notification);
tray.setAnimation(Animations.POPUP);
tray.showAndDismiss(Duration.seconds(3), btnSearchSubmit);
tray.setOnDismiss(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
int c = 0;
for (TableColumn column : tableName.getColumns()) {
c++;
if (c == 2) {
refreshPriorityCell(column);
}
if (c == 3) {
// refreshFlagyCell(column);
}
}
}
});
}/* ======================== End verify locking ==================== */
} else {
showPopupMessages.showWarning("Your pending enquiry limit reached !", "Please complete all pending enquiries !", row);
}
/* ======================== Refresh All Columns ==================== */
// int c = 0;
// for (TableColumn column : tableName.getColumns()) {
// c++;
// if (c == 2) {
// refreshPriorityCell(column);
// }
// if (c == 3) {
// refreshFlagyCell(column);
// }
// }
}
}
}
});
} else {
contextMenu.getItems().addAll(itemOpenEnquiry, itemForwardEnquiry, itemOpenRegistration);
}
row.contextMenuProperty().bind(
Bindings.when(row.emptyProperty())
.then((ContextMenu) null)
.otherwise(contextMenu));
return row;
}
}
);