private void saveState() {
    XMLMemento memento = XMLMemento.createWriteRoot("map");
    for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry entry = (Map.Entry) i.next();
      String workingSetId = (String) entry.getKey();
      Record record = (Record) entry.getValue();
      IPersistableElement element =
          (IPersistableElement) record.root.getAdapter(IPersistableElement.class);
      if (element == null) {
        StatusManager.getManager()
            .handle(
                new Status(
                    IStatus.ERROR,
                    Activator.PLUGIN_ID,
                    "could not persist root element for dynamic resource working set.  No persistable element adapter found."));
      }

      IMemento child = memento.createChild("workingSet", workingSetId);
      child.putString("pattern", record.pattern.pattern());

      IMemento rootItem = memento.createChild("root");
      rootItem.putString("factoryID", element.getFactoryId());
      element.saveState(rootItem);
    }
    StringWriter result = new StringWriter();
    try {
      memento.save(result);
      Activator.getInstance().getPreferenceStore().setValue("expressionMemento", result.toString());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Beispiel #2
0
 /**
  * Saves the code folding state to a XML file in the state location.
  *
  * @param uriString the key to determine the file to save to
  */
 public void saveCodeFoldingStateFile(String uriString) {
   org.eclipse.jface.text.IDocument document = sourceViewer.getDocument();
   if (document == null) {
     return;
   }
   org.eclipse.ui.XMLMemento codeFoldingMemento = org.eclipse.ui.XMLMemento.createWriteRoot(MODEL);
   codeFoldingMemento.putString(VERIFY_KEY, makeMD5(document.get()));
   saveCodeFolding(codeFoldingMemento);
   java.io.File stateFile = getCodeFoldingStateFile(uriString);
   if (stateFile == null) {
     return;
   }
   try {
     java.io.FileOutputStream stream = new java.io.FileOutputStream(stateFile);
     java.io.OutputStreamWriter writer = new java.io.OutputStreamWriter(stream, "utf-8");
     codeFoldingMemento.save(writer);
     writer.close();
   } catch (java.io.IOException e) {
     stateFile.delete();
     org.eclipse.jface.dialogs.MessageDialog.openError(
         (org.eclipse.swt.widgets.Shell) null,
         "Saving Problems",
         "Unable to save code folding state.");
   }
 }
 /**
  * Reads an object from a {@link IMemento}. The memento's type (root) must equal the bean's {@link
  * Root} annotation name attribute.
  */
 static <T> T fromMemento(Class<T> clazz, IMemento memento) throws IOException {
   try {
     final StringWriter sw = new StringWriter();
     final XMLMemento m = XMLMemento.createWriteRoot(memento.getType());
     m.putMemento(memento);
     m.save(sw);
     return new Persister().read(clazz, new StringReader(sw.toString()));
   } catch (Exception e) {
     throw ExceptionUtils.wrapAs(IOException.class, e);
   }
 }
 protected String createViewMemento(IIssue issue) {
   StringWriter out = new StringWriter();
   XMLMemento memento = XMLMemento.createWriteRoot("root"); // $NON-NLS-1$
   issue.getViewMemento(memento);
   try {
     memento.save(out);
   } catch (IOException e) {
     IssuesActivator.log("", e); // $NON-NLS-1$
   }
   return out.toString();
 }
Beispiel #5
0
  /**
   * Save monitors to persistent storage. Just saves the monitor metadata. The actual monitor
   * information will be saved when the monitor is created.
   */
  private void saveMonitors() {
    final XMLMemento memento = XMLMemento.createWriteRoot(MONITORS_ATTR);
    for (IMonitorControl monitor : fMonitorControls.values()) {
      memento.createChild(MONITOR_ID_ATTR, monitor.getId());
    }

    try {
      FileWriter writer = new FileWriter(getSaveLocation());
      memento.save(writer);
    } catch (final IOException e) {
      LMLMonitorCorePlugin.log(e.getLocalizedMessage());
    }
  }
  /**
   * saves the given root memento with the given key in the preference area
   *
   * @param xmlMemento the memento to save
   * @param key the key for the preference store
   */
  private static void saveMemento(XMLMemento xmlMemento, String key) {
    // save memento
    StringWriter writer = new StringWriter();
    try {
      xmlMemento.save(writer);

      if (getPreferenceStore() != null) {
        getPreferenceStore().setValue(key, writer.toString());
      }
    } catch (IOException e) {
      Activator.getDefault().logError("input/ouput exception", e);
    }
  }
Beispiel #7
0
  private static void writeMementoToDisk(XMLMemento memento) {
    IPath path = URLWaypointPlugin.getDefault().getStateLocation().append(URL_FILE);
    File mementoFile = path.toFile();
    mementoFile.getParentFile().mkdirs();

    try {
      FileOutputStream stream = new FileOutputStream(mementoFile);
      OutputStreamWriter writer = new OutputStreamWriter(stream, "utf-8"); // $NON-NLS-1$
      memento.save(writer);
      writer.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  /** Convert any {@link IMemento} to a string. */
  public static String toString(IMemento memento) {
    if (!(memento instanceof XMLMemento)) {
      XMLMemento m = XMLMemento.createWriteRoot(memento.getType());
      m.putMemento(memento);
      memento = m;
    }

    try {
      final StringWriter w = new StringWriter();
      ((XMLMemento) memento).save(w);
      return w.toString();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  boolean persist() {
    XMLMemento persistedState = (XMLMemento) getEditorState();
    if (persistedState == null) return false;

    StringWriter writer = new StringWriter();
    try {
      persistedState.save(writer);
      getModel().getPersistedState().put(MEMENTO_KEY, writer.toString());
    } catch (IOException e) {
      WorkbenchPlugin.log(e);
      return false;
    }

    return true;
  }