diff --git a/project.ant/apichanges.xml b/project.ant/apichanges.xml --- a/project.ant/apichanges.xml +++ b/project.ant/apichanges.xml @@ -105,6 +105,32 @@ + + + Support for (IDE) variables in Ant based project types + + + + + +

FileChooser enhanced with "Use Variable Path" option. Following + methods were added: + FileChooser.getSelectedPathVariables and + FileChooser.enableVariableBasedSelection. + Existing getSelectedPaths() method will keep returning either absolute + or relative paths. If "Use Variable Path" option was selected it will + return absolute path. Variable based paths are returned via new + getSelectedPathVariables method. +

+

+ Support class added for showing variables manager. +

+
+ + + +
+ Support for project-specific libraries diff --git a/project.ant/manifest.mf b/project.ant/manifest.mf --- a/project.ant/manifest.mf +++ b/project.ant/manifest.mf @@ -1,6 +1,7 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.project.ant/1 -OpenIDE-Module-Specification-Version: 1.20 +OpenIDE-Module-Specification-Version: 1.21 +OpenIDE-Module-Layer: org/netbeans/modules/project/ant/resources/mf-layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bundle.properties OpenIDE-Module-Install: org/netbeans/modules/project/ant/AntProjectModule.class diff --git a/project.ant/nbproject/project.xml b/project.ant/nbproject/project.xml --- a/project.ant/nbproject/project.xml +++ b/project.ant/nbproject/project.xml @@ -115,6 +115,14 @@ + org.openide.explorer + + + + 6.8 + + + org.openide.filesystems diff --git a/project.ant/src/org/netbeans/api/project/ant/FileChooser.java b/project.ant/src/org/netbeans/api/project/ant/FileChooser.java --- a/project.ant/src/org/netbeans/api/project/ant/FileChooser.java +++ b/project.ant/src/org/netbeans/api/project/ant/FileChooser.java @@ -105,11 +105,27 @@ } /** + * Enable or disable variable based selection, that is show or hide + * "Use Variable Path" option. By default variable based selection is enabled. + * + * @since org.netbeans.modules.project.ant/1 1.21 + */ + public void enableVariableBasedSelection(boolean enable) { + if (accessory != null) { + accessory.enableVariableBasedSelection(enable); + } + } + + /** * Returns array of paths selected. The difference from - * {@link #getSelectedFiles} is that depends on user's choice the files - * may be relative and they may have been copied to different location. + * {@link #getSelectedFiles} is that returned paths might be relative to + * base folder this file chooser was created for. If user selected in UI + * "Use Relative Path" or "Copy To Libraries Folder" then returned paths + * will be relative. For options "Use Absolute Path" and "Use Variable Path" + * this method return absolute paths. In case of option "Use Variable Path" + * see also {@link #getSelectedPathVariables}. * - * @return array of files which may be relative to base folder this chooser + * @return array of files which are absolute or relative to base folder this chooser * was created for; e.g. project folder in case of AntProjectHelper * constructor; never null; can be empty array * @throws java.io.IOException any IO problem; for example during @@ -139,6 +155,25 @@ } } } + + /** + * For "Use Variable Path" option this method returns list of paths which + * start with a variable from {@link PropertyUtils.getGlobalProperties()}. eg. + * "${var.MAVEN}/path/file.jar". For all other options selected this method + * returns null. + * + * @return null or list of variable based paths; if not null items in returned + * array corresponds to items in array returned from {@link #getSelectedPaths} + * @since org.netbeans.modules.project.ant/1 1.21 + */ + public String[] getSelectedPathVariables() { + if (accessory != null) { + if (accessory.isVariableBased()) { + return accessory.getVariableBasedFiles(); + } + } + return null; + } @Override public void approveSelection() { diff --git a/project.ant/src/org/netbeans/modules/project/ant/resources/mf-layer.xml b/project.ant/src/org/netbeans/modules/project/ant/resources/mf-layer.xml new file mode 100644 --- /dev/null +++ b/project.ant/src/org/netbeans/modules/project/ant/resources/mf-layer.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + diff --git a/project.ant/src/org/netbeans/spi/project/support/ant/ui/VariablesSupport.java b/project.ant/src/org/netbeans/spi/project/support/ant/ui/VariablesSupport.java new file mode 100644 --- /dev/null +++ b/project.ant/src/org/netbeans/spi/project/support/ant/ui/VariablesSupport.java @@ -0,0 +1,62 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.spi.project.support.ant.ui; + +import org.netbeans.modules.project.ant.VariablesPanel; + +/** + * Helper methods for variable based path manipulation. + * + * @author David Konecny + * @since org.netbeans.modules.project.ant/1 1.21 + */ +public class VariablesSupport { + + private VariablesSupport() { + } + + /** + * Show global variables customizer. + */ + public static void showVariablesCustomizer() { + VariablesPanel.showVariablesCustomizer(); + } + +} ///////////////// follows implemenation classes: diff --git a/project.ant/src/org/netbeans/modules/project/ant/Bundle.properties b/project.ant/src/org/netbeans/modules/project/ant/Bundle.properties --- a/project.ant/src/org/netbeans/modules/project/ant/Bundle.properties +++ b/project.ant/src/org/netbeans/modules/project/ant/Bundle.properties @@ -65,3 +65,22 @@ RelativizeFilePathCustomizer.title=Adding Artifact to Project RelativizeFilePathCustomizer.jLabel1.text=How to Reference File {0}? ACSD_FileChooserAccessory_NA=N/A +FileChooserAccessory.rbVariable.text=Use Variable Path: +FileChooserAccessory.variablesButton.text=... +FileChooserAccessory.noSuitableVariable= + +VariablesPanel.editButton.text=Edit +VariablesPanel.removeButton.text=Remove +VariablesPanel.addButton.text=Add +VariablePanel.jLabel2.text=Location: +VariablePanel.jLabel1.text=Name: +VariablePanel.browseButton.text=Browse +MSG_Choose_Folder=Choose a folder +DIALOG_Edit_Variable=Edit Variable +DIALOG_Add_New_Variable=Add New Variable +BUTTON_OK=OK +TITLE_Manage_Variables=Manage Variables +ACTION_NAME_Variables=Variables +MSG_Invalid_Location=Valid location must be set +MSG_Variable_Already_Exists=Variable with this name already exists +MSG_Invalid_Name=Valid name must be set diff --git a/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.form b/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.form --- a/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.form +++ b/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.form @@ -5,14 +5,6 @@ - - - - - - - - @@ -27,25 +19,34 @@ - + + + + + + + + + + + + + + + + + + - - - - + + + + + + - - - - - - - - - - + - @@ -53,15 +54,22 @@ - + - + + + + + + + + - + - + - + @@ -132,5 +140,27 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.java b/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.java --- a/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.java +++ b/project.ant/src/org/netbeans/modules/project/ant/FileChooserAccessory.java @@ -55,6 +55,7 @@ import javax.swing.JFileChooser; import org.netbeans.api.queries.CollocationQuery; import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.netbeans.spi.project.support.ant.ui.VariablesSupport; import org.openide.DialogDisplayer; import org.openide.NotifyDescriptor; import org.openide.filesystems.FileObject; @@ -80,6 +81,8 @@ private List copiedRelativeFiles = null; /** In RelativizeFilePathCustomizer scenario this property holds preselected file */ private File usetThisFileInsteadOfOneFromChooser = null; + private VariablesModel varModel; + private boolean enableVariableBasedSelection = true; /** * Constructor for usage from RelativizeFilePathCustomizer. @@ -93,12 +96,12 @@ //when deciding on predefined file, we can assume certain options to be preferable. if (CollocationQuery.areCollocated(baseFolder, selectedFile)) { rbRelative.setSelected(true); + } else if (getVariablesModel().getRelativePath(selectedFile, true) != null) { + rbVariable.setSelected(true); + } else if (copyAllowed) { + rbCopy.setSelected(true); } else { - if (copyAllowed) { - rbCopy.setSelected(true); - } else { - rbAbsolute.setSelected(true); - } + rbAbsolute.setSelected(true); } } @@ -125,6 +128,7 @@ rbCopy.addActionListener(this); rbRelative.addActionListener(this); rbAbsolute.addActionListener(this); + rbVariable.addActionListener(this); if (chooser != null) { chooser.addPropertyChangeListener(this); } @@ -136,6 +140,13 @@ rbCopy.setVisible(false); copyTo.setVisible(false); } + } + + public void enableVariableBasedSelection(boolean enable) { + this.enableVariableBasedSelection = enable; + rbVariable.setVisible(enableVariableBasedSelection); + variablePath.setVisible(enableVariableBasedSelection); + variablesButton.setVisible(enableVariableBasedSelection); } public String[] getFiles() { @@ -207,10 +218,23 @@ private void enableAccessory(boolean enable) { rbRelative.setEnabled(enable); + relativePath.setEnabled(enable); rbCopy.setEnabled(enable && copyAllowed); rbAbsolute.setEnabled(enable); + absolutePath.setEnabled(enable); copyTo.setEnabled(enable); copyTo.setEditable(enable && rbCopy.isSelected()); + if (enable) { + File f = getSelectedFiles()[0]; + boolean b = getVariablesModel().getRelativePath(f, true) != null; + rbVariable.setEnabled(b); + variablePath.setEnabled(b); + } else { + rbVariable.setEnabled(false); + variablePath.setEnabled(false); + } + variablePath.setEditable(false); + variablesButton.setEnabled(enable); } private File[] getSelectedFiles() { @@ -230,6 +254,10 @@ public boolean isRelative() { return (rbRelative.isEnabled() && rbRelative.isSelected()) || isCopy(); + } + + public boolean isVariableBased() { + return rbVariable.isEnabled() && rbVariable.isSelected(); } private boolean isCopy() { @@ -253,14 +281,13 @@ private void update(List files) { StringBuffer absolute = new StringBuffer(); StringBuffer relative = new StringBuffer(); + StringBuffer variable = new StringBuffer(); boolean isRelative = true; for (File file : files) { if (absolute.length() != 0) { absolute.append(", "); relative.append(", "); - if (file.getParentFile() != null && file.getParentFile().getParentFile() != null && - file.getParentFile().getName().length() > 0) { - } + variable.append(", "); } absolute.append(file.getAbsolutePath()); String s = PropertyUtils.relativizeFile(baseFolder, file); @@ -268,6 +295,11 @@ isRelative = false; } relative.append(s); + + String varPath = getVariablesModel().getRelativePath(file, true); + if (varPath != null) { + variable.append(varPath); + } } rbRelative.setEnabled(isRelative && rbRelative.isEnabled()); relativePath.setText(relative.toString()); @@ -280,12 +312,44 @@ absolutePath.setText(absolute.toString()); absolutePath.setCaretPosition(0); absolutePath.setToolTipText(absolute.toString()); + + if (variable.length() == 0) { + variable.append(NbBundle.getMessage(FileChooserAccessory.class, "FileChooserAccessory.noSuitableVariable")); // NOI18N + } + variablePath.setText(variable.toString()); + variablePath.setCaretPosition(0); + variablePath.setToolTipText(variable.toString()); + } + + private VariablesModel getVariablesModel() { + if (varModel == null) { + varModel = new VariablesModel(); + } + return varModel; } private List getRelativeFiles(List files) { List fs = new ArrayList(); for (File file : files) { String s = PropertyUtils.relativizeFile(baseFolder, file); + if (s != null) { + fs.add(s); + } + } + return fs; + } + + public String[] getVariableBasedFiles() { + assert isVariableBased(); + List files = Arrays.asList(getSelectedFiles()); + List l = getVariableBasedFiles(files); + return l.toArray(new String[l.size()]); + } + + private List getVariableBasedFiles(List files) { + List fs = new ArrayList(); + for (File file : files) { + String s = getVariablesModel().getRelativePath(file, false); if (s != null) { fs.add(s); } @@ -348,9 +412,9 @@ copyTo = new javax.swing.JTextField(); rbAbsolute = new javax.swing.JRadioButton(); absolutePath = new javax.swing.JTextField(); - - setMinimumSize(new java.awt.Dimension(250, 139)); - setPreferredSize(new java.awt.Dimension(250, 139)); + rbVariable = new javax.swing.JRadioButton(); + variablePath = new javax.swing.JTextField(); + variablesButton = new javax.swing.JButton(); buttonGroup1.add(rbRelative); rbRelative.setSelected(true); @@ -371,39 +435,62 @@ absolutePath.setEditable(false); absolutePath.setText(null); + buttonGroup1.add(rbVariable); + org.openide.awt.Mnemonics.setLocalizedText(rbVariable, org.openide.util.NbBundle.getMessage(FileChooserAccessory.class, "FileChooserAccessory.rbVariable.text")); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(variablesButton, org.openide.util.NbBundle.getMessage(FileChooserAccessory.class, "FileChooserAccessory.variablesButton.text")); // NOI18N + variablesButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + variablesButtonActionPerformed(evt); + } + }); + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() + .add(rbAbsolute) + .addContainerGap(104, Short.MAX_VALUE)) + .add(layout.createSequentialGroup() + .add(rbCopy, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE) + .addContainerGap(12, Short.MAX_VALUE)) + .add(layout.createSequentialGroup() + .add(rbVariable) + .addContainerGap(108, Short.MAX_VALUE)) + .add(layout.createSequentialGroup() + .add(rbRelative) + .addContainerGap(110, Short.MAX_VALUE)) + .add(layout.createSequentialGroup() + .add(21, 21, 21) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(rbRelative) - .add(layout.createSequentialGroup() - .add(21, 21, 21) - .add(relativePath, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)) - .add(rbCopy, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE) - .add(layout.createSequentialGroup() - .add(21, 21, 21) - .add(copyTo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)) - .add(rbAbsolute) - .add(layout.createSequentialGroup() - .add(21, 21, 21) - .add(absolutePath, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE))) - .addContainerGap()) + .add(copyTo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE) + .add(relativePath, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(variablePath, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(variablesButton)) + .add(absolutePath, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE))) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(rbRelative) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(0, 0, 0) .add(relativePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(rbVariable) + .add(0, 0, 0) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(variablesButton) + .add(variablePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(rbCopy) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(0, 0, 0) .add(copyTo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(rbAbsolute) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(0, 0, 0) .add(absolutePath, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) ); @@ -411,6 +498,14 @@ rbCopy.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FileChooserAccessory.class, "ACSD_FileChooserAccessory_NA")); // NOI18N rbAbsolute.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(FileChooserAccessory.class, "ACSD_FileChooserAccessory_NA")); // NOI18N }// //GEN-END:initComponents + +private void variablesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_variablesButtonActionPerformed + VariablesSupport.showVariablesCustomizer(); + varModel = null; + File[] files = getSelectedFiles(); + update(Arrays.asList(files)); + enableAccessory(files.length != 0); +}//GEN-LAST:event_variablesButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables @@ -420,7 +515,10 @@ private javax.swing.JRadioButton rbAbsolute; private javax.swing.JRadioButton rbCopy; private javax.swing.JRadioButton rbRelative; + private javax.swing.JRadioButton rbVariable; private javax.swing.JTextField relativePath; + private javax.swing.JTextField variablePath; + private javax.swing.JButton variablesButton; // End of variables declaration//GEN-END:variables } diff --git a/project.ant/src/org/netbeans/modules/project/ant/VariablePanel.form b/project.ant/src/org/netbeans/modules/project/ant/VariablePanel.form new file mode 100644 --- /dev/null +++ b/project.ant/src/org/netbeans/modules/project/ant/VariablePanel.form @@ -0,0 +1,98 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/project.ant/src/org/netbeans/modules/project/ant/VariablePanel.java b/project.ant/src/org/netbeans/modules/project/ant/VariablePanel.java new file mode 100644 --- /dev/null +++ b/project.ant/src/org/netbeans/modules/project/ant/VariablePanel.java @@ -0,0 +1,208 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.project.ant; + +import java.io.File; +import javax.swing.JFileChooser; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import org.netbeans.modules.project.ant.VariablesModel.Variable; +import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.openide.DialogDescriptor; +import org.openide.filesystems.FileUtil; +import org.openide.util.NbBundle; + +/** + * + */ +public class VariablePanel extends javax.swing.JPanel implements DocumentListener { + + private VariablesModel model; + private DialogDescriptor dd; + private Variable variableBeingEditted; + + /** Creates new form VariableCustomizer */ + public VariablePanel(VariablesModel model, Variable variableBeingEditted) { + this.model = model; + this.variableBeingEditted = variableBeingEditted; + initComponents(); + if (variableBeingEditted != null) { + nameTextField.setText(variableBeingEditted.getName()); + nameTextField.setEditable(false); + locationTextField.setText(variableBeingEditted.getValue().getAbsolutePath()); + } + nameTextField.getDocument().addDocumentListener(this); + locationTextField.getDocument().addDocumentListener(this); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jLabel1 = new javax.swing.JLabel(); + jLabel2 = new javax.swing.JLabel(); + nameTextField = new javax.swing.JTextField(); + locationTextField = new javax.swing.JTextField(); + browseButton = new javax.swing.JButton(); + errorLabel = new javax.swing.JLabel(); + + jLabel1.setText(org.openide.util.NbBundle.getMessage(VariablePanel.class, "VariablePanel.jLabel1.text")); // NOI18N + + jLabel2.setText(org.openide.util.NbBundle.getMessage(VariablePanel.class, "VariablePanel.jLabel2.text")); // NOI18N + + browseButton.setText(org.openide.util.NbBundle.getMessage(VariablePanel.class, "VariablePanel.browseButton.text")); // NOI18N + browseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + browseButtonActionPerformed(evt); + } + }); + + errorLabel.setForeground(java.awt.Color.red); + errorLabel.setText(" "); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(errorLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE) + .add(layout.createSequentialGroup() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(jLabel2) + .add(jLabel1)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(nameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE) + .add(locationTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(browseButton))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel1) + .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(jLabel2) + .add(browseButton) + .add(locationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(errorLabel)) + ); + }// //GEN-END:initComponents + +private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed + JFileChooser chooser = new JFileChooser(); + chooser.setFileHidingEnabled(false); + FileUtil.preventFileChooserSymlinkTraversal(chooser, null); + chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); + chooser.setMultiSelectionEnabled(false); + chooser.setDialogTitle(NbBundle.getBundle(VariablePanel.class).getString("MSG_Choose_Folder")); + if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { + File file = FileUtil.normalizeFile(chooser.getSelectedFile()); + locationTextField.setText(file.getAbsolutePath()); + } +}//GEN-LAST:event_browseButtonActionPerformed + + void setDialogDescriptor(DialogDescriptor dd) { + assert this.dd == null; + this.dd = dd; + checkValidity(); + } + + private void checkValidity() { + String error = null; + if (nameTextField.getText().length() == 0) { + error =NbBundle.getBundle(VariablePanel.class).getString("MSG_Invalid_Name"); + } else if (variableBeingEditted == null && model.find(nameTextField.getText()) != null) { + error = NbBundle.getBundle(VariablePanel.class).getString("MSG_Variable_Already_Exists"); + } else if (locationTextField.getText().length() == 0 || + !new File(locationTextField.getText()).exists()) { + error = NbBundle.getBundle(VariablePanel.class).getString("MSG_Invalid_Location"); + } else if (variableBeingEditted == null && !PropertyUtils.isUsablePropertyName(nameTextField.getText())) { + error = NbBundle.getBundle(VariablePanel.class).getString("MSG_Invalid_Name"); + } + dd.setValid(error == null); + errorLabel.setText(error == null ? " " : error); // NOI18N + } + + public String getVariableName() { + return nameTextField.getText(); + } + + public File getVariableLocation() { + return new File(locationTextField.getText()); + } + + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton browseButton; + private javax.swing.JLabel errorLabel; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JTextField locationTextField; + private javax.swing.JTextField nameTextField; + // End of variables declaration//GEN-END:variables + + public void insertUpdate(DocumentEvent arg0) { + checkValidity(); + } + + public void removeUpdate(DocumentEvent arg0) { + checkValidity(); + } + + public void changedUpdate(DocumentEvent arg0) { + checkValidity(); + } + +} diff --git a/project.ant/src/org/netbeans/modules/project/ant/VariablesCustomizerAction.java b/project.ant/src/org/netbeans/modules/project/ant/VariablesCustomizerAction.java new file mode 100644 --- /dev/null +++ b/project.ant/src/org/netbeans/modules/project/ant/VariablesCustomizerAction.java @@ -0,0 +1,78 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.project.ant; + +import org.openide.util.HelpCtx; +import org.openide.util.NbBundle; +import org.openide.util.actions.CallableSystemAction; + + + + +public class VariablesCustomizerAction extends CallableSystemAction { + + public VariablesCustomizerAction () { + putValue("noIconInMenu", Boolean.TRUE); // NOI18N + } + + public void performAction() { + showCustomizer(); + } + + public String getName() { + return NbBundle.getBundle(VariablesCustomizerAction.class).getString("ACTION_NAME_Variables"); + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + @Override + protected boolean asynchronous () { + return false; + } + + private static void showCustomizer () { + VariablesPanel.showVariablesCustomizer(); + } + + +} diff --git a/project.ant/src/org/netbeans/modules/project/ant/VariablesModel.java b/project.ant/src/org/netbeans/modules/project/ant/VariablesModel.java new file mode 100644 --- /dev/null +++ b/project.ant/src/org/netbeans/modules/project/ant/VariablesModel.java @@ -0,0 +1,195 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.project.ant; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.netbeans.api.project.ProjectManager; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.openide.util.Exceptions; + +/** + * + */ +public class VariablesModel { + + private static final String VARIABLE_PREFIX = "var."; // NOI18N + + private List vars; + + VariablesModel() { + vars = readVariables(); + } + + public List getVariables() { + return vars; + } + + public Variable find(String name) { + return find(name, vars); + } + + private static Variable find(String name, List vs) { + for (Variable v : vs) { + if (v.getName().equals(name)) { + return v; + } + } + return null; + } + + void remove(Variable var) { + vars.remove(var); + } + + void save() { + ProjectManager.mutex().writeAccess(new Runnable() { + public void run() { + EditableProperties ep = PropertyUtils.getGlobalProperties(); + boolean change = false; + List old = readVariables(); + for (Variable var : vars) { + Variable oldVar = find(var.getName(), old); + if (oldVar == null || !oldVar.getValue().equals(var.getValue())) { + ep.put(VARIABLE_PREFIX+var.getName(), var.getValue().getAbsolutePath()); + change = true; + } + if (oldVar != null) { + old.remove(oldVar); + } + } + for (Variable v : old) { + ep.remove(VARIABLE_PREFIX+v.getName()); + change = true; + } + if (change) { + try { + PropertyUtils.putGlobalProperties(ep); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + } + }); + } + + private List readVariables() { + List vs = new ArrayList(); + EditableProperties ep = PropertyUtils.getGlobalProperties(); + for (Map.Entry entry : ep.entrySet()) { + if (entry.getKey().startsWith(VARIABLE_PREFIX)) { + vs.add(new Variable(entry.getKey().substring(VARIABLE_PREFIX.length()), new File(entry.getValue()))); + } + } + return vs; + } + + public void add(String name, File location) { + assert find(name) == null : name; + vars.add(new Variable(name, location)); + } + + public String getRelativePath(File path, boolean forDisplay) { + //FileObject fo = FileUtil.toFileObject(path); + for (Variable v : vars) { + //if (FileUtil.isParentOf(FileUtil.toFileObject(v.value), fo)) { + if (path.getAbsolutePath().startsWith(v.getValue().getAbsolutePath())) { + String s; + if (forDisplay) { + s = v.name; + } else { + s = "${var."+v.name+"}"; // NOI18N + } + String p = path.getAbsolutePath().substring(v.getValue().getAbsolutePath().length()).replace('\\', '/'); // NOI18N + if (p.startsWith("/")) { // NOI18N + p = p.substring(1); + } + return s + "/" + p; // NOI18N + } + } + return null; + } + + + public static class Variable { + + private String name; + private File value; + + public Variable(String name, File value) { + this.name = name; + this.value = value; + } + + public String getName() { + return name; + } + + public File getValue() { + return value; + } + + @Override + public boolean equals(Object arg0) { + return name.equals(((Variable)arg0).name); + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + public void setValue(File loc) { + this.value = loc; + } + + @Override + public String toString() { + return "var["+getName()+"="+getValue().getAbsolutePath()+"]"; + } + + + } + +} diff --git a/project.ant/src/org/netbeans/modules/project/ant/VariablesPanel.form b/project.ant/src/org/netbeans/modules/project/ant/VariablesPanel.form new file mode 100644 --- /dev/null +++ b/project.ant/src/org/netbeans/modules/project/ant/VariablesPanel.form @@ -0,0 +1,76 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/project.ant/src/org/netbeans/modules/project/ant/VariablesPanel.java b/project.ant/src/org/netbeans/modules/project/ant/VariablesPanel.java new file mode 100644 --- /dev/null +++ b/project.ant/src/org/netbeans/modules/project/ant/VariablesPanel.java @@ -0,0 +1,247 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.project.ant; + +import java.awt.BorderLayout; +import java.awt.Dialog; +import java.awt.Image; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.List; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.border.EmptyBorder; +import org.netbeans.modules.project.ant.VariablesModel.Variable; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.explorer.ExplorerManager; +import org.openide.filesystems.Repository; +import org.openide.loaders.DataFolder; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.NbBundle; +import org.openide.util.lookup.Lookups; + +/** + * + */ +public class VariablesPanel extends javax.swing.JPanel implements ExplorerManager.Provider { + + private final ExplorerManager explorer; + private VariablesModel model; + + /** Creates new form VariablesPanel */ + public VariablesPanel() { + model = new VariablesModel(); + initComponents(); + tree.setRootVisible(false); + explorer = new ExplorerManager(); + } + + public static void showVariablesCustomizer() { + new VariablesPanel().showDialog(); + } + + private void showDialog() { + JPanel inset = new JPanel(new BorderLayout()); + inset.setBorder(new EmptyBorder(12,12,0,12)); + inset.add(this); + DialogDescriptor dd = new DialogDescriptor(inset, NbBundle.getMessage(VariablesPanel.class, "TITLE_Manage_Variables")); + dd.setModal(true); + final JButton ok = new JButton(NbBundle.getMessage(VariablesPanel.class, "BUTTON_OK")); + ok.setDefaultCapable(true); + explorer.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + removeButton.setEnabled(explorer.getSelectedNodes().length > 0); + editButton.setEnabled(explorer.getSelectedNodes().length == 1); + } + }); + dd.setOptions(new Object[] {ok, NotifyDescriptor.CANCEL_OPTION}); + dd.setClosingOptions(new Object[] {ok, NotifyDescriptor.CANCEL_OPTION}); + if (DialogDisplayer.getDefault().notify(dd) == ok) { + model.save(); + } + } + + private void setRootNode() { + explorer.setRootContext(new AbstractNode(new VariableChildren(model.getVariables()))); + tree.requestFocus(); + } + + @Override + public void addNotify() { + super.addNotify(); + setRootNode(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + tree = new org.openide.explorer.view.BeanTreeView(); + addButton = new javax.swing.JButton(); + removeButton = new javax.swing.JButton(); + editButton = new javax.swing.JButton(); + + addButton.setText(org.openide.util.NbBundle.getMessage(VariablesPanel.class, "VariablesPanel.addButton.text")); // NOI18N + addButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addButtonActionPerformed(evt); + } + }); + + removeButton.setText(org.openide.util.NbBundle.getMessage(VariablesPanel.class, "VariablesPanel.removeButton.text")); // NOI18N + removeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + removeButtonActionPerformed(evt); + } + }); + + editButton.setText(org.openide.util.NbBundle.getMessage(VariablesPanel.class, "VariablesPanel.editButton.text")); // NOI18N + editButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + editButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .add(tree, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) + .add(removeButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(addButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(editButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .add(addButton) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(removeButton) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(editButton)) + .add(tree, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + +private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed + VariablePanel p = new VariablePanel(model, null); + DialogDescriptor dd = new DialogDescriptor (p, NbBundle.getMessage(VariablesPanel.class, "DIALOG_Add_New_Variable"), + true, DialogDescriptor.OK_CANCEL_OPTION, null, null); + p.setDialogDescriptor(dd); + Dialog dlg = DialogDisplayer.getDefault().createDialog (dd); + dlg.setVisible(true); + if (dd.getValue() == DialogDescriptor.OK_OPTION) { + model.add(p.getVariableName(), p.getVariableLocation()); + setRootNode(); + } +}//GEN-LAST:event_addButtonActionPerformed + +private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed + Node nodes[] = explorer.getSelectedNodes(); + for (Node n : nodes) { + model.remove(n.getLookup().lookup(Variable.class)); + } + setRootNode(); +}//GEN-LAST:event_removeButtonActionPerformed + +private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed + Variable var = explorer.getSelectedNodes()[0].getLookup().lookup(Variable.class); + VariablePanel p = new VariablePanel(model, var); + DialogDescriptor dd = new DialogDescriptor (p, NbBundle.getMessage(VariablesPanel.class, "DIALOG_Edit_Variable"), + true, DialogDescriptor.OK_CANCEL_OPTION, null, null); + p.setDialogDescriptor(dd); + Dialog dlg = DialogDisplayer.getDefault().createDialog (dd); + dlg.setVisible(true); + if (dd.getValue() == DialogDescriptor.OK_OPTION) { + var.setValue(p.getVariableLocation()); + setRootNode(); + } +}//GEN-LAST:event_editButtonActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton addButton; + private javax.swing.JButton editButton; + private javax.swing.JButton removeButton; + private org.openide.explorer.view.BeanTreeView tree; + // End of variables declaration//GEN-END:variables + + public ExplorerManager getExplorerManager() { + return explorer; + } + + private class VariableChildren extends Children.Keys { + + private Node iconDelegate; + + private VariableChildren(List vars) { + setKeys(vars); + this.iconDelegate = DataFolder.findFolder (Repository.getDefault().getDefaultFileSystem().getRoot()).getNodeDelegate(); + } + + protected Node[] createNodes(Variable var) { + Children ch = Children.LEAF; + AbstractNode n = new AbstractNode(ch, Lookups.singleton(var)) { + @Override + public Image getIcon(int type) { + return iconDelegate.getIcon(type); + } + }; + n.setName(var.getName()); + n.setDisplayName(var.getName() + "("+var.getValue().getPath()+")"); // NOI18N + n.setShortDescription(var.getName() + "("+var.getValue().getPath()+")"); // NOI18N + return new Node[] {n}; + } + + } + +}