1 package net.mograsim.logic.model.editor;
3 import java.io.IOException;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.widgets.FileDialog;
7 import org.eclipse.swt.widgets.Shell;
9 import net.mograsim.logic.model.model.ViewModelModifiable;
10 import net.mograsim.logic.model.serializing.DeserializedSubmodelComponent;
11 import net.mograsim.logic.model.serializing.IdentifierGetter;
12 import net.mograsim.logic.model.serializing.SubmodelComponentSerializer;
14 public class SaveLoadManager
16 private String savePath = null;
17 private Editor editor;
19 public SaveLoadManager(Editor editor)
32 public void openSaveAsDialog()
34 Shell fdShell = new Shell();
35 FileDialog fd = new FileDialog(fdShell, SWT.SAVE);
36 fd.setText("Save as...");
37 fd.setFilterExtensions(new String[] { "*.json" });
38 String result = fd.open();
47 private void innerSave()
51 IdentifierGetter idGetter = new IdentifierGetter();
52 idGetter.componentIDs = c ->
54 if (Editor.identifierPerComponent.containsKey(c))
55 return Editor.identifierPerComponent.get(c);
56 return "class:" + c.getClass().getCanonicalName();
58 SubmodelComponentSerializer.serialize(editor.toBeEdited, idGetter, savePath);
63 System.err.println("Failed to save component!");
68 public static void openLoadDialog() throws IOException
70 Shell fdShell = new Shell();
71 FileDialog fd = new FileDialog(fdShell, SWT.OPEN);
72 fd.setText("Load component...");
73 fd.setFilterExtensions(new String[] { "*.json" });
74 String result = fd.open();
78 new Editor((DeserializedSubmodelComponent) SubmodelComponentSerializer.deserialize(new ViewModelModifiable(), result));