Search in sources :

Example 6 with ListCell

use of javafx.scene.control.ListCell in project SmartCity-Market by TechnionYP5777.

the class CustomerMainScreen method initialize.

@Override
public void initialize(URL location, ResourceBundle __) {
    AbstractApplicationScreen.fadeTransition(customerMainScreenPane);
    barcodeEventHandler.register(this);
    customer = TempCustomerPassingData.customer;
    filteredProductList = new FilteredList<>(productsObservableList, s -> true);
    searchField.textProperty().addListener(obs -> {
        String filter = searchField.getText();
        filteredProductList.setPredicate((filter == null || filter.length() == 0) ? s -> true : s -> s.getCatalogProduct().getName().contains(filter));
    });
    productsListView.setItems(filteredProductList);
    productsListView.setCellFactory(new Callback<ListView<CartProduct>, ListCell<CartProduct>>() {

        @Override
        public ListCell<CartProduct> call(ListView<CartProduct> __) {
            return new CustomerProductCellFormat();
        }
    });
    productsListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<CartProduct>() {

        @Override
        public void changed(ObservableValue<? extends CartProduct> __, CartProduct oldValue, CartProduct newValue) {
            updateProductInfoPaine(newValue.getCatalogProduct(), newValue.getTotalAmount(), ProductInfoPaneVisibleMode.PRESSED_PRODUCT);
        }
    });
    productsListView.depthProperty().set(1);
    productsListView.setExpanded(true);
    setAbilityAndVisibilityOfProductInfoPane(false);
}
Also used : Button(javafx.scene.control.Button) TempCustomerPassingData(CustomerGuiHelpers.TempCustomerPassingData) Initializable(javafx.fxml.Initializable) ListView(javafx.scene.control.ListView) URL(java.net.URL) ListCell(javafx.scene.control.ListCell) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) IConfiramtionDialog(UtilsContracts.IConfiramtionDialog) ICustomer(CustomerContracts.ICustomer) Logger(org.apache.log4j.Logger) CatalogProduct(BasicCommonClasses.CatalogProduct) ResourceBundle(java.util.ResourceBundle) BarcodeEventHandler(UtilsImplementations.BarcodeEventHandler) Subscribe(com.google.common.eventbus.Subscribe) Callback(javafx.util.Callback) CustomerProductCellFormat(CustomerGuiHelpers.CustomerProductCellFormat) GridPane(javafx.scene.layout.GridPane) CartProduct(BasicCommonClasses.CartProduct) Label(javafx.scene.control.Label) MalformedURLException(java.net.MalformedURLException) SmartCode(BasicCommonClasses.SmartCode) StackTraceUtil(UtilsImplementations.StackTraceUtil) JFXListView(com.jfoenix.controls.JFXListView) FilteredList(javafx.collections.transformation.FilteredList) SMException(SMExceptions.SMException) DialogMessagesService(GuiUtils.DialogMessagesService) File(java.io.File) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) InjectionFactory(UtilsImplementations.InjectionFactory) ActionEvent(javafx.event.ActionEvent) IBarcodeEventHandler(UtilsContracts.IBarcodeEventHandler) Stage(javafx.stage.Stage) ImageView(javafx.scene.image.ImageView) LocalDate(java.time.LocalDate) SmartcodeScanEvent(UtilsContracts.SmartcodeScanEvent) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) AbstractApplicationScreen(GuiUtils.AbstractApplicationScreen) ChangeListener(javafx.beans.value.ChangeListener) Image(javafx.scene.image.Image) JFXTextField(com.jfoenix.controls.JFXTextField) ListView(javafx.scene.control.ListView) JFXListView(com.jfoenix.controls.JFXListView) ListCell(javafx.scene.control.ListCell) CartProduct(BasicCommonClasses.CartProduct) CustomerProductCellFormat(CustomerGuiHelpers.CustomerProductCellFormat)

Example 7 with ListCell

use of javafx.scene.control.ListCell in project Gargoyle by callakrsos.

the class ArticleExtractorComposite method initialize.

@FXML
public void initialize() {
    cbAlgorisms.getItems().addAll(ValueUtil.HTML.getAvaliablesExtractorBase());
    cbAlgorisms.getSelectionModel().select(ArticleExtractor.class);
    cbAlgorisms.setCellFactory(new Callback<ListView<Class<? extends ExtractorBase>>, ListCell<Class<? extends ExtractorBase>>>() {

        @Override
        public ListCell<Class<? extends ExtractorBase>> call(ListView<Class<? extends ExtractorBase>> param) {
            return new TextFieldListCell<>(new StringConverter<Class<? extends ExtractorBase>>() {

                @Override
                public String toString(Class<? extends ExtractorBase> object) {
                    return object.getSimpleName();
                }

                @Override
                public Class<? extends ExtractorBase> fromString(String string) {
                    // TODO Auto-generated method stub
                    return null;
                }
            });
        }
    });
    cbAlgorisms.setConverter(new StringConverter<Class<? extends ExtractorBase>>() {

        @Override
        public String toString(Class<? extends ExtractorBase> object) {
            return object.getSimpleName();
        }

        @Override
        public Class<? extends ExtractorBase> fromString(String string) {
            // TODO Auto-generated method stub
            return null;
        }
    });
    cbAlgorisms.valueProperty().addListener((oba, o, n) -> {
        Class<? extends ExtractorBase> algorism = n;
        // webPreview.getEngine().getDocument().getBaseURI();
        String baseURI = txtUrl.getText();
        if (ValueUtil.isEmpty(baseURI))
            return;
        RealtimeSearchItemVO vo = new RealtimeSearchItemVO();
        vo.setLink(baseURI);
        try {
            URLModel htmlContent = getHTMLContent(vo);
            if (!htmlContent.isEmpty()) {
                String boilderPipe = boilderPipe(algorism, htmlContent.getContent());
                txtResult.setText(boilderPipe);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    cbSmmy.valueProperty().addListener((oba, o, n) -> {
        txtSummary.setText(n.getUrl());
        txtSummary.nextWord();
        txtSummary.appendText(n.getContent());
    });
    StringConverter<URLModel> converter = new StringConverter<URLModel>() {

        @Override
        public String toString(URLModel object) {
            return String.format("[%s] - %s", object.getTitle(), object.getUrl());
        }

        @Override
        public URLModel fromString(String string) {
            return null;
        }
    };
    cbSmmy.setCellFactory(param -> {
        TextFieldListCell<URLModel> textFieldListCell = new TextFieldListCell<>(converter);
        textFieldListCell.setMaxWidth(600d);
        textFieldListCell.setPrefWidth(600d);
        return textFieldListCell;
    });
    /** Size the combo-box drop down list. */
    cbSmmy.setConverter(converter);
    Platform.runLater(() -> {
        request(userData);
    // Platform.runLater(() -> {
    // WebEngine engine = webPreview.getEngine();
    // engine.getLoadWorker().stateProperty().addListener((ChangeListener<State>)
    // (ov, oldState, newState) -> {
    // LOGGER.debug("{} - {}", newState.name(), engine.getLocation());
    //
    // if (newState == Worker.State.RUNNING) {
    // String location = engine.getLocation();
    // if (ValueUtil.isNotEmpty(location)) {
    //
    // Class<? extends ExtractorBase> algorism = cbAlgorisms.getValue();
    // RealtimeSearchItemVO vo = new RealtimeSearchItemVO();
    // vo.setLink(location);
    // try {
    // updateMainContent(algorism, getHTMLContent(vo));
    // } catch (Exception e) {
    // e.printStackTrace();
    // }
    // }
    //
    // }
    // });
    // txtUrl.textProperty().addListener((oba, o, n) -> {
    //
    // if (ValueUtil.isNotEmpty(n)) {
    // RealtimeSearchItemVO realtimeSearchItemVO = new
    // RealtimeSearchItemVO();
    // realtimeSearchItemVO.setLink(n);
    // request(userData);
    // }
    //
    // });
    });
// engine.load(url);
// engine.getLoadWorker().messageProperty().addListener((oba, o, n) -> {
// LOGGER.debug("Browser Message : {}", n);
// });
// engine.setJavaScriptEnabled(true);
// HTML 코드를 engine에서 얻기위한 처리가 필요함.
// org.w3c.dom.Document doc = engine.getDocument();
// try {
// Transformer transformer =
// TransformerFactory.newInstance().newTransformer();
// transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
// transformer.setOutputProperty(OutputKeys.METHOD, "xml");
// transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
// transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount",
// "4");
//
// try (ByteArrayOutputStream outputStream = new
// ByteArrayOutputStream()) {
//
// try (OutputStreamWriter writer = new OutputStreamWriter(outputStream,
// "UTF-8")) {
// transformer.transform(new DOMSource(doc), new StreamResult(writer));
// Class<? extends ExtractorBase> algorism = cbAlgorisms.getValue();
// String boilderPipe = boilderPipe(algorism,
// outputStream.toString("UTF-8"));
// txtResult.setText(boilderPipe);
// }
// }
//
// } catch (Exception ex) {
// txtResult.setText(
// String.format("[%s] Something Problems Occured. \n\nStackTrace : {}",
// newState.name(), ValueUtil.toString(ex)));
// }
// } else {
// txtResult.setText("Waitings.... " + newState.name());
// }
// });
}
Also used : TextFieldListCell(javafx.scene.control.cell.TextFieldListCell) ExtractorBase(com.kohlschutter.boilerpipe.extractors.ExtractorBase) ListCell(javafx.scene.control.ListCell) TextFieldListCell(javafx.scene.control.cell.TextFieldListCell) RealtimeSearchItemVO(com.kyj.fx.voeditor.visual.framework.RealtimeSearchItemVO) StringConverter(javafx.util.StringConverter) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ListView(javafx.scene.control.ListView) URLModel(com.kyj.fx.voeditor.visual.framework.URLModel) FXML(javafx.fxml.FXML)

Example 8 with ListCell

use of javafx.scene.control.ListCell in project Gargoyle by callakrsos.

the class FxSVNHistoryDataSupplier method createHistoryListView.

public ListView<GargoyleSVNLogEntryPath> createHistoryListView(ObservableList<GargoyleSVNLogEntryPath> list) {
    ListView<GargoyleSVNLogEntryPath> listView = new ListView<GargoyleSVNLogEntryPath>(list);
    listView.setCellFactory(new Callback<ListView<GargoyleSVNLogEntryPath>, ListCell<GargoyleSVNLogEntryPath>>() {

        @Override
        public ListCell<GargoyleSVNLogEntryPath> call(ListView<GargoyleSVNLogEntryPath> param) {
            ListCell<GargoyleSVNLogEntryPath> listCell = new ListCell<GargoyleSVNLogEntryPath>() {

                /* (non-Javadoc)
					 * @see javafx.scene.control.Cell#updateItem(java.lang.Object, boolean)
					 */
                @Override
                protected void updateItem(GargoyleSVNLogEntryPath item, boolean empty) {
                    super.updateItem(item, empty);
                    if (empty) {
                        setText(null);
                    } else {
                        String type = "Modify";
                        switch(item.getType()) {
                            case GargoyleSVNLogEntryPath.TYPE_ADDED:
                                type = "Add";
                                break;
                            case GargoyleSVNLogEntryPath.TYPE_MODIFIED:
                                type = "Modify";
                                break;
                            case GargoyleSVNLogEntryPath.TYPE_REPLACED:
                                type = "Replace";
                                break;
                            case GargoyleSVNLogEntryPath.TYPE_DELETED:
                                type = "Delete";
                                break;
                        }
                        String path = item.getPath();
                        setText(String.format("Resivion :%d File : %s Date : %s Type : %s ", item.getCopyRevision(), path.substring(path.lastIndexOf("/")), YYYY_MM_DD_HH_MM_SS_PATTERN.format(item.getDate()), type));
                    }
                }
            };
            return listCell;
        }
    });
    listView.setPrefSize(600, ListView.USE_COMPUTED_SIZE);
    listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    listView.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
        ContextMenu contextMenu = null;
        ObservableList<GargoyleSVNLogEntryPath> selectedItems = listView.getSelectionModel().getSelectedItems();
        GargoyleSVNLogEntryPath selectedItem = null;
        if (selectedItems != null && !selectedItems.isEmpty()) {
            selectedItem = selectedItems.get(0);
        }
        if (ev.getClickCount() == 2 && ev.getButton() == MouseButton.PRIMARY) {
            if (selectedItem != null) {
                String path = selectedItem.getPath();
                long copyRevision = selectedItem.getCopyRevision();
                String rootUrl = getRootUrl();
                LOGGER.debug("{}", rootUrl);
                LOGGER.debug("Cat Command, Path : {} Revision {}", path, copyRevision);
                String content = "";
                VBox vBox = new VBox(5);
                if (isExists(path)) {
                    content = cat(path, String.valueOf(copyRevision));
                    List<SVNLogEntry> log = log(path, String.valueOf(copyRevision), ex -> {
                        LOGGER.error(ValueUtil.toString(ex));
                    });
                    if (ValueUtil.isNotEmpty(log)) {
                        SVNLogEntry svnLogEntry = log.get(0);
                        String apply = getManager().fromPrettySVNLogConverter().apply(svnLogEntry);
                        Label e = new Label(apply);
                        e.setStyle("-fx-text-fill:black");
                        vBox.getChildren().add(e);
                    }
                    vBox.getChildren().add(createJavaTextArea(content));
                } else {
                    content = "Does not exists. Repository. [Removed]";
                    Label e = new Label(content);
                    e.setStyle("-fx-text-fill:black");
                    vBox.getChildren().add(e);
                }
                FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), vBox);
            }
            ev.consume();
        } else if (ev.getClickCount() == 1 && ev.getButton() == MouseButton.SECONDARY) {
            ObservableList<MenuItem> menus = FXCollections.observableArrayList();
            MenuItem miHist = new MenuItem("History");
            miHist.setUserData(selectedItem);
            MenuItem miAllHist = new MenuItem("All History");
            MenuItem miDiff = new MenuItem("Diff");
            miDiff.setDisable(true);
            menus.add(miHist);
            menus.add(miAllHist);
            menus.add(new SeparatorMenuItem());
            menus.add(miDiff);
            if (selectedItems.size() == 2) {
                miDiff.setUserData(selectedItems);
                miDiff.setDisable(false);
            }
            miHist.setOnAction(event -> {
                GargoyleSVNLogEntryPath userData = (GargoyleSVNLogEntryPath) miHist.getUserData();
                if (userData == null)
                    return;
                FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), createHistoryListView(userData.getPath()));
            });
            miAllHist.setOnAction(event -> {
                GargoyleSVNLogEntryPath userData = (GargoyleSVNLogEntryPath) miHist.getUserData();
                if (userData == null)
                    return;
                String path = userData.getPath();
                try {
                    Collection<SVNLogEntry> allLogs = getManager().getAllLogs(path);
                    ObservableList<GargoyleSVNLogEntryPath> collect = createStream(allLogs).filter(v -> {
                        return path.equals(v.getPath());
                    }).collect(FxCollectors.toObservableList());
                    FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), createHistoryListView(collect));
                } catch (Exception e) {
                    LOGGER.error(ValueUtil.toString(e));
                }
            });
            miDiff.setOnAction(event -> {
                List<GargoyleSVNLogEntryPath> userData = (List<GargoyleSVNLogEntryPath>) miDiff.getUserData();
                if (userData == null && userData.size() != 2)
                    return;
                GargoyleSVNLogEntryPath gargoyleSVNLogEntryPath1 = userData.get(0);
                GargoyleSVNLogEntryPath gargoyleSVNLogEntryPath2 = userData.get(1);
                try {
                    String diff = diff(gargoyleSVNLogEntryPath1.getPath(), gargoyleSVNLogEntryPath1.getCopyRevision(), gargoyleSVNLogEntryPath2.getCopyRevision());
                    TextArea showingNode = new TextArea(diff);
                    showingNode.setPrefSize(600d, 800d);
                    FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), showingNode);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
            contextMenu = new ContextMenu(menus.stream().toArray(MenuItem[]::new));
            contextMenu.show(ev.getPickResult().getIntersectedNode(), ev.getScreenX(), ev.getScreenY());
        }
    });
    return listView;
}
Also used : Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) ListView(javafx.scene.control.ListView) TextArea(javafx.scene.control.TextArea) ListCell(javafx.scene.control.ListCell) MouseEvent(javafx.scene.input.MouseEvent) LoggerFactory(org.slf4j.LoggerFactory) JavaTextArea(com.kyj.fx.voeditor.visual.component.text.JavaTextArea) FXCollections(javafx.collections.FXCollections) JavaSVNManager(com.kyj.scm.manager.svn.java.JavaSVNManager) VBox(javafx.scene.layout.VBox) ContextMenu(javafx.scene.control.ContextMenu) Map(java.util.Map) FxCollectors(com.kyj.fx.voeditor.visual.util.FxCollectors) Callback(javafx.util.Callback) SVNLogEntryPath(org.tmatesoft.svn.core.SVNLogEntryPath) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) MenuItem(javafx.scene.control.MenuItem) Collection(java.util.Collection) SVNNodeKind(org.tmatesoft.svn.core.SVNNodeKind) Node(javafx.scene.Node) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Collectors(java.util.stream.Collectors) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) DateUtil(com.kyj.fx.voeditor.visual.util.DateUtil) ObservableList(javafx.collections.ObservableList) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) TextArea(javafx.scene.control.TextArea) JavaTextArea(com.kyj.fx.voeditor.visual.component.text.JavaTextArea) ListCell(javafx.scene.control.ListCell) Label(javafx.scene.control.Label) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) ListView(javafx.scene.control.ListView) ObservableList(javafx.collections.ObservableList) Collection(java.util.Collection) List(java.util.List) ObservableList(javafx.collections.ObservableList) VBox(javafx.scene.layout.VBox)

Aggregations

ListCell (javafx.scene.control.ListCell)8 ListView (javafx.scene.control.ListView)7 Label (javafx.scene.control.Label)5 FXML (javafx.fxml.FXML)4 Callback (javafx.util.Callback)4 ObservableList (javafx.collections.ObservableList)3 Node (javafx.scene.Node)3 Button (javafx.scene.control.Button)3 MalformedURLException (java.net.MalformedURLException)2 FXCollections (javafx.collections.FXCollections)2 SelectionMode (javafx.scene.control.SelectionMode)2 MouseEvent (javafx.scene.input.MouseEvent)2 VBox (javafx.scene.layout.VBox)2 CartProduct (BasicCommonClasses.CartProduct)1 CatalogProduct (BasicCommonClasses.CatalogProduct)1 SmartCode (BasicCommonClasses.SmartCode)1 ICustomer (CustomerContracts.ICustomer)1 CustomerProductCellFormat (CustomerGuiHelpers.CustomerProductCellFormat)1 TempCustomerPassingData (CustomerGuiHelpers.TempCustomerPassingData)1 AbstractApplicationScreen (GuiUtils.AbstractApplicationScreen)1