Search in sources :

Example 1 with PicoCustomer

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;
}
Also used : java.util(java.util) Initializable(javafx.fxml.Initializable) javafx.scene.control(javafx.scene.control) URL(java.net.URL) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) CustomerContinue(eu.ggnet.dwoss.customer.ui.neo.CustomerSimpleController.CustomerContinue) Ui(eu.ggnet.saft.Ui) PicoCustomer(eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer) Dl(eu.ggnet.saft.Dl) AlertType(eu.ggnet.saft.core.ui.AlertType) READY(javafx.concurrent.Worker.State.READY) CustomerAgent(eu.ggnet.dwoss.customer.ee.CustomerAgent) KeyCode(javafx.scene.input.KeyCode) HBox(javafx.scene.layout.HBox) Logger(org.slf4j.Logger) Css(eu.ggnet.dwoss.rules.Css) CustomerTaskService(eu.ggnet.dwoss.customer.ui.CustomerTaskService) eu.ggnet.saft.api.ui(eu.ggnet.saft.api.ui) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) MAX_VALUE(java.lang.Double.MAX_VALUE) SearchField(eu.ggnet.dwoss.customer.ee.entity.Customer.SearchField) FxSaft(eu.ggnet.saft.core.ui.FxSaft) Reply(eu.ggnet.saft.api.Reply) Customer(eu.ggnet.dwoss.customer.ee.entity.Customer) ObservableList(javafx.collections.ObservableList) StringProperty(javafx.beans.property.StringProperty) HtmlPane(eu.ggnet.dwoss.util.HtmlPane) PicoCustomer(eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer) Customer(eu.ggnet.dwoss.customer.ee.entity.Customer) ActionEvent(javafx.event.ActionEvent) Reply(eu.ggnet.saft.api.Reply) PicoCustomer(eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer) HtmlPane(eu.ggnet.dwoss.util.HtmlPane)

Example 2 with PicoCustomer

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);
}
Also used : CustomerTaskService(eu.ggnet.dwoss.customer.ui.CustomerTaskService) ActionEvent(javafx.event.ActionEvent) PicoCustomer(eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer)

Example 3 with PicoCustomer

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());
}
Also used : CustomerGenerator(eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGenerator) Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) java.util(java.util) Logger(org.slf4j.Logger) AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer) eu.ggnet.dwoss.customer.ee.entity(eu.ggnet.dwoss.customer.ee.entity) LoggerFactory(org.slf4j.LoggerFactory) AddressType(eu.ggnet.dwoss.rules.AddressType) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) PicoCustomer(eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer) SearchField(eu.ggnet.dwoss.customer.ee.entity.Customer.SearchField) Reply(eu.ggnet.saft.api.Reply) LockModeType(javax.persistence.LockModeType) CustomerAgent(eu.ggnet.dwoss.customer.ee.CustomerAgent) SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer) PicoCustomer(eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer)

Aggregations

PicoCustomer (eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer)3 CustomerAgent (eu.ggnet.dwoss.customer.ee.CustomerAgent)2 SearchField (eu.ggnet.dwoss.customer.ee.entity.Customer.SearchField)2 CustomerTaskService (eu.ggnet.dwoss.customer.ui.CustomerTaskService)2 Reply (eu.ggnet.saft.api.Reply)2 java.util (java.util)2 ActionEvent (javafx.event.ActionEvent)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 CustomerGenerator (eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGenerator)1 eu.ggnet.dwoss.customer.ee.entity (eu.ggnet.dwoss.customer.ee.entity)1 Type (eu.ggnet.dwoss.customer.ee.entity.Communication.Type)1 Customer (eu.ggnet.dwoss.customer.ee.entity.Customer)1 SimpleCustomer (eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer)1 AddressLabel (eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel)1 CustomerContinue (eu.ggnet.dwoss.customer.ui.neo.CustomerSimpleController.CustomerContinue)1 AddressType (eu.ggnet.dwoss.rules.AddressType)1 Css (eu.ggnet.dwoss.rules.Css)1 HtmlPane (eu.ggnet.dwoss.util.HtmlPane)1 Dl (eu.ggnet.saft.Dl)1