use of javafx.collections.ObservableList in project Gargoyle by callakrsos.
the class GagoyleSpreadSheetView method paste.
/**
* 특수문자에대한 문자열 paste에 대한 버그를 수정하기 위한 함수.
* @작성자 : KYJ
* @작성일 : 2016. 11. 23.
* @param items
* @param startRowIndex
* @param startColumnIndex
*/
public void paste(List<Map<String, Object>> items, int startRowIndex, int startColumnIndex) {
int row = startRowIndex;
int column = startColumnIndex;
int _column = column;
// String[] split = pastString.split("\n");
Grid grid = ssv.getGrid();
ObservableList<ObservableList<SpreadsheetCell>> rows = grid.getRows();
for (Map<String, Object> str : items) {
// String[] split2 = str.split("\t");
_column = column;
Iterator<String> iterator = str.keySet().iterator();
while (iterator.hasNext()) {
String strCol = iterator.next();
Object value = str.get(strCol);
SpreadsheetCell spreadsheetCell = null;
if (rows.size() > row) {
ObservableList<SpreadsheetCell> observableList = rows.get(row);
try {
spreadsheetCell = observableList.get(_column);
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}
} else /* 새로운 로우를 생성함. */
{
ObservableList<SpreadsheetCell> newCells = createNewRow();
spreadsheetCell = newCells.get(_column);
}
if (value != null)
value = value.toString();
spreadsheetCell.setItem(value);
_column++;
}
row++;
}
}
use of javafx.collections.ObservableList in project Gargoyle by callakrsos.
the class DaoWizardViewController method menuToVoEditorOnAction.
/********************************
* 작성일 : 2016. 2. 27. 작성자 : KYJ
*
* 내용 : VO에티터로 결과내용을 전달처리한다.
*******************************/
public void menuToVoEditorOnAction(ActionEvent e) {
ObservableList<TbpSysDaoColumnsDVO> items = tbMappings.getItems();
if (items.isEmpty())
return;
DatabaseTypeMappingFunction typeConverter = new DatabaseTypeMappingFunction();
try {
FXMLLoader loader = FxUtil.createNewFxmlLoader();
loader.setLocation(getClass().getResource("VoEditorView.fxml"));
BorderPane root = loader.load();
VoEditorController controller = loader.getController();
List<TableModelDVO> resultItems = items.stream().map(m -> {
TableModelDVO dvo = new TableModelDVO();
dvo.setName(ValueUtil.getPrefixLowerTextMyEdit(m.getColumnName()));
String programType = m.getProgramType();
if (programType == null || programType.isEmpty()) {
programType = typeConverter.apply(m.getColumnType());
}
dvo.setType(programType);
return dvo;
}).collect(Collectors.toList());
controller.addItem(resultItems);
SharedMemory.getSystemLayoutViewController().loadNewSystemTab("New VO", root);
} catch (IOException e1) {
LOGGER.error(ValueUtil.toString(e1));
}
}
use of javafx.collections.ObservableList in project Gargoyle by callakrsos.
the class SchoolMgrerSpreadSheetView method miSaveAsOnAction.
/**
* 파일 저장 처리.
* @작성자 : KYJ
* @작성일 : 2016. 12. 27.
* @param event
*/
public void miSaveAsOnAction(ActionEvent event) {
File saveFile = DialogUtil.showFileSaveCheckDialog(getScene().getWindow(), chooser -> {
chooser.getExtensionFilters().add(new ExtensionFilter(GargoyleExtensionFilters.XLSX_NAME, GargoyleExtensionFilters.XLSX));
});
if (saveFile != null) {
ThreadUtil.createNewThreadAndRun(() -> {
try (Workbook workBookXlsx = ExcelUtil.createNewWorkBookXlsx()) {
Sheet createSheet = workBookXlsx.createSheet("Sheet1");
ObservableList<ObservableList<SpreadsheetCell>> rows = gagoyleSpreadSheetView.getRows();
IntStream.iterate(0, r -> r + 1).limit(rows.size()).forEach(rIndex -> {
ObservableList<SpreadsheetCell> cellList = rows.get(rIndex);
IntStream.iterate(0, a -> a + 1).limit(cellList.size()).forEach(cidx -> {
SpreadsheetCell spreadsheetCell = cellList.get(cidx);
String text = spreadsheetCell.getText();
try {
ExcelUtil.createCell(createSheet, text, rIndex, cidx);
} catch (Exception e1) {
e1.printStackTrace();
}
});
});
workBookXlsx.write(new FileOutputStream(saveFile));
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
use of javafx.collections.ObservableList in project Gargoyle by callakrsos.
the class VoEditorController method initialize.
/**
* 이벤트 초기화
*
* @작성자 : KYJ
* @작성일 : 2015. 10. 15.
*/
@FXML
public void initialize() {
colType.setCellFactory(new ClassTypeCheckBoxCellFactory());
colName.setCellFactory(TextFieldTableCell.forTableColumn());
colSize.setCellFactory(TextFieldTableCell.forTableColumn());
colDesc.setCellFactory(TextFieldTableCell.forTableColumn());
CommonsContextMenu.addMenus(tbVoEditor, (Menus.useCudButtons() | Menus.UP | Menus.DOWN));
// tbVoEditor.setContextMenu();
tbVoEditor.addEventHandler(ActionEvent.ACTION, event -> {
if (event instanceof CommonContextMenuEvent) {
CommonContextMenuEvent _event = (CommonContextMenuEvent) event;
int mode = _event.getMode();
ObservableList<TableModelDVO> items = tbVoEditor.getItems();
int selectedIndex = tbVoEditor.getSelectionModel().getSelectedIndex();
int rowSize = items.size();
boolean isMove = false;
if (Menus.isAdd(mode)) {
items.add(defaultTableModelDVO());
isMove = true;
} else if (Menus.isDelete(mode)) {
items.remove(selectedIndex);
isMove = true;
} else if (Menus.isUp(mode)) {
btnUpOnMouseClick();
} else if (Menus.isDown(mode)) {
btnDownOnMouseClick();
}
if (isMove) {
tbVoEditor.getSelectionModel().select(rowSize - 1);
}
}
});
// 컨트롤 키를 누르면 그리드 데이터 이동처리.
tbVoEditor.setOnKeyPressed(event -> {
if (event.isControlDown()) {
KeyCode code = event.getCode();
switch(code) {
case UP:
btnUpOnMouseClick();
break;
case DOWN:
btnDownOnMouseClick();
break;
default:
break;
}
event.consume();
}
});
btnGenerate.addEventHandler(MouseEvent.MOUSE_CLICKED, this::btnGenerateOnMouseClick);
btnSelect.setOnMouseClicked(this::btnSelectOnMouseClick);
btnDatabase.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
DatabaseTableView databaseTableView = new DatabaseTableView();
TableDVO show = databaseTableView.show();
if (show != null) {
TableMasterDVO tableMasterDVO = show.getTableMasterDVO();
List<TableModelDVO> tableModelDVOList = show.getTableModelDVOList();
ObservableList<TableModelDVO> items = tbVoEditor.getItems();
if (tableMasterDVO != null) {
txtClassName.setText(tableMasterDVO.getClassName());
txtAreaDesc.setText(tableMasterDVO.getDescription());
}
if (tableModelDVOList != null) {
items.clear();
items.addAll(tableModelDVOList);
}
}
}
});
}
use of javafx.collections.ObservableList in project bitsquare by bitsquare.
the class SpreadViewModel method update.
private void update(ObservableList<OfferBookListItem> offerBookListItems) {
Map<String, List<Offer>> offersByCurrencyMap = new HashMap<>();
for (OfferBookListItem offerBookListItem : offerBookListItems) {
Offer offer = offerBookListItem.getOffer();
String currencyCode = offer.getCurrencyCode();
if (!offersByCurrencyMap.containsKey(currencyCode))
offersByCurrencyMap.put(currencyCode, new ArrayList<>());
offersByCurrencyMap.get(currencyCode).add(offer);
}
spreadItems.clear();
for (String currencyCode : offersByCurrencyMap.keySet()) {
List<Offer> offers = offersByCurrencyMap.get(currencyCode);
List<Offer> buyOffers = offers.stream().filter(e -> e.getDirection().equals(Offer.Direction.BUY)).sorted((o1, o2) -> {
long a = o1.getPrice() != null ? o1.getPrice().value : 0;
long b = o2.getPrice() != null ? o2.getPrice().value : 0;
if (a != b)
return a < b ? 1 : -1;
return 0;
}).collect(Collectors.toList());
List<Offer> sellOffers = offers.stream().filter(e -> e.getDirection().equals(Offer.Direction.SELL)).sorted((o1, o2) -> {
long a = o1.getPrice() != null ? o1.getPrice().value : 0;
long b = o2.getPrice() != null ? o2.getPrice().value : 0;
if (a != b)
return a > b ? 1 : -1;
return 0;
}).collect(Collectors.toList());
Fiat spread = null;
String percentage = "";
Fiat bestSellOfferPrice = sellOffers.isEmpty() ? null : sellOffers.get(0).getPrice();
Fiat bestBuyOfferPrice = buyOffers.isEmpty() ? null : buyOffers.get(0).getPrice();
if (bestBuyOfferPrice != null && bestSellOfferPrice != null) {
MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode);
// happens again
try {
spread = bestSellOfferPrice.subtract(bestBuyOfferPrice);
if (spread != null && marketPrice != null) {
double marketPriceAsDouble = marketPrice.getPrice(PriceFeedService.Type.LAST);
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
double result = ((double) spread.value / 10000D) / marketPriceAsDouble;
percentage = " (" + formatter.formatPercentagePrice(result) + ")";
} else {
final double spreadAsDouble = spread.value != 0 ? 10000D / spread.value : 0;
double result = marketPriceAsDouble / spreadAsDouble;
percentage = " (" + formatter.formatPercentagePrice(result) + ")";
}
}
} catch (Throwable t) {
try {
String msg = "An error occurred at the spread calculation.\n" + "Error msg: " + t.toString() + "\n" + "Details of offer data: \n" + "bestSellOfferPrice: " + bestSellOfferPrice.value + "\n" + "bestBuyOfferPrice: " + bestBuyOfferPrice.value + "\n" + "sellOffer getCurrencyCode: " + sellOffers.get(0).getCurrencyCode() + "\n" + "buyOffer getCurrencyCode: " + buyOffers.get(0).getCurrencyCode() + "\n\n" + "Please copy and paste this data and send it to the developers so they can investigate the issue.";
new Popup().error(msg).show();
log.error(t.toString());
t.printStackTrace();
} catch (Throwable t2) {
log.error(t2.toString());
t2.printStackTrace();
}
}
}
Coin totalAmount = Coin.valueOf(offers.stream().mapToLong(offer -> offer.getAmount().getValue()).sum());
spreadItems.add(new SpreadItem(currencyCode, buyOffers.size(), sellOffers.size(), offers.size(), spread, percentage, totalAmount));
}
}
Aggregations