Search in sources :

Example 16 with TableView

use of javafx.scene.control.TableView in project financial by greatkendy123.

the class TgWaizhaiService method get_SSJE_Gudong_Map.

/**
 * 获取每个托管团队的实时金额
 * 备注:不包括个人和存在于左边的团队
 */
public static Map<String, List<CurrentMoneyInfo>> get_SSJE_Gudong_Map(TableView<CurrentMoneyInfo> tableCurrentMoneyInfo) {
    int pageIndex = DataConstans.Index_Table_Id_Map.size();
    if (pageIndex < 0) {
        return new HashMap<>();
    }
    // 获取托管团队ID
    Set<String> tgTeamIdSet = getTGTeamId();
    // 获取实时金额数据
    List<CurrentMoneyInfo> CurrentMoneyInfoList = new ArrayList<>();
    for (CurrentMoneyInfo infos : tableCurrentMoneyInfo.getItems()) {
        CurrentMoneyInfoList.add(infos);
    }
    // 情况2:从最新的锁定表中获取数据
    // CurrentMoneyInfoList = JSON.parseObject(MoneyService.getJsonString(map,"实时金额"), new TypeReference<List<CurrentMoneyInfo>>() {});
    // 添加只属于托管的团队和个人信息
    List<CurrentMoneyInfo> SSJE_obList = new LinkedList<>();
    for (CurrentMoneyInfo infos : CurrentMoneyInfoList) {
        if (!StringUtil.isAnyBlank(infos.getWanjiaId(), infos.getMingzi())) {
            String playerId = infos.getWanjiaId();
            Player player = DataConstans.membersMap.get(playerId);
            if (player == null || StringUtil.isBlank(player.getTeamName()) || !tgTeamIdSet.contains(player.getTeamName().toUpperCase())) {
                continue;
            } else if (tgTeamIdSet.contains(player.getTeamName().toUpperCase())) {
                // 深层克隆
                SSJE_obList.add(copyCurrentMoneyInfo(infos));
            }
        }
    }
    // 获取每个股东的实时金额数据
    List<String> gudongList = DataConstans.gudongList;
    int gudongSize = gudongList.size();
    List<CurrentMoneyInfo> eachGudongList = null;
    // 托管团队的实时金额信息{ 托管团队:托管团队金额列表List}
    String playerId;
    Player player;
    // 步骤1:添加玩家
    Map<String, List<CurrentMoneyInfo>> tgTeamCMIMap = SSJE_obList.stream().filter(infos -> {
        boolean isSuperId = DataConstans.Combine_Super_Id_Map.containsKey(infos.getWanjiaId());
        if (!isSuperId) {
            // 为解决联合ID的问题,在这里把父节点信息加了进来,后面会把父节点的联合额度为0或空的清除掉,问题:能否在此处就过滤过??
            if (StringUtil.isBlank(infos.getShishiJine()) || "0".equals(infos.getShishiJine()) || !infos.getShishiJine().contains("-")) {
                return false;
            }
        }
        return true;
    }).collect(Collectors.groupingBy(info -> {
        CurrentMoneyInfo cmi = (CurrentMoneyInfo) info;
        Player p = DataConstans.membersMap.get(cmi.getWanjiaId());
        if (p == null) {
            return UNKNOW_TG_TEAM;
        } else {
            return p.getTeamName();
        }
    }));
    // 步骤2:处理个人外债和有联合额度的外债
    // Map<String,CurrentMoneyInfo> ssje_map = get_SSJE_Map(SSJE_obList);
    // handlePersonWaizhai(tgTeamIdMap,ssje_map); TODO
    System.out.println("===============================================以上外债信息为:处理个人外债和有联合额度的外债finishes");
    tgTeamCMIMap = getFinalTGTeamMap(SSJE_obList);
    return tgTeamCMIMap;
}
Also used : ListIterator(java.util.ListIterator) NumUtil(com.kendy.util.NumUtil) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) MapUtil(com.kendy.util.MapUtil) TypeValueInfo(com.kendy.entity.TypeValueInfo) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) HashSet(java.util.HashSet) Logger(org.apache.log4j.Logger) Insets(javafx.geometry.Insets) StringUtil(com.kendy.util.StringUtil) Map(java.util.Map) MyController(application.MyController) LinkedList(java.util.LinkedList) TeamInfo(com.kendy.entity.TeamInfo) TableView(javafx.scene.control.TableView) DataConstans(application.DataConstans) DBUtil(com.kendy.db.DBUtil) Player(com.kendy.entity.Player) HBox(javafx.scene.layout.HBox) Iterator(java.util.Iterator) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Node(javafx.scene.Node) DecimalFormat(java.text.DecimalFormat) Set(java.util.Set) TGController(com.kendy.controller.TGController) com.kendy.entity.zhaiwuInfo(com.kendy.entity.zhaiwuInfo) Collectors(java.util.stream.Collectors) TGCompanyModel(com.kendy.entity.TGCompanyModel) List(java.util.List) ZonghuiInfo(com.kendy.entity.ZonghuiInfo) Stream(java.util.stream.Stream) CollectUtil(com.kendy.util.CollectUtil) ShowUtil(com.kendy.util.ShowUtil) ObservableList(javafx.collections.ObservableList) ErrorUtil(com.kendy.util.ErrorUtil) Collections(java.util.Collections) CurrentMoneyInfo(com.kendy.entity.CurrentMoneyInfo) Player(com.kendy.entity.Player) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CurrentMoneyInfo(com.kendy.entity.CurrentMoneyInfo) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ObservableList(javafx.collections.ObservableList)

Example 17 with TableView

use of javafx.scene.control.TableView in project financial by greatkendy123.

the class WaizhaiService method get_SSJE_Gudong_Map.

/**
 * 获取每个股东的实时金额
 * 包括个人和存在于左边的团队
 * @time 2017年12月27日
 * @param tableCurrentMoneyInfo
 * @param tableTeam
 * @return
 */
public static Map<String, List<CurrentMoneyInfo>> get_SSJE_Gudong_Map(TableView<CurrentMoneyInfo> tableCurrentMoneyInfo, TableView<TeamInfo> tableTeam) {
    int pageIndex = DataConstans.Index_Table_Id_Map.size();
    if (pageIndex < 0) {
        return new HashMap<>();
    }
    // 获取实时金额数据
    Map<String, String> map = DataConstans.All_Locked_Data_Map.get(pageIndex + "");
    List<CurrentMoneyInfo> CurrentMoneyInfoList = null;
    List<TeamInfo> teamInfoList = null;
    // 情况1:从最新的表中获取数据
    if (tableTeam != null && tableTeam.getItems() != null) {
        CurrentMoneyInfoList = new ArrayList<>();
        for (CurrentMoneyInfo infos : tableCurrentMoneyInfo.getItems()) {
            CurrentMoneyInfoList.add(infos);
        }
        teamInfoList = new ArrayList<>();
        for (TeamInfo infos : tableTeam.getItems()) {
            teamInfoList.add(infos);
        }
    } else // 情况2:从最新的锁定表中获取数据
    {
        CurrentMoneyInfoList = JSON.parseObject(MoneyService.getJsonString(map, "实时金额"), new TypeReference<List<CurrentMoneyInfo>>() {
        });
        teamInfoList = JSON.parseObject(MoneyService.getJsonString(map, "团队回水"), new TypeReference<List<TeamInfo>>() {
        });
    }
    List<CurrentMoneyInfo> SSJE_obList = new LinkedList<>();
    for (CurrentMoneyInfo infos : CurrentMoneyInfoList) {
        if (!StringUtil.isBlank(infos.getWanjiaId()) && !StringUtil.isBlank(infos.getMingzi())) {
            SSJE_obList.add(infos);
        }
    }
    // 获取每个股东的实时金额数据
    List<String> gudongList = DataConstans.gudongList;
    int gudongSize = gudongList.size();
    List<CurrentMoneyInfo> eachGudongList = null;
    Map<String, List<CurrentMoneyInfo>> gudongMap = new HashMap<>();
    String playerId;
    Player player;
    // 步骤1:添加玩家
    for (CurrentMoneyInfo infos : SSJE_obList) {
        boolean isSuperId = DataConstans.Combine_Super_Id_Map.containsKey(infos.getWanjiaId());
        if (!isSuperId) {
            // 为解决联合ID的问题,在这里把父节点信息加了进来,后面会把父节点的联合额度为0或空的清除掉,问题:能否在此处就过滤过??
            if (StringUtil.isBlank(infos.getShishiJine()) || "0".equals(infos.getShishiJine()) || !infos.getShishiJine().contains("-")) {
                continue;
            }
        }
        // if(StringUtil.isBlank(infos.getShishiJine())
        // || "0".equals(infos.getShishiJine())
        // || !infos.getShishiJine().contains("-")) {
        // continue;
        // }
        playerId = infos.getWanjiaId();
        if (!StringUtil.isBlank(playerId)) {
            player = DataConstans.membersMap.get(playerId);
            if (player == null) {
                ShowUtil.show("名单列表中匹配不到该玩家!玩家名称:" + infos.getMingzi() + " ID是" + infos.getWanjiaId());
                continue;
            }
            if (gudongList.contains(player.getGudong())) {
                for (String gudong : gudongList) {
                    if (gudong.equals(player.getGudong())) {
                        if (gudongMap.get(gudong) == null) {
                            eachGudongList = new ArrayList<>();
                        // eachGudongList.add(infos);
                        } else {
                            eachGudongList = gudongMap.get(gudong);
                        // eachGudongList.add(infos);
                        }
                        /**
                         ***2018-01-01 add***
                         */
                        CurrentMoneyInfo tempInfo = copyCurrentMoneyInfo(infos);
                        eachGudongList.add(tempInfo);
                        /**
                         ******
                         */
                        gudongMap.put(gudong, eachGudongList);
                        break;
                    }
                }
            } else {
                ShowUtil.show("玩家的股东不存在于股东表中!玩家名称:" + infos.getMingzi() + " ID是" + infos.getWanjiaId());
                break;
            }
        } else {
            ShowUtil.show("玩家ID为空!玩家名称:" + infos.getMingzi() + " ID是" + infos.getWanjiaId());
        }
    }
    // 步骤2:处理个人外债和有联合额度的外债
    Map<String, CurrentMoneyInfo> ssje_map = get_SSJE_Map(SSJE_obList);
    handlePersonWaizhai(gudongMap, ssje_map);
    System.out.println("===============================================以上外债信息为:处理个人外债和有联合额度的外债finishes");
    // 步骤3:添加团队
    for (TeamInfo infos : teamInfoList) {
        String teamId = infos.getTeamID();
        Huishui hsInfo = DataConstans.huishuiMap.get(teamId);
        if (hsInfo == null) {
            ErrorUtil.err("外债信息:添加负数团队时检测到缓存中没有该团队信息,团队ID:" + teamId);
            continue;
        }
        String isManaged = hsInfo.getZjManaged();
        String gudong = hsInfo.getGudong();
        String hasJiesuan = infos.getHasJiesuaned();
        String zhanji = infos.getTeamZJ();
        if (// 战绩非管理的团队
        !"是".equals(isManaged) && // 未结算的团队
        !"1".equals(hasJiesuan) && zhanji.contains("-")) {
            // 战绩为负数的团队
            CurrentMoneyInfo cmi = new CurrentMoneyInfo();
            cmi.setMingzi("团队" + teamId);
            cmi.setShishiJine(infos.getTeamZJ());
            if (gudongMap.get(gudong) == null) {
                eachGudongList = new ArrayList<>();
                eachGudongList.add(cmi);
            } else {
                eachGudongList = gudongMap.get(gudong);
                eachGudongList.add(cmi);
            }
            gudongMap.put(gudong, eachGudongList);
        }
    }
    /*
		 * A、负数个人(若其父节点的联合额度为正则不显示 )
		 * B、公司(不显示团队;若其父节点的联合额度为正则不显示,否则不显示子ID,只显示联合额度;其他节点不变
		 * C、非公司团队(全部累加到相应团队;若其父节点的联合额度为正则只累加联合额度;其他节点累加实时金额)
		 */
    if (MapUtil.isHavaValue(gudongMap)) {
        // LMController.allClubMap.keySet().forEach(clubID -> log.info(LMController.allClubMap.keySet()));
        Iterator<Map.Entry<String, List<CurrentMoneyInfo>>> it = gudongMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, List<CurrentMoneyInfo>> entry = it.next();
            String gudongName = entry.getKey();
            // if(!"B".equals(gudongName)) continue;//只测试股东B
            List<CurrentMoneyInfo> eachList = entry.getValue();
            // 深层复制
            List<CurrentMoneyInfo> tempEachList = copyListCurrentMoneyInfo(eachList);
            List<CurrentMoneyInfo> tempSuperList = new ArrayList<>();
            // 过滤掉没有负数团队的股东,过滤掉没有联合ID的股东
            if (CollectUtil.isNullOrEmpty(eachList))
                continue;
            // if(eachList.stream().filter(cmi->cmi.getMingzi().startsWith("团队")).count() == 0) continue;
            if (eachList.stream().filter(cmi -> DataConstans.Combine_Super_Id_Map.containsKey(cmi.getWanjiaId())).count() == 0)
                continue;
            // 处理包含有负数团队的股东(既有联合ID,又有负数团队)
            ListIterator<CurrentMoneyInfo> ite = eachList.listIterator();
            while (ite.hasNext()) {
                CurrentMoneyInfo cmi = ite.next();
                String pId = cmi.getWanjiaId();
                // TODO 对下面的特殊情况进行分析
                if (pId == null && cmi.getMingzi() != null && cmi.getMingzi().startsWith("团队")) {
                    continue;
                }
                boolean isSuperId = DataConstans.Combine_Super_Id_Map.containsKey(pId);
                // 1528833636
                Player _player = DataConstans.membersMap.get(pId);
                // 如ST,公司
                String teamID = _player.getTeamName();
                // 将联合ID的金额设置到对应的团队里
                if (isSuperId) {
                    String playerName = DataConstans.membersMap.get(pId).getPlayerName();
                    if ("公司".equals(teamID)) {
                        final String _cmSuperIdSum = cmi.getCmSuperIdSum();
                        cmi.setShishiJine(_cmSuperIdSum);
                        log.info(String.format("外债:股东%s--属于公司的父节点%s(%s)设置联合额度%s为实时金额", gudongName, playerName, pId, _cmSuperIdSum));
                        continue;
                    }
                    final String _teamId = "团队" + DataConstans.membersMap.get(pId).getTeamName();
                    Optional<CurrentMoneyInfo> teamInfoOpt = eachList.stream().filter(info -> info.getMingzi().equals(_teamId)).findFirst();
                    if (teamInfoOpt.isPresent()) {
                        CurrentMoneyInfo teamInfo = teamInfoOpt.get();
                        teamInfo.setShishiJine(NumUtil.getSum(teamInfo.getShishiJine(), cmi.getShishiJine()));
                        ite.remove();
                        log.info(String.format("外债:股东%s--有联合ID的父节点%s(%s)将%s转移到%s,并删除父节点", gudongName, playerName, pId, cmi.getShishiJine(), teamInfo.getMingzi()));
                    } else {
                        // 新增一个所属团队信息
                        ite.remove();
                        CurrentMoneyInfo cmiInfo = new CurrentMoneyInfo(_teamId, cmi.getCmSuperIdSum(), "", "");
                        ite.add(cmiInfo);
                        log.info(String.format("外债:股东%s--根据父点(%s)新建团队外债信息(%s),联合额度(团队的实时金额)为%s,并删除父节点", gudongName, playerName, _teamId, cmi.getCmSuperIdSum()));
                    }
                } else // 非公司团队,非父节点,累加进其所属的团队中
                if (!"公司".equals(teamID)) {
                    String playerName = DataConstans.membersMap.get(pId).getPlayerName();
                    final String _teamId = "团队" + DataConstans.membersMap.get(pId).getTeamName();
                    Optional<CurrentMoneyInfo> teamInfoOpt = eachList.stream().filter(info -> info.getMingzi().equals(_teamId)).findFirst();
                    if (teamInfoOpt.isPresent()) {
                        CurrentMoneyInfo teamInfo = teamInfoOpt.get();
                        teamInfo.setShishiJine(NumUtil.getSum(teamInfo.getShishiJine(), cmi.getShishiJine()));
                        ite.remove();
                        log.info(String.format("外债:股东%s--非父节点%s(%s)将%s转移到%s,并删除非父节点", gudongName, playerName, pId, cmi.getShishiJine(), teamInfo.getMingzi()));
                    } else {
                        // 新增一个所属团队信息
                        ite.remove();
                        CurrentMoneyInfo cmiInfo = new CurrentMoneyInfo(_teamId, cmi.getShishiJine(), "", "");
                        ite.add(cmiInfo);
                        log.info(String.format("外债:股东%s--根据非父点(%s)新建团队外债信息(%s),联合额度(团队的实时金额)为%s,并删除非父节点", gudongName, playerName, _teamId, cmi.getShishiJine()));
                    }
                }
            }
        }
    }
    return gudongMap;
}
Also used : ListIterator(java.util.ListIterator) NumUtil(com.kendy.util.NumUtil) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) MapUtil(com.kendy.util.MapUtil) Club(com.kendy.entity.Club) Huishui(com.kendy.entity.Huishui) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Logger(org.apache.log4j.Logger) Insets(javafx.geometry.Insets) WaizhaiInfo(com.kendy.entity.WaizhaiInfo) StringUtil(com.kendy.util.StringUtil) Map(java.util.Map) MyController(application.MyController) LinkedList(java.util.LinkedList) TeamInfo(com.kendy.entity.TeamInfo) TableView(javafx.scene.control.TableView) DataConstans(application.DataConstans) Player(com.kendy.entity.Player) HBox(javafx.scene.layout.HBox) Iterator(java.util.Iterator) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Node(javafx.scene.Node) DecimalFormat(java.text.DecimalFormat) com.kendy.entity.zhaiwuInfo(com.kendy.entity.zhaiwuInfo) LMController(com.kendy.controller.LMController) List(java.util.List) ZonghuiInfo(com.kendy.entity.ZonghuiInfo) JSON(com.alibaba.fastjson.JSON) TypeReference(com.alibaba.fastjson.TypeReference) CollectUtil(com.kendy.util.CollectUtil) ShowUtil(com.kendy.util.ShowUtil) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) ErrorUtil(com.kendy.util.ErrorUtil) CurrentMoneyInfo(com.kendy.entity.CurrentMoneyInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CurrentMoneyInfo(com.kendy.entity.CurrentMoneyInfo) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ObservableList(javafx.collections.ObservableList) TypeReference(com.alibaba.fastjson.TypeReference) Huishui(com.kendy.entity.Huishui) Player(com.kendy.entity.Player) Optional(java.util.Optional) TeamInfo(com.kendy.entity.TeamInfo) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with TableView

use of javafx.scene.control.TableView in project blue by kunstmusik.

the class BlueJFXControlsApplication method setTablesTest.

private void setTablesTest(TabPane root) {
    TableView<Person> jfxTable = new TableView<>();
    ObservableList<Person> people = FXCollections.observableArrayList();
    for (int i = 0; i < 20; i++) {
        Person p = new Person();
        p.setFirstName("test");
        p.setLastName(Integer.toString(i));
        people.add(p);
    }
    TableColumn<Person, String> firstNameCol = new TableColumn<Person, String>("First Name");
    firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
    TableColumn<Person, String> lastNameCol = new TableColumn<Person, String>("Last Name");
    lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName"));
    jfxTable.getColumns().addAll(firstNameCol, lastNameCol);
    jfxTable.setItems(people);
    SwingNode swingNode = new SwingNode();
    Vector v = new Vector();
    for (int i = 0; i < 20; i++) {
        Vector t = new Vector();
        t.add("test");
        t.add(Integer.toString(i));
        v.add(t);
    }
    Vector labels = new Vector();
    labels.add("First Name");
    labels.add("Last Name");
    SwingUtilities.invokeLater(() -> {
        DefaultTableModel tm = new DefaultTableModel(v, labels);
        JTable table = new JTable(tm);
        table.updateUI();
        JScrollPane scrollPane = new JScrollPane(table);
        scrollPane.setBorder(BorderFactory.createEmptyBorder());
        swingNode.setContent(scrollPane);
    });
    root.getTabs().add(new Tab("Tables", new SplitPane(jfxTable, swingNode)));
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultTableModel(javax.swing.table.DefaultTableModel) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) SplitPane(javafx.scene.control.SplitPane) TableColumn(javafx.scene.control.TableColumn) SwingNode(javafx.embed.swing.SwingNode) Tab(javafx.scene.control.Tab) JTable(javax.swing.JTable) Vector(java.util.Vector) TableView(javafx.scene.control.TableView)

Example 19 with TableView

use of javafx.scene.control.TableView in project blue by kunstmusik.

the class ParameterLineView method editPoints.

private void editPoints() {
    TableView<LinePoint> table = new TableView<>();
    TableColumn<LinePoint, Double> xCol = new TableColumn<>("x");
    TableColumn<LinePoint, Double> yCol = new TableColumn<>("y");
    table.getColumns().setAll(xCol, yCol);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    table.setItems(getSelectedLine().getObservableList());
    table.setEditable(true);
    xCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<LinePoint, Double>, ObservableValue<Double>>() {

        @Override
        public ObservableValue<Double> call(TableColumn.CellDataFeatures<LinePoint, Double> param) {
            return new ReadOnlyObjectWrapper<>(param.getValue().getX() * getDuration() + getStartTime());
        }
    });
    xCol.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
    xCol.setOnEditCommit(te -> {
        LinePoint lp = te.getRowValue();
        ObservableList<LinePoint> lpList = getSelectedLine().getObservableList();
        if (getSelectedLine().getLinePoint(0) == lp || getSelectedLine().getLinePoint(getSelectedLine().size() - 1) == lp) {
            return;
        }
        int index = lpList.indexOf(lp);
        double v = (te.getNewValue() - getStartTime()) / getDuration();
        lp.setX(Utils.clamp(lpList.get(index - 1).getX(), v, lpList.get(index + 1).getX()));
    });
    xCol.setEditable(true);
    yCol.setCellValueFactory(new PropertyValueFactory<>("y"));
    yCol.setCellFactory(TextFieldTableCell.forTableColumn(new DoubleStringConverter()));
    yCol.setOnEditCommit(te -> {
        te.getRowValue().setY(Utils.clamp(getSelectedLine().getMin(), te.getNewValue(), getSelectedLine().getMax()));
    });
    yCol.setEditable(true);
    Dialog<ButtonType> d = new Dialog<>();
    d.initOwner(getScene().getWindow());
    d.initModality(Modality.APPLICATION_MODAL);
    d.getDialogPane().setContent(new ScrollPane(table));
    d.getDialogPane().getStylesheets().add(BlueFX.getBlueFxCss());
    d.getDialogPane().getButtonTypes().setAll(ButtonType.OK);
    d.setTitle("Edit Points");
    TableModelListener tml = tme -> {
        repaint();
    };
    getSelectedLine().addTableModelListener(tml);
    Optional<ButtonType> res = d.showAndWait();
    getSelectedLine().removeTableModelListener(tml);
}
Also used : DoubleStringConverter(javafx.util.converter.DoubleStringConverter) NumberUtilities(blue.utility.NumberUtilities) ButtonType(javafx.scene.control.ButtonType) LineList(blue.components.lines.LineList) Glow(javafx.scene.effect.Glow) MouseEvent(javafx.scene.input.MouseEvent) DoubleProperty(javafx.beans.property.DoubleProperty) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) TableModelListener(javax.swing.event.TableModelListener) LinePoint(blue.components.lines.LinePoint) TableColumn(javafx.scene.control.TableColumn) DragDirection(blue.components.DragDirection) Utils(org.controlsfx.tools.Utils) BlueFX(blue.jfx.BlueFX) ScrollPane(javafx.scene.control.ScrollPane) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) ContextMenu(javafx.scene.control.ContextMenu) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Modality(javafx.stage.Modality) Dialog(javafx.scene.control.Dialog) MenuItem(javafx.scene.control.MenuItem) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) GraphicsContext(javafx.scene.canvas.GraphicsContext) Canvas(javafx.scene.canvas.Canvas) Line(blue.components.lines.Line) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Optional(java.util.Optional) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) DoubleStringConverter(javafx.util.converter.DoubleStringConverter) ObservableValue(javafx.beans.value.ObservableValue) TableColumn(javafx.scene.control.TableColumn) LinePoint(blue.components.lines.LinePoint) LinePoint(blue.components.lines.LinePoint) Dialog(javafx.scene.control.Dialog) ScrollPane(javafx.scene.control.ScrollPane) TableModelListener(javax.swing.event.TableModelListener) ButtonType(javafx.scene.control.ButtonType) TableView(javafx.scene.control.TableView)

Example 20 with TableView

use of javafx.scene.control.TableView in project jvarkit by lindenb.

the class IgvReview method start.

@Override
public void start(final Stage stage) throws Exception {
    stage.setTitle(getClass().getSimpleName());
    Predicate<VariantContext> ctxFilter;
    Map<String, String> params = super.getParameters().getNamed();
    if (params.containsKey("--filter")) {
        ctxFilter = JexlVariantPredicate.create(params.get("--filter"));
    } else {
        ctxFilter = V -> true;
    }
    final List<String> args = super.getParameters().getUnnamed();
    final File configFile;
    if (args.isEmpty()) {
        final FileChooser fc = new FileChooser();
        final String lastDirStr = preferences.get(LAST_USED_DIR_KEY, null);
        if (lastDirStr != null && !lastDirStr.isEmpty()) {
            fc.setInitialDirectory(new File(lastDirStr));
        }
        fc.getExtensionFilters().addAll(Collections.singletonList(new FileChooser.ExtensionFilter("Config file", "*.config", "*.cfg", "*.list")));
        configFile = fc.showOpenDialog(stage);
    } else if (args.size() == 1) {
        configFile = new File(args.get(0));
    } else {
        configFile = null;
    }
    if (configFile == null || !configFile.exists()) {
        JfxUtils.dialog().cause("Illegal number of arguments or file doesn't exists.").show(stage);
        Platform.exit();
        return;
    }
    if (configFile.isFile() && configFile.getParentFile() != null) {
        this.preferences.put(LAST_USED_DIR_KEY, configFile.getParentFile().getPath());
    }
    final List<String> configLines = Files.readAllLines(configFile.toPath());
    final Predicate<String> ignoreComment = (S) -> !S.startsWith("#");
    final Predicate<String> predVcf = S -> S.endsWith(".vcf") || S.endsWith(".vcf.gz");
    if (configLines.stream().filter(ignoreComment).filter(predVcf).count() != 1) {
        JfxUtils.dialog().cause("Found more than one vcf file in " + configFile).show(stage);
        Platform.exit();
        return;
    }
    final File vcfFile = configLines.stream().filter(ignoreComment).filter(predVcf).map(S -> new File(S)).findFirst().get();
    LOG.info("Opening vcf file and loading in memory");
    VCFFileReader vfr = null;
    CloseableIterator<VariantContext> iter = null;
    final Set<String> sampleNames;
    try {
        this.variants.clear();
        vfr = new VCFFileReader(vcfFile, false);
        this.vcfHeader = vfr.getFileHeader();
        sampleNames = new HashSet<>(this.vcfHeader.getSampleNamesInOrder());
        if (sampleNames.isEmpty()) {
            JfxUtils.dialog().cause("No Genotypes in " + vcfFile).show(stage);
            Platform.exit();
            return;
        }
        iter = vfr.iterator();
        this.variants.addAll(iter.stream().filter(ctxFilter).filter(CTX -> CTX.isVariant()).collect(Collectors.toList()));
    } catch (final Exception err) {
        JfxUtils.dialog().cause(err).show(stage);
        Platform.exit();
        return;
    } finally {
        CloserUtil.close(iter);
        CloserUtil.close(vfr);
    }
    if (this.variants.isEmpty()) {
        JfxUtils.dialog().cause("No Variants").show(stage);
        Platform.exit();
        return;
    }
    final SAMSequenceDictionary dict = this.vcfHeader.getSequenceDictionary();
    if (dict == null || dict.isEmpty()) {
        JfxUtils.dialog().cause(JvarkitException.VcfDictionaryMissing.getMessage(vcfFile.getPath())).show(stage);
        Platform.exit();
        return;
    }
    final SamReaderFactory srf = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.LENIENT);
    configLines.stream().filter(ignoreComment).filter(S -> S.endsWith(".bam")).map(S -> new File(S)).forEach(F -> {
        final SamReader samIn = srf.open(F);
        final SAMFileHeader header = samIn.getFileHeader();
        CloserUtil.close(samIn);
        String sample = null;
        for (final SAMReadGroupRecord rg : header.getReadGroups()) {
            String s = rg.getSample();
            if (s == null)
                continue;
            if (sample == null) {
                sample = s;
            } else if (!sample.equals(s)) {
                JfxUtils.dialog().cause("Two samples in " + F).show(stage);
                Platform.exit();
                return;
            }
        }
        if (sample == null) {
            JfxUtils.dialog().cause("No sample in " + F + ". Ignoring").show(stage);
            return;
        }
        if (!sampleNames.contains(sample)) {
            JfxUtils.dialog().cause("Not in VCF header " + sample + " / " + F + ". Ignoring").show(stage);
            return;
        }
        this.sample2bamFile.put(sample, F);
    });
    if (this.sample2bamFile.isEmpty()) {
        JfxUtils.dialog().cause("No valid bam file in " + configFile).show(stage);
        return;
    }
    sampleNames.retainAll(this.sample2bamFile.keySet());
    if (sampleNames.isEmpty()) {
        JfxUtils.dialog().cause("No Sample associated to bam").show(stage);
        return;
    }
    ObservableList<VariantAndGenotype> genotypes = FXCollections.observableArrayList(this.variants.stream().flatMap(CTX -> CTX.getGenotypes().stream().filter(G -> sampleNames.contains(G.getSampleName())).map(G -> new VariantAndGenotype(CTX, G))).collect(Collectors.toList()));
    if (genotypes.isEmpty()) {
        JfxUtils.dialog().cause("No Genotype to show").show(stage);
        return;
    }
    Menu menu = new Menu("File");
    MenuItem menuItem = new MenuItem("Save as...");
    menuItem.setOnAction(AE -> {
        saveVariantsAs(stage);
    });
    menu.getItems().add(menuItem);
    menuItem = new MenuItem("Save");
    menuItem.setOnAction(AE -> {
        if (this.saveAsFile != null) {
            saveVariants(stage, this.saveAsFile);
        } else {
            saveVariantsAs(stage);
        }
    });
    menu.getItems().add(menuItem);
    menu.getItems().add(new SeparatorMenuItem());
    menuItem = new MenuItem("Quit");
    menuItem.setOnAction(AE -> {
        Platform.exit();
    });
    menu.getItems().add(menuItem);
    MenuBar bar = new MenuBar(menu);
    this.genotypeTable = new TableView<>(genotypes);
    this.genotypeTable.getColumns().add(makeColumn("CHROM", G -> G.ctx.getContig()));
    this.genotypeTable.getColumns().add(makeColumn("POS", G -> G.ctx.getStart()));
    this.genotypeTable.getColumns().add(makeColumn("ID", G -> G.ctx.getID()));
    this.genotypeTable.getColumns().add(makeColumn("REF", G -> G.ctx.getReference().getDisplayString()));
    this.genotypeTable.getColumns().add(makeColumn("ALT", G -> G.ctx.getAlternateAlleles().stream().map(A -> A.getDisplayString()).collect(Collectors.joining(","))));
    this.genotypeTable.getColumns().add(makeColumn("Sample", G -> G.g.getSampleName()));
    this.genotypeTable.getColumns().add(makeColumn("Type", G -> G.g.getType().name()));
    this.genotypeTable.getColumns().add(makeColumn("Alleles", G -> G.g.getAlleles().stream().map(A -> A.getDisplayString()).collect(Collectors.joining(","))));
    TableColumn<VariantAndGenotype, String> reviewCol = new TableColumn<>("Review");
    reviewCol.setCellValueFactory(C -> C.getValue().getReviewProperty());
    reviewCol.setCellFactory(TextFieldTableCell.forTableColumn());
    reviewCol.setOnEditCommit((E) -> {
        int y = E.getTablePosition().getRow();
        this.genotypeTable.getItems().get(y).setReview(E.getNewValue());
    });
    reviewCol.setEditable(true);
    this.genotypeTable.getColumns().add(reviewCol);
    this.genotypeTable.getSelectionModel().cellSelectionEnabledProperty().set(true);
    this.genotypeTable.setEditable(true);
    final ContextMenu cm = new ContextMenu();
    MenuItem mi1 = new MenuItem("Menu 1");
    cm.getItems().add(mi1);
    MenuItem mi2 = new MenuItem("Menu 2");
    cm.getItems().add(mi2);
    this.genotypeTable.setOnMousePressed(event -> {
        if (event.isPrimaryButtonDown() && (event.getClickCount() == 3 || event.isShiftDown())) {
            moveIgvTo(stage, genotypeTable.getSelectionModel().getSelectedItem());
        } else if (event.isSecondaryButtonDown()) {
            cm.show(genotypeTable, event.getScreenX(), event.getScreenY());
        }
    });
    final BorderPane pane2 = new BorderPane(this.genotypeTable);
    pane2.setPadding(new Insets(10, 10, 10, 10));
    VBox vbox1 = new VBox(bar, pane2);
    final Scene scene = new Scene(vbox1, 500, 300);
    stage.setScene(scene);
    stage.show();
}
Also used : JexlVariantPredicate(com.github.lindenb.jvarkit.util.vcf.JexlVariantPredicate) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VCFHeader(htsjdk.variant.vcf.VCFHeader) VariantContextWriterBuilder(htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder) VBox(javafx.scene.layout.VBox) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Application(javafx.application.Application) Vector(java.util.Vector) ContextMenu(javafx.scene.control.ContextMenu) IgvConstants(com.github.lindenb.jvarkit.util.igv.IgvConstants) Map(java.util.Map) TableView(javafx.scene.control.TableView) CloserUtil(htsjdk.samtools.util.CloserUtil) PrintWriter(java.io.PrintWriter) MenuItem(javafx.scene.control.MenuItem) GenotypeBuilder(htsjdk.variant.variantcontext.GenotypeBuilder) Predicate(java.util.function.Predicate) Logger(com.github.lindenb.jvarkit.util.log.Logger) Set(java.util.Set) Collectors(java.util.stream.Collectors) JvarkitException(com.github.lindenb.jvarkit.lang.JvarkitException) Platform(javafx.application.Platform) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) VariantContext(htsjdk.variant.variantcontext.VariantContext) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) SamReaderFactory(htsjdk.samtools.SamReaderFactory) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) Genotype(htsjdk.variant.variantcontext.Genotype) CloseableIterator(htsjdk.samtools.util.CloseableIterator) Scene(javafx.scene.Scene) Socket(java.net.Socket) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) BackingStoreException(java.util.prefs.BackingStoreException) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Function(java.util.function.Function) ValidationStringency(htsjdk.samtools.ValidationStringency) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) HashSet(java.util.HashSet) Insets(javafx.geometry.Insets) Launcher(com.github.lindenb.jvarkit.util.jcommander.Launcher) VCFHeaderLineType(htsjdk.variant.vcf.VCFHeaderLineType) MenuBar(javafx.scene.control.MenuBar) Files(java.nio.file.Files) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) IOException(java.io.IOException) SamReader(htsjdk.samtools.SamReader) InputStreamReader(java.io.InputStreamReader) File(java.io.File) Preferences(java.util.prefs.Preferences) Menu(javafx.scene.control.Menu) FileChooser(javafx.stage.FileChooser) Stage(javafx.stage.Stage) Closeable(java.io.Closeable) JfxUtils(com.github.lindenb.jvarkit.jfx.components.JfxUtils) VCFFormatHeaderLine(htsjdk.variant.vcf.VCFFormatHeaderLine) Window(javafx.stage.Window) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) BorderPane(javafx.scene.layout.BorderPane) Insets(javafx.geometry.Insets) SAMReadGroupRecord(htsjdk.samtools.SAMReadGroupRecord) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) VariantContext(htsjdk.variant.variantcontext.VariantContext) MenuBar(javafx.scene.control.MenuBar) ContextMenu(javafx.scene.control.ContextMenu) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) SamReader(htsjdk.samtools.SamReader) FileChooser(javafx.stage.FileChooser) ContextMenu(javafx.scene.control.ContextMenu) Menu(javafx.scene.control.Menu) SamReaderFactory(htsjdk.samtools.SamReaderFactory) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) Scene(javafx.scene.Scene) TableColumn(javafx.scene.control.TableColumn) JvarkitException(com.github.lindenb.jvarkit.lang.JvarkitException) BackingStoreException(java.util.prefs.BackingStoreException) IOException(java.io.IOException) SAMFileHeader(htsjdk.samtools.SAMFileHeader) File(java.io.File) VBox(javafx.scene.layout.VBox)

Aggregations

TableView (javafx.scene.control.TableView)70 TableColumn (javafx.scene.control.TableColumn)60 Map (java.util.Map)40 List (java.util.List)39 ArrayList (java.util.ArrayList)38 Button (javafx.scene.control.Button)38 Label (javafx.scene.control.Label)38 FXCollections (javafx.collections.FXCollections)37 Insets (javafx.geometry.Insets)36 Collectors (java.util.stream.Collectors)33 Scene (javafx.scene.Scene)33 Tab (javafx.scene.control.Tab)33 BorderPane (javafx.scene.layout.BorderPane)32 Optional (java.util.Optional)31 ObservableValue (javafx.beans.value.ObservableValue)30 VBox (javafx.scene.layout.VBox)29 Collections (java.util.Collections)28 MenuItem (javafx.scene.control.MenuItem)28 HashMap (java.util.HashMap)27 Set (java.util.Set)27