Example #1
0
  private void save() {

    // If the save directory does not exist, create it
    File saveDir = new File(SAVE_DIR);
    if (!saveDir.exists()) saveDir.mkdir();

    // The save file
    File saveFile = new File(SAVE_FILE);

    // Create the root memento
    XMLMemento memento = XMLMemento.createWriteRoot("root");

    // Save the data sources
    for (CyclistDatasource source : _model.getSources()) {
      source.save(memento.createChild("CyclistDatasource"));
    }

    // Save the data tables
    for (Table table : _model.getTables()) {
      table.save(memento.createChild("Table"));
    }

    try {
      memento.save(new PrintWriter(saveFile));

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #2
0
  // Load saved properties
  private void load() {

    // Check if the save file exists
    File saveFile = new File(SAVE_FILE);

    // If we have a save file, read it in
    if (saveFile.exists()) {

      Reader reader;
      try {
        reader = new FileReader(saveFile);
        try {
          // Create the root memento
          XMLMemento memento = XMLMemento.createReadRoot(reader);

          // Read in the data sources
          IMemento[] sources = memento.getChildren("CyclistDatasource");
          for (IMemento source : sources) {
            CyclistDatasource datasource = new CyclistDatasource();
            datasource.restore(source);
            _model.getSources().add(datasource);
          }

          // Read in the tables
          IMemento[] tables = memento.getChildren("Table");
          // System.out.println("tables " + tables.length);
          for (IMemento table : tables) {
            Table tbl = new Table();
            tbl.restore(table, _model.getSources());
            _model.getTables().add(tbl);
          }

        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }
  }