Package edu.wpi.grip.core.serialization
Class Project
- java.lang.Object
-
- edu.wpi.grip.core.serialization.Project
-
@Singleton public class Project extends java.lang.Object
Helper for saving and loading a processing pipeline to and from a file.
-
-
Field Summary
Fields Modifier and Type Field Description protected com.thoughtworks.xstream.XStream
xstream
-
Constructor Summary
Constructors Constructor Description Project()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addIsSaveDirtyConsumer(java.util.function.Consumer<java.lang.Boolean> consumer)
java.util.Optional<java.io.File>
getFile()
void
initialize(StepConverter stepConverter, SourceConverter sourceConverter, SocketConverter socketConverter, ConnectionConverter connectionConverter, ProjectSettingsConverter projectSettingsConverter, CodeGenerationSettingsConverter codeGenerationSettingsConverter)
boolean
isSaveDirty()
void
onDirtiesSaveEvent(DirtiesSaveEvent dirtySaveEvent)
void
open(java.io.File file)
Load the project from a file.void
open(java.lang.String projectXml)
Loads the project defined by the given XML string.void
save(java.io.File file)
Save the project to a file.void
save(java.io.Writer writer)
void
setFile(java.util.Optional<java.io.File> file)
boolean
trySave(java.io.File file)
Tries to save this project to the given file.
-
-
-
Method Detail
-
initialize
@Inject public void initialize(StepConverter stepConverter, SourceConverter sourceConverter, SocketConverter socketConverter, ConnectionConverter connectionConverter, ProjectSettingsConverter projectSettingsConverter, CodeGenerationSettingsConverter codeGenerationSettingsConverter)
-
getFile
public java.util.Optional<java.io.File> getFile()
- Returns:
- The file that this project is located in, if it was loaded from/saved to a file.
-
setFile
public void setFile(java.util.Optional<java.io.File> file)
-
open
public void open(java.io.File file) throws java.io.IOException
Load the project from a file.- Throws:
java.io.IOException
- if the project file could not be read
-
open
public void open(java.lang.String projectXml)
Loads the project defined by the given XML string. This is intended to be used to be able to programmatically run a pipeline from a remote source. Therefore, this does not save the contents to disk; if it is called in GUI mode, the user will have to manually save the file.- Parameters:
projectXml
- the XML string defining the project to open
-
trySave
public boolean trySave(java.io.File file)
Tries to save this project to the given file. Unlikesave(File)
, this will not throw an IOException and will instead post a warning event to the event bus.- Parameters:
file
- the file to save to- Returns:
- true if the project was successfully saved to the given file, or false if the file could not be written to
-
save
public void save(java.io.File file) throws java.io.IOException
Save the project to a file.- Throws:
java.io.IOException
- if the file could not written
-
save
public void save(java.io.Writer writer)
-
isSaveDirty
public boolean isSaveDirty()
-
addIsSaveDirtyConsumer
public void addIsSaveDirtyConsumer(java.util.function.Consumer<java.lang.Boolean> consumer)
-
onDirtiesSaveEvent
public void onDirtiesSaveEvent(DirtiesSaveEvent dirtySaveEvent)
-
-