javafx.scene.control.cell.ComboBoxTableCell Java Examples

The following examples show how to use javafx.scene.control.cell.ComboBoxTableCell. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RFXTableViewComboBoxTableCell.java    From marathonv5 with Apache License 2.0 7 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void select() {
    TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        Point2D point = getPoint(tableView, 2, 1);
        ComboBoxTableCell cell = (ComboBoxTableCell) getCellAt(tableView, 1, 2);
        RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
        rfxTableView.focusGained(null);
        cell.startEdit();
        tableView.edit(1, (TableColumn) tableView.getColumns().get(2));
        Person person = (Person) tableView.getItems().get(1);
        person.setLastName("Jones");
        cell.commitEdit("Jones");
        rfxTableView.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Jones", recording.getParameters()[0]);
}
 
Example #2
Source File: RFXTableViewComboBoxTableCell.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void selectEditable() {
    TableView<?> tableView = (TableView<?>) getPrimaryStage().getScene().getRoot().lookup(".table-view");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        Point2D point = getPoint(tableView, 2, 1);
        ComboBoxTableCell cell = (ComboBoxTableCell) getCellAt(tableView, 1, 2);
        cell.setEditable(true);
        RFXTableView rfxTableView = new RFXTableView(tableView, null, point, lr);
        rfxTableView.focusGained(null);
        cell.startEdit();
        tableView.edit(1, (TableColumn) tableView.getColumns().get(2));
        Person person = (Person) tableView.getItems().get(1);
        person.setLastName("Jones");
        cell.commitEdit("Jones");
        rfxTableView.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("Jones", recording.getParameters()[0]);
}
 
Example #3
Source File: StatisticalQueryGroupAndSortController.java    From arcgis-runtime-samples-java with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the Order By table view. Configures the table columns to show the correct field values and allow the
 * sort order of each field to be changed with a ComboBox.
 */
private void initializeOrderByTableView() {
  // make the table columns stretch to fill the width of the table
  orderByTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

  // show the field name and sort order values in the column cells
  orderByFieldNameTableColumn.setCellValueFactory(cellData -> cellData.getValue().fieldNameProperty());
  orderBySortOrderTableColumn.setCellValueFactory(cellData -> cellData.getValue().sortOrderProperty());

  // show an editable ComboBox in the sort order column cells to change the sort order
  orderBySortOrderTableColumn.setCellFactory(col -> {
    ComboBoxTableCell<OrderByField, QueryParameters.SortOrder> ct = new ComboBoxTableCell<>();
    ct.getItems().addAll(QueryParameters.SortOrder.values());
    ct.setEditable(true);
    return ct;
  });

  // switch to edit mode when the user selects the Sort Order column
  orderByTableView.getSelectionModel().selectedItemProperty().addListener(e -> {
    List<TablePosition> tablePositions = orderByTableView.getSelectionModel().getSelectedCells();
    if (!tablePositions.isEmpty()) {
      tablePositions.forEach(tp -> orderByTableView.edit(tp.getRow(), orderBySortOrderTableColumn));
    }
  });
}
 
Example #4
Source File: JavaFXElementFactory.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static void reset() {
    add(Node.class, JavaFXElement.class);
    add(TextInputControl.class, JavaFXTextInputControlElement.class);
    add(HTMLEditor.class, JavaFXHTMLEditor.class);
    add(CheckBox.class, JavaFXCheckBoxElement.class);
    add(ToggleButton.class, JavaFXToggleButtonElement.class);
    add(Slider.class, JavaFXSliderElement.class);
    add(Spinner.class, JavaFXSpinnerElement.class);
    add(SplitPane.class, JavaFXSplitPaneElement.class);
    add(ProgressBar.class, JavaFXProgressBarElement.class);
    add(ChoiceBox.class, JavaFXChoiceBoxElement.class);
    add(ColorPicker.class, JavaFXColorPickerElement.class);
    add(ComboBox.class, JavaFXComboBoxElement.class);
    add(DatePicker.class, JavaFXDatePickerElement.class);
    add(TabPane.class, JavaFXTabPaneElement.class);
    add(ListView.class, JavaFXListViewElement.class);
    add(TreeView.class, JavaFXTreeViewElement.class);
    add(TableView.class, JavaFXTableViewElement.class);
    add(TreeTableView.class, JavaFXTreeTableViewElement.class);
    add(CheckBoxListCell.class, JavaFXCheckBoxListCellElement.class);
    add(ChoiceBoxListCell.class, JavaFXChoiceBoxCellElement.class);
    add(ComboBoxListCell.class, JavaFXComboBoxCellElement.class);
    add(CheckBoxTreeCell.class, JavaFXCheckBoxTreeCellElement.class);
    add(ChoiceBoxTreeCell.class, JavaFXChoiceBoxCellElement.class);
    add(ComboBoxTreeCell.class, JavaFXComboBoxCellElement.class);
    add(TableCell.class, JavaFXTableViewCellElement.class);
    add(CheckBoxTableCell.class, JavaFXCheckBoxTableCellElement.class);
    add(ChoiceBoxTableCell.class, JavaFXChoiceBoxCellElement.class);
    add(ComboBoxTableCell.class, JavaFXComboBoxCellElement.class);
    add(TreeTableCell.class, JavaFXTreeTableCellElement.class);
    add(CheckBoxTreeTableCell.class, JavaFXCheckBoxTreeTableCell.class);
    add(ChoiceBoxTreeTableCell.class, JavaFXChoiceBoxCellElement.class);
    add(ComboBoxTreeTableCell.class, JavaFXComboBoxCellElement.class);
    add(WebView.class, JavaFXWebViewElement.class);
    add(GenericStyledArea.GENERIC_STYLED_AREA_CLASS, RichTextFXGenericStyledAreaElement.class);
}
 
Example #5
Source File: JavaFXComboBoxCellElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
private StringConverter getConverter() {
    if (node instanceof ComboBoxListCell<?>) {
        return ((ComboBoxListCell) node).getConverter();
    } else if (node instanceof ComboBoxTableCell<?, ?>)
        return ((ComboBoxTableCell) node).getConverter();
    else if (node instanceof ComboBoxTreeCell<?>)
        return ((ComboBoxTreeCell) node).getConverter();
    else if (node instanceof ComboBoxTreeTableCell<?, ?>)
        return ((ComboBoxTreeTableCell) node).getConverter();
    return null;
}
 
Example #6
Source File: RFXComboBoxTableCell.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public String _getValue() {
    @SuppressWarnings("rawtypes")
    ComboBoxTableCell cell = (ComboBoxTableCell) node;
    return cell.getConverter().toString(cell.getItem());
}
 
Example #7
Source File: ProjectsPresenter.java    From spring-labs with Apache License 2.0 5 votes vote down vote up
private void configureTasksTable() {

		taskNameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
		taskDescriptionColumn.setCellValueFactory(new PropertyValueFactory<>("description"));

		taskStatusColumn.setCellValueFactory(new PropertyValueFactory<>("status"));
		taskStatusColumn.setCellFactory(ComboBoxTableCell.forTableColumn(Task.Status.values()));

		taskStatusColumn.setOnEditCommit(edit -> {
			edit.getRowValue().setStatus(edit.getNewValue());
			projectTrackingService.save(edit.getRowValue());
		});
	}
 
Example #8
Source File: ProjectsController.java    From spring-labs with Apache License 2.0 5 votes vote down vote up
private void configureTasksTable() {

		taskNameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
		taskDescriptionColumn.setCellValueFactory(new PropertyValueFactory<>("description"));

		taskStatusColumn.setCellValueFactory(new PropertyValueFactory<>("status"));
		taskStatusColumn.setCellFactory(ComboBoxTableCell.forTableColumn(Task.Status.values()));

		taskStatusColumn.setOnEditCommit(edit -> {
			edit.getRowValue().setStatus(edit.getNewValue());
			projectTrackingService.save(edit.getRowValue());
		});
	}
 
Example #9
Source File: ObjectTableView.java    From OpenLabeler with Apache License 2.0 4 votes vote down vote up
public ObjectTableView() {
    super(null);
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/ObjectTableView.fxml"), bundle);
    loader.setRoot(this);
    loader.setController(this);

    try {
        loader.load();
    }
    catch (Exception ex) {
        LOG.log(Level.SEVERE, "Unable to load FXML", ex);
    }

    getSelectionModel().setSelectionMode(SelectionMode.SINGLE);

    showAllCheckBox.setAllowIndeterminate(true);

    visibleColumn.setCellFactory(CheckBoxTableCell.forTableColumn(visibleColumn));
    visibleColumn.setCellValueFactory(cell -> cell.getValue().visibleProperty());

    thumbColumn.setCellFactory(param -> new ImageViewTableCell<>());
    thumbColumn.setCellValueFactory(cell -> cell.getValue().thumbProperty());

    List<String> names = IteratorUtils.toList(Settings.recentNamesProperty.stream().map(NameColor::getName).iterator());
    nameColumn.setCellFactory(ComboBoxTableCell.forTableColumn(FXCollections.observableList(names)));
    nameColumn.setCellValueFactory(cell -> cell.getValue().nameProperty());

    itemsProperty().addListener((observable, oldValue, newValue) -> {
        ObservableList<ObservableValue<Boolean>> visibles = EasyBind.map(newValue, ObjectTag::visibleProperty);
        visibleCount = EasyBind.combine(visibles, stream -> stream.filter(b -> b).count());
        visibleCount.addListener((obs, oldCount, newCount) -> {
            if (newCount == 0) {
                showAllCheckBox.setIndeterminate(false);
                showAllCheckBox.setSelected(false);
            }
            else if (newCount < getItems().size()) {
                showAllCheckBox.setIndeterminate(true);
            }
            else {
                showAllCheckBox.setIndeterminate(false);
                showAllCheckBox.setSelected(true);
            }
        });
    });
}
 
Example #10
Source File: SQLColumnSettingsComponent.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public SQLColumnSettingsComponent() {
    columnsTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    value = new SQLColumnSettings();
    TableColumn<SQLRowObject,String> columnName=new TableColumn<SQLRowObject,String> (value.getColumnName(0));
    TableColumn<SQLRowObject,SQLExportDataType>  columnType=new TableColumn<SQLRowObject,SQLExportDataType> (value.getColumnName(1));
    TableColumn<SQLRowObject,String>  columnValue= new TableColumn<SQLRowObject,String> (value.getColumnName(2));

    columnName.setCellValueFactory(new PropertyValueFactory<>("Name")); //this is needed during connection to a database
    columnType.setCellValueFactory(new PropertyValueFactory<>("Type"));
    columnValue.setCellValueFactory(new PropertyValueFactory<>("Value"));

    columnsTable.getColumns().addAll(columnName,columnType,columnValue);  //added all the columns in the table
    setValue(value);
    columnsTable.setStyle("-fx-selection-bar: #3399FF; -fx-selection-bar-non-focused: #E3E3E3;"); //CSS color change on selection of row


    columnsTable.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    columnName.setSortable(false);
    columnValue.setSortable(false);
    columnType.setSortable(false);

    columnName.setReorderable(false);
    columnValue.setReorderable(false);
    columnType.setReorderable(false);

    columnsTable.setPrefSize(550, 220);
    columnsTable.setFixedCellSize(columnsTable.getFixedCellSize()+20);
    columnsTable.setStyle("-fx-font: 10 \"Plain\"");

    //Setting action event on cells
    columnsTable.getSelectionModel().setCellSelectionEnabled(true);  //individual cell selection enabled
    columnsTable.setEditable(true);

    //Editors on each cell
  columnName.setCellFactory(TextFieldTableCell.<SQLRowObject>forTableColumn());
  columnName.setOnEditCommit(event -> {
    getValue().setValueAt(event.getNewValue(), event.getTablePosition().getRow(), 0);
    setValue(getValue()); //refresh the table
  });

  columnValue.setCellFactory(TextFieldTableCell.<SQLRowObject>forTableColumn());
  columnValue.setOnEditCommit(event -> {
    getValue().setValueAt(event.getNewValue().toUpperCase(), event.getTablePosition().getRow(), 2);
    setValue(getValue()); //refresh the table
  });

  ArrayList<SQLExportDataType> exportDataTypeValues=new ArrayList<SQLExportDataType>(Arrays.asList(SQLExportDataType.values()));

  columnType.setCellFactory(ComboBoxTableCell.forTableColumn(FXCollections.observableArrayList(SQLExportDataType.values())));
  columnType.setOnEditCommit(event -> {
    boolean selected = event.getNewValue().isSelectableValue();
    if(!selected){ //case of  invalid(Title) datatype selection
      getValue().setValueAt(exportDataTypeValues.get(exportDataTypeValues.indexOf(event.getNewValue())+1),event.getTablePosition().getRow(),1);
    }
    else {
      getValue().setValueAt(event.getNewValue(), event.getTablePosition().getRow(), 1);
    }
    setValue(getValue());
  });

    // Add buttons
    VBox buttonsPanel=new VBox(20);
    addColumnButton=new Button("Add");
    removeColumnButton=new Button("Remove");
    addColumnButton.setOnAction(this::actionPerformed);
    removeColumnButton.setOnAction(this::actionPerformed);
    buttonsPanel.getChildren().addAll(addColumnButton,removeColumnButton);


    this.setRight(buttonsPanel);
    this.setCenter(columnsTable);
    BorderPane.setMargin(buttonsPanel, new Insets(10));

}
 
Example #11
Source File: WatchlistController.java    From Noexes with GNU General Public License v3.0 4 votes vote down vote up
@FXML
public void initialize() {
    updateCol.setCellValueFactory(param -> param.getValue().updateProperty());
    lockedCol.setCellValueFactory(param -> param.getValue().lockedProperty());
    typeCol.setCellValueFactory(param -> param.getValue().typeProperty());
    addrCol.setCellValueFactory(param -> param.getValue().addrProperty());
    descCol.setCellValueFactory(param -> param.getValue().descProperty());
    valueCol.setCellValueFactory(param -> param.getValue().valueProperty());

    updateCol.setCellFactory(param -> new CheckBoxTableCell<>());
    lockedCol.setCellFactory(param -> new CheckBoxTableCell<>());
    typeCol.setCellFactory(param -> new ComboBoxTableCell<>(DataType.values()) {
        {
            setItem(DataType.INT);
        }
    });
    addrCol.setCellFactory(TextFieldTableCell.forTableColumn());
    descCol.setCellFactory(TextFieldTableCell.forTableColumn());
    valueCol.setCellFactory(param -> new SpinnerTableCell<>(valueCol, new HexSpinner() {
                {
                    setEditable(true);
                    setSize(16);
                }
            }) {
                @Override
                protected void updateItem(Long item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item == null || empty) {
                        return;
                    }
                    WatchlistModel model = getTableRow().getItem();
                    if (model == null) {
                        return;
                    }
                    getSpinner().setSize(model.getSize() * 2);
                }
            }
    );

    watchlistTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> removeButton.setDisable(newValue == null));
}
 
Example #12
Source File: TableViewCombo.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void init() {
        TableColumn<SettlementBase, String> nameCol = new TableColumn<>(headers[0]);
        nameCol.setCellValueFactory(cellData -> cellData.getValue().nameProperty());
        //nameCol.setCellFactory(TextFieldTableCell.forTableColumn());
        nameCol = setCellFactory(nameCol);
        nameCol.setMinWidth(150);

        templateCol = new TableColumn<>(headers[1]);
        templateCol.setCellValueFactory(cellData -> cellData.getValue().templateProperty());
        templateCol.setCellFactory(ComboBoxTableCell.forTableColumn(
        		templates.get(0).getTemplateName(),
        		templates.get(1).getTemplateName(),
        		templates.get(2).getTemplateName(),
        		templates.get(3).getTemplateName(),
        		templates.get(4).getTemplateName(),
        		templates.get(5).getTemplateName()));
        templateCol.setMinWidth(250);

        settlerCol = new TableColumn<>(headers[2]);
        settlerCol.setCellValueFactory(cellData -> cellData.getValue().settlerProperty());
        //settlerCol.setCellFactory(TextFieldTableCell.forTableColumn());
        settlerCol = setCellFactory(settlerCol);
        settlerCol.setMinWidth(50);

        //private ValidationSupport validationSupport = new ValidationSupport();
		//validationSupport.registerValidator(TextField, Validator.createEmptyValidator("Text is required"));

        botCol = new TableColumn<>(headers[3]);
        botCol.setCellValueFactory(cellData -> cellData.getValue().botProperty());
        //botCol.setCellFactory(TextFieldTableCell.forTableColumn());
        botCol = setCellFactory(botCol);
        botCol.setMinWidth(50);

        TableColumn<SettlementBase, String> sponsorCol = new TableColumn<>(headers[4]);
        sponsorCol.setCellValueFactory(cellData -> cellData.getValue().sponsorProperty());
        sponsorCol.setCellFactory(ComboBoxTableCell.forTableColumn(
        		SPONSORS[0].toString(),
        		SPONSORS[1].toString(),
        		SPONSORS[2].toString(),
        		SPONSORS[3].toString(),
        		SPONSORS[4].toString(),
        		SPONSORS[5].toString(),
        		SPONSORS[6].toString(),
        		SPONSORS[7].toString()
//        		SPONSORS[8].toString()    		
        		));
        sponsorCol.setMinWidth(300);


        latCol = new TableColumn<>(headers[5]);
        latCol.setCellValueFactory(cellData -> cellData.getValue().latitudeProperty());
        //latCol.setCellFactory(TextFieldTableCell.forTableColumn());
        latCol = setCellFactory(latCol);
        latCol.setMinWidth(70);


        longCol = new TableColumn<>(headers[6]);
        longCol.setCellValueFactory(cellData -> cellData.getValue().longitudeProperty());
        //longCol.setCellFactory(TextFieldTableCell.forTableColumn());
        longCol = setCellFactory(longCol);
        longCol.setMinWidth(70);

        table_view.getColumns().addAll(nameCol, templateCol ,settlerCol ,botCol ,sponsorCol ,latCol, longCol);
        table_view.getItems().addAll(generateDataInMap());

		// attach a list change listener to allData
		addListChangeListener();
    }
 
Example #13
Source File: OptionsController.java    From CPUSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Initializes the Highlighting tab.
 */
private void initializeHighlightingTab() {

    // Disable tab if there is nothing to show.
    if (registers.size() < 1 || RAMs.size() < 1) {
        highlightingTab.setDisable(true);
        return;
    }

    // Making column widths adjust properly
    highlightingTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    // updates selectedSet, disables/enables buttons
    highlightingTable.getSelectionModel().selectedItemProperty().addListener(
            new ChangeListener<RegisterRAMPair>() {
                @Override
                public void changed(ObservableValue<? extends RegisterRAMPair> selected,
                                    RegisterRAMPair oldSet, RegisterRAMPair newSet) {
                    highlightingSelectedSet = newSet;
                    updateHighlightingClickables();
                }
            });

    // Accounts for width changes.
    highlightingTable.widthProperty().addListener(
            new ChangeListener<Number>() {
                @Override
                public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
                    Double newWidth = (Double) newValue;
                    Double sum = registerColumn.getWidth()
                            + RAMColumn.getWidth()
                            + dynamicColumn.getWidth();
                    Double perc = sum / oldValue.doubleValue() * .94;

                    registerColumn.setPrefWidth(newWidth * perc *
                            registerColumn.getWidth() / sum);
                    RAMColumn.setPrefWidth(newWidth * perc *
                            RAMColumn.getWidth() / sum);
                    dynamicColumn.setPrefWidth(newWidth * perc *
                            dynamicColumn.getWidth() / sum);
                }
            });

    // Callbacks
    Callback<TableColumn<RegisterRAMPair, Register>, TableCell<RegisterRAMPair, Register>>
            cellComboRegisterFactory =
            new Callback<TableColumn<RegisterRAMPair, Register>, TableCell<RegisterRAMPair, Register>>() {
                @Override
                public TableCell<RegisterRAMPair, Register> call(
                        TableColumn<RegisterRAMPair, Register> setStringTableColumn) {
                    return new ComboBoxTableCell<>(registers);
                }
            };

    Callback<TableColumn<RegisterRAMPair, RAM>, TableCell<RegisterRAMPair, RAM>>
            cellComboRAMFactory = setStringTableColumn -> new ComboBoxTableCell<>(RAMs);

    Callback<TableColumn<RegisterRAMPair, Boolean>, TableCell<RegisterRAMPair, Boolean>>
            cellCheckBoxFactory = setStringTableColumn -> {
                CheckBoxTableCell<RegisterRAMPair, Boolean> cbtc =
                        new CheckBoxTableCell<>();
                cbtc.setAlignment(Pos.CENTER);
                return cbtc;
            };

    // SetCellValueFactories
    registerColumn.setCellValueFactory(new PropertyValueFactory<>("register"));
    RAMColumn.setCellValueFactory(new PropertyValueFactory<>("ram"));
    dynamicColumn.setCellValueFactory(new PropertyValueFactory<>("dynamic"));

    // Register Factories and setOnEditCommits
    registerColumn.setCellFactory(cellComboRegisterFactory);
    registerColumn.setOnEditCommit(text -> text.getRowValue().setRegister(
            text.getNewValue()));

    RAMColumn.setCellFactory(cellComboRAMFactory);
    RAMColumn.setOnEditCommit(text -> text.getRowValue().setRam(
            text.getNewValue()));

    dynamicColumn.setCellFactory(cellCheckBoxFactory);
    dynamicColumn.setOnEditCommit(text -> text.getRowValue().setDynamic(
            text.getNewValue()));

    // Load in Rows
    ObservableList<RegisterRAMPair> data = highlightingTable.getItems();
    ObservableList<RegisterRAMPair> regRamPairs = mediator.getRegisterRAMPairs();
    for (RegisterRAMPair rrp : regRamPairs) {
        data.add(rrp.clone());
    }
    highlightingTable.setItems(data);
}
 
Example #14
Source File: OptionsController.java    From CPUSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Initializes the Punctuation tab.
 */
private void initializePunctuationTab() {

    // Making column widths adjust properly
    leftPunctuationTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    rightPunctuationTable.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    // Callbacks
    Callback<TableColumn<PunctChar, String>, TableCell<PunctChar, String>>
            cellStrFactory = setStringTableColumn -> {
        EditingStrCell<PunctChar> esc = new EditingStrCell<>();
        esc.setAlignment(Pos.CENTER);
        esc.setFont(new Font("Courier", 18));
        return esc;
    };

    Callback<TableColumn<PunctChar, Use>, TableCell<PunctChar, Use>> cellComboFactory1
            = setStringTableColumn -> new ComboBoxTableCell<>(Use.values());

    Callback<TableColumn<PunctChar, Use>, TableCell<PunctChar, Use>>
        cellComboFactory2 =
            setStringTableColumn -> new ComboBoxTableCell<>(Use.values());

    // Set cellValue Factory
    leftASCIIColumn.setCellValueFactory(new PropertyValueFactory<>("Char"));
    leftTypeColumn.setCellValueFactory(new PropertyValueFactory<>("Use"));
    rightASCIIColumn.setCellValueFactory(new PropertyValueFactory<>("Char"));
    rightTypeColumn.setCellValueFactory(new PropertyValueFactory<>("Use"));

    // Set cell factory and onEditCommit
    leftASCIIColumn.setCellFactory(cellStrFactory);
    rightASCIIColumn.setCellFactory(cellStrFactory);
    // no on edit necessary

    leftTypeColumn.setCellFactory(cellComboFactory1);
    leftTypeColumn.setOnEditCommit(text -> text.getRowValue().setUse(
            text.getNewValue()));
    rightTypeColumn.setCellFactory(cellComboFactory2);
    rightTypeColumn.setOnEditCommit(text -> text.getRowValue().setUse(
            text.getNewValue()));

    // Put values into table
    ObservableList<PunctChar> leftData = leftPunctuationTable.getItems();
    ObservableList<PunctChar> rightData = rightPunctuationTable.getItems();
    PunctChar[] originalPunctChars = mediator.getMachine().getPunctChars();
    int leftSize = (originalPunctChars.length) / 2;
    int rightSize = originalPunctChars.length - leftSize;
    for (int i = 0; i < leftSize + rightSize; i++) {
        if (i < leftSize) {
            leftData.add(originalPunctChars[i].copy());
        } else {
            rightData.add(originalPunctChars[i].copy());
        }
    }
    leftPunctuationTable.setItems(leftData);
    rightPunctuationTable.setItems(rightData);

    // for disabling appropriately
    punctuationTab.disableProperty().bind(mediator.getDesktopController().inDebugOrRunningModeProperty());
}
 
Example #15
Source File: EditFieldsController.java    From CPUSim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Initializes the controller class.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    table.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY);
    name.prefWidthProperty().bind(table.widthProperty().subtract(2).multiply(.15));
    type.prefWidthProperty().bind(table.widthProperty().subtract(2).multiply(.16));
    numBits.prefWidthProperty().bind(table.widthProperty().subtract(2).multiply(.17));
    defaultValue.prefWidthProperty().bind(table.widthProperty().subtract(2).multiply(.20));
    relativity.prefWidthProperty().bind(table.widthProperty().subtract(2).multiply(.18));
    signed.prefWidthProperty().bind(table.widthProperty().subtract(2).multiply(.14));

    selectedField = null;
    deleteButton.setDisable(true);
    duplicateButton.setDisable(true);
    valuesButton.setDisable(true);

    final ObservableList<Field.Relativity> relBoxOptions = FXCollections.observableArrayList();
    
    relBoxOptions.addAll(Field.Relativity.absolute, Field.Relativity.pcRelativePreIncr,
            Field.Relativity.pcRelativePostIncr);
    
    final ObservableList<Field.Type> typeBoxOptions = FXCollections.observableArrayList();
    
    typeBoxOptions.addAll(Field.Type.required, Field.Type.optional, Field.Type.ignored);
    
    Callback<TableColumn<Field, String>, TableCell<Field, String>> cellStrFactory =
            setStringTableColumn -> new cpusim.gui.util.EditingStrCell<>();
    Callback<TableColumn<Field,Integer>, TableCell<Field,Integer>> cellIntFactory =
            setIntegerTableColumn -> new EditingNonNegativeIntCell<>();
    Callback<TableColumn<Field,Long>, TableCell<Field,Long>> cellLongFactory =
            setLongTableColumn -> new EditingLongCell<>();
    Callback<TableColumn<Field,Field.Relativity>,
            TableCell<Field,Field.Relativity>> cellRelFactory =
            setStringTableColumn -> new ComboBoxTableCell<>(relBoxOptions);
    Callback<TableColumn<Field,Boolean>,TableCell<Field, Boolean>> cellBoolFactory =
            booleanTableColumn -> new CheckBoxTableCell<>();
    Callback<TableColumn<Field,Field.Type>,
            TableCell<Field, Field.Type>> cellTypeFactory =
            setStringTableColumn -> new ComboBoxTableCell<>(typeBoxOptions);

    name.setCellValueFactory(new PropertyValueFactory<>("name"));
    type.setCellValueFactory(new PropertyValueFactory<>("type"));
    numBits.setCellValueFactory(new PropertyValueFactory<>("numBits"));
    defaultValue.setCellValueFactory(new PropertyValueFactory<>("defaultValue"));
    relativity.setCellValueFactory(new PropertyValueFactory<>("relativity"));
    signed.setCellValueFactory(new PropertyValueFactory<>("signed"));
    
    //Add for Editable Cell of each field, in String or in Integer
    name.setCellFactory(cellStrFactory);
    name.setOnEditCommit(
            text -> {
                String newName = text.getNewValue();
                String oldName = text.getOldValue();
                ( text.getRowValue()).setName(newName);
                try{
                    Validate.namedObjectsAreUniqueAndNonempty(table.getItems().toArray());
                } catch (ValidationException ex) {
                    (text.getRowValue()).setName(oldName);
                }
                updateTable();
            }
    );

    type.setCellFactory(cellTypeFactory);
    type.setOnEditCommit(text -> text.getRowValue().setType(text.getNewValue()));

    numBits.setCellFactory(cellIntFactory);
    numBits.setOnEditCommit(text -> text.getRowValue().setNumBits(text.getNewValue
            ()));

    defaultValue.setCellFactory(cellLongFactory);
    defaultValue.setOnEditCommit(text ->
            text.getRowValue().setDefaultValue(text.getNewValue()));

    relativity.setCellFactory(cellRelFactory);
    relativity.setOnEditCommit(text -> text.getRowValue().setRelativity(text.getNewValue()));

    signed.setCellFactory(cellBoolFactory);
    signed.setOnEditCommit(text -> text.getRowValue().setSigned(text.getNewValue()));

    table.getSelectionModel().selectedItemProperty().addListener((ov, t, t1) -> {
        deleteButton.setDisable(false);
        duplicateButton.setDisable(false);
        valuesButton.setDisable(false);
        selectedField = t1;
    });
            
    table.setItems(allFields);
}
 
Example #16
Source File: PersonTypeCellFactory.java    From examples-javafx-repos1 with Apache License 2.0 4 votes vote down vote up
@Override
 public TableCell<Person, String> call(TableColumn<Person, String> param) {

     return new ComboBoxTableCell<Person, String>(new DefaultStringConverter()) {      
     	
     	{
         	ContextMenu cm = new ContextMenu();
         	MenuItem deletePersonsMenuItem = new MenuItem("Delete");
         	deletePersonsMenuItem.setOnAction( PersonTypeCellFactory.this.deletePersonsHandler );
         	cm.getItems().add(deletePersonsMenuItem);
         	this.setContextMenu(cm);    
         	
         	this.getItems().addAll( "Friend", "Co-worker", "Other" );
         	
         	this.setEditable(true);
     	}
     	
         @Override
         public void updateItem(String arg0, boolean empty) {
         	
             super.updateItem(arg0, empty);
             
             if( !empty ) {
                 this.setText( arg0 );
             } else {
                 this.setText( null );  // clear from recycled obj
             }
         }

@SuppressWarnings("unchecked")
@Override
public void commitEdit(String newValue) {
	super.commitEdit(newValue);
	TableRow<Person> row = this.getTableRow();
	Person p = row.getItem();
	
	String msg = p.validate();
	if( logger.isLoggable(Level.FINE) ) {
		logger.fine("[COMMIT EDIT] validate=" + msg);
	}
		
	if( msg == null || msg.isEmpty() ) {
		if( logger.isLoggable(Level.FINE) ) {
			logger.fine("[COMMIT EDIT] validation passed");
		}
		Task<Void> task = new Task<Void>() {
			@Override
			protected Void call() {
				dao.updatePerson(p);  // updates AR too
				return null;
			}
		};
		new Thread(task).start();
	} else {
		
		System.out.println("layoutBounds=" + this.getLayoutBounds());
		System.out.println("boundsInLocal=" + this.getBoundsInLocal());
		System.out.println("boundsInParent=" + this.getBoundsInParent());
		System.out.println("boundsInParent (Scene)=" + this.localToScene(this.getBoundsInParent()));
		System.out.println("boundsInParent (Screen)=" + this.localToScreen(this.getBoundsInParent()));

		System.out.println("row layoutBounds=" + row.getLayoutBounds());
		System.out.println("row boundsInLocal=" + row.getBoundsInLocal());
		System.out.println("row boundsInParent=" + row.getBoundsInParent());
		System.out.println("row boundsInParent (Scene)=" + row.localToScene(this.getBoundsInParent()));
		System.out.println("row boundsInParent (Screen)=" + row.localToScreen(this.getBoundsInParent()));

		VBox vbox = new VBox();
		vbox.setPadding(new Insets(10.0d));
		vbox.setStyle("-fx-background-color: white; -fx-border-color: red");
		vbox.getChildren().add( new Label(msg));
		//vbox.setEffect(new DropShadow());
		
		Popup popup = new Popup();
		popup.getContent().add( vbox );
		popup.setAutoHide(true);
		popup.setOnShown((evt) -> {
			
			System.out.println("vbox layoutBounds=" + vbox.getLayoutBounds());
			System.out.println("vbox boundsInLocal=" + vbox.getBoundsInLocal());
			System.out.println("vbox boundsInParent=" + vbox.getBoundsInParent());
			System.out.println("vbox boundsInParent (Scene)=" + vbox.localToScene(this.getBoundsInParent()));
			System.out.println("vbox boundsInParent (Screen)=" + vbox.localToScreen(this.getBoundsInParent()));

		});
		popup.show( row, 
				row.localToScreen(row.getBoundsInParent()).getMinX(), 
				row.localToScreen(row.getBoundsInParent()).getMaxY());					
	}
}
     };
 }