01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08:
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19:
20: package org.netbeans.modules.bpel.project;
21:
22: import java.io.File;
23: import java.util.LinkedList;
24: import java.util.List;
25: import org.netbeans.api.project.ProjectUtils;
26: import org.netbeans.api.project.SourceGroup;
27: import org.netbeans.api.project.Sources;
28: import org.netbeans.modules.bpel.debugger.api.BpelSourcesRegistry;
29: import org.openide.filesystems.FileObject;
30: import org.openide.filesystems.FileUtil;
31: import org.openide.util.Lookup;
32:
33: /**
34: *
35: * @author Alexander Zgursky
36: */
37: public class BpelSourcesRegistryHelper {
38: private final BpelproProject myProject;
39: private final List<String> myRegisteredSources = new LinkedList<String>();
40: private final BpelSourcesRegistry mySourcesRegistry;
41:
42: /** Creates a new instance of BpelSourcesRegistryHelper */
43: public BpelSourcesRegistryHelper(BpelproProject project) {
44: myProject = project;
45: mySourcesRegistry = (BpelSourcesRegistry) Lookup.getDefault()
46: .lookup(BpelSourcesRegistry.class);
47: }
48:
49: public synchronized void register() {
50: if (mySourcesRegistry == null) {
51: return;
52: }
53: Sources sources = ProjectUtils.getSources(myProject);
54: SourceGroup sgs[] = sources
55: .getSourceGroups(IcanproProject.SOURCES_TYPE_ICANPRO);
56: for (int i = 0; i < sgs.length; i++) {
57: FileObject fo = sgs[i].getRootFolder();
58: if (fo == null) {
59: continue;
60: }
61:
62: File file = FileUtil.toFile(fo);
63: if (file == null) {
64: continue;
65: }
66:
67: String path = file.getPath();
68: if (mySourcesRegistry.addSourceRoot(path)) {
69: myRegisteredSources.add(path);
70: }
71: }
72: }
73:
74: public synchronized void unregister() {
75: if (mySourcesRegistry == null) {
76: return;
77: }
78: for (String path : myRegisteredSources) {
79: mySourcesRegistry.removeSourceRoot(path);
80: }
81: myRegisteredSources.clear();
82: }
83: }
|