Skip to content
Snippets Groups Projects
Commit 8355a915 authored by tobias's avatar tobias
Browse files

Fixed RequestedModule Checking

parent 9321393e
No related branches found
No related tags found
No related merge requests found
......@@ -210,6 +210,7 @@ public class PadSerializer implements XMLSerializer<Pad>, XMLDeserializer<Pad> {
content.save(contentElement);
Module module = PlayPadPlugin.getRegistryCollection().getPadContents().getModule(content.getType());
// Für verschiedene Pad Typen wird hier das Modul gespeichert, damit das Projekt weis, welche notwendig sien beim öffnen
project.getProjectReference().addRequestedModule(module);
}
}
......
......@@ -43,24 +43,31 @@ public class ProjectReference implements Displayable {
private ProfileReference profileReference;
private Set<Module> requestedModules;
private long size;
private long lastMofied;
public ProjectReference(UUID uuid, String name, ProfileReference profileReference) {
this.uuid = uuid;
this.name = name;
this.lastMofied = System.currentTimeMillis();
this.size = 0;
this.profileReference = profileReference;
requestedModules = new HashSet<>();
updateDisplayProperty();
}
public ProjectReference(UUID uuid, String name, long size, long lastMofied, ProfileReference profileReference) {
public ProjectReference(UUID uuid, String name, ProfileReference profileReference, Set<Module> modules) {
this.uuid = uuid;
this.name = name;
this.lastMofied = System.currentTimeMillis();
this.profileReference = profileReference;
requestedModules = modules;
updateDisplayProperty();
}
public ProjectReference(UUID uuid, String name, long lastMofied, ProfileReference profileReference) {
this.uuid = uuid;
this.name = name;
this.size = size;
this.lastMofied = lastMofied;
this.profileReference = profileReference;
requestedModules = new HashSet<>();
......@@ -68,11 +75,9 @@ public class ProjectReference implements Displayable {
updateDisplayProperty();
}
public ProjectReference(UUID uuid, String name, long size, long lastMofied, ProfileReference profileReference,
Set<Module> requestedModules) {
public ProjectReference(UUID uuid, String name, long lastMofied, ProfileReference profileReference, Set<Module> requestedModules) {
this.uuid = uuid;
this.name = name;
this.size = size;
this.lastMofied = lastMofied;
this.profileReference = profileReference;
this.requestedModules = requestedModules;
......@@ -88,14 +93,6 @@ public class ProjectReference implements Displayable {
return name;
}
public long getSize() {
return size;
}
public void setSize(long size) {
this.size = size;
}
public void setLastMofied(long lastMofied) {
this.lastMofied = lastMofied;
}
......@@ -125,10 +122,15 @@ public class ProjectReference implements Displayable {
missedModules.add(requested);
}
}
for (Module requested : profileReference.getRequestedModules()) {
if (!activeModules.contains(requested)) {
missedModules.add(requested);
}
}
return missedModules;
}
public ProfileReference getProfileReference() {
return profileReference;
}
......
......@@ -3,14 +3,19 @@ package de.tobias.playpad.project.ref;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.dom4j.Element;
import de.tobias.playpad.plugin.Module;
import de.tobias.playpad.plugin.ModuleSerializer;
import de.tobias.playpad.settings.ProfileReference;
import de.tobias.utils.application.ApplicationUtils;
import de.tobias.utils.application.container.PathType;
import de.tobias.utils.xml.XMLDeserializer;
import de.tobias.utils.xml.XMLHandler;
import de.tobias.utils.xml.XMLSerializer;
public class ProjectReferenceSerializer implements XMLDeserializer<ProjectReference>, XMLSerializer<ProjectReference> {
......@@ -18,6 +23,7 @@ public class ProjectReferenceSerializer implements XMLDeserializer<ProjectRefere
private static final String UUID_ATTR = "uuid";
private static final String NAME_ATTR = "name";
private static final String PROFILE_ATTR = "profile";
private static final String MODULE_ELEMENT = "Module";
@Override
public ProjectReference loadElement(Element element) {
......@@ -25,14 +31,16 @@ public class ProjectReferenceSerializer implements XMLDeserializer<ProjectRefere
String name = element.attributeValue(NAME_ATTR);
UUID profile = UUID.fromString(element.attributeValue(PROFILE_ATTR));
XMLHandler<Module> handler = new XMLHandler<>(element);
Set<Module> modules = new HashSet<>(handler.loadElements(MODULE_ELEMENT, new ModuleSerializer()));
ProfileReference profileRef = ProfileReference.getReference(profile);
ProjectReference ref = new ProjectReference(uuid, name, profileRef);
ProjectReference ref = new ProjectReference(uuid, name, profileRef, modules);
Path projectPath = ApplicationUtils.getApplication().getPath(PathType.DOCUMENTS, ref.getFileName());
if (Files.exists(projectPath)) {
try {
ref.setLastMofied(Files.getLastModifiedTime(projectPath).toMillis());
ref.setSize(Files.size(projectPath));
} catch (IOException e) {
e.printStackTrace();
}
......@@ -45,5 +53,8 @@ public class ProjectReferenceSerializer implements XMLDeserializer<ProjectRefere
newElement.addAttribute(UUID_ATTR, data.getUuid().toString());
newElement.addAttribute(NAME_ATTR, data.getName());
newElement.addAttribute(PROFILE_ATTR, data.getProfileReference().getUuid().toString());
XMLHandler<Module> handler = new XMLHandler<>(newElement);
handler.saveElements(MODULE_ELEMENT, data.getRequestedModules(), new ModuleSerializer());
}
}
......@@ -26,6 +26,7 @@ import de.tobias.playpad.plugin.Module;
public class ComponentRegistry<C> implements Registry<C> {
private HashMap<String, C> components;
// Zu einem Component die zugehörigen Meta Daten (das Modul)
private HashMap<String, Module> modules;
private String name;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment