01: /*
02: * {START_JAVA_COPYRIGHT_NOTICE
03: * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
04: * Use is subject to license terms.
05: * END_COPYRIGHT_NOTICE}
06: */
07:
08: package org.netbeans.modules.visualweb.project.jsf.libraries;
09:
10: import org.netbeans.api.project.Project;
11: import org.netbeans.modules.visualweb.complib.api.ComplibService;
12: import org.netbeans.spi.project.LookupProvider;
13: import org.netbeans.spi.project.ui.ProjectOpenedHook;
14: import org.openide.util.Lookup;
15: import org.openide.util.lookup.Lookups;
16:
17: /**
18: * Code used to initialize and clean up complibs associated with a project.
19: *
20: * @author Edwin Goei
21: */
22: public class ComplibLookupProvider implements LookupProvider {
23:
24: public static class ComplibProjectOpenedHook extends
25: ProjectOpenedHook {
26:
27: private Project project;
28:
29: private ComplibProjectOpenedHook(Project project) {
30: this .project = project;
31: }
32:
33: @Override
34: protected void projectOpened() {
35: ComplibService complibService = Lookup.getDefault().lookup(
36: ComplibService.class);
37: if (complibService != null) {
38: complibService.initProjectComplibs(project);
39: }
40: }
41:
42: @Override
43: protected void projectClosed() {
44: ComplibService complibService = Lookup.getDefault().lookup(
45: ComplibService.class);
46: if (complibService != null) {
47: complibService.cleanUpProjectComplibs(project);
48: }
49: }
50:
51: }
52:
53: public Lookup createAdditionalLookup(Lookup baseContext) {
54: Project project = baseContext.lookup(Project.class);
55: if (project == null) {
56: assert false : "Unable to derive Project";
57: return Lookup.EMPTY;
58: }
59:
60: ComplibProjectOpenedHook projectOpenedHook = new ComplibProjectOpenedHook(
61: project);
62: return Lookups.fixed(projectOpenedHook);
63: }
64: }
|