Exemplo n.º 1
0
  /** Constructor */
  public WorkspaceSpecManager() {
    // initialize the spec life cycle manager
    lifecycleManager = new SpecLifecycleManager();

    IProgressMonitor monitor = null;

    IWorkspace ws = ResourcesPlugin.getWorkspace();

    String specLoadedName =
        PreferenceStoreHelper.getInstancePreferenceStore()
            .getString(IPreferenceConstants.I_SPEC_LOADED);

    IProject[] projects = ws.getRoot().getProjects();
    try {

      Spec spec = null;
      for (int i = 0; i < projects.length; i++) {
        // changed from projects[i].isAccessible()
        if (projects[i].isOpen()) {
          if (projects[i].hasNature(TLANature.ID)) {
            spec = new Spec(projects[i]);
            // Added by LL on 12 Apr 2011
            // If spec.rootFile = null, then this is a bad spec. So
            // we should report it and not perform addSpec(spec).  It
            // would be nice if we could report it to the user, but
            // it seems to be impossible to popup a window at this point
            // in the code.
            if (spec.getRootFile() == null) {
              Activator.getDefault()
                  .logError("The bad spec is: `" + projects[i].getName() + "'", null);
            } else {
              // This to threw a null pointer exception for Tom, probably causing the abortion
              // of the Toolbox start. But it started on the next attempt.  Should we catch the
              // and perhaps report the bad spec?
              addSpec(spec);
            }

            // load the spec if found
            if (spec.getName().equals(specLoadedName)) {
              this.setSpecLoaded(spec);
            }
          }
        } else {
          // DELETE closed projects
          projects[i].delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, monitor);
        }
      }

      if (specLoadedName != null && !specLoadedName.equals("") && this.loadedSpec == null) {
        // there was a spec loaded but it was not found
        // explicit un-set it
        setSpecLoaded(null);
      }

    } catch (CoreException e) {
      Activator.getDefault().logError("Error initializing specification workspace", e);
    }

    ws.addResourceChangeListener(this);

    Platform.getAdapterManager().registerAdapters(this, IProject.class);
  }