raster@14498
|
1 |
/*
|
raster@14498
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
raster@14498
|
3 |
*
|
raster@14498
|
4 |
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
|
raster@14498
|
5 |
*
|
raster@14498
|
6 |
* The contents of this file are subject to the terms of either the GNU
|
raster@14498
|
7 |
* General Public License Version 2 only ("GPL") or the Common
|
raster@14498
|
8 |
* Development and Distribution License("CDDL") (collectively, the
|
raster@14498
|
9 |
* "License"). You may not use this file except in compliance with the
|
raster@14498
|
10 |
* License. You can obtain a copy of the License at
|
raster@14498
|
11 |
* http://www.netbeans.org/cddl-gplv2.html
|
raster@14498
|
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
raster@14498
|
13 |
* specific language governing permissions and limitations under the
|
raster@14498
|
14 |
* License. When distributing the software, include this License Header
|
raster@14498
|
15 |
* Notice in each file and include the License file at
|
raster@14498
|
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
|
raster@14498
|
17 |
* particular file as subject to the "Classpath" exception as provided
|
raster@14498
|
18 |
* by Sun in the GPL Version 2 section of the License file that
|
raster@14498
|
19 |
* accompanied this code. If applicable, add the following below the
|
raster@14498
|
20 |
* License Header, with the fields enclosed by brackets [] replaced by
|
raster@14498
|
21 |
* your own identifying information:
|
raster@14498
|
22 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
raster@14498
|
23 |
*
|
raster@14498
|
24 |
* If you wish your version of this file to be governed by only the CDDL
|
raster@14498
|
25 |
* or only the GPL Version 2, indicate your decision by adding
|
raster@14498
|
26 |
* "[Contributor] elects to include this software in this distribution
|
raster@14498
|
27 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
raster@14498
|
28 |
* single choice of license, a recipient has the option to distribute
|
raster@14498
|
29 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
raster@14498
|
30 |
* to extend the choice of license to its licensees as provided above.
|
raster@14498
|
31 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
raster@14498
|
32 |
* Version 2 license, then the option applies only if the new code is
|
raster@14498
|
33 |
* made subject to such option by the copyright holder.
|
raster@14498
|
34 |
*
|
raster@14498
|
35 |
* Contributor(s):
|
raster@14498
|
36 |
*
|
raster@14498
|
37 |
* Portions Copyrighted 2008 Sun Microsystems, Inc.
|
raster@14498
|
38 |
*/
|
raster@14498
|
39 |
|
raster@14498
|
40 |
package org.netbeans.modules.ada.options;
|
raster@14498
|
41 |
|
raster@14498
|
42 |
import java.beans.PropertyChangeListener;
|
raster@14498
|
43 |
import java.beans.PropertyChangeSupport;
|
raster@14498
|
44 |
import java.util.Collection;
|
raster@14498
|
45 |
import java.util.LinkedHashMap;
|
raster@14498
|
46 |
import java.util.Map;
|
raster@14498
|
47 |
import java.util.Map.Entry;
|
raster@14498
|
48 |
import java.util.Set;
|
raster@14498
|
49 |
import javax.swing.JComponent;
|
raster@14498
|
50 |
import javax.swing.JTabbedPane;
|
raster@14498
|
51 |
import javax.swing.event.ChangeEvent;
|
raster@14498
|
52 |
import javax.swing.event.ChangeListener;
|
raster@15779
|
53 |
import org.netbeans.modules.ada.project.options.AdaOptions;
|
raster@16367
|
54 |
import org.netbeans.modules.ada.project.options.ui.AdaGeneralOptionsPanel;
|
raster@14498
|
55 |
import org.netbeans.modules.ada.editor.formatter.ui.FormattingOptionsPanel;
|
raster@14498
|
56 |
import org.netbeans.spi.options.AdvancedOption;
|
raster@14498
|
57 |
import org.netbeans.spi.options.OptionsPanelController;
|
raster@14498
|
58 |
import org.openide.util.HelpCtx;
|
raster@14498
|
59 |
import org.openide.util.Lookup;
|
raster@14498
|
60 |
import org.openide.util.NbBundle;
|
raster@14498
|
61 |
import org.openide.util.lookup.Lookups;
|
raster@14498
|
62 |
|
raster@14498
|
63 |
/**
|
raster@14498
|
64 |
* @author Andrea Lucarelli
|
raster@14498
|
65 |
*/
|
raster@16367
|
66 |
public class AdaOptionsPanelController extends OptionsPanelController implements ChangeListener, HelpCtx.Provider {
|
raster@14498
|
67 |
|
raster@14498
|
68 |
private static final String TAB_FOLDER = "org.netbeans.modules.ada/options/"; // NOI18N
|
raster@15779
|
69 |
private final AdaGeneralOptionsPanel generalOptionsPanel = new AdaGeneralOptionsPanel(null);
|
raster@14498
|
70 |
private final FormattingOptionsPanel formattingOptionsPanel = new FormattingOptionsPanel();
|
raster@14498
|
71 |
private final Collection<? extends AdvancedOption> options;
|
raster@14498
|
72 |
private final PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
|
raster@14498
|
73 |
private Map<OptionsPanelController, AdvancedOption> controllers2Options;
|
raster@14498
|
74 |
private JTabbedPane pane;
|
raster@14498
|
75 |
private boolean changed;
|
raster@14498
|
76 |
|
raster@14498
|
77 |
public AdaOptionsPanelController() {
|
raster@14498
|
78 |
options = Lookups.forPath(TAB_FOLDER).lookupAll(AdvancedOption.class);
|
raster@14498
|
79 |
generalOptionsPanel.addChangeListener(this);
|
raster@14498
|
80 |
}
|
raster@14498
|
81 |
|
raster@14498
|
82 |
private synchronized Map<OptionsPanelController, AdvancedOption> getControllers2Options() {
|
raster@14498
|
83 |
if (controllers2Options == null) {
|
raster@14498
|
84 |
controllers2Options = new LinkedHashMap<OptionsPanelController, AdvancedOption>();
|
raster@14498
|
85 |
for (AdvancedOption o : options) {
|
raster@14498
|
86 |
OptionsPanelController c = o.create();
|
raster@14498
|
87 |
controllers2Options.put(c, o);
|
raster@14498
|
88 |
}
|
raster@14498
|
89 |
}
|
raster@14498
|
90 |
|
raster@14498
|
91 |
return controllers2Options;
|
raster@14498
|
92 |
}
|
raster@14498
|
93 |
|
raster@14498
|
94 |
private Set<OptionsPanelController> getControllers() {
|
raster@14498
|
95 |
return getControllers2Options().keySet();
|
raster@14498
|
96 |
}
|
raster@14498
|
97 |
|
raster@14498
|
98 |
@Override
|
raster@14498
|
99 |
public void update() {
|
raster@14498
|
100 |
for (OptionsPanelController c : getControllers()) {
|
raster@14498
|
101 |
c.update();
|
raster@14498
|
102 |
}
|
raster@15779
|
103 |
|
raster@15779
|
104 |
generalOptionsPanel.setAdaDialects(getAdaOptions().getAdaDialects());
|
raster@15779
|
105 |
generalOptionsPanel.setAdaRestrictions(getAdaOptions().getAdaRestrictions());
|
raster@15779
|
106 |
generalOptionsPanel.setPkgSpecPrefix(getAdaOptions().getPkgSpecPrefix());
|
raster@15779
|
107 |
generalOptionsPanel.setPkgBodyPrefix(getAdaOptions().getPkgBodyPrefix());
|
raster@15779
|
108 |
generalOptionsPanel.setSeparatePrefix(getAdaOptions().getSeparatePrefix());
|
raster@15779
|
109 |
generalOptionsPanel.setPkgSpecPostfix(getAdaOptions().getPkgSpecPostfix());
|
raster@15779
|
110 |
generalOptionsPanel.setPkgBodyPostfix(getAdaOptions().getPkgBodyPostfix());
|
raster@15779
|
111 |
generalOptionsPanel.setSeparatePostfix(getAdaOptions().getSeparatePostfix());
|
raster@15779
|
112 |
generalOptionsPanel.setPkgSpecExt(getAdaOptions().getPkgSpecExt());
|
raster@15779
|
113 |
generalOptionsPanel.setPkgBodyExt(getAdaOptions().getPkgBodyExt());
|
raster@15779
|
114 |
generalOptionsPanel.setSeparateExt(getAdaOptions().getSeparateExt());
|
raster@14498
|
115 |
|
raster@14498
|
116 |
changed = false;
|
raster@14498
|
117 |
}
|
raster@14498
|
118 |
|
raster@14498
|
119 |
@Override
|
raster@14498
|
120 |
public void applyChanges() {
|
raster@14498
|
121 |
for (OptionsPanelController c : getControllers()) {
|
raster@14498
|
122 |
c.applyChanges();
|
raster@14498
|
123 |
}
|
raster@14498
|
124 |
|
raster@15779
|
125 |
getAdaOptions().setAdaDialects(generalOptionsPanel.getAdaDialects());
|
raster@15779
|
126 |
getAdaOptions().setAdaRestrictions(generalOptionsPanel.getAdaRestrictions());
|
raster@15779
|
127 |
getAdaOptions().setPkgSpecPrefix(generalOptionsPanel.getPkgSpecPrefix());
|
raster@15779
|
128 |
getAdaOptions().setPkgBodyPrefix(generalOptionsPanel.getPkgBodyPrefix());
|
raster@15779
|
129 |
getAdaOptions().setSeparatePrefix(generalOptionsPanel.getSeparatePrefix());
|
raster@15779
|
130 |
getAdaOptions().setPkgSpecPostfix(generalOptionsPanel.getPkgSpecPostfix());
|
raster@15779
|
131 |
getAdaOptions().setPkgBodyPostfix(generalOptionsPanel.getPkgBodyPostfix());
|
raster@15779
|
132 |
getAdaOptions().setSeparatePostfix(generalOptionsPanel.getSeparatePostfix());
|
raster@15779
|
133 |
getAdaOptions().setPkgSpecExt(generalOptionsPanel.getPkgSpecExt());
|
raster@15779
|
134 |
getAdaOptions().setPkgBodyExt(generalOptionsPanel.getPkgBodyExt());
|
raster@15779
|
135 |
getAdaOptions().setSeparateExt(generalOptionsPanel.getSeparateExt());
|
raster@15779
|
136 |
|
raster@14498
|
137 |
changed = false;
|
raster@14498
|
138 |
}
|
raster@14498
|
139 |
|
raster@14498
|
140 |
@Override
|
raster@14498
|
141 |
public void cancel() {
|
raster@14498
|
142 |
for (OptionsPanelController c : getControllers()) {
|
raster@14498
|
143 |
c.cancel();
|
raster@14498
|
144 |
}
|
raster@14498
|
145 |
}
|
raster@14498
|
146 |
|
raster@14498
|
147 |
@Override
|
raster@14498
|
148 |
public boolean isValid() {
|
raster@14498
|
149 |
for (OptionsPanelController c : getControllers()) {
|
raster@14498
|
150 |
if (!c.isValid()) {
|
raster@14498
|
151 |
return false;
|
raster@14498
|
152 |
}
|
raster@14498
|
153 |
}
|
raster@14498
|
154 |
|
raster@14498
|
155 |
return validateComponent();
|
raster@14498
|
156 |
}
|
raster@14498
|
157 |
|
raster@14498
|
158 |
@Override
|
raster@14498
|
159 |
public boolean isChanged() {
|
raster@14498
|
160 |
for (OptionsPanelController c : getControllers()) {
|
raster@14498
|
161 |
if (c.isChanged()) {
|
raster@14498
|
162 |
return true;
|
raster@14498
|
163 |
}
|
raster@14498
|
164 |
}
|
raster@14498
|
165 |
|
raster@14498
|
166 |
return false;
|
raster@14498
|
167 |
}
|
raster@14498
|
168 |
|
raster@14498
|
169 |
@Override
|
raster@14498
|
170 |
public JComponent getComponent(Lookup masterLookup) {
|
raster@14498
|
171 |
if (pane == null) {
|
raster@14498
|
172 |
pane = new JTabbedPane();
|
raster@14498
|
173 |
pane.add(NbBundle.getMessage(AdaOptionsPanelController.class, "LBL_GeneralOPtions"), generalOptionsPanel);
|
raster@14498
|
174 |
pane.add(NbBundle.getMessage(AdaOptionsPanelController.class, "LBL_FormattingPtions"), formattingOptionsPanel);
|
raster@14498
|
175 |
formattingOptionsPanel.load();
|
raster@14498
|
176 |
for (Entry<OptionsPanelController, AdvancedOption> e : getControllers2Options().entrySet()) {
|
raster@14498
|
177 |
OptionsPanelController controller = e.getKey();
|
raster@14498
|
178 |
AdvancedOption option = e.getValue();
|
raster@14498
|
179 |
pane.add(option.getDisplayName(), controller.getComponent(controller.getLookup()));
|
raster@14498
|
180 |
}
|
raster@14498
|
181 |
}
|
raster@14498
|
182 |
return pane;
|
raster@14498
|
183 |
}
|
raster@14498
|
184 |
|
raster@14498
|
185 |
@Override
|
raster@14498
|
186 |
public HelpCtx getHelpCtx() {
|
raster@16367
|
187 |
return new HelpCtx(AdaGeneralOptionsPanel.class);
|
raster@14498
|
188 |
}
|
raster@14498
|
189 |
|
raster@14498
|
190 |
@Override
|
raster@14498
|
191 |
public void addPropertyChangeListener(PropertyChangeListener l) {
|
raster@14498
|
192 |
propertyChangeSupport.addPropertyChangeListener(l);
|
raster@14498
|
193 |
}
|
raster@14498
|
194 |
|
raster@14498
|
195 |
@Override
|
raster@14498
|
196 |
public void removePropertyChangeListener(PropertyChangeListener l) {
|
raster@14498
|
197 |
propertyChangeSupport.removePropertyChangeListener(l);
|
raster@14498
|
198 |
}
|
raster@14498
|
199 |
|
raster@14498
|
200 |
private AdaOptions getAdaOptions() {
|
raster@14498
|
201 |
return AdaOptions.getInstance();
|
raster@14498
|
202 |
}
|
raster@14498
|
203 |
|
raster@14498
|
204 |
public void stateChanged(ChangeEvent e) {
|
raster@14498
|
205 |
changed();
|
raster@14498
|
206 |
}
|
raster@14498
|
207 |
|
raster@14498
|
208 |
private boolean validateComponent() {
|
raster@14498
|
209 |
// errors
|
raster@16367
|
210 |
String postfixSpec = generalOptionsPanel.getPkgSpecPostfix();
|
raster@16367
|
211 |
String postfixBody = generalOptionsPanel.getPkgBodyPostfix();
|
raster@16367
|
212 |
String specExt = generalOptionsPanel.getPkgSpecExt();
|
raster@16367
|
213 |
String bodyExt = generalOptionsPanel.getPkgBodyExt();
|
raster@16367
|
214 |
|
raster@16367
|
215 |
if (specExt.equalsIgnoreCase(bodyExt)) {
|
raster@16367
|
216 |
if (postfixSpec.equalsIgnoreCase(postfixBody)) {
|
raster@16367
|
217 |
generalOptionsPanel.setError(NbBundle.getMessage(AdaOptionsPanelController.class, "MSG_ExtetionsError"));
|
raster@16367
|
218 |
return false;
|
raster@16367
|
219 |
}
|
raster@16367
|
220 |
}
|
raster@14498
|
221 |
|
raster@14498
|
222 |
// everything ok
|
raster@14498
|
223 |
generalOptionsPanel.setError(" "); // NOI18N
|
raster@14498
|
224 |
return true;
|
raster@14498
|
225 |
}
|
raster@14498
|
226 |
|
raster@14498
|
227 |
private void changed() {
|
raster@14498
|
228 |
if (!changed) {
|
raster@14498
|
229 |
changed = true;
|
raster@14498
|
230 |
propertyChangeSupport.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true);
|
raster@14498
|
231 |
}
|
raster@14498
|
232 |
propertyChangeSupport.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
|
raster@14498
|
233 |
}
|
raster@14498
|
234 |
}
|