Just set up a watcher on your project files.

On 11/12/21 20:35, Peter Cheung wrote:
Hi
     I am developing verilog plugins, i creatre a new project type. When the 
file is deleted in the fs, the project tree won't auto refresh. Any hints 
please?
thanks
Peter

/*
  * Copyright 2021 Peter <[email protected]>.
  *
  * Licensed 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 hk.quantr.netbeans.verilog.projecttype;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.swing.event.ChangeListener;
import org.netbeans.api.project.Project;
import org.netbeans.spi.project.ui.support.NodeFactory;
import org.netbeans.spi.project.ui.support.NodeList;
import org.openide.filesystems.FileObject;
import org.openide.loaders.DataObject;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.nodes.FilterNode;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;

/**
  *
  * @author Peter <[email protected]>
  */
@NodeFactory.Registration(projectType = "verilog-project", position = 10)
public class VerilogNodeFactory implements NodeFactory {

@Override
public NodeList<?> createNodes(Project project) {
System.out.println("createNodes");
return new VerilogNodeList(project);
}

private class VerilogNodeList implements NodeList<Node> {

Project project;

public VerilogNodeList(Project project) {
this.project = project;
}

@Override
public List<Node> keys() {
System.out.println("keys");
FileObject folder = project.getProjectDirectory();
List<Node> result = new ArrayList<>();
if (folder != null) {
for (FileObject f : Stream.of(folder.getChildren())
.filter(e -> e.isFolder() && !e.getName().equals(".git"))
.sorted(Comparator.comparing(FileObject::getName))
.collect(Collectors.toList())) {
try {
result.add(DataObject.find(f).getNodeDelegate());
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
}
for (FileObject f : Stream.of(folder.getChildren())
.filter(e -> !e.isFolder())
.sorted(Comparator.comparing(FileObject::getName))
.collect(Collectors.toList())) {
try {
result.add(DataObject.find(f).getNodeDelegate());
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
}
}
return result;
}

@Override
public Node node(Node node) {
return new FilterNode(node);
}

@Override
public void addNotify() {
System.out.println("addNotify");
}

@Override
public void removeNotify() {
System.out.println("removeNotify");
}

@Override
public void addChangeListener(ChangeListener cl) {
System.out.println("addChangeListener");
}

@Override
public void removeChangeListener(ChangeListener cl) {
System.out.println("removeChangeListener");
}

}
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Reply via email to