Search in sources :

Example 31 with StringConverter

use of javafx.util.StringConverter in project TeachingInSimulation by ScOrPiOzzy.

the class ResourceList method createTable.

private void createTable() {
    // 数据库唯一表示
    Column<Integer> id = new Column<>();
    id.setPrimary(true);
    id.setVisible(false);
    id.setKey("id");
    // 资源图标
    Column<Integer> icon = new Column<>();
    icon.setAlignment(Pos.CENTER_RIGHT);
    icon.setKey("type");
    icon.setText("");
    icon.setMaxWidth(25);
    Function<Integer, SVGGlyph> converter = new Function<Integer, SVGGlyph>() {

        @Override
        public SVGGlyph apply(Integer type) {
            if (type == null) {
                return null;
            }
            ResourceType resourceType = ResourceType.getResourceType(type);
            return new SVGGlyph(resourceType.getIcon(), resourceType.getColor(), 22);
        }
    };
    icon.setCellFactory(SVGIconCell.forTableColumn(converter));
    // 资源名称
    Column<String> name = new Column<>();
    name.setAlignment(Pos.CENTER_LEFT);
    name.setKey("name");
    name.setText(MsgUtil.getMessage("resource.name"));
    name.setMaxWidth(250);
    // 日期
    Column<Date> date = new Column<>();
    date.setAlignment(Pos.CENTER);
    date.setKey("createDate");
    date.setText(type.getDateLabel());
    date.setMaxWidth(160);
    date.setCellFactory(Cell.forTableColumn(new StringConverter<Date>() {

        @Override
        public String toString(Date date) {
            return DateUtil.date2Str(date, DateUtil.DATE_TIME_PAT_SHOW_);
        }

        @Override
        public Date fromString(String string) {
            return null;
        }
    }));
    table.getColumns().addAll(id, icon, name, date);
    // 查看按钮
    Column<String> view = new Column<String>();
    view.setCellFactory(BtnCell.forTableColumn(MsgUtil.getMessage("button.view"), Priority.ALWAYS, "blue-btn", rid -> {
        SpringUtil.getBean(ResourceAction.class).browsed((Integer) rid);
        ResourceAction action = SpringUtil.getBean(ResourceAction.class);
        Resource resource = action.findResourceByID((Integer) rid);
        // 跳转到查看页面
        PageController controller = SpringUtil.getBean(PageController.class);
        controller.loadContent(new ResourceViewer(resource), PageLevel.Level2);
    }));
    view.setAlignment(Pos.CENTER_RIGHT);
    table.getColumns().add(view);
    if (type.isEditable()) {
        // 删除按钮
        Column<String> delete = new Column<String>();
        delete.setCellFactory(BtnCell.forTableColumn(MsgUtil.getMessage("button.delete"), "blue-btn", rid -> {
            AlertUtil.showConfirm(MsgUtil.getMessage("alert.confirmation.data.delete"), response -> {
                if (response == ButtonType.YES) {
                    SpringUtil.getBean(ResourceAction.class).detele((Integer) rid);
                    pagination.reload();
                }
            });
        }));
        delete.setAlignment(Pos.CENTER_RIGHT);
        delete.setMaxWidth(58);
        table.getColumns().add(delete);
    }
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) Title(com.cas.sim.tis.view.control.imp.Title) URL(java.net.URL) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) VBox(javafx.scene.layout.VBox) SVGGlyph(com.cas.sim.tis.svg.SVGGlyph) StringUtil(com.cas.util.StringUtil) ResourceViewer(com.cas.sim.tis.view.control.imp.ResourceViewer) AlertType(javafx.scene.control.Alert.AlertType) PaginationBar(com.cas.sim.tis.view.control.imp.pagination.PaginationBar) Data(javafx.scene.chart.PieChart.Data) HBox(javafx.scene.layout.HBox) ResourceConsts(com.cas.sim.tis.consts.ResourceConsts) TextField(javafx.scene.control.TextField) IContent(com.cas.sim.tis.view.control.IContent) Table(com.cas.sim.tis.view.control.imp.table.Table) PageController(com.cas.sim.tis.view.controller.PageController) Resource(com.cas.sim.tis.entity.Resource) UUID(java.util.UUID) PageInfo(com.github.pagehelper.PageInfo) FXML(javafx.fxml.FXML) PieChart(javafx.scene.chart.PieChart) Priority(javafx.scene.layout.Priority) List(java.util.List) Region(javafx.scene.layout.Region) GUIState(de.felixroske.jfxsupport.GUIState) ResourceAction(com.cas.sim.tis.action.ResourceAction) Cell(com.cas.sim.tis.view.control.imp.table.Cell) ObservableList(javafx.collections.ObservableList) SearchBox(com.cas.sim.tis.view.control.imp.SearchBox) ButtonType(javafx.scene.control.ButtonType) FXCollections(javafx.collections.FXCollections) FileUtil(com.cas.util.FileUtil) Function(java.util.function.Function) ArrayList(java.util.ArrayList) SVGIconCell(com.cas.sim.tis.view.control.imp.table.SVGIconCell) JSONArray(com.alibaba.fastjson.JSONArray) PageLevel(com.cas.sim.tis.view.controller.PageController.PageLevel) ResourceBundle(java.util.ResourceBundle) BtnCell(com.cas.sim.tis.view.control.imp.table.BtnCell) Column(com.cas.sim.tis.view.control.imp.table.Column) FXMLLoader(javafx.fxml.FXMLLoader) SpringUtil(com.cas.sim.tis.util.SpringUtil) MsgUtil(com.cas.sim.tis.util.MsgUtil) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) Node(javafx.scene.Node) DecimalFormat(java.text.DecimalFormat) CheckBox(javafx.scene.control.CheckBox) IOException(java.io.IOException) StringConverter(javafx.util.StringConverter) File(java.io.File) AlertUtil(com.cas.sim.tis.util.AlertUtil) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) ToggleGroup(javafx.scene.control.ToggleGroup) DateUtil(com.cas.util.DateUtil) ResourceType(com.cas.sim.tis.consts.ResourceType) FTPUtils(com.cas.sim.tis.util.FTPUtils) Resource(com.cas.sim.tis.entity.Resource) ResourceType(com.cas.sim.tis.consts.ResourceType) StringConverter(javafx.util.StringConverter) Date(java.util.Date) Function(java.util.function.Function) PageController(com.cas.sim.tis.view.controller.PageController) SVGGlyph(com.cas.sim.tis.svg.SVGGlyph) Column(com.cas.sim.tis.view.control.imp.table.Column) ResourceViewer(com.cas.sim.tis.view.control.imp.ResourceViewer) ResourceAction(com.cas.sim.tis.action.ResourceAction)

Example 32 with StringConverter

use of javafx.util.StringConverter in project dwoss by gg-net.

the class CustomerEnhanceController method buildFlagBox.

/**
 * Build up a ListView with CheckBoxes for the Set of CunstomerFlags
 */
private void buildFlagBox() {
    // transform a Set to a ObservableList of CustomerFlag
    List<CustomerFlag> templist = new ArrayList<>();
    flagsSet.forEach(f -> templist.add(f));
    ObservableList<CustomerFlag> allFlagsFromTheCustomer = FXCollections.observableArrayList(templist);
    // fill with all posibile flags
    ObservableList<CustomerFlag> observableArrayListOfAllFlags = FXCollections.observableArrayList(CustomerFlag.values());
    ObservableList<CustomerFlagWithSelect> listForTheView = FXCollections.observableArrayList();
    // fill the CustomerFlagWithSelect List
    observableArrayListOfAllFlags.stream().map((ovall) -> {
        CustomerFlagWithSelect cfs = new CustomerFlagWithSelect(ovall);
        if (allFlagsFromTheCustomer.contains(ovall)) {
            cfs.setSelected(true);
        }
        return cfs;
    }).forEachOrdered((cfs) -> {
        listForTheView.add(cfs);
    });
    listForTheView.forEach(flag -> flag.selectedProperty().addListener((observable, wasSelected, isSelected) -> {
        if (isSelected) {
            outputFlagslist.add(flag.getFlag());
        }
    }));
    ListView<CustomerFlagWithSelect> checklist = new ListView<>();
    checklist.setItems(listForTheView);
    checklist.setMinWidth(150.0);
    checklist.setCellFactory(CheckBoxListCell.forListView(CustomerFlagWithSelect::selectedProperty, new StringConverter<CustomerFlagWithSelect>() {

        @Override
        public String toString(CustomerFlagWithSelect object) {
            return object.getFlag().getName();
        }

        @Override
        public CustomerFlagWithSelect fromString(String string) {
            return null;
        }
    }));
    Label flagLable = new Label("Flags: ");
    flagVBox.getChildren().addAll(flagLable, checklist);
}
Also used : EventHandler(javafx.event.EventHandler) ButtonData(javafx.scene.control.ButtonBar.ButtonData) java.util(java.util) javafx.collections(javafx.collections) Initializable(javafx.fxml.Initializable) ExternalSystem(eu.ggnet.dwoss.customer.ee.entity.Customer.ExternalSystem) javafx.scene.layout(javafx.scene.layout) javafx.scene.control(javafx.scene.control) URL(java.net.URL) CheckBoxListCell(javafx.scene.control.cell.CheckBoxListCell) Source(eu.ggnet.dwoss.customer.ee.entity.Customer.Source) Sex(eu.ggnet.dwoss.customer.ee.entity.Contact.Sex) Ui(eu.ggnet.saft.Ui) InvalidationListener(javafx.beans.InvalidationListener) CustomerFlag(eu.ggnet.dwoss.rules.CustomerFlag) Insets(javafx.geometry.Insets) AlertType(javafx.scene.control.Alert.AlertType) WINDOW_MODAL(javafx.stage.Modality.WINDOW_MODAL) javafx.beans.property(javafx.beans.property) AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) eu.ggnet.dwoss.customer.ee.entity(eu.ggnet.dwoss.customer.ee.entity) Node(javafx.scene.Node) StringConverter(javafx.util.StringConverter) Collectors(java.util.stream.Collectors) eu.ggnet.saft.api.ui(eu.ggnet.saft.api.ui) Consumer(java.util.function.Consumer) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) Data(lombok.Data) AllArgsConstructor(lombok.AllArgsConstructor) CustomerFlag(eu.ggnet.dwoss.rules.CustomerFlag) AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) StringConverter(javafx.util.StringConverter)

Example 33 with StringConverter

use of javafx.util.StringConverter in project POL-POM-5 by PlayOnLinux.

the class ChooseRepositoryTypePanel method populate.

/**
 * Populates the content of this component
 */
private void populate() {
    choiceBox = new ComboBox<>(repositoryChoices);
    choiceBox.setPromptText(tr("Please select the repository type you want to add"));
    choiceBox.setConverter(new StringConverter<RepositoryType>() {

        @Override
        public String toString(RepositoryType repositoryType) {
            return repositoryType.getLabel();
        }

        @Override
        public RepositoryType fromString(String string) {
            return Arrays.stream(RepositoryType.values()).filter(type -> type.getLabel().equals(string)).findAny().orElse(null);
        }
    });
    choiceBox.setOnAction(event -> onRepositoryTypeSelection.accept(choiceBox.getSelectionModel().getSelectedItem()));
    Label choiceBoxLabel = new Label(tr("Repository type:"));
    choiceBoxLabel.setLabelFor(choiceBox);
    HBox content = new HBox(choiceBoxLabel, choiceBox);
    content.setId("repositoryTypeSelection");
    HBox.setHgrow(choiceBox, Priority.ALWAYS);
    this.setCenter(content);
}
Also used : Consumer(java.util.function.Consumer) HBox(javafx.scene.layout.HBox) Priority(javafx.scene.layout.Priority) Arrays(java.util.Arrays) Label(javafx.scene.control.Label) ComboBox(javafx.scene.control.ComboBox) FXCollections(javafx.collections.FXCollections) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) StringConverter(javafx.util.StringConverter) HBox(javafx.scene.layout.HBox) Label(javafx.scene.control.Label)

Aggregations

StringConverter (javafx.util.StringConverter)33 Label (javafx.scene.control.Label)14 Callback (javafx.util.Callback)14 FXCollections (javafx.collections.FXCollections)12 Insets (javafx.geometry.Insets)12 Button (javafx.scene.control.Button)11 ImageView (javafx.scene.image.ImageView)11 Inject (javax.inject.Inject)11 ChangeListener (javafx.beans.value.ChangeListener)10 ObservableList (javafx.collections.ObservableList)10 ComboBox (javafx.scene.control.ComboBox)10 Priority (javafx.scene.layout.Priority)9 Arrays (java.util.Arrays)8 List (java.util.List)8 ListChangeListener (javafx.collections.ListChangeListener)8 GridPane (javafx.scene.layout.GridPane)8 HBox (javafx.scene.layout.HBox)8 Consumer (java.util.function.Consumer)7 Res (bisq.core.locale.Res)6 VPos (javafx.geometry.VPos)6