Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
import javax.swing.Icon;
import javax.swing.ImageIcon;
import org.openide.util.ImageUtilities;
import org.openide.util.Utilities;


/**
* Class for persisting icons
* @author Milan Kubec, mkleint
*/
public class ExtIcon {
public final class ExtIcon {

Icon icon;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectInformation;
import org.netbeans.api.project.ProjectUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.logging.Level;
import javax.swing.Action;
import javax.swing.Icon;
import org.netbeans.api.project.Project;
Expand Down Expand Up @@ -55,21 +56,27 @@ final class LazyProject implements
ExtIcon icon;
private FileObject fo;

public LazyProject(URL url, String displayName, ExtIcon icon) {
LazyProject(URL url, String displayName, ExtIcon icon) {
super();
this.url = url;
this.displayName = displayName;
this.icon = icon;
}

static LazyProject forUrl(URL url) {
var slash = url.toString().lastIndexOf('/');
var dn = url.toString().substring(slash + 1);
return new LazyProject(url, dn, new ExtIcon());
}

@Override
public FileObject getProjectDirectory() {
if (fo != null) {
return fo;
}
fo = URLMapper.findFileObject(url);
if (fo == null) {
OpenProjectList.LOGGER.warning("Project dir with " + url + " not found!");
OpenProjectsLogging.LOGGER.log(Level.WARNING, "Project dir with {0} not found!", url);
fo = FileUtil.createMemoryFileSystem().getRoot();
}
return fo;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.project.ui;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.netbeans.api.project.Project;
import org.openide.filesystems.FileObject;
import org.openide.util.Lookup;
import org.openide.windows.WindowManager;

final class OpenProjectImpl {
/** Main project */
private Project mainProject;
/** List which holds the open projects */
private List<Project> openProjects = List.of();
private volatile OpenProjectOperation LOAD;

OpenProjectImpl() {

}

final List<Project> openProjects() {
return openProjects;
}

final void replaceProjectsImpl(OpenProjectsLoading.Callback callback, List<LazyProject> projects, URL mainProject, Lookup.Result<FileObject> selectedFiles) {
openProjects = new ArrayList<>(projects);
var urls = projects.stream().map(p -> p.url).toList();
var load = new OpenProjectsLoading(callback, selectedFiles, urls, mainProject);
LOAD = load;
WindowManager.getDefault().invokeWhenUIReady(load);
}

boolean waitFinished(long timeout) {
return LOAD.waitFinished(timeout);
}

void preferredProject(Set<FileObject> singleton) {
LOAD.preferredProject(singleton);
}

boolean isDone() {
return LOAD.isDone();
}

void enter() {
LOAD.enter();
}

void exit() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacement can permanently corrupt completion tracking.
exit() delegates to the current LOAD. However, close() increments the old loader before queuing close hooks, and replacement installs another loader before those hooks finish. Their completion decrements the new counter to -1, leaving isDone() false indefinitely. I reproduced this by holding the close queue during replacement and then draining it.

LOAD.exit();
}

boolean closeBeforeOpen(Project[] someProjects) {
return LOAD.closeBeforeOpen(someProjects);
}

void updateGlobalState(List<Project> projects, Project mainProject) {
this.openProjects = projects;
this.mainProject = mainProject;
}

Project mainProject() {
return this.mainProject;
}
}
Loading
Loading