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.makewizard;
043:
044: import java.io.File;
045: import java.util.ArrayList;
046: import org.netbeans.modules.cnd.api.utils.IpeUtils;
047:
048: /**
049: * Create the BuildOutputPanel in the MakefileWizard.
050: */
051:
052: public class BuildOutputPanel extends DirectoryChooserPanel {
053:
054: /** Serial version number */
055: static final long serialVersionUID = 2730227827286861351L;
056:
057: /** Store the target key */
058: private int key;
059:
060: private boolean initialized;
061:
062: /**
063: * Constructor for the BuildOutputPanel.
064: */
065: public BuildOutputPanel(MakefileWizard wd) {
066: super (wd);
067: String subtitle = getString("LBL_BuildOutputPanel"); // NOI18N
068: setSubTitle(subtitle);
069: this .getAccessibleContext().setAccessibleDescription(subtitle);
070: initialized = false;
071: }
072:
073: /** Defer widget creation until the panel needs to be displayed */
074: private void create() {
075:
076: //create(getString("LBL_TargetDirectory"), NAME_ONLY); // NOI18N
077: create(getString("LBL_TargetDirectory"), RELATIVE_PATH); // NOI18N
078: getLabel().setLabelFor(getText());
079: getLabel().setDisplayedMnemonic(
080: getString("MNEM_TargetDirectory").charAt(0)); // NOI18N
081: }
082:
083: /** Validate the output directory */
084: public void validateData(ArrayList msgs, int key) {
085: TargetData target = (TargetData) getMakefileData().getTarget(
086: key);
087: String cwd = getMakefileData().getBaseDirectory(
088: MakefileData.EXPAND);
089: String odir = IpeUtils.expandPath(target.getOutputDirectory());
090: File outdir = null;
091: File outpar = null;
092: File cwf = null;
093:
094: if (odir.length() > 0 && !odir.equals(cwd)) {
095: if (odir.startsWith(File.separator)) {
096: outdir = new File(odir);
097: } else {
098: outdir = new File(cwd, odir);
099: }
100: outpar = outdir.getParentFile();
101: cwf = new File(cwd);
102: }
103:
104: if (outdir != null && !outdir.equals(cwf)) {
105: if (!outdir.exists()) {
106: if (outpar == null || !outpar.canWrite()) {
107: warn(msgs, WARN_CANNOT_CREATE_OUTPUT_DIR, outdir
108: .getPath());
109: }
110: } else if (!outdir.canWrite()) {
111: warn(msgs, WARN_CANNOT_WRITE_TO_OUTPUT_DIR, outdir
112: .getPath());
113: }
114: }
115: }
116:
117: /** Initialize the panel and update the values when displayed */
118: public void addNotify() {
119: TargetData target = getMakefileData().getCurrentTarget();
120: String od = target.getOutputDirectory();
121: String real_od = od;
122: key = target.getKey();
123:
124: if (!initialized) {
125: create();
126: initialized = true;
127: }
128:
129: if (od.charAt(0) == '$') {
130: od = IpeUtils.expandPath(real_od);
131: }
132: if (od.charAt(0) == '/' || od.charAt(0) == '~') {
133: getText().setText(real_od);
134: } else {
135: //getText().setText(getMakefileData().getBaseDirectory() + File.separator + real_od);
136: getText().setText(
137: IpeUtils.getRelativePath(getMakefileData()
138: .getBaseDirectory(), real_od));
139: }
140: super .addNotify();
141: }
142:
143: /** Update the MakefileData */
144: public void removeNotify() {
145: super .removeNotify();
146:
147: TargetData target = getMakefileData().getTarget(key);
148: String od = getText().getText();
149: if (od == null)
150: od = "."; // NOI18N
151: od = od.trim();
152: if (od.length() > 1)
153: od = IpeUtils.trimpath(od);
154: if (od.length() == 0)
155: od = "."; // NOI18N
156: target.setOutputDirectory(od); // FIXUP: no trim here ????
157: }
158: }
|