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: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.php.project.options;
042:
043: import java.awt.BorderLayout;
044: import java.awt.GridBagConstraints;
045: import java.awt.GridBagLayout;
046: import java.beans.PropertyChangeListener;
047: import java.util.ArrayList;
048: import java.util.HashMap;
049: import java.util.Iterator;
050: import java.util.List;
051: import java.util.Map;
052: import javax.swing.JComponent;
053: import javax.swing.JPanel;
054: import org.netbeans.spi.options.AdvancedOption;
055: import org.netbeans.spi.options.OptionsPanelController;
056: import org.openide.util.HelpCtx;
057: import org.openide.util.Lookup;
058: import org.openide.util.NbBundle;
059: import org.openide.util.lookup.Lookups;
060:
061: /**
062: * Php Actions options panel combined from panels for various settings.
063: *
064: * @author akorostelev
065: */
066: public class ActionsOptionsContainerPanel extends AdvancedOption {
067:
068: private static final String TAB_FOLDER = "org.netbeans.modules.php/ActionsOptions";
069:
070: private static String CTL_ACTIONS_NAME = "CTL_Actions_DisplayName";
071:
072: private static String CTL_ACTIONS_TIP = "CTL_Actions_ToolTip";
073:
074: public String getDisplayName() {
075: return NbBundle.getMessage(ActionsOptionsContainerPanel.class,
076: CTL_ACTIONS_NAME); // NOI18N
077: }
078:
079: public String getTooltip() {
080: return NbBundle.getMessage(ActionsOptionsContainerPanel.class,
081: CTL_ACTIONS_TIP); // NOI18N
082: }
083:
084: public OptionsPanelController create() {
085: return new Controller();
086: }
087:
088: private static final class Controller extends
089: OptionsPanelController {
090: private JPanel panel;
091: private boolean initialized = false;
092: private Map<String, AdvancedOption> categoryToOption = new HashMap<String, AdvancedOption>();
093: private Map<String, JComponent> categoryToPanel = new HashMap<String, JComponent>();
094: private Map<String, OptionsPanelController> categoryToController = new HashMap<String, OptionsPanelController>();
095: private List<String> categoriesOrdered = new ArrayList<String>();
096:
097: private void init(Lookup masterLookup) {
098: if (initialized)
099: return;
100: initialized = true;
101:
102: Lookup lookup = Lookups.forPath(TAB_FOLDER); // NOI18N
103: Iterator<? extends AdvancedOption> it = lookup.lookup(
104: new Lookup.Template<AdvancedOption>(
105: AdvancedOption.class)).allInstances()
106: .iterator();
107: while (it.hasNext()) {
108: AdvancedOption option = it.next();
109: String category = option.getDisplayName();
110: categoriesOrdered.add(category);
111: categoryToOption.put(category, option);
112: OptionsPanelController controller = option.create();
113: categoryToController.put(category, controller);
114: JPanel panel = new JPanel();
115: //panel.setBorder(BorderFactory.createTitledBorder(category));
116: panel.setLayout(new BorderLayout());
117: panel.add(controller.getComponent(masterLookup));
118: categoryToPanel.put(category, panel);
119: }
120: }
121:
122: public JComponent getComponent(Lookup masterLookup) {
123: init(masterLookup);
124: if (panel == null) {
125: panel = new JPanel();
126: panel.setLayout(new GridBagLayout());
127: for (String category : categoriesOrdered) {
128: JComponent component = categoryToPanel
129: .get(category);
130: GridBagConstraints gbc = new GridBagConstraints();
131: gbc.anchor = GridBagConstraints.NORTHWEST;
132: gbc.fill = GridBagConstraints.BOTH;
133: gbc.weightx = 0.0;
134: gbc.weighty = 0.0;
135: gbc.gridwidth = java.awt.GridBagConstraints.REMAINDER;
136: panel.add(component, gbc);
137: }
138: // Dummy panel to eat up all the rest of the space
139: GridBagConstraints gridBagConstraints = new GridBagConstraints();
140: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
141: gridBagConstraints.weightx = 1.0;
142: gridBagConstraints.weighty = 1.0;
143: panel.add(new JPanel(), gridBagConstraints);
144: }
145:
146: return panel;
147: }
148:
149: public void removePropertyChangeListener(
150: PropertyChangeListener l) {
151: }
152:
153: public void addPropertyChangeListener(PropertyChangeListener l) {
154: }
155:
156: public void update() {
157: Iterator it = categoryToController.values().iterator();
158: while (it.hasNext())
159: ((OptionsPanelController) it.next()).update();
160: }
161:
162: public void applyChanges() {
163: Iterator it = categoryToController.values().iterator();
164: while (it.hasNext())
165: ((OptionsPanelController) it.next()).applyChanges();
166: }
167:
168: public void cancel() {
169: Iterator it = categoryToController.values().iterator();
170: while (it.hasNext())
171: ((OptionsPanelController) it.next()).cancel();
172: }
173:
174: public boolean isValid() {
175: Iterator it = categoryToController.values().iterator();
176: while (it.hasNext())
177: if (!((OptionsPanelController) it.next()).isValid())
178: return false;
179: return true;
180: }
181:
182: public boolean isChanged() {
183: Iterator it = categoryToController.values().iterator();
184: while (it.hasNext())
185: if (((OptionsPanelController) it.next()).isChanged())
186: return true;
187: return false;
188: }
189:
190: public HelpCtx getHelpCtx() {
191: return HelpCtx.DEFAULT_HELP;
192: }
193: }
194: }
|