use of eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer in project dwoss by gg-net.
the class CustomerSearchController method buildContextMenu.
/**
* Build a ContextMenu for ListView of the search results for a better navigation
*
* @return ContextMenu the filled ContextMenu
*/
private ContextMenu buildContextMenu() {
// Create a ContextMenu
ContextMenu contextMenu = new ContextMenu();
MenuItem viewCustomer = new MenuItem("Detailansicht");
MenuItem viewCompleteCustomer = new MenuItem("Detailansicht inc. aller Mandatendetails");
MenuItem editCustomer = new MenuItem("Bearbeiten");
// adding actions to the context menu
viewCustomer.setOnAction((ActionEvent event) -> {
// open toHtml(String matchcode, DefaultCustomerSalesdata defaults)
if (resultListView.getSelectionModel().getSelectedItem() == null)
return;
PicoCustomer selectedCustomer = resultListView.getSelectionModel().getSelectedItem();
Ui.exec(() -> {
Ui.build(statusHbox).title("Kunde mit Mandant").fx().show(() -> Css.toHtml5WithStyle(AGENT.findCustomerAsMandatorHtml(selectedCustomer.getId())), () -> new HtmlPane());
});
});
viewCompleteCustomer.setOnAction((ActionEvent event) -> {
// open toHtml(String salesRow, String comment)
if (resultListView.getSelectionModel().getSelectedItem() == null)
return;
PicoCustomer selectedCustomer = resultListView.getSelectionModel().getSelectedItem();
Ui.exec(() -> {
Ui.build(statusHbox).title("Kunden Ansicht").fx().show(() -> Css.toHtml5WithStyle(AGENT.findCustomerAsHtml(selectedCustomer.getId())), () -> new HtmlPane());
});
});
editCustomer.setOnAction((ActionEvent event) -> {
if (resultListView.getSelectionModel().getSelectedItem() == null)
return;
PicoCustomer picoCustomer = resultListView.getSelectionModel().getSelectedItem();
Ui.exec(() -> {
Customer customer = Ui.progress().call(() -> AGENT.findByIdEager(Customer.class, picoCustomer.getId()));
if (!customer.isValid()) {
Ui.build(resultListView).title("Fehlerhafter Datensatz").alert().message("Kundendaten sind invalid (aktuell normal): " + customer.getViolationMessage()).show(AlertType.WARNING);
} else if (customer.isSimple()) {
L.info("Edit Simple Customer {}", customer.getId());
Optional<CustomerContinue> result = Ui.build(resultListView).fxml().eval(() -> customer, CustomerSimpleController.class).opt();
if (!result.isPresent())
return;
Reply<Customer> reply = Dl.remote().lookup(CustomerAgent.class).store(result.get().simpleCustomer);
if (!Ui.failure().handle(reply))
return;
if (!result.get().continueEnhance)
return;
Ui.build(statusHbox).fxml().eval(() -> reply.getPayload(), CustomerEnhanceController.class).opt().ifPresent(c -> Ui.build(statusHbox).alert("Would store + " + c));
} else if (customer.isBusiness()) {
L.info("Edit (Complex) Customer {}", customer.getId());
Ui.build(statusHbox).fxml().eval(() -> customer, CustomerEnhanceController.class).opt().ifPresent(c -> Ui.build(statusHbox).alert("Would store + " + c));
}
});
});
// add MenuItemes to ContextMenu
contextMenu.getItems().addAll(viewCustomer, viewCompleteCustomer, editCustomer);
return contextMenu;
}
use of eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer in project dwoss by gg-net.
the class CustomerSearchController method initialize.
@Override
public void initialize(URL url, ResourceBundle rb) {
resultListView.setCellFactory(listView -> {
return new ListCell<PicoCustomer>() {
@Override
protected void updateItem(PicoCustomer item, boolean empty) {
super.updateItem(item, empty);
// Platform.runLater(() -> { // WTF i need this, i don't know, but otherwise
if (item == null || empty) {
setText("");
} else {
setText(item.getShortDescription());
}
// });
}
};
});
// bind the checkboxes to the Set of SearchField
bindCheckBoxes();
// add contextmenu to listview
resultListView.setContextMenu(buildContextMenu());
CUSTOMER_TASK_SERVICE = new CustomerTaskService();
observableCustomers = CUSTOMER_TASK_SERVICE.getPartialResults();
resultListView.setItems(observableCustomers);
searchButton.setOnAction((ActionEvent event) -> search());
searchField.setOnKeyPressed((ke) -> {
if (ke.getCode() == KeyCode.ENTER) {
search();
}
});
SEARCH_PROPERTY.bind(searchField.textProperty());
// Needed, so the bar will fill the space, otherwise it keeps beeing small
progressBar.setMaxWidth(MAX_VALUE);
progressBar.setMaxHeight(MAX_VALUE);
// hidde the HBox
progressBar.visibleProperty().bind(CUSTOMER_TASK_SERVICE.runningProperty());
progressIndicator.visibleProperty().bind(CUSTOMER_TASK_SERVICE.runningProperty());
statusHbox.visibleProperty().bind(CUSTOMER_TASK_SERVICE.runningProperty());
progressIndicator.setProgress(0);
progressBar.setProgress(0);
progressBar.progressProperty().bind(CUSTOMER_TASK_SERVICE.progressProperty());
progressIndicator.progressProperty().bind(CUSTOMER_TASK_SERVICE.progressProperty());
Ui.progress().observe(CUSTOMER_TASK_SERVICE);
}
use of eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer in project dwoss by gg-net.
the class CustomerAgentStub method search.
/**
* this methoes drops NPE like hell because many fields of the genaratet customer get checkt
*
* @param search
* @param customerFields
* @param start
* @param limit
* @return
*/
@Override
public List<PicoCustomer> search(String search, Set<SearchField> customerFields, int start, int limit) {
L.info("SearchString {},{},start={},limit={}", search, customerFields.size(), start, limit);
try {
Thread.sleep(200L, SLOW);
} catch (InterruptedException ex) {
L.error("InterruptedException get throw");
}
if (start >= CUSTOMERS.size())
return Collections.emptyList();
if (limit >= CUSTOMERS.size())
limit = CUSTOMERS.size();
List<Customer> result = CUSTOMERS.subList(start, limit + start);
List<Customer> tempList = new ArrayList<>();
if (customerFields.contains(SearchField.LASTNAME)) {
result.forEach(c -> {
c.getContacts().stream().filter((contact) -> (contact.getLastName().contains(search))).forEachOrdered((sa) -> {
tempList.add(c);
});
});
result.addAll(tempList);
}
if (customerFields.contains(SearchField.FIRSTNAME)) {
result.forEach((customer) -> {
customer.getContacts().stream().filter((cont) -> (cont.getFirstName().contains(search))).forEachOrdered((_item) -> {
tempList.add(customer);
});
});
}
if (customerFields.contains(SearchField.ID)) {
if (search.matches("\\d*")) {
result.stream().filter((customer) -> (customer.getId() == Long.parseLong(search))).forEachOrdered((customer) -> {
tempList.add(customer);
});
result.addAll(tempList);
}
}
if (customerFields.contains(SearchField.COMPANY)) {
result.forEach((customer) -> {
customer.getCompanies().stream().filter((com) -> (com.getName().contains(search))).forEachOrdered((_item) -> {
tempList.add(customer);
});
});
result.addAll(tempList);
}
if (customerFields.contains(SearchField.ADDRESS)) {
for (Customer customer : result) {
customer.getContacts().forEach((contact) -> {
contact.getAddresses().stream().map((addr) -> {
if (addr.getStreet().contains(search)) {
tempList.add(customer);
}
return addr;
}).map((addr) -> {
if (addr.getCity().contains(search)) {
tempList.add(customer);
}
return addr;
}).filter((addr) -> (addr.getZipCode().contains(search))).forEachOrdered((_item) -> {
tempList.add(customer);
});
});
result.addAll(tempList);
}
}
L.info("Returning {}", result);
return result.stream().map(Customer::toPico).collect(Collectors.toList());
}
Aggregations