package com.ecep.contract.controller.table.cell;

import org.springframework.util.StringUtils;

import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.TableCell;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
public class CompanyFilePathTableCell<T> extends TableCell<T, String> {
    private SimpleStringProperty companyPathProperty;

    public void setCompanyPathProperty(SimpleStringProperty property) {
        this.companyPathProperty = property;
    }

    @Override
    protected void updateItem(String item, boolean empty) {
        super.updateItem(item, empty);
        if (empty || item == null) {
            setText("");
            return;
        }
        if (companyPathProperty != null) {
            String path = companyPathProperty.get();
            if (StringUtils.hasText(path)) {
                if (item.startsWith(path)) {
                    item = "~" + item.substring(path.length());
                }
            }
        }
        setText(item);
    }
}
