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

Fix #41 #42

Merged
merged 1 commit into from
Sep 16, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/main/java/model/diagram/PackageDiagram.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
public class PackageDiagram
{

private final Map<PackageVertex, Integer> graphNodes;
private Map<PackageVertex, Set<Arc<PackageVertex>>> diagram;
private Map<Path, PackageVertex> vertices;
private Map<Integer, Pair<Double, Double>> diagramGeometryGraphML;
private DiagramGeometry diagramGeometry;
private final Map<PackageVertex, Integer> graphNodes;
private Map<PackageVertex, Set<Arc<PackageVertex>>> diagram;
private Map<Path, PackageVertex> vertices;
private Map<Integer, Pair<Double, Double>> diagramGeometryGraphML;
private DiagramGeometry diagramGeometry;


public PackageDiagram()
Expand Down Expand Up @@ -54,12 +54,10 @@ public List<PackageVertex> getChosenNodes(List<String> chosenPackagesNames)
List<PackageVertex> chosenPackages = new ArrayList<>();
for (String chosenPackage : chosenPackagesNames)
{
Optional<PackageVertex> vertex = vertices.values().stream()
//.filter(it -> it.getName().equals(chosenPackage))
.filter(it -> it.getPath().toString().equals(chosenPackage))
.findFirst();

vertex.ifPresent(chosenPackages::add);
vertices.values().stream()
.filter(it -> it.getName().equals(chosenPackage))
.findFirst()
.ifPresent(chosenPackages::add);
}

return chosenPackages;
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/view/DiagramCreation.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import java.io.File;
import java.util.List;

import static view.FileType.PACKAGE;
import static view.FileType.SOURCE;

public class DiagramCreation
{

Expand Down Expand Up @@ -57,7 +60,7 @@ public void viewProject(String type)
PopupWindow.createPopupInfoWindow("You have neither created a diagram nor loaded it yet!", "Error");
return;
}
if (!wereFilesChosen())
if (!wereAnyFilesChosen())
{
PopupWindow.createPopupInfoWindow("You haven't selected any files!", "Error");
return;
Expand Down Expand Up @@ -123,21 +126,16 @@ public void exportPlantUMLText()

private List<String> getSelectedFiles(String diagramType)
{
if (diagramType.equals("Package"))
{
return projectTreeView.getSelectedFiles(projectTreeView.getFolderFiles(), "package");
}
else
{
return projectTreeView.getSelectedFiles(projectTreeView.getJavaSourceFiles(), "java");
}
return diagramType.equals("Package") ?
projectTreeView.getSelectedFiles(PACKAGE) :
projectTreeView.getSelectedFiles(SOURCE);
}


private boolean wereFilesChosen()
private boolean wereAnyFilesChosen()
{
return !(projectTreeView.getSelectedFiles(projectTreeView.getFolderFiles(), "package").isEmpty() &&
projectTreeView.getSelectedFiles(projectTreeView.getJavaSourceFiles(), "java").isEmpty());
return !(projectTreeView.getSelectedFiles(PACKAGE).isEmpty() &&
projectTreeView.getSelectedFiles(SOURCE).isEmpty());
}


Expand Down
7 changes: 7 additions & 0 deletions src/main/java/view/FileType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package view;

public enum FileType
{
SOURCE,
PACKAGE
}
1 change: 0 additions & 1 deletion src/main/java/view/FileUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import javafx.stage.Stage;

import java.io.File;
import java.nio.file.Path;
import java.util.Map;

import static java.util.Map.entry;
Expand Down
50 changes: 24 additions & 26 deletions src/main/java/view/ProjectTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import javafx.scene.control.TreeView;
import javafx.scene.control.cell.CheckBoxTreeCell;

import java.io.File;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import static view.FileType.PACKAGE;

public class ProjectTreeView
{

Expand Down Expand Up @@ -90,29 +93,36 @@ else if (isFileExtensionJava(path.normalize().toString()))

private String getRelativePath(Path path)
{
return path.normalize().toString().replace(sourceFolderPath.normalize().toString().substring(0,
sourceFolderPath.normalize().toString().lastIndexOf("/") + 1), "").replace("/", ".");
return path.normalize()
.toString()
.replace(sourceFolderPath.normalize()
.toString()
.substring(0, sourceFolderPath.normalize()
.toString()
.lastIndexOf(File.separator) + 1), "")
.replace(File.separator, ".");
}


public List<String> getSelectedFiles(List<String> files, String fileType)
public List<String> getSelectedFiles(FileType fileType)
{
List<String> files = fileType.equals(PACKAGE) ?
folderFiles :
javaSourceFiles;

List<String> selectedFiles = new ArrayList<>();
for (CheckBoxTreeItem<?> c : checkedItems)
{
if (!files.contains((String)c.getValue()))
{
continue;
}
if (fileType.equals("java"))
{
selectedFiles.add(subtractFileExtension((String)c.getValue()));
}
else
{
selectedFiles.add(((String)c.getValue()));
String name = (String) c.getValue();
if (!files.contains(name)) continue;

switch (fileType) {
case SOURCE -> selectedFiles.add(subtractFileExtension(name));
case PACKAGE -> selectedFiles.add(name);
default -> throw new UnsupportedOperationException();
}
}

return selectedFiles;
}

Expand Down Expand Up @@ -149,18 +159,6 @@ private String subtractFileExtension(String s)
}


public List<String> getFolderFiles()
{
return folderFiles;
}


public List<String> getJavaSourceFiles()
{
return javaSourceFiles;
}


public CheckBoxTreeItem<String> getRootItem()
{
return rootItem;
Expand Down
Loading