package com.celertech.web.orderrouting.client; import java.util.Comparator; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Scene; import javafx.scene.control.SelectionMode; import javafx.scene.control.TableColumn; import javafx.scene.control.TableColumn.SortType; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.stage.Stage; import com.celertech.web.orderrouting.client.desktop.trading.staticdata.view.ExchangesEventList; import com.sun.javafx.collections.ObservableListWrapper; public class TestApplication extends Application { private TableView exchangesTable = new TableView(); private ExchangesTestEventList exchangesTestEventList = new ExchangesTestEventList(); static ObservableList data = FXCollections.observableArrayList(); @Override public void start(final Stage stage) throws Exception { final VBox rootPane = new VBox(); rootPane.getChildren().add(exchangesTable); TableColumn exchangeFlagCol = new TableColumn(""); exchangeFlagCol.setCellValueFactory(new PropertyValueFactory("id")); exchangeFlagCol.setMaxWidth(50); TableColumn exchangeCol = new TableColumn("Exchange"); exchangeCol.setCellValueFactory(new PropertyValueFactory("name")); exchangeCol.setSortType(SortType.DESCENDING); TableColumn descCol = new TableColumn("Description"); descCol.setCellValueFactory(new PropertyValueFactory("description")); descCol.setPrefWidth(250); descCol.setSortType(SortType.DESCENDING); this.exchangesTable.setPrefWidth(200); this.exchangesTable.setItems(this.exchangesTestEventList); this.exchangesTable.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); this.exchangesTable.getColumns().addAll(exchangeFlagCol, exchangeCol, descCol); this.exchangesTable.getSortOrder().add(exchangeCol); Scene scene = new Scene(rootPane, 600, 400, Color.WHITE); stage.setResizable(true); stage.setScene(scene); stage.show(); initData(); } private void initData() { for (int i = 0; i < 50; i++) { this.exchangesTestEventList.add(new ExchangeDataEvent(+i, "CME", "CME EXCHANGE", true)); this.exchangesTestEventList.add(new ExchangeDataEvent(+i, "SFE", "SFE EXCHANGE", true)); this.exchangesTestEventList.add(new ExchangeDataEvent(+i, "LSE", "SLE MARKETS EXCHNAGE", true)); this.exchangesTestEventList.add(new ExchangeDataEvent(+i, "NYSE", "NEW YORK", true)); this.exchangesTestEventList.add(new ExchangeDataEvent(+i, "KSE", "KKOREA", true)); } } public static void main(String[] args) { Application.launch(TestApplication.class, args); } class ExchangesTestEventList extends ObservableListWrapper { /** * Creates a new instance of {@link ExchangesEventList}. */ public ExchangesTestEventList() { super(data); } /** * Adds a new data record to the market data list * @param event */ public final void addMarketDataEvent(ExchangeDataEvent event) { data.add(event); this.sort(new MovieComparator()); // this.sort(); } class MovieComparator implements Comparator{ @Override public int compare(ExchangeDataEvent ex1, ExchangeDataEvent ex2) { if(ex1.getName().equals(ex2.getName())) { return 1; } if(!ex1.getName().equals(ex2.getName())) { return 0; } return -1; } } } public class ExchangeDataEvent { private final String name; private final String description; private final boolean enabled; private final long id; public ExchangeDataEvent(long id, String name, String description, boolean enabled) { this.id = id; this.name = name; this.description = description; this.enabled = enabled; } public long getId() { return this.id; } public String getName() { return this.name; } public String getDescription() { return this.description; } public boolean isEnabled() { return this.enabled; } } }