Skip to content

Commit

Permalink
Add rename features for Columnizers
Browse files Browse the repository at this point in the history
It is now possible to rename a columnizer, edit its columns and regexs directly in the tables/lists.
  • Loading branch information
joffrey-bion committed Feb 9, 2016
1 parent e5724ea commit 31d5933
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
12 changes: 2 additions & 10 deletions src/main/java/org/hildan/fxlog/columns/ColumnDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,25 @@ public ColumnDefinition(String headerLabel, String capturingGroupName) {
/**
* @return the header of this column
*/
public String getHeaderLabel() {
String getHeaderLabel() {
return headerLabel.get();
}

public StringProperty headerLabelProperty() {
return headerLabel;
}

public void setHeaderLabel(String headerLabel) {
this.headerLabel.set(headerLabel);
}

/**
* @return the name of the capturing group to get the data from for this column
*/
public String getCapturingGroupName() {
String getCapturingGroupName() {
return capturingGroupName.get();
}

public StringProperty capturingGroupNameProperty() {
return capturingGroupName;
}

public void setCapturingGroupName(String capturingGroupName) {
this.capturingGroupName.set(capturingGroupName);
}

/**
* @return the preferred width for this column
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.*;
import javafx.util.StringConverter;

import org.hildan.fxlog.columns.ColumnDefinition;
import org.hildan.fxlog.columns.Columnizer;
Expand Down Expand Up @@ -76,6 +78,22 @@ public void initialize(URL location, ResourceBundle resources) {
private void initializeColumnizersList() {
columnizersList.setItems(config.getColumnizers());
columnizersList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
columnizersList.setCellFactory(TextFieldListCell.forListView(new StringConverter<Columnizer>() {
@Override
public String toString(Columnizer columnizer) {
return columnizer.toString();
}

@Override
public Columnizer fromString(String string) {
// temporary object
return new Columnizer(string);
}
}));
columnizersList.setOnEditCommit(e -> {
Columnizer editedColumnizer = columnizersList.getItems().get(e.getIndex());
editedColumnizer.setName(e.getNewValue().getName());
});
}

private void initializeSelectedColumnizerPane() {
Expand All @@ -87,6 +105,33 @@ private void initializeSelectedColumnizerPane() {

private void initializePatternsList() {
patternList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
patternList.setCellFactory(l -> new TextFieldListCell<Pattern>(new StringConverter<Pattern>() {
@Override
public String toString(Pattern pattern) {
return pattern.toString();
}

@Override
public Pattern fromString(String string) {
try {
return Pattern.compile(string);
} catch (PatternSyntaxException e) {
return null;
}
}
}) {
@Override
public void commitEdit(Pattern pattern) {
if (!isEditing()) return;
PseudoClass errorClass = PseudoClass.getPseudoClass("error");
pseudoClassStateChanged(errorClass, pattern == null);
if (pattern != null) {
// only if the pattern is valid, otherwise we stay in edit state
super.commitEdit(pattern);
}
}
});
patternList.setOnEditCommit(e -> patternList.getItems().set(e.getIndex(), e.getNewValue()));
ListBinding<Pattern> patterns = new ListBinding<Pattern>() {
{
bind(columnizersList.getSelectionModel().selectedItemProperty());
Expand All @@ -107,8 +152,15 @@ protected ObservableList<Pattern> computeValue() {

private void initializeColumnsTable() {
columnsTable.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
newColumnHeaderField.setMaxWidth(headerColumn.getPrefWidth());
newColumnGroupField.setMaxWidth(capturingGroupColumn.getPrefWidth());

headerColumn.setCellFactory(TextFieldTableCell.forTableColumn());
headerColumn.setCellValueFactory(data -> data.getValue().headerLabelProperty());

capturingGroupColumn.setCellFactory(TextFieldTableCell.forTableColumn());
capturingGroupColumn.setCellValueFactory(data -> data.getValue().capturingGroupNameProperty());

ListBinding<ColumnDefinition> columnDefinitions = new ListBinding<ColumnDefinition>() {
{
bind(columnizersList.getSelectionModel().selectedItemProperty());
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/org/hildan/fxlog/light_theme.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.text-field:error {
-fx-text-box-border: red;
-fx-focus-color: red;
}

.list-cell:error {
-fx-text-box-border: red;
-fx-focus-color: red;
}
2 changes: 1 addition & 1 deletion src/main/resources/org/hildan/fxlog/view/columnizers.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<SplitPane dividerPositions="0.3" prefHeight="480.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.hildan.fxlog.controllers.ColumnizersController">
<SplitPane dividerPositions="0.3" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.hildan.fxlog.controllers.ColumnizersController">
<items>
<BorderPane>
<center>
Expand Down

0 comments on commit 31d5933

Please sign in to comment.