Search in sources :

Example 41 with Callback

use of javafx.util.Callback in project Gargoyle by callakrsos.

the class FxTableViewUtil method getDisplayText.

/**
	 * 테이블컬럼에서 화면에 보여주는 텍스트를 리턴한다.
	 * @작성자 : KYJ
	 * @작성일 : 2017. 3. 31. 
	 * @param tc
	 * @param row
	 * @return
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Object getDisplayText(TableColumn<?, ?> tc, int row) {
    Callback cellFactory = tc.getCellFactory();
    if (cellFactory != null) /*&& cellObservableValue != null*/
    {
        //			Object value = cellObservableValue.getValue();
        Object call = cellFactory.call(tc);
        if (call != null && call instanceof TableCell) {
            TableCell cell = (TableCell) call;
            StringConverter converter = null;
            if (cell instanceof TextFieldTableCell) {
                TextFieldTableCell txtCell = (TextFieldTableCell) cell;
                converter = txtCell.getConverter();
            } else //					} 
            if (cell instanceof ComboBoxTableCell) {
                ComboBoxTableCell txtCell = (ComboBoxTableCell) cell;
                converter = txtCell.getConverter();
            } else //					else if (cell instanceof HyperlinkTableCell) {
            //						HyperlinkTableCell txtCell = (HyperlinkTableCell) cell;
            //						converter = txtCell.getConverter();
            //					}
            /* else 기본값. */
            {
                try {
                    Method m = cell.getClass().getMethod("converterProperty");
                    if (m != null) {
                        Object object = m.invoke(cell);
                        if (object != null && object instanceof ObjectProperty) {
                            ObjectProperty<StringConverter> convert = (ObjectProperty<StringConverter>) object;
                            converter = convert.get();
                        }
                    }
                } catch (Exception e) {
                // Nothing...
                }
            }
            if (converter != null) {
                Object cellData = tc.getCellData(row);
                return converter.toString(cellData);
            }
        }
        return call;
    }
    return tc.getCellData(row);
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) Callback(javafx.util.Callback) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) TableCell(javafx.scene.control.TableCell) ComboBoxTableCell(javafx.scene.control.cell.ComboBoxTableCell) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Method(java.lang.reflect.Method) StringConverter(javafx.util.StringConverter) ComboBoxTableCell(javafx.scene.control.cell.ComboBoxTableCell)

Example 42 with Callback

use of javafx.util.Callback in project Gargoyle by callakrsos.

the class FxSVNHistoryDataSupplier method createHistoryListView.

public ListView<GargoyleSVNLogEntryPath> createHistoryListView(ObservableList<GargoyleSVNLogEntryPath> list) {
    ListView<GargoyleSVNLogEntryPath> listView = new ListView<GargoyleSVNLogEntryPath>(list);
    listView.setCellFactory(new Callback<ListView<GargoyleSVNLogEntryPath>, ListCell<GargoyleSVNLogEntryPath>>() {

        @Override
        public ListCell<GargoyleSVNLogEntryPath> call(ListView<GargoyleSVNLogEntryPath> param) {
            ListCell<GargoyleSVNLogEntryPath> listCell = new ListCell<GargoyleSVNLogEntryPath>() {

                /* (non-Javadoc)
					 * @see javafx.scene.control.Cell#updateItem(java.lang.Object, boolean)
					 */
                @Override
                protected void updateItem(GargoyleSVNLogEntryPath item, boolean empty) {
                    super.updateItem(item, empty);
                    if (empty) {
                        setText(null);
                    } else {
                        String type = "Modify";
                        switch(item.getType()) {
                            case GargoyleSVNLogEntryPath.TYPE_ADDED:
                                type = "Add";
                                break;
                            case GargoyleSVNLogEntryPath.TYPE_MODIFIED:
                                type = "Modify";
                                break;
                            case GargoyleSVNLogEntryPath.TYPE_REPLACED:
                                type = "Replace";
                                break;
                            case GargoyleSVNLogEntryPath.TYPE_DELETED:
                                type = "Delete";
                                break;
                        }
                        String path = item.getPath();
                        setText(String.format("Resivion :%d File : %s Date : %s Type : %s ", item.getCopyRevision(), path.substring(path.lastIndexOf("/")), YYYY_MM_DD_HH_MM_SS_PATTERN.format(item.getDate()), type));
                    }
                }
            };
            return listCell;
        }
    });
    listView.setPrefSize(600, ListView.USE_COMPUTED_SIZE);
    listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    listView.addEventHandler(MouseEvent.MOUSE_CLICKED, ev -> {
        ContextMenu contextMenu = null;
        ObservableList<GargoyleSVNLogEntryPath> selectedItems = listView.getSelectionModel().getSelectedItems();
        GargoyleSVNLogEntryPath selectedItem = null;
        if (selectedItems != null && !selectedItems.isEmpty()) {
            selectedItem = selectedItems.get(0);
        }
        if (ev.getClickCount() == 2 && ev.getButton() == MouseButton.PRIMARY) {
            if (selectedItem != null) {
                String path = selectedItem.getPath();
                long copyRevision = selectedItem.getCopyRevision();
                String rootUrl = getRootUrl();
                LOGGER.debug("{}", rootUrl);
                LOGGER.debug("Cat Command, Path : {} Revision {}", path, copyRevision);
                String content = "";
                VBox vBox = new VBox(5);
                if (isExists(path)) {
                    content = cat(path, String.valueOf(copyRevision));
                    List<SVNLogEntry> log = log(path, String.valueOf(copyRevision), ex -> {
                        LOGGER.error(ValueUtil.toString(ex));
                    });
                    if (ValueUtil.isNotEmpty(log)) {
                        SVNLogEntry svnLogEntry = log.get(0);
                        String apply = getManager().fromPrettySVNLogConverter().apply(svnLogEntry);
                        Label e = new Label(apply);
                        e.setStyle("-fx-text-fill:black");
                        vBox.getChildren().add(e);
                    }
                    vBox.getChildren().add(createJavaTextArea(content));
                } else {
                    content = "Does not exists. Repository. [Removed]";
                    Label e = new Label(content);
                    e.setStyle("-fx-text-fill:black");
                    vBox.getChildren().add(e);
                }
                FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), vBox);
            }
            ev.consume();
        } else if (ev.getClickCount() == 1 && ev.getButton() == MouseButton.SECONDARY) {
            ObservableList<MenuItem> menus = FXCollections.observableArrayList();
            MenuItem miHist = new MenuItem("History");
            miHist.setUserData(selectedItem);
            MenuItem miAllHist = new MenuItem("All History");
            MenuItem miDiff = new MenuItem("Diff");
            miDiff.setDisable(true);
            menus.add(miHist);
            menus.add(miAllHist);
            menus.add(new SeparatorMenuItem());
            menus.add(miDiff);
            if (selectedItems.size() == 2) {
                miDiff.setUserData(selectedItems);
                miDiff.setDisable(false);
            }
            miHist.setOnAction(event -> {
                GargoyleSVNLogEntryPath userData = (GargoyleSVNLogEntryPath) miHist.getUserData();
                if (userData == null)
                    return;
                FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), createHistoryListView(userData.getPath()));
            });
            miAllHist.setOnAction(event -> {
                GargoyleSVNLogEntryPath userData = (GargoyleSVNLogEntryPath) miHist.getUserData();
                if (userData == null)
                    return;
                String path = userData.getPath();
                try {
                    Collection<SVNLogEntry> allLogs = getManager().getAllLogs(path);
                    ObservableList<GargoyleSVNLogEntryPath> collect = createStream(allLogs).filter(v -> {
                        return path.equals(v.getPath());
                    }).collect(FxCollectors.toObservableList());
                    FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), createHistoryListView(collect));
                } catch (Exception e) {
                    LOGGER.error(ValueUtil.toString(e));
                }
            });
            miDiff.setOnAction(event -> {
                List<GargoyleSVNLogEntryPath> userData = (List<GargoyleSVNLogEntryPath>) miDiff.getUserData();
                if (userData == null && userData.size() != 2)
                    return;
                GargoyleSVNLogEntryPath gargoyleSVNLogEntryPath1 = userData.get(0);
                GargoyleSVNLogEntryPath gargoyleSVNLogEntryPath2 = userData.get(1);
                try {
                    String diff = diff(gargoyleSVNLogEntryPath1.getPath(), gargoyleSVNLogEntryPath1.getCopyRevision(), gargoyleSVNLogEntryPath2.getCopyRevision());
                    TextArea showingNode = new TextArea(diff);
                    showingNode.setPrefSize(600d, 800d);
                    FxUtil.showPopOver(ev.getPickResult().getIntersectedNode(), showingNode);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
            contextMenu = new ContextMenu(menus.stream().toArray(MenuItem[]::new));
            contextMenu.show(ev.getPickResult().getIntersectedNode(), ev.getScreenX(), ev.getScreenY());
        }
    });
    return listView;
}
Also used : Arrays(java.util.Arrays) MouseButton(javafx.scene.input.MouseButton) ListView(javafx.scene.control.ListView) TextArea(javafx.scene.control.TextArea) ListCell(javafx.scene.control.ListCell) MouseEvent(javafx.scene.input.MouseEvent) LoggerFactory(org.slf4j.LoggerFactory) JavaTextArea(com.kyj.fx.voeditor.visual.component.text.JavaTextArea) FXCollections(javafx.collections.FXCollections) JavaSVNManager(com.kyj.scm.manager.svn.java.JavaSVNManager) VBox(javafx.scene.layout.VBox) ContextMenu(javafx.scene.control.ContextMenu) Map(java.util.Map) FxCollectors(com.kyj.fx.voeditor.visual.util.FxCollectors) Callback(javafx.util.Callback) SVNLogEntryPath(org.tmatesoft.svn.core.SVNLogEntryPath) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) MenuItem(javafx.scene.control.MenuItem) Collection(java.util.Collection) SVNNodeKind(org.tmatesoft.svn.core.SVNNodeKind) Node(javafx.scene.Node) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Collectors(java.util.stream.Collectors) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) DateUtil(com.kyj.fx.voeditor.visual.util.DateUtil) ObservableList(javafx.collections.ObservableList) SVNLogEntry(org.tmatesoft.svn.core.SVNLogEntry) TextArea(javafx.scene.control.TextArea) JavaTextArea(com.kyj.fx.voeditor.visual.component.text.JavaTextArea) ListCell(javafx.scene.control.ListCell) Label(javafx.scene.control.Label) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) ListView(javafx.scene.control.ListView) ObservableList(javafx.collections.ObservableList) Collection(java.util.Collection) List(java.util.List) ObservableList(javafx.collections.ObservableList) VBox(javafx.scene.layout.VBox)

Example 43 with Callback

use of javafx.util.Callback in project Gargoyle by callakrsos.

the class AbstractTableColumnInformationController method initialize.

@FXML
public void initialize() {
    colNumber.setCellValueFactory(new NumberingCellValueFactory<TableColumnMetaVO>(tbColumns));
    colKeyType.setCellFactory(param -> new TableCell<TableColumnMetaVO, KEY_TYPE>() {

        @Override
        protected void updateItem(KEY_TYPE item, boolean empty) {
            super.updateItem(item, empty);
            if (empty) {
                setGraphic(null);
            } else {
                ImageView image = null;
                switch(item) {
                    case PRI:
                        image = getImage(PRIMAKRY_KEY_IMAGE_NAME);
                        image.setFitWidth(getPrefWidth());
                        setGraphic(image);
                        break;
                    case MULTI:
                        image = getImage(MULTI_KEY_IMAGE_NAME);
                        image.setFitWidth(getPrefWidth());
                        setGraphic(image);
                        break;
                    case FOREIGN:
                        image = getImage(FOREIGN_KEY_IMAGE_NAME);
                        image.setFitWidth(getPrefWidth());
                        setGraphic(image);
                        break;
                    default:
                        image = new ImageView();
                }
                setGraphic(image);
            }
        }
    });
    colReference.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<TableColumnMetaVO, String>, ObservableValue<String>>() {

        @Override
        public ObservableValue<String> call(CellDataFeatures<TableColumnMetaVO, String> param) {
            TableColumnMetaVO value = param.getValue();
            SimpleStringProperty stringProperty = new SimpleStringProperty();
            if (value != null && value.getRefs() != null) {
                Optional<String> reduce = value.getRefs().stream().map(v -> v.getPkColumnName() + " ->  [ " + v.getFkTableName() + "-" + v.getFkColumnName() + " ]").reduce((str1, str2) -> str1.concat("\n").concat(str2));
                reduce.ifPresent(stringProperty::setValue);
            }
            return stringProperty;
        }
    });
    colKeyType.setCellValueFactory(new PropertyValueFactory<>("keyType"));
    colKeyType.setStyle("-fx-alignment:center");
    this.tbColumns.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    FxUtil.installClipboardKeyEvent(this.tbColumns);
}
Also used : KEY_TYPE(com.kyj.fx.voeditor.visual.component.sql.table.IKeyType.KEY_TYPE) NumberingCellValueFactory(com.kyj.fx.voeditor.visual.component.NumberingCellValueFactory) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) LoggerFactory(org.slf4j.LoggerFactory) DatabaseMetaData(java.sql.DatabaseMetaData) Function(java.util.function.Function) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) SQLException(java.sql.SQLException) TableCell(javafx.scene.control.TableCell) ResultSet(java.sql.ResultSet) Map(java.util.Map) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Logger(org.slf4j.Logger) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Set(java.util.Set) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) Collectors(java.util.stream.Collectors) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) FXML(javafx.fxml.FXML) FxUtil(com.kyj.fx.voeditor.visual.util.FxUtil) List(java.util.List) SelectionMode(javafx.scene.control.SelectionMode) TreeMap(java.util.TreeMap) ImageView(javafx.scene.image.ImageView) RowMapper(org.springframework.jdbc.core.RowMapper) Optional(java.util.Optional) ObservableValue(javafx.beans.value.ObservableValue) Collections(java.util.Collections) Image(javafx.scene.image.Image) InputStream(java.io.InputStream) CellDataFeatures(javafx.scene.control.TableColumn.CellDataFeatures) Optional(java.util.Optional) ObservableValue(javafx.beans.value.ObservableValue) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) ImageView(javafx.scene.image.ImageView) KEY_TYPE(com.kyj.fx.voeditor.visual.component.sql.table.IKeyType.KEY_TYPE) FXML(javafx.fxml.FXML)

Aggregations

Callback (javafx.util.Callback)43 Inject (javax.inject.Inject)27 FxmlView (io.bitsquare.gui.common.view.FxmlView)26 javafx.scene.control (javafx.scene.control)25 Popup (io.bitsquare.gui.main.overlays.popups.Popup)24 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)23 ObservableList (javafx.collections.ObservableList)22 FXML (javafx.fxml.FXML)22 VBox (javafx.scene.layout.VBox)21 HyperlinkWithIcon (io.bitsquare.gui.components.HyperlinkWithIcon)20 BSFormatter (io.bitsquare.gui.util.BSFormatter)20 SortedList (javafx.collections.transformation.SortedList)19 ImageView (javafx.scene.image.ImageView)18 ChangeListener (javafx.beans.value.ChangeListener)17 GUIUtil (io.bitsquare.gui.util.GUIUtil)16 FXCollections (javafx.collections.FXCollections)16 Insets (javafx.geometry.Insets)15 AwesomeIcon (de.jensd.fx.fontawesome.AwesomeIcon)13 UserThread (io.bitsquare.common.UserThread)13 ActivatableView (io.bitsquare.gui.common.view.ActivatableView)13