Exemplo n.º 1
0
  /** Open attributes from an XML file. May return an empty value set, but never null. */
  static AttributeValueSets openAttributes() {
    final IPath pathHint = FileDialogs.recallPath(REMEMBER_DIRECTORY);
    final IPath readLocation = FileDialogs.openReadXML(pathHint);
    if (readLocation != null) {
      FileDialogs.rememberDirectory(REMEMBER_DIRECTORY, readLocation);
      try {
        final Persister persister = new Persister();
        final AttributeValueSets avs =
            persister.read(AttributeValueSets.class, readLocation.toFile());

        return avs;
      } catch (Exception e) {
        Utils.showError(
            new Status(
                IStatus.ERROR,
                WorkbenchCorePlugin.PLUGIN_ID,
                "Failed to read attributes from: " + readLocation.toOSString(),
                e));
      }
    }

    return new AttributeValueSets();
  }
Exemplo n.º 2
0
  /** Save attributes to an XML file. */
  static void saveAttributes(IPath filenameHint, AttributeValueSets attributes) {
    final IPath pathHint =
        filenameHint.isAbsolute()
            ? filenameHint
            : FileDialogs.recallPath(REMEMBER_DIRECTORY).append(filenameHint);

    final Path saveLocation = FileDialogs.openSaveXML(pathHint);
    if (saveLocation != null) {
      try {
        final Persister persister = new Persister(new Format(2));
        persister.write(attributes, saveLocation.toFile());
      } catch (Exception e) {
        Utils.showError(
            new Status(
                IStatus.ERROR,
                WorkbenchCorePlugin.PLUGIN_ID,
                "An error occurred while saving attributes.",
                e));
      }

      FileDialogs.rememberDirectory(REMEMBER_DIRECTORY, saveLocation);
    }
  }