@Override
    protected void projectOpened() {
      GradleModelLoader.addModelLoadedListener(modelLoadListener);
      reloadProject(true);

      if (licenseChangeListener != null) {
        LOGGER.warning("projectOpened() without close.");
        properties.getLicenseHeader().removeChangeListener(licenseChangeListener);
      }

      licenseChangeListener =
          new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
              registerLicense();
            }
          };
      properties.getLicenseHeader().addChangeListener(licenseChangeListener);

      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              opened = true;
              registerLicenseNow();
            }
          });
    }
  private NbGradleProject(FileObject projectDir, ProjectState state) throws IOException {
    this.projectDir = projectDir;
    this.projectDirAsFile = FileUtil.toFile(projectDir);
    if (projectDirAsFile == null) {
      throw new IOException("Project directory does not exist.");
    }

    this.mergedCommandQueryRef = new AtomicReference<BuiltInGradleCommandQuery>(null);
    this.delayedInitTasks =
        new AtomicReference<Queue<Runnable>>(new LinkedBlockingQueue<Runnable>());
    this.state = state;
    this.defaultLookupRef = new AtomicReference<Lookup>(null);
    this.properties = new ProjectPropertiesProxy(this);
    this.projectInfoManager = new ProjectInfoManager();

    this.hasModelBeenLoaded = new AtomicBoolean(false);
    this.loadErrorRef = new AtomicReference<ProjectInfoRef>(null);
    this.modelChanges = new ChangeSupport(this);
    this.currentModelRef =
        new AtomicReference<NbGradleModelRef>(
            new NbGradleModelRef(GradleModelLoader.createEmptyModel(projectDirAsFile)));

    this.loadedAtLeastOnceSignal = new WaitableSignal();
    this.name = projectDir.getNameExt();
    this.exceptionDisplayer = new ExceptionDisplayer(NbStrings.getProjectErrorTitle(name));
    this.extensionRefs = Collections.emptyList();
    this.extensionsOnLookup = Lookup.EMPTY;
    this.lookupRef = new AtomicReference<DynamicLookup>(null);
    this.protectedLookupRef = new AtomicReference<Lookup>(null);
  }
    @Override
    protected void projectClosed() {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              opened = false;

              if (licenseRef != null) {
                licenseRef.unregister();
                licenseRef = null;
              }
            }
          });

      if (licenseChangeListener != null) {
        properties.getLicenseHeader().removeChangeListener(licenseChangeListener);
        licenseChangeListener = null;
      }

      GradleModelLoader.removeModelLoadedListener(modelLoadListener);
    }