Skip to content

Commit

Permalink
Merge pull request #22 from sillydan1/feature/lints
Browse files Browse the repository at this point in the history
Feature/lints
  • Loading branch information
sillydan1 authored Dec 7, 2023
2 parents 5e14f69 + 1e634d3 commit 2a5547c
Show file tree
Hide file tree
Showing 55 changed files with 1,413 additions and 207 deletions.
25 changes: 15 additions & 10 deletions PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,16 @@
- [x] Release format (ship plugins)
- [x] TODOs round
- [x] update readme (screenshots etc)
- [ ] Release `v1.1.0
- [ ] Custom keybinds
- [ ] Cut / Copy / Paste support
- [ ] Release core as a library on ossrch
- [x] Release `v1.1.0
- [ ] GraphDiff algorithm (look at https://stackoverflow.com/questions/16553343/diff-for-directed-acyclic-graphs)
- [ ] Additions (new syntactic elements), Deletions (B does not have some syntactic element), Edits (Some syntactic element's properties has been changed)
- [ ] Cut / Copy / Paste support
- [ ] Plan for git integration
- [ ] Diff view?
- [x] Lint layer
- [ ] Lint protobuf specification
- [ ] Implement `ILint` / `ILinter` interfaces
- [x] Release core as a library on ossrh
- [ ] Additional Syntaxes
- [x] Simple Text
- [x] LTS
Expand All @@ -120,17 +126,16 @@
- [ ] Polish
- [ ] Release `v1.2.0
- [ ] Trace-traverser & specification
- [ ] Release `v1.3.0`
- [ ] LSP like specification (use docusaurus, or github wiki)
- [ ] Protobuf specification (that way, you are language agnostic)
- [ ] Implement `ILsp` / `ILspEngine` interfaces
- [ ] Lint protobuf specification
- [ ] Implement `ILint` / `ILinter` interfaces
- [ ] Release `v1.2.0`
- [ ] Release `v1.4.0`
- [ ] DAP like specification
- [ ] Protobuf specification (that way, you are language agnostic)
- [ ] Implement `IDap` / `IDapEngine` interfaces
- [ ] Release `v1.3.0`
- [ ] Release `v1.5.0`
- [ ] Add plugin API and [LuaJava](https://github.com/gudzpoz/luajava/tree/main)
- [ ] Rewrite the default "plugins" as a lua plugin. This will simplify the codebase tremendously
- [ ] Custom keybinds
- [ ] Rewrite the default plugins as a lua plugin. This will simplify the codebase tremendously
- [ ] Release `v2.0.0`

5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java';
id 'com.github.gmazzo.buildconfig' version '4.1.2';
id 'com.github.gmazzo.buildconfig' version '4.2.0';
}

def gitCommitSha = { ->
Expand Down Expand Up @@ -89,8 +89,9 @@ subprojects {
}

buildConfig {
documentation.set("Generated by BuildConfig plugin");
buildConfigField("String", "APP_NAME", "\"${project.name}\"");
buildConfigField("String", "APP_VERSION", provider { "\"${project.version}\"" } );
buildConfigField("String", "APP_VERSION", "\"${project.version}\"");
buildConfigField("long", "BUILD_TIME", "${System.currentTimeMillis()}L");
buildConfigField("String", "COMMIT_SHA", "\"${gitCommitSha()}\"");
buildConfigField("String", "COMMIT_SHA_LONG", "\"${gitCommitShaLong()}\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public record EdgeMouseEvent(
Affine viewportAffine,
ISyntaxFactory syntax,
ViewModelGraph graph,
String bufferId,
ViewModelEditorSettings editorSettings) {}

Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ public record VertexMouseEvent(
Affine viewportAffine,
ISyntaxFactory syntax,
ViewModelGraph graph,
String bufferId,
ViewModelEditorSettings editorSettings) {}

Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public record ViewportKeyEvent(
boolean isTargetDrawpane,
ISyntaxFactory syntax,
ViewModelGraph graph,
String bufferId,
ViewModelEditorSettings editorSettings) {}

Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ public record ViewportMouseEvent(
boolean isTargetDrawPane,
ISyntaxFactory syntax,
ViewModelGraph graph,
String bufferId,
ViewModelEditorSettings editorSettings) {}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package dk.gtz.graphedit.exceptions;

/**
* An error occurred during a compare
*/
public class UncomparableException extends RuntimeException {
/**
* Construct a new instance
* @param message The detail message
*/
public UncomparableException(String message) {
super(message);
}

/**
* Construct a new instance
* @param message The detail message
* @param inner The throwable that caused this
*/
public UncomparableException(String message, Throwable inner) {
super(message, inner);
}

/**
* Construct a new instance
* @param inner The throwable that caused this
*/
public UncomparableException(Throwable inner) {
super(inner);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,35 @@ public String getSyntaxDescription() {
}

@Override
public Node createVertexView(UUID vertexKey, ViewModelVertex vertexValue, ModelEditorController creatorController) {
public Node createVertexView(String bufferKey, UUID vertexKey, ViewModelVertex vertexValue, ModelEditorController creatorController) {
var toolbox = DI.get(IToolbox.class);
return new VertexController(vertexKey, vertexValue,
creatorController.getViewportTransform(),
creatorController.getProjectResource().syntax(),
creatorController.getEditorSettings(),
toolbox.getSelectedTool(),
this);
this, bufferKey);
}

@Override
public Node createEdgeView(UUID edgeKey, ViewModelEdge edgeValue, ModelEditorController creatorController) {
public Node createEdgeView(String bufferKey, UUID edgeKey, ViewModelEdge edgeValue, ModelEditorController creatorController) {
var toolbox = DI.get(IToolbox.class);
return new EdgeController(edgeKey, edgeValue,
creatorController.getProjectResource(),
creatorController.getViewportTransform(),
creatorController.getEditorSettings(),
toolbox.getSelectedTool(),
this);
this, bufferKey);
}

@Override
public ViewModelVertex createVertexViewModel(ModelVertex vertexValue) {
return new ViewModelVertex(vertexValue, new ViewModelVertexShape(ViewModelShapeType.OVAL));
public ViewModelVertex createVertexViewModel(UUID vertexKey, ModelVertex vertexValue) {
return new ViewModelVertex(vertexKey, vertexValue, new ViewModelVertexShape(ViewModelShapeType.OVAL));
}

@Override
public ViewModelEdge createEdgeViewModel(ModelEdge edgeValue) {
return new ViewModelEdge(edgeValue);
public ViewModelEdge createEdgeViewModel(UUID edgeKey, ModelEdge edgeValue) {
return new ViewModelEdge(edgeKey, edgeValue);
}

@Override
Expand All @@ -91,4 +91,3 @@ public Optional<IToolbox> getSyntaxTools() {
return Optional.empty();
}
}

13 changes: 13 additions & 0 deletions core/src/main/java/dk/gtz/graphedit/model/ModelLint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dk.gtz.graphedit.model;

import java.util.List;
import java.util.UUID;

public record ModelLint(
String lintIdentifier,
ModelLintSeverity severity,
String title,
String message,
List<UUID> affectedElements,
List<List<ModelPoint>> affectedRegions) {}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dk.gtz.graphedit.model;

public enum ModelLintSeverity {
INFO,
WARNING,
ERROR
}

12 changes: 8 additions & 4 deletions core/src/main/java/dk/gtz/graphedit/spi/ISyntaxFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,39 @@ public interface ISyntaxFactory {

/**
* Create a new javafx vertex representation
* @param bufferKey The key of the buffer that contains the graph that contains this view
* @param vertexKey The primary key of the new vertex representation
* @param vertexValue The viewmodel value of the new vertex representation
* @param creatorController The model editor to attach the vertex to. TODO: Consider removing, or interfacing this
* @return The new vertex javafx representation
*/
Node createVertexView(UUID vertexKey, ViewModelVertex vertexValue, ModelEditorController creatorController);
Node createVertexView(String bufferKey, UUID vertexKey, ViewModelVertex vertexValue, ModelEditorController creatorController);

/**
* Create a new viewmodel vertex representation
* @param vertexKey The primary key of the new vertex representation
* @param vertexValue The model vertex to base on
* @return A new instance of a viewmodel vertex representation specific to this syntax.
*/
ViewModelVertex createVertexViewModel(ModelVertex vertexValue);
ViewModelVertex createVertexViewModel(UUID vertexKey, ModelVertex vertexValue);

/**
* Create a new javafx edge representation
* @param bufferKey The key of the buffer that contains the graph that contains this view
* @param edgeKey The primary key of the new edge representation
* @param edgeValue The viewmodel value of the new edge representation
* @param creatorController The model editor to attach the edge to. TODO: Consider removing, or interfacing this
* @return The new edge javafx representation
*/
Node createEdgeView(UUID edgeKey, ViewModelEdge edgeValue, ModelEditorController creatorController);
Node createEdgeView(String bufferKey, UUID edgeKey, ViewModelEdge edgeValue, ModelEditorController creatorController);

/**
* Create a new viewmodel edge representation
* @param edgeKey The primary key of the new edge representation
* @param edgeValue The model edge to base on
* @return A new instance of a viewmodel edge representation specific to this syntax.
*/
ViewModelEdge createEdgeViewModel(ModelEdge edgeValue);
ViewModelEdge createEdgeViewModel(UUID edgeKey, ModelEdge edgeValue);

/**
* Get the associated syntax version migrater.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void release(UUID releaseTarget, ViewModelGraph graph) {
public void create(UUID sourceTarget, ViewModelGraph graph, ISyntaxFactory factory) {
var tracker = DI.get(MouseTracker.class);
currenEdgeId = Optional.of(UUID.randomUUID());
currentEdge = Optional.of(factory.createEdgeViewModel(new ModelEdge(sourceTarget, tracker.getTrackerUUID())));
currentEdge = Optional.of(factory.createEdgeViewModel(currenEdgeId.get(), new ModelEdge(sourceTarget, tracker.getTrackerUUID())));
if(!currentEdge.get().isSourceValid(sourceTarget, graph)) {
clear();
return;
Expand Down
108 changes: 108 additions & 0 deletions core/src/main/java/dk/gtz/graphedit/tool/LintInspectorTool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package dk.gtz.graphedit.tool;

import java.util.List;
import java.util.Optional;

import org.kordamp.ikonli.bootstrapicons.BootstrapIcons;
import org.kordamp.ikonli.javafx.FontIcon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import atlantafx.base.theme.Styles;
import dk.gtz.graphedit.events.EdgeMouseEvent;
import dk.gtz.graphedit.events.VertexMouseEvent;
import dk.gtz.graphedit.viewmodel.LintContainer;
import dk.gtz.graphedit.viewmodel.ViewModelLint;
import dk.yalibs.yadi.DI;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.Separator;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;

public class LintInspectorTool extends AbstractBaseTool {
private static Logger logger = LoggerFactory.getLogger(LintInspectorTool.class);
private final LintContainer lints;

public LintInspectorTool() {
this.lints = DI.get(LintContainer.class);
}

@Override
public Optional<String> getTooltip() {
return Optional.of("Inspect lints");
}

@Override
public Node getGraphic() {
return new FontIcon(BootstrapIcons.STAR);
}

@Override
public String getHelpDescription() {
return """
Tool to inspect lints of vertices.
When selected, simply hover over a vertex, and all the lints that are affecting
that vertex will be displayed in a context menu
""";
}

@Override
public void onVertexMouseEvent(VertexMouseEvent e) {
if(e.event().getEventType().equals(MouseEvent.MOUSE_ENTERED)) {
var affectingLints = lints.get(e.bufferId()).stream().filter(l -> l.affectedElements().contains(e.vertexId())).toList();
if(!affectingLints.isEmpty())
e.vertex().hover(createLintList(affectingLints));
}
}

@Override
public void onEdgeMouseEvent(EdgeMouseEvent e) {
if(e.event().getEventType().equals(MouseEvent.MOUSE_ENTERED)) {
var affectingLints = lints.get(e.bufferId()).stream().filter(l -> l.affectedElements().contains(e.edgeId())).toList();
if(!affectingLints.isEmpty())
e.edge().hover(createLintList(affectingLints));
}
}

private Node createLintList(List<ViewModelLint> lints) {
var result = new VBox();
result.setSpacing(5);
for(var lint : lints)
result.getChildren().addAll(createLint(lint), new Separator());
return result;
}

private Node createLint(ViewModelLint lint) {
var box = new VBox();
var icon = new FontIcon(BootstrapIcons.INFO_CIRCLE);
switch(lint.severity().get()) {
case ERROR:
icon = new FontIcon(BootstrapIcons.X_CIRCLE);
icon.getStyleClass().add(Styles.DANGER);
break;
case WARNING:
icon = new FontIcon(BootstrapIcons.EXCLAMATION_CIRCLE);
icon.getStyleClass().add(Styles.WARNING);
break;
case INFO:
icon = new FontIcon(BootstrapIcons.INFO_CIRCLE);
break;
default: break;
}
var title = new HBox(icon, new Label(lint.title().get()));
title.setSpacing(5);
title.setCenterShape(true);
title.getStyleClass().add(Styles.TITLE_4);
var body = new Text(lint.message().get());
box.getChildren().addAll(title, body);
VBox.setVgrow(title, Priority.ALWAYS);
VBox.setVgrow(body, Priority.ALWAYS);
VBox.setVgrow(box, Priority.ALWAYS);
return box;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class UnifiedModellingTool extends AbstractBaseTool {
private final EdgeCreateTool edgeCreateTool;
private final EdgeDeleteTool edgeDeleteTool;
private final SelectTool selectTool;
private final LintInspectorTool hoverTool;

/**
* Cronstruct a new instance
Expand All @@ -43,6 +44,7 @@ public UnifiedModellingTool() {
this.edgeCreateTool = new EdgeCreateTool();
this.edgeDeleteTool = new EdgeDeleteTool();
this.selectTool = new SelectTool();
this.hoverTool = new LintInspectorTool();
}

@Override
Expand Down Expand Up @@ -84,6 +86,7 @@ public void onViewportMouseEvent(ViewportMouseEvent e) {

@Override
public void onVertexMouseEvent(VertexMouseEvent e) {
hoverTool.onVertexMouseEvent(e);
if(edgeCreateTool.isCurrentlyCreatingEdge()) {
edgeCreateTool.onVertexMouseEvent(e);
return;
Expand All @@ -98,6 +101,7 @@ public void onVertexMouseEvent(VertexMouseEvent e) {

@Override
public void onEdgeMouseEvent(EdgeMouseEvent e) {
hoverTool.onEdgeMouseEvent(e);
edgeCreateTool.onEdgeMouseEvent(e);
selectTool.onEdgeMouseEvent(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void onViewportMouseEvent(ViewportMouseEvent e) {
}

private void createCircleVertex(ViewModelPoint point, ViewModelGraph graph, ISyntaxFactory syntaxFactory) {
var vertex = syntaxFactory.createVertexViewModel(new ModelVertex(point.toModel()));
var id = UUID.randomUUID();
var vertex = syntaxFactory.createVertexViewModel(id, new ModelVertex(point.toModel()));
graph.vertices().put(id, vertex);
undoSystem.push(new Undoable("vertex create action",
() -> graph.vertices().remove(id),
Expand Down
Loading

0 comments on commit 2a5547c

Please sign in to comment.