Package archmapper.main

Source Code of archmapper.main.Preferences

package archmapper.main;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.osgi.service.prefs.BackingStoreException;

public class Preferences {
  IEclipsePreferences pref;

  public Preferences(IProject project) {
    IScopeContext projectScope = new ProjectScope(project);
    pref = projectScope.getNode(Activator.PLUGIN_ID);
  }
 
  /**
   * Returns whether the preferences for the given project are set so that
   * a conformance check or code generation for the project can be performed.
   *
   * @param project
   * @return
   */
  public static boolean isPreferencesSet(IProject project) {
    return (new Preferences(project)).getArchitectureFile() != null;
  }

  /**
   * Returns the architecture file stored in the project preferences or the
   * empty string (""), if none has been set.
   *
   * @return
   */
  public String getArchitectureFilename() {
    return pref.get("archFile", "");
  }

  /**
   * Returns the architecture file or null, if none is set for the project.
   *
   * @return
   */
  public IFile getArchitectureFile() {
    if (!getArchitectureFilename().equals("")) {
      return ResourcesPlugin.getWorkspace().getRoot().getFile(
          new Path(getArchitectureFilename()));
    } else {
      return null;
    }
  }

  public void setArchitectureFilename(String filename) {
    pref.put("archFile", filename);
  }
 
  public String getArchitectureMappingFilename() {
    return pref.get("archMappingFile", "");
  }
 
  public void setArchitectureMappingFilename(String filename) {
    pref.put("archMappingFile", filename);
  }
 
  /**
   * Returns the file in which the architecture mapping is stored,
   * or null, if no mapping file is defined in the preferences.
   *
   * @return
   */
  public IFile getArchitectureMappingFile() {
    if (!getArchitectureMappingFilename().equals("")) {
      return ResourcesPlugin.getWorkspace().getRoot().getFile(
          new Path(getArchitectureMappingFilename()));
    }
    return null;
  }

  /**
   * Returns whether the StyleChecker is enabled or not. Default is false.
   *
   * @return
   */
  public boolean isArchitectureMappingPresent() {
    return pref.getBoolean("architectureMappingPresent", false);
  }

  public void setArchitectureMappingPresent(boolean present) {
    pref.putBoolean("architectureMappingPresent", present);
  }

  /**
   * Writes the preferences to disk. Opens an error dialog if something went
   * wrong.
   *
   */
  public void flushPreferencesFile() {
    try {
      pref.flush();
    } catch (BackingStoreException e) {
      ErrorDialog.openError(null, "Error",
          "The preferences for ArchChecker could not be saved: "
              + e.getMessage(), new Status(Status.ERROR,
              Activator.PLUGIN_ID, Status.OK, e.getMessage(), e));
    }
  }

}
TOP

Related Classes of archmapper.main.Preferences

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.