Search in sources :

Example 1 with PropertyTypeId

use of net.sourceforge.pmd.properties.PropertyTypeId in project pmd by pmd.

the class PropertyTableView method initialize.

private void initialize() {
    this.getColumns().add(propertyNameColumn);
    this.getColumns().add(propertyTypeColumn);
    this.getColumns().add(propertyValueColumn);
    this.setColumnResizePolicy(CONSTRAINED_RESIZE_POLICY);
    this.setTableMenuButtonVisible(true);
    ObservableList<PropertyTypeId> availableBuilders = FXCollections.observableArrayList(PropertyTypeId.typeIdsToConstants().values());
    Collections.sort(availableBuilders);
    StringConverter<PropertyTypeId> converter = DesignerUtil.stringConverter(PropertyTypeId::getStringId, PropertyTypeId::lookupMnemonic);
    propertyTypeColumn.setCellFactory(ChoiceBoxTableCell.forTableColumn(converter, availableBuilders));
    propertyNameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));
    propertyValueColumn.setCellValueFactory(new PropertyValueFactory<>("value"));
    propertyTypeColumn.setCellValueFactory(new PropertyValueFactory<>("typeId"));
    this.setPlaceholder(new Label("Right-click to add properties"));
    MenuItem editItem = new MenuItem("Edit...");
    editItem.setOnAction(e -> {
        PropertyDescriptorSpec spec = this.getSelectionModel().getSelectedItem();
        if (spec != null) {
            popEditPropertyDialog(spec);
        }
    });
    MenuItem removeItem = new MenuItem("Remove");
    removeItem.setOnAction(e -> {
        PropertyDescriptorSpec selected = this.getSelectionModel().getSelectedItem();
        if (selected != null) {
            this.getItems().remove(selected);
        }
    });
    MenuItem addItem = new MenuItem("Add property...");
    addItem.setOnAction(e -> onAddPropertyClicked());
    ContextMenu fullMenu = new ContextMenu();
    fullMenu.getItems().addAll(editItem, removeItem, new SeparatorMenuItem(), addItem);
    // Reduced context menu, for when there are no properties or none is selected
    MenuItem addItem2 = new MenuItem("Add property...");
    addItem2.setOnAction(e -> onAddPropertyClicked());
    ContextMenu smallMenu = new ContextMenu();
    smallMenu.getItems().add(addItem2);
    this.addEventHandler(MouseEvent.MOUSE_CLICKED, t -> {
        if (t.getButton() == MouseButton.SECONDARY || t.getButton() == MouseButton.PRIMARY && t.getClickCount() > 1) {
            if (this.getSelectionModel().getSelectedItem() != null) {
                fullMenu.show(this, t.getScreenX(), t.getScreenY());
            } else {
                smallMenu.show(this, t.getScreenX(), t.getScreenY());
            }
        }
    });
    propertyNameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
    propertyValueColumn.setCellFactory(TextFieldTableCell.forTableColumn());
    this.setEditable(false);
}
Also used : PropertyDescriptorSpec(net.sourceforge.pmd.util.fxdesigner.util.PropertyDescriptorSpec) PropertyTypeId(net.sourceforge.pmd.properties.PropertyTypeId) Label(javafx.scene.control.Label) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) ContextMenu(javafx.scene.control.ContextMenu) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem)

Aggregations

ContextMenu (javafx.scene.control.ContextMenu)1 Label (javafx.scene.control.Label)1 MenuItem (javafx.scene.control.MenuItem)1 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)1 PropertyTypeId (net.sourceforge.pmd.properties.PropertyTypeId)1 PropertyDescriptorSpec (net.sourceforge.pmd.util.fxdesigner.util.PropertyDescriptorSpec)1