Skip to content

Commit

Permalink
Added better HTML-parsing, folder-download and view-options for folde…
Browse files Browse the repository at this point in the history
…r-contents.
  • Loading branch information
Daniel-Schroeter committed Nov 29, 2023
1 parent da24c23 commit eee18ed
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Module {
private String name;
private Integer instance;
private Integer contextid;
private String description;
private Integer visible;
private Boolean uservisible;
private String modname;
Expand Down
7 changes: 6 additions & 1 deletion moodle-sync-fx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
Expand Down Expand Up @@ -206,5 +205,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- jsoup HTML parser library @ https://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.17.1</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import javafx.util.converter.DefaultStringConverter;

import moodle.sync.core.model.json.Content;
import moodle.sync.core.util.MoodleAction;
import moodle.sync.javafx.core.control.SvgIcon;
import moodle.sync.javafx.model.SyncTableElement;

import org.controlsfx.control.PopOver;
import java.util.Objects;
import static java.util.Objects.isNull;

/**
* Class used to display the Name of a Section/ Module including different styles/background colors inside a cell.
Expand Down Expand Up @@ -56,7 +59,7 @@ public void updateItem(String item, boolean empty) {
Label textArea = new Label();
textArea.setText(getTableRow().getItem().getModuleType().replaceAll("\\<.*?>", ""));
textArea.setWrapText(true);
textArea.setMaxWidth(200);
textArea.setMaxWidth(500);
textArea.setStyle("-fx-font-weight: normal");
textArea.getStyleClass().add("popUpTextArea");
VBox vBox = new VBox(textArea);
Expand Down Expand Up @@ -123,7 +126,61 @@ else if(getTableRow().getItem().getAction() == MoodleAction.MoodleUpload ||
else {
setGraphic(icon);
}
setText(this.getText().replaceAll("\\u00a0\\n|&nbsp;\\r\\n", ""));
if(getTableRow().getItem().getAction() == MoodleAction.NotLocalFile && Objects.equals(getTableRow().getItem().getModuleType(), "label")) {
setText(getTableRow().getItem().getExistingFileName());
if(!(getTableRow().getItem().getModuleType().replaceAll("\\<.*?>", "")).isEmpty()){
Label textArea = new Label();
textArea.setText(getTableRow().getItem().getExistingFileName());
textArea.setWrapText(true);
textArea.setMaxWidth(500);
textArea.setStyle("-fx-font-weight: normal");
textArea.getStyleClass().add("popUpTextArea");
VBox vBox = new VBox(textArea);
vBox.setPadding(new Insets(5));
popOver = new PopOver(vBox);
popOver.setArrowLocation(PopOver.ArrowLocation.LEFT_CENTER);

this.setOnMouseEntered(mouseEvent -> {
//Show PopOver when mouse enters label
popOver.show(this);
});
this.setOnMouseExited(mouseEvent -> {
//Hide PopOver when mouse exits label
popOver.hide();
});
}
}
else if ((getTableRow().getItem().getAction() == MoodleAction.NotLocalFile || getTableRow().getItem().getAction() == MoodleAction.ExistingFile)
&& Objects.equals(getTableRow().getItem().getModuleType(), "folder")
&& !isNull(getTableRow().getItem().getContentsOnline())) {
Label textArea = new Label();
String contents = "";
String newline = System.getProperty("line.separator");
for(Content content : getTableRow().getItem().getContentsOnline()) {
contents = contents + content.getFilename() + newline;
}
textArea.setText(contents);
textArea.setWrapText(true);
textArea.setMaxWidth(500);
textArea.setStyle("-fx-font-weight: normal");
textArea.getStyleClass().add("popUpTextArea");
VBox vBox = new VBox(textArea);
vBox.setPadding(new Insets(5));
popOver = new PopOver(vBox);
popOver.setArrowLocation(PopOver.ArrowLocation.LEFT_CENTER);

this.setOnMouseEntered(mouseEvent -> {
//Show PopOver when mouse enters label
popOver.show(this);
});
this.setOnMouseExited(mouseEvent -> {
//Hide PopOver when mouse exits label
popOver.hide();
});
}
else {
setText(this.getText().replaceAll("\\u00a0\\n|&nbsp;\\r\\n", ""));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package moodle.sync.javafx.model;

import javafx.beans.property.*;
import moodle.sync.core.model.json.Content;
import moodle.sync.core.util.MoodleAction;

import java.nio.file.Path;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -54,7 +56,7 @@ public class SyncTableElement {

private StringProperty sectionName;

private StringProperty fileurl;
private ObjectProperty<List<Content>> contentOnline;



Expand All @@ -76,8 +78,9 @@ public SyncTableElement(String moduleName, Integer cmid, Integer section, Intege
this.visible = new SimpleBooleanProperty(visible);
this.availabilityDateTime = new SimpleObjectProperty(new TimeDateElement(null, null));
this.userVisible = new SimpleBooleanProperty(userVisible);
this.sectionName = new SimpleStringProperty("");
this.downloadable = new SimpleBooleanProperty(false);
this.fileurl = new SimpleStringProperty("");
this.contentOnline = new SimpleObjectProperty<List<Content>>(new ArrayList<>());
}

public SyncTableElement(String moduleName, Integer cmid, Integer section, Integer sectionId, Integer oldPos,
Expand All @@ -97,8 +100,9 @@ public SyncTableElement(String moduleName, Integer cmid, Integer section, Intege
this.visible = new SimpleBooleanProperty(visible);
this.availabilityDateTime = new SimpleObjectProperty(new TimeDateElement(null, null));
this.userVisible = new SimpleBooleanProperty(userVisible);
this.sectionName = new SimpleStringProperty("");
this.downloadable = new SimpleBooleanProperty(false);
this.fileurl = new SimpleStringProperty("");
this.contentOnline = new SimpleObjectProperty<List<Content>>(new ArrayList<>());
}

public SyncTableElement(String moduleName, Integer cmid, Integer section, Integer sectionId, Integer oldPos,
Expand All @@ -124,8 +128,9 @@ public SyncTableElement(String moduleName, Integer cmid, Integer section, Intege
this.content = new SimpleObjectProperty<List<Path>>(content);
this.contextId = new SimpleIntegerProperty(contextId);
this.userVisible = new SimpleBooleanProperty(userVisible);
this.sectionName = new SimpleStringProperty("");
this.downloadable = new SimpleBooleanProperty(false);
this.fileurl = new SimpleStringProperty("");
this.contentOnline = new SimpleObjectProperty<List<Content>>(new ArrayList<>());
}

public SyncTableElement(String moduleName, Integer cmid, Integer section, Integer sectionId, Integer oldPos, String moduleType,
Expand All @@ -145,8 +150,9 @@ public SyncTableElement(String moduleName, Integer cmid, Integer section, Intege
this.visible = new SimpleBooleanProperty(visible);
this.availabilityDateTime = new SimpleObjectProperty(availabilityDateTime);
this.userVisible = new SimpleBooleanProperty(userVisible);
this.sectionName = new SimpleStringProperty("");
this.downloadable = new SimpleBooleanProperty(false);
this.fileurl = new SimpleStringProperty("");
this.contentOnline = new SimpleObjectProperty<List<Content>>(new ArrayList<>());
}

public SyncTableElement(String moduleName, Integer cmid, Integer section, Integer sectionId, Integer oldPos, String moduleType,
Expand All @@ -167,8 +173,9 @@ public SyncTableElement(String moduleName, Integer cmid, Integer section, Intege
this.visible = new SimpleBooleanProperty(visible);
this.availabilityDateTime = new SimpleObjectProperty(availabilityDateTime);
this.userVisible = new SimpleBooleanProperty(userVisible);
this.sectionName = new SimpleStringProperty("");
this.downloadable = new SimpleBooleanProperty(false);
this.fileurl = new SimpleStringProperty("");
this.contentOnline = new SimpleObjectProperty<List<Content>>(new ArrayList<>());
}

public SyncTableElement(String moduleName, Integer cmid, Integer section, Integer sectionId, Integer oldPos,
Expand All @@ -190,7 +197,8 @@ public SyncTableElement(String moduleName, Integer cmid, Integer section, Intege
this.availabilityDateTime = new SimpleObjectProperty(new TimeDateElement(null, null));
this.userVisible = new SimpleBooleanProperty(userVisible);
this.downloadable = new SimpleBooleanProperty(false);
this.fileurl = new SimpleStringProperty("");
this.sectionName = new SimpleStringProperty("");
this.contentOnline = new SimpleObjectProperty<List<Content>>(new ArrayList<>());
}

public SyncTableElement(String moduleName, Integer cmid, Integer section, Integer sectionId, Integer oldPos,
Expand All @@ -213,7 +221,7 @@ public SyncTableElement(String moduleName, Integer cmid, Integer section, Intege
this.userVisible = new SimpleBooleanProperty(userVisible);
this.downloadable = new SimpleBooleanProperty(false);
this.sectionName = new SimpleStringProperty("");
this.fileurl = new SimpleStringProperty("");
this.contentOnline = new SimpleObjectProperty<List<Content>>(new ArrayList<>());
}

public SyncTableElement(String moduleName, Integer cmid, Integer section, Integer sectionId, Integer oldPos, String moduleType,
Expand All @@ -235,7 +243,6 @@ public SyncTableElement(String moduleName, Integer cmid, Integer section, Intege
this.availabilityDateTime = new SimpleObjectProperty(new TimeDateElement(null, null));
this.userVisible = new SimpleBooleanProperty(userVisible);
this.downloadable = new SimpleBooleanProperty(false);
this.fileurl = new SimpleStringProperty("");
}

/**
Expand Down Expand Up @@ -759,26 +766,26 @@ public void setSectionName(String value) {
*
* @return the messageProprty.
*/
public StringProperty fileurlProperty() {
return fileurl;
public ObjectProperty<List<Content>> contentsOnlineProperty() {
return contentOnline;
}

/**
* Providing the files message as a String.
*
* @return the files message as a String.
*/
public String getFileUrl() {
return this.fileurl.get();
public List<Content> getContentsOnline() {
return this.contentOnline.get();
}

/**
* Sets a new message.
*
* @param value the new message.
*/
public void setFileUrl(String value) {
this.fileurl.set(value);
public void addContentOnline(Content value) {
this.contentOnline.get().add(value);
}

}
Loading

0 comments on commit eee18ed

Please sign in to comment.