Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HistoryCommits refactoring and UI tweaks #28

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/az/gitember/data/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ interface View {
String FILE_DIFF = "diffviewer";
String EDITOR = "editor";
String FILE_HISTORY = "filehistory";
String HISTORY = "history";
String HISTORY_DETAIL = "historydetail";
String HISTORY = "module/history/history";
String HISTORY_DETAIL = "module/history/history-detail";
String MAIN = "main";

String STASH = "stash";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,46 @@
package com.az.gitember.controller;
package com.az.gitember.module.history;

import com.az.gitember.App;
import com.az.gitember.control.ChangeListenerHistoryHint;
import com.az.gitember.controller.handlers.CheckoutRevisionhEventHandler;
import com.az.gitember.data.Const;
import com.az.gitember.data.ScmItem;
import com.az.gitember.data.Settings;
import com.az.gitember.module.history.factory.HistoryCommitsTableLaneCellFactory;
import com.az.gitember.module.history.factory.HistoryCommitsTableRowFactory;
import com.az.gitember.module.history.listener.HistoryCommitsTableViewChangeListener;
import com.az.gitember.module.history.renderer.HistoryPlotCommitRenderer;
import com.az.gitember.service.Context;
import com.az.gitember.service.GitemberUtil;
import javafx.beans.InvalidationListener;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.eclipse.jgit.api.CheckoutCommand;
import org.eclipse.jgit.api.CherryPickResult;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.revplot.PlotCommit;
import org.eclipse.jgit.revplot.PlotLane;
import org.eclipse.jgit.revwalk.RevCommit;

import java.io.IOException;
import java.net.URL;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

public class History implements Initializable {

private final static Logger log = Logger.getLogger(History.class.getName());
public class HistoryController implements Initializable {
private final static Logger log = Logger.getLogger(HistoryController.class.getName());

private static final int HEIGH = 40;


private int plotWidth = 20 * HEIGH;

@FXML
public AnchorPane hostHistoryViewPanel;
public AnchorPane hostCommitViewPanel;
public SplitPane splitPanel;
public BorderPane mainBorderPanel;
public Pane spacerPane;
Expand All @@ -59,160 +53,45 @@ public class History implements Initializable {
private TextField searchText;

@FXML
private TableColumn<PlotCommit, Canvas> laneTableColumn;

@FXML
private TableColumn<PlotCommit, String> dateTableColumn;

@FXML
private TableColumn<PlotCommit, String> messageTableColumn;
private TableColumn<PlotCommit<PlotLane>, Canvas> laneTableColumn;

@FXML
private TableColumn<PlotCommit, String> authorTableColumn;
private TableColumn<PlotCommit<PlotLane>, String> dateTableColumn;

@FXML
public TableColumn<PlotCommit, String> shaTableColumn;
private TableColumn<PlotCommit<PlotLane>, String> authorTableColumn;

@FXML
public TableColumn<PlotCommit, String> refTableColumn;
public TableColumn<PlotCommit<PlotLane>, String> shaTableColumn;

@FXML
private TableView commitsTableView;





@Override
@SuppressWarnings("unchecked")
public void initialize(URL location, ResourceBundle resources) {


commitsTableView.setFixedCellSize(HEIGH);
commitsTableView
.getSelectionModel()
.selectedItemProperty()
.addListener(new ChangeListener<PlotCommit>() {

@Override
public void changed(final ObservableValue<? extends PlotCommit> observable,
final PlotCommit oldValue,
final PlotCommit newValue) {

if (splitPanel.getItems().size() == 1) {
hostCommitViewPanel = new AnchorPane();
hostCommitViewPanel.prefHeight(330);
hostCommitViewPanel.minHeight(250);
splitPanel.getItems().add(hostCommitViewPanel);
splitPanel.setDividerPositions(0.65);
mainBorderPanel.layout();
}
if (newValue != null) {
try {
Context.scmRevCommitDetails.setValue(Context.getGitRepoService().adapt(newValue));
final Parent commitView = App.loadFXML(Const.View.HISTORY_DETAIL).getFirst();
hostCommitViewPanel.getChildren().clear();
hostCommitViewPanel.getChildren().add(commitView);
} catch (IOException e) {
e.printStackTrace();
}
}

}

});



commitsTableView.setRowFactory(
tr -> {
return new TableRow<PlotCommit>() {
private String calculateStyle(final PlotCommit plotCommit) {
String searchString = searchText.getText();
if (isSearchEligible(plotCommit, searchString)) {
Map<String, Set<String>> map = Context.searchResult.getValue();
if (map != null && map.containsKey(plotCommit.getName()) ) {
return LookAndFeelSet.FOUND_ROW;
}
}
return "";
}

@Override
protected void updateItem(PlotCommit item, boolean empty) {
super.updateItem(item, empty);
setStyle(calculateStyle(item));
}

private boolean isSearchEligible(PlotCommit plotCommit, String searchString) {
return plotCommit != null
&& plotCommit.getName() != null
&& searchString != null
&& searchString.length() > Const.SEARCH_LIMIT_CHAR;
}
};
}
);
.addListener(new HistoryCommitsTableViewChangeListener(mainBorderPanel, splitPanel));

laneTableColumn.setCellValueFactory(
c -> {
return new ObservableValue<Canvas>() {
@Override
public Canvas getValue() {
Canvas canvas = new Canvas(plotWidth, HEIGH);
GraphicsContext gc = canvas.getGraphicsContext2D();
plotCommitRenderer.render(gc, c.getValue(), HEIGH);
return canvas;
}
commitsTableView.setRowFactory(tableView -> new HistoryCommitsTableRowFactory(searchText));

@Override
public void addListener(InvalidationListener listener) {
}

@Override
public void removeListener(InvalidationListener listener) {
}

@Override
public void addListener(ChangeListener<? super Canvas> listener) {
}

@Override
public void removeListener(ChangeListener<? super Canvas> listener) {
}

};
}
);
commitsTableView.widthProperty().addListener((observable, oldValue, newValue) -> {
laneTableColumn.setPrefWidth(newValue.doubleValue() - authorTableColumn.getWidth() - dateTableColumn.getWidth() - shaTableColumn.getWidth() - 20);
});
laneTableColumn.setCellValueFactory(c -> new HistoryCommitsTableLaneCellFactory(c.getValue(), plotCommitRenderer, HEIGH));

shaTableColumn.setCellValueFactory(
c -> new ReadOnlyStringWrapper(c.getValue().getName())
);

refTableColumn.setCellValueFactory(
c -> {
PlotCommit plotCommit = c.getValue();
LinkedList<String> refs = new LinkedList<>();
for (int i = 0; i < plotCommit.getRefCount(); i++) {
refs.add(
plotCommit.getRef(i).getName()
);
}
return new ReadOnlyStringWrapper(refs.stream().collect(Collectors.joining(", ")));
}
);

authorTableColumn.setCellValueFactory(
c -> new ReadOnlyStringWrapper(c.getValue().getAuthorIdent().getName())
);

messageTableColumn.setCellValueFactory(
c -> {
return new ReadOnlyStringWrapper( c.getValue().getShortMessage().replace("\n","") );
}
);


dateTableColumn.setCellValueFactory(
c -> new ReadOnlyStringWrapper(
GitemberUtil.formatDate(GitemberUtil.intToDate(c.getValue().getCommitTime()))
Expand Down Expand Up @@ -259,12 +138,8 @@ public void removeListener(ChangeListener<? super Canvas> listener) {

HBox.setHgrow(spacerPane, Priority.ALWAYS);
commitsTableView.setItems(Context.plotCommitList);

}




public void checkoutMenuItemClickHandler(ActionEvent actionEvent) {

new CheckoutRevisionhEventHandler((RevCommit) commitsTableView.getSelectionModel().getSelectedItem(), null).handle(actionEvent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.az.gitember.controller;
package com.az.gitember.module.history;

import com.az.gitember.App;
import com.az.gitember.controller.LookAndFeelSet;
import com.az.gitember.controller.WorkingcopyTableGraphicsValueFactory;
import com.az.gitember.controller.handlers.DiffEventHandler;
import com.az.gitember.controller.handlers.DiffWithDiskEventHandler;
import com.az.gitember.controller.handlers.OpenFileEventHandler;
import com.az.gitember.data.CommitInfo;
import com.az.gitember.data.Const;
Expand All @@ -28,9 +29,9 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

public class HistoryDetail implements Initializable {
public class HistoryDetailController implements Initializable {

private final static Logger log = Logger.getLogger(HistoryDetail.class.getName());
private final static Logger log = Logger.getLogger(HistoryDetailController.class.getName());

@FXML
public Menu stashMenu;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.az.gitember.module.history.factory;

import com.az.gitember.module.history.renderer.HistoryPlotCommitRenderer;
import javafx.beans.InvalidationListener;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import org.eclipse.jgit.revplot.PlotCommit;
import org.eclipse.jgit.revplot.PlotLane;

public class HistoryCommitsTableLaneCellFactory implements ObservableValue<Canvas> {

private final PlotCommit<PlotLane> commit;
private final HistoryPlotCommitRenderer historyPlotCommitRenderer;
private final double canvasWidth;
private final double canvasHeight;


public HistoryCommitsTableLaneCellFactory(PlotCommit<PlotLane> commit,
HistoryPlotCommitRenderer historyPlotCommitRenderer,
double canvasHeight) {
this.commit = commit;
this.historyPlotCommitRenderer = historyPlotCommitRenderer;
this.canvasWidth = 100 * canvasHeight;
this.canvasHeight = canvasHeight;
}

@Override
public Canvas getValue() {
var canvas = new Canvas(canvasWidth, canvasHeight);
GraphicsContext gc = canvas.getGraphicsContext2D();
historyPlotCommitRenderer.render(gc, commit, (int) canvasHeight);
return canvas;
}

@Override
public void addListener(InvalidationListener listener) {
}

@Override
public void removeListener(InvalidationListener listener) {
}

@Override
public void addListener(ChangeListener<? super Canvas> listener) {
}

@Override
public void removeListener(ChangeListener<? super Canvas> listener) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.az.gitember.module.history.factory;

import com.az.gitember.controller.LookAndFeelSet;
import com.az.gitember.data.Const;
import com.az.gitember.service.Context;
import javafx.scene.control.TableRow;
import javafx.scene.control.TextField;
import org.eclipse.jgit.revplot.PlotCommit;
import org.eclipse.jgit.revplot.PlotLane;

import java.util.Map;
import java.util.Set;

public class HistoryCommitsTableRowFactory extends TableRow<PlotCommit<PlotLane>> {

private final TextField searchTextField;


public HistoryCommitsTableRowFactory(TextField searchTextField) {
this.searchTextField = searchTextField;
}

@Override
protected void updateItem(PlotCommit item, boolean empty) {
super.updateItem(item, empty);
setStyle(calculateStyle(item));
}

private String calculateStyle(final PlotCommit<PlotLane> plotCommit) {
String searchString = searchTextField.getText();
if (isSearchEligible(plotCommit, searchString)) {
Map<String, Set<String>> map = Context.searchResult.getValue();
if (map != null && map.containsKey(plotCommit.getName()) ) {
return LookAndFeelSet.FOUND_ROW;
}
}
return "";
}

private boolean isSearchEligible(PlotCommit<PlotLane> plotCommit, String searchString) {
return plotCommit != null
&& plotCommit.getName() != null
&& searchString != null
&& searchString.length() > Const.SEARCH_LIMIT_CHAR;
}
}