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-2007 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:
042: package org.netbeans.modules.cnd.makeproject.configurations.ui;
043:
044: import java.beans.PropertyEditor;
045: import java.beans.PropertyEditorSupport;
046: import java.util.StringTokenizer;
047: import org.netbeans.modules.cnd.makeproject.api.configurations.BooleanConfiguration;
048: import org.netbeans.modules.cnd.makeproject.api.configurations.OptionsConfiguration;
049: import org.netbeans.modules.cnd.makeproject.api.configurations.AllOptionsProvider;
050: import org.netbeans.modules.cnd.api.utils.CppUtils;
051: import org.netbeans.modules.cnd.makeproject.api.compilers.BasicCompiler;
052: import org.openide.explorer.propertysheet.ExPropertyEditor;
053: import org.openide.explorer.propertysheet.PropertyEnv;
054: import org.openide.nodes.PropertySupport;
055:
056: public class OptionsNodeProp extends PropertySupport {
057: private OptionsConfiguration commandLineConfiguration;
058: private BooleanConfiguration inheritValues;
059: private AllOptionsProvider optionsProvider;
060: private BasicCompiler compiler;
061: private String delimiter = ""; // NOI18N
062: private String txt1;
063: private String txt2;
064: private String txt3;
065: private String[] texts;
066:
067: public OptionsNodeProp(
068: OptionsConfiguration commandLineConfiguration,
069: BooleanConfiguration inheritValues,
070: AllOptionsProvider optionsProvider, BasicCompiler compiler,
071: String delimiter, String[] texts) {
072: super ("ID", String.class, texts[0], texts[1], true, true); // NOI18N
073: this .commandLineConfiguration = commandLineConfiguration;
074: this .inheritValues = inheritValues;
075: this .optionsProvider = optionsProvider;
076: this .compiler = compiler;
077: if (delimiter != null)
078: this .delimiter = delimiter;
079: this .texts = texts;
080: }
081:
082: public String getHtmlDisplayName() {
083: if (commandLineConfiguration.getModified())
084: return "<b>" + getDisplayName(); // NOI18N
085: else
086: return null;
087: }
088:
089: public Object getValue() {
090: return commandLineConfiguration.getValue();
091: }
092:
093: public void setValue(Object v) {
094: String s = CppUtils.reformatWhitespaces((String) v);
095: commandLineConfiguration.setValue(s);
096: }
097:
098: public PropertyEditor getPropertyEditor() {
099: return new CommandLinePropEditor();
100: }
101:
102: /*
103: public Object getValue(String attributeName) {
104: if (attributeName.equals("canEditAsText")) // NOI18N
105: return Boolean.FALSE;
106: else
107: return super.getValue(attributeName);
108: }
109: */
110:
111: public void restoreDefaultValue() {
112: commandLineConfiguration.optionsReset();
113: }
114:
115: public boolean supportsDefaultValue() {
116: return true;
117: }
118:
119: public boolean isDefaultValue() {
120: return !commandLineConfiguration.getModified();
121: }
122:
123: private class CommandLinePropEditor extends PropertyEditorSupport
124: implements ExPropertyEditor {
125: private PropertyEnv env;
126:
127: public void setAsText(String text) {
128: StringBuilder newText = new StringBuilder();
129: if (delimiter.length() > 0) {
130: // Remove delimiter
131: StringTokenizer st = new StringTokenizer(text,
132: delimiter);
133: while (st.hasMoreTokens()) {
134: newText.append(st.nextToken());
135: }
136: } else {
137: newText.append(text);
138: }
139: setValue(newText.toString());
140: }
141:
142: public String getAsText() {
143: String s = (String) getValue();
144: return CppUtils.reformatWhitespaces(s, "", delimiter); // NOI18N
145: }
146:
147: public java.awt.Component getCustomEditor() {
148: OptionsEditorPanel commandLineEditorPanel = new OptionsEditorPanel(
149: texts, inheritValues, this , env);
150: commandLineEditorPanel.setAllOptions(optionsProvider
151: .getAllOptions(compiler));
152: commandLineEditorPanel
153: .setAdditionalOptions((String) getValue());
154: return commandLineEditorPanel;
155: }
156:
157: public boolean supportsCustomEditor() {
158: return true;
159: }
160:
161: public void attachEnv(PropertyEnv env) {
162: this.env = env;
163: }
164: }
165: }
|