001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.modules.php.project.options;
029:
030: import java.beans.PropertyChangeListener;
031: import java.beans.PropertyChangeSupport;
032: import java.util.Collection;
033: import java.util.LinkedHashMap;
034: import java.util.LinkedList;
035: import java.util.List;
036: import java.util.Map;
037: import javax.swing.JComponent;
038: import javax.swing.JTabbedPane;
039: import org.netbeans.spi.options.AdvancedOption;
040: import org.netbeans.spi.options.OptionsPanelController;
041: import org.openide.util.HelpCtx;
042: import org.openide.util.Lookup;
043: import org.openide.util.lookup.Lookups;
044:
045: /**
046: *
047: * @author avk
048: */
049: final class PhpOptionsPanelController extends OptionsPanelController {
050:
051: private static final String TAB_FOLDER = "org.netbeans.modules.php/options/";
052:
053: public PhpOptionsPanelController() {
054: readPanels();
055: }
056:
057: public void update() {
058: for (OptionsPanelController c : getControllers()) {
059: c.update();
060: }
061: }
062:
063: public void applyChanges() {
064: for (OptionsPanelController c : getControllers()) {
065: c.applyChanges();
066: }
067: }
068:
069: public void cancel() {
070: for (OptionsPanelController c : getControllers()) {
071: c.cancel();
072: }
073: }
074:
075: public boolean isValid() {
076: for (OptionsPanelController c : getControllers()) {
077: if (!c.isValid()) {
078: return false;
079: }
080: }
081: return true;
082: }
083:
084: public boolean isChanged() {
085: for (OptionsPanelController c : getControllers()) {
086: if (c.isChanged()) {
087: return true;
088: }
089: }
090: return false;
091: }
092:
093: public HelpCtx getHelpCtx() {
094: return null; // new HelpCtx("...ID") if you have a help set
095: }
096:
097: public synchronized JComponent getComponent(Lookup masterLookup) {
098: if (myPane == null) {
099: myPane = new JTabbedPane();
100: for (OptionsPanelController c : getControllers()) {
101: myPane.add(myControllers2Options.get(c)
102: .getDisplayName(), c
103: .getComponent(c.getLookup()));
104: }
105: }
106: return myPane;
107: }
108:
109: public void addPropertyChangeListener(PropertyChangeListener l) {
110: myPcs.addPropertyChangeListener(l);
111: }
112:
113: public void removePropertyChangeListener(PropertyChangeListener l) {
114: myPcs.removePropertyChangeListener(l);
115: }
116:
117: private void readPanels() {
118: myOptions = new LinkedList<AdvancedOption>();
119: for (AdvancedOption advancedOption : Lookups
120: .forPath(TAB_FOLDER).lookupAll(AdvancedOption.class)) {
121: myOptions.add(advancedOption);
122: }
123: }
124:
125: private synchronized Collection<OptionsPanelController> getControllers() {
126: if (myControllers == null) {
127: myControllers2Options = new LinkedHashMap<OptionsPanelController, AdvancedOption>();
128: myControllers = new LinkedList<OptionsPanelController>();
129: for (AdvancedOption o : myOptions) {
130: OptionsPanelController c = o.create();
131: myControllers2Options.put(c, o);
132: myControllers.add(c);
133: }
134: }
135:
136: return myControllers;
137: }
138:
139: private Map<OptionsPanelController, AdvancedOption> myControllers2Options;
140:
141: private List<OptionsPanelController> myControllers;
142:
143: private final PropertyChangeSupport myPcs = new PropertyChangeSupport(
144: this );
145:
146: private List<AdvancedOption> myOptions;
147:
148: private JTabbedPane myPane;
149:
150: }
|