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.actions;
043:
044: import java.awt.Dialog;
045: import java.awt.Dimension;
046: import java.awt.event.ActionEvent;
047: import java.beans.PropertyChangeEvent;
048: import java.beans.PropertyChangeListener;
049: import java.util.ArrayList;
050: import javax.swing.JButton;
051: import javax.swing.JPanel;
052: import org.netbeans.modules.cnd.ui.options.LocalToolsPanelModel;
053: import org.netbeans.modules.cnd.ui.options.ToolsPanel;
054: import org.netbeans.modules.cnd.ui.options.ToolsPanelModel;
055: import org.openide.DialogDescriptor;
056: import org.openide.DialogDisplayer;
057: import org.openide.util.HelpCtx;
058: import org.openide.util.NbBundle;
059: import org.openide.util.actions.CallableSystemAction;
060:
061: /**
062: * Post the ToolsPanel as a standalone dialog.
063: *
064: * @author gordonp
065: */
066: public class BuildToolsAction extends CallableSystemAction implements
067: PropertyChangeListener {
068:
069: private String title;
070: private String name;
071: private JButton jOK = null;
072: private ToolsPanel tp;
073: private ToolsPanelModel model;
074:
075: public BuildToolsAction() {
076: name = NbBundle.getMessage(BuildToolsAction.class,
077: "LBL_BuildToolsName"); // NOI18N
078: title = NbBundle.getMessage(BuildToolsAction.class,
079: "LBL_BuildToolsTitle"); // NOI18N
080: }
081:
082: public String getName() {
083: return name;
084: }
085:
086: public void setName(String name) {
087: this .name = name;
088: }
089:
090: public String getTitle() {
091: return title;
092: }
093:
094: public void setTitle(String title) {
095: this .title = title;
096: }
097:
098: public void performAction() {
099: initBuildTools(new LocalToolsPanelModel(),
100: new ArrayList<String>());
101: }
102:
103: public void propertyChange(PropertyChangeEvent ev) {
104: if (ev.getPropertyName().equals(ToolsPanel.PROP_VALID)
105: && ev.getSource() instanceof ToolsPanel) {
106: jOK.setEnabled(((Boolean) ev.getNewValue()).booleanValue());
107: }
108: }
109:
110: public ToolsPanelModel getModel() {
111: return model;
112: }
113:
114: /**
115: * Initialize the build tools
116: *
117: * @returns true if the user pressed OK, false if Cancel
118: */
119: public boolean initBuildTools(ToolsPanelModel model,
120: ArrayList<String> errs) {
121: if (Boolean.getBoolean("netbeans.cnd.bta_debug")) { // NOI18N
122: // The following should be shown in the TP, but did not get implemented for CND 5.5.1
123: for (String err : errs) { // GRP - FIXME
124: System.err.println(err);
125: }
126: }
127: tp = new ToolsPanel(model);
128: JPanel panel = new JPanel();
129: tp.addPropertyChangeListener(this );
130: jOK = new JButton(NbBundle.getMessage(BuildToolsAction.class,
131: "BTN_OK")); // NOI18N
132: tp.setPreferredSize(new Dimension(700, 500));
133: tp.update();
134: DialogDescriptor dd = new DialogDescriptor(
135: (Object) constructOuterPanel(tp), getTitle(), true,
136: new Object[] { jOK, DialogDescriptor.CANCEL_OPTION },
137: DialogDescriptor.OK_OPTION,
138: DialogDescriptor.DEFAULT_ALIGN, null, null);
139: Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
140: dialog.setVisible(true);
141: if (dd.getValue() == jOK) {
142: tp.applyChanges(true);
143: return true;
144: }
145: return false;
146: }
147:
148: private JPanel constructOuterPanel(JPanel innerPanel) {
149: JPanel panel = new JPanel();
150: panel.setLayout(new java.awt.GridBagLayout());
151: java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
152: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
153: gridBagConstraints.weightx = 1.0;
154: gridBagConstraints.weighty = 1.0;
155: gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 12);
156: panel.add(innerPanel, gridBagConstraints);
157: return panel;
158: }
159:
160: public void actionPerformed(ActionEvent ev) {
161: performAction();
162: }
163:
164: public HelpCtx getHelpCtx() {
165: return null;
166: }
167: }
|