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.builds;
043:
044: import java.awt.Component;
045: import java.awt.Graphics;
046: import java.awt.Rectangle;
047: import java.beans.PropertyEditorSupport;
048: import java.util.Collection;
049: import java.util.HashSet;
050: import org.netbeans.modules.cnd.settings.MakeSettings;
051:
052: /**
053: * Provide a reasonable method for users to change the default property editor
054: * for ErrorExpressions.
055: */
056: public class ErrorExpressionEditor extends PropertyEditorSupport {
057:
058: /** shared list of error expressions in the system */
059: private static Collection sharedList;
060:
061: static {
062: sharedList = new HashSet();
063: sharedList.add(MakeSettings.SUN_COMPILERS);
064: sharedList.add(MakeSettings.GNU_COMPILERS);
065: }
066:
067: /** list to use for error expressions */
068: private Collection list;
069:
070: /** value to edit */
071: private ErrorExpression value;
072:
073: /**
074: * Constructs property editor with shared array of registered expressions.
075: */
076: public ErrorExpressionEditor() {
077: this (sharedList);
078: }
079:
080: /**
081: * Constructs property editor given list of ErrorExpression. This list will be
082: * presented to the user when the editor is used. Also the list is modified when
083: * user adds a new ErrorExpression.
084: *
085: * @param list modifiable collection of <CODE>ErrorExpression</CODE>s
086: */
087: public ErrorExpressionEditor(Collection list) {
088: this .list = list;
089: }
090:
091: public Object getValue() {
092: return value;
093: }
094:
095: public void setValue(Object value) {
096: synchronized (this ) {
097: this .value = (ErrorExpression) value;
098: list.add(value);
099: }
100: firePropertyChange();
101: }
102:
103: public String getAsText() {
104: return "";//value.getName(); // FIXUP - TRUNK - THP // NOI18N
105: }
106:
107: public void setAsText(String string) {
108: ErrorExpression[] exprs = getExpressions();
109:
110: for (int i = 0; i < exprs.length; i++) {
111: /* // FIXUP - TRUNK - THP
112: if (string.equals(exprs[i].getName())) {
113: setValue(exprs[i]);
114: break;
115: }
116: */// FIXUP - TRUNK - THP
117: }
118: }
119:
120: public String getJavaInitializationString() {
121: return "new ErrorExpression (" + // NOI18N
122: //value.getName() + ", " + // NOI18N // FIXUP - TRUNK - THP
123: //value.getErrorExpression() + ", " + // NOI18N // FIXUP - TRUNK - THP
124: //value.getFilePos() + ", " + // NOI18N // FIXUP - TRUNK - THP
125: //value.getLinePos() + ", " + // NOI18N // FIXUP - TRUNK - THP
126: //value.getColumnPos() + ", " + // NOI18N // FIXUP - TRUNK - THP
127: //value.getDescriptionPos() + // FIXUP - TRUNK - THP
128: ")"; // NOI18N
129: }
130:
131: public String[] getTags() {
132: ErrorExpression[] exprs = getExpressions();
133: String[] tags = new String[exprs.length];
134:
135: /* // FIXUP - TRUNK - THP
136: for (int i = 0; i < exprs.length; i++) {
137: tags[i] = exprs[i].getName();
138: }
139: */// FIXUP - TRUNK - THP
140: return tags;
141: }
142:
143: public boolean isPaintable() {
144: return false;
145: }
146:
147: public void paintValue(Graphics g, Rectangle rectangle) {
148: }
149:
150: public boolean supportsCustomEditor() {
151: return true;
152: }
153:
154: public Component getCustomEditor() {
155: return new ErrorExpressionPanel(this );
156: }
157:
158: synchronized ErrorExpression[] getExpressions() {
159: return (ErrorExpression[]) list
160: .toArray(new ErrorExpression[list.size()]);
161: }
162:
163: Collection getExpressionsVector() {
164: return list;
165: }
166: }
|