diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathSupport.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathSupport.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathSupport.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/ClassPathSupport.java @@ -149,6 +149,12 @@ } else { // Standalone jar or property String eval = evaluator.evaluate( pe[i] ); + + String variableBaseProperty = null; + if (pe[i].startsWith("${var.")) { + variableBaseProperty = pe[i]; + } + File f = null; if (eval != null) { f = antProjectHelper.resolveFile( eval ); @@ -158,7 +164,7 @@ item = Item.createBroken( eval, pe[i] ); } else { - item = Item.create( eval, pe[i] ); + item = Item.create( eval, pe[i], variableBaseProperty); } //TODO these should be encapsulated in the Item class @@ -212,9 +218,14 @@ if (reference == null) { // New file String file = item.getFilePath(); - // pass null as expected artifact type to always get file reference - reference = referenceHelper.createForeignFileReferenceAsIs(file, null); - item.property = reference; + if (item.getVariableBaseProperty() != null) { + item.property = item.getVariableBaseProperty(); + reference = item.getVariableBaseProperty(); + } else { + // pass null as expected artifact type to always get file reference + reference = referenceHelper.createForeignFileReferenceAsIs(file, null); + item.property = reference; + } } if (item.hasChangedSource()) { if (item.getSourceFilePath() != null) { @@ -360,6 +371,8 @@ private File initialJavadocFile; private String libraryName; + private String variableBaseProperty; + private Item( int type, Object object, String property, boolean broken ) { this.type = type; this.object = object; @@ -401,10 +414,17 @@ } public static Item create( String path, String property ) { + return create(path, property, null); + } + + public static Item create( String path, String property, String variableBaseProperty ) { if ( path == null ) { throw new IllegalArgumentException( "path must not be null" ); // NOI18N } - return new Item( TYPE_JAR, path, property ); + Item i = new Item( TYPE_JAR, path, property); + i.variableBaseProperty = variableBaseProperty; + return i; + } public static Item create( String property ) { @@ -458,6 +478,13 @@ throw new IllegalArgumentException( "Item is not of required type - JAR" ); // NOI18N } return (String)object; + } + + public String getVariableBaseProperty() { + if ( getType() != TYPE_JAR ) { + throw new IllegalArgumentException( "Item is not of required type - JAR" ); // NOI18N + } + return variableBaseProperty; } public AntArtifact getArtifact() { diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/classpath/J2SEProjectClassPathModifier.java @@ -167,7 +167,7 @@ else { for (Iterator it = resources.iterator(); it.hasNext();) { ClassPathSupport.Item _r = it.next(); - if (_r.isBroken() && _r.getType() == ClassPathSupport.Item.TYPE_JAR && f.equals(_r.getFilePath())) { + if (_r.isBroken() && _r.getType() == ClassPathSupport.Item.TYPE_JAR && (f.equals(_r.getFilePath()) || f.equals(_r.getVariableBaseProperty()))) { it.remove(); changed = true; } diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/ClassPathUiSupport.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/ClassPathUiSupport.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/ClassPathUiSupport.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/ClassPathUiSupport.java @@ -238,13 +238,18 @@ return indexes; } - public static int[] addJarFiles( DefaultListModel listModel, int[] indices, String[] files ) { + public static int[] addJarFiles( DefaultListModel listModel, int[] indices, String[] files, String[] variables) { int lastIndex = indices == null || indices.length == 0 ? listModel.getSize() - 1 : indices[indices.length - 1]; int[] indexes = new int[files.length]; for( int i = 0, delta = 0; i+delta < files.length; ) { int current = lastIndex + 1 + i; - ClassPathSupport.Item item = ClassPathSupport.Item.create( files[i+delta], null ); + ClassPathSupport.Item item; + if (variables == null) { + item = ClassPathSupport.Item.create( files[i+delta], null ); + } else { + item = ClassPathSupport.Item.create( files[i+delta], null, variables[i+delta] ); + } if ( !listModel.contains( item ) ) { listModel.add( current, item ); indexes[delta + i] = current; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.form b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.form --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.form +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.form @@ -22,8 +22,8 @@ - - + + @@ -51,7 +51,7 @@ - + @@ -157,7 +157,7 @@ - + @@ -231,7 +231,7 @@ - + @@ -251,7 +251,7 @@ - + @@ -271,7 +271,7 @@ - + @@ -291,7 +291,7 @@ - + @@ -311,7 +311,7 @@ - + @@ -326,7 +326,17 @@ - + + + + + + + + + + + @@ -942,9 +952,6 @@ - - - diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/CustomizerLibraries.java @@ -48,6 +48,7 @@ import java.util.Iterator; import java.util.List; import javax.swing.DefaultListModel; +import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.event.ListDataEvent; import javax.swing.event.ListDataListener; @@ -93,6 +94,7 @@ jButtonAddJarC.getModel(), jButtonAddLibraryC.getModel(), jButtonAddArtifactC.getModel(), + jButtonAddVariable.getModel(), jButtonRemoveC.getModel(), jButtonMoveUpC.getModel(), jButtonMoveDownC.getModel(), @@ -107,6 +109,7 @@ jButtonAddJarCT.getModel(), jButtonAddLibraryCT.getModel(), jButtonAddArtifactCT.getModel(), + new JButton().getModel(), jButtonRemoveCT.getModel(), jButtonMoveUpCT.getModel(), jButtonMoveDownCT.getModel(), @@ -121,6 +124,7 @@ jButtonAddJarR.getModel(), jButtonAddLibraryR.getModel(), jButtonAddArtifactR.getModel(), + new JButton().getModel(), jButtonRemoveR.getModel(), jButtonMoveUpR.getModel(), jButtonMoveDownR.getModel(), @@ -135,6 +139,7 @@ jButtonAddJarRT.getModel(), jButtonAddLibraryRT.getModel(), jButtonAddArtifactRT.getModel(), + new JButton().getModel(), jButtonRemoveRT.getModel(), jButtonMoveUpRT.getModel(), jButtonMoveDownRT.getModel(), @@ -321,6 +326,7 @@ jButtonMoveUpC = new javax.swing.JButton(); jButtonMoveDownC = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); + jButtonAddVariable = new javax.swing.JButton(); jPanelRun = new javax.swing.JPanel(); librariesJLabel3 = new javax.swing.JLabel(); librariesJScrollPane2 = new javax.swing.JScrollPane(); @@ -388,7 +394,9 @@ jListCpC.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerLibraries.class, "ACSD_CustomizerLibraries_jLabelClasspathC")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridheight = 7; + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 1; + gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; @@ -416,12 +424,14 @@ gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0); jPanelCompile.add(jButtonAddJarC, gridBagConstraints); jButtonAddJarC.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerLibraries.class, "ACSD_CustomizerLibraries_jButtonAddJar")); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(jButtonEditC, org.openide.util.NbBundle.getMessage(CustomizerLibraries.class, "LBL_CustomizeLibraries_Edit_JButton")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 5; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; @@ -431,6 +441,8 @@ org.openide.awt.Mnemonics.setLocalizedText(jButtonRemoveC, org.openide.util.NbBundle.getMessage(CustomizerLibraries.class, "LBL_CustomizeLibraries_Remove_JButton")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 6; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; @@ -440,6 +452,8 @@ org.openide.awt.Mnemonics.setLocalizedText(jButtonMoveUpC, org.openide.util.NbBundle.getMessage(CustomizerLibraries.class, "LBL_CustomizeLibraries_MoveUp_JButton")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 7; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; @@ -449,6 +463,8 @@ org.openide.awt.Mnemonics.setLocalizedText(jButtonMoveDownC, org.openide.util.NbBundle.getMessage(CustomizerLibraries.class, "LBL_CustomizeLibraries_MoveDown_JButton")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 8; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; @@ -460,13 +476,24 @@ jLabel1.setLabelFor(jListCpC); org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CustomizerLibraries.class, "MSG_CustomizerLibraries_CompileCpMessage")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridy = 8; + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 9; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0); jPanelCompile.add(jLabel1, gridBagConstraints); + + org.openide.awt.Mnemonics.setLocalizedText(jButtonAddVariable, "Add Variable"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 4; + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + jPanelCompile.add(jButtonAddVariable, gridBagConstraints); jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(CustomizerLibraries.class, "LBL_CustomizeLibraries_LibrariesTab"), jPanelCompile); // NOI18N @@ -732,7 +759,6 @@ jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(CustomizerLibraries.class, "LBL_CustomizeLibraries_RunTests_Tab"), jPanelRunTests); // NOI18N org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxBuildSubprojects, org.openide.util.NbBundle.getMessage(CustomizerLibraries.class, "LBL_CustomizeLibraries_Build_Subprojects")); // NOI18N - jCheckBoxBuildSubprojects.setMargin(new java.awt.Insets(0, 0, 0, 0)); org.openide.awt.Mnemonics.setLocalizedText(jLabelErrorMessage, " "); jLabelErrorMessage.setOpaque(true); @@ -759,8 +785,8 @@ .add(jLabelTarget)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(librariesLocation, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE) - .add(jComboBoxTarget, 0, 264, Short.MAX_VALUE)) + .add(librariesLocation, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 303, Short.MAX_VALUE) + .add(jComboBoxTarget, 0, 303, Short.MAX_VALUE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) .add(librariesBrowse, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) @@ -782,7 +808,7 @@ .add(librariesBrowse) .add(librariesLocation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 320, Short.MAX_VALUE) + .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 342, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jCheckBoxBuildSubprojects) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) @@ -887,6 +913,7 @@ private javax.swing.JButton jButtonAddLibraryCT; private javax.swing.JButton jButtonAddLibraryR; private javax.swing.JButton jButtonAddLibraryRT; + private javax.swing.JButton jButtonAddVariable; private javax.swing.JButton jButtonEditC; private javax.swing.JButton jButtonEditCT; private javax.swing.JButton jButtonEditR; diff --git a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEClassPathUi.java b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEClassPathUi.java --- a/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEClassPathUi.java +++ b/java.j2seproject/src/org/netbeans/modules/java/j2seproject/ui/customizer/J2SEClassPathUi.java @@ -50,10 +50,12 @@ import java.net.MalformedURLException; import java.net.URL; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; @@ -77,7 +79,6 @@ import org.netbeans.api.project.ProjectInformation; import org.netbeans.api.project.ProjectUtils; import org.netbeans.api.project.ant.FileChooser; -import org.netbeans.api.project.libraries.LibrariesCustomizer; import org.netbeans.api.project.libraries.Library; import org.netbeans.api.project.libraries.LibraryChooser; import org.netbeans.api.project.libraries.LibraryManager; @@ -87,13 +88,13 @@ import org.netbeans.modules.java.j2seproject.ui.FoldersListSettings; import org.netbeans.spi.project.support.ant.PropertyEvaluator; import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.netbeans.spi.project.support.ant.VariablesSupport; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.Repository; import org.openide.loaders.DataFolder; import org.openide.util.Exceptions; import org.openide.util.NbBundle; -import org.openide.util.NbPreferences; import org.openide.util.Utilities; /** Classes containing code speciic for handling UI of J2SE project classpath @@ -200,7 +201,12 @@ return NbBundle.getMessage( J2SEClassPathUi.class, "LBL_MISSING_FILE", getFileRefName( item ) ); } else { - return item.getFilePath(); + if (item.getVariableBaseProperty() != null) { + String s = item.getVariableBaseProperty(); + return s.substring(6, s.indexOf("}")) + s.substring(s.indexOf("}")+1); + } else { + return item.getFilePath(); + } } } @@ -274,7 +280,7 @@ case ClassPathSupport.Item.TYPE_JAR: String path = item.getFilePath(); File f = new File(path); - if (!f.isAbsolute()) { + if (!f.isAbsolute() || item.getVariableBaseProperty() != null) { f = PropertyUtils.resolveFile(FileUtil.toFile(projectFolder), path); return f.getAbsolutePath(); } @@ -343,6 +349,7 @@ private final ButtonModel addJar; private final ButtonModel addLibrary; private final ButtonModel addAntArtifact; + private final ButtonModel addVariable; private final ButtonModel remove; private final ButtonModel moveUp; private final ButtonModel moveDown; @@ -355,6 +362,7 @@ ButtonModel addJar, ButtonModel addLibrary, ButtonModel addAntArtifact, + ButtonModel addVariable, ButtonModel remove, ButtonModel moveUp, ButtonModel moveDown, @@ -375,6 +383,7 @@ this.addJar = addJar; this.addLibrary = addLibrary; this.addAntArtifact = addAntArtifact; + this.addVariable = addVariable; this.remove = remove; this.moveUp = moveUp; this.moveDown = moveDown; @@ -390,6 +399,7 @@ ButtonModel addJar, ButtonModel addLibrary, ButtonModel addAntArtifact, + ButtonModel addVariable, ButtonModel remove, ButtonModel moveUp, ButtonModel moveDown, @@ -402,6 +412,7 @@ addJar, addLibrary, addAntArtifact, + addVariable, remove, moveUp, moveDown, @@ -412,6 +423,7 @@ addJar.addActionListener( em ); addLibrary.addActionListener( em ); addAntArtifact.addActionListener( em ); + addVariable.addActionListener( em ); remove.addActionListener( em ); moveUp.addActionListener( em ); moveDown.addActionListener( em ); @@ -461,7 +473,7 @@ return; } - int[] newSelection = ClassPathUiSupport.addJarFiles( listModel, list.getSelectedIndices(), files ); + int[] newSelection = ClassPathUiSupport.addJarFiles( listModel, list.getSelectedIndices(), files, null ); list.setSelectedIndices( newSelection ); curDir = FileUtil.normalizeFile(chooser.getCurrentDirectory()); FoldersListSettings.getDefault().setLastUsedClassPathFolder(curDir); @@ -540,6 +552,21 @@ list.setSelectedIndices( newSelection ); } } + else if ( source == addVariable ) { + List names = new ArrayList(); + List files = new ArrayList(); + boolean ok = VariablesSupport.showItemChooser(names, files); + if (ok) { + String files2[] = new String[files.size()]; + int i=0; + for (File f : files) { + files2[i] = f.getAbsolutePath(); + i++; + } + int[] newSelection = ClassPathUiSupport.addJarFiles( listModel, list.getSelectedIndices(), files2, names.toArray(new String[names.size()])); + list.setSelectedIndices( newSelection ); + } + } else if ( source == remove ) { int[] newSelection = ClassPathUiSupport.remove( listModel, list.getSelectedIndices() ); list.setSelectedIndices( newSelection ); diff --git a/java.project/src/org/netbeans/modules/java/project/BrokenReferencesCustomizer.form b/java.project/src/org/netbeans/modules/java/project/BrokenReferencesCustomizer.form --- a/java.project/src/org/netbeans/modules/java/project/BrokenReferencesCustomizer.form +++ b/java.project/src/org/netbeans/modules/java/project/BrokenReferencesCustomizer.form @@ -1,6 +1,6 @@ -
+ @@ -14,6 +14,16 @@ + + + + + + + + + + diff --git a/java.project/src/org/netbeans/modules/java/project/BrokenReferencesCustomizer.java b/java.project/src/org/netbeans/modules/java/project/BrokenReferencesCustomizer.java --- a/java.project/src/org/netbeans/modules/java/project/BrokenReferencesCustomizer.java +++ b/java.project/src/org/netbeans/modules/java/project/BrokenReferencesCustomizer.java @@ -43,7 +43,6 @@ import java.awt.Component; import java.io.File; -import javax.swing.AbstractListModel; import javax.swing.DefaultListCellRenderer; import javax.swing.Icon; import javax.swing.ImageIcon; @@ -52,8 +51,8 @@ import org.netbeans.api.java.platform.PlatformsCustomizer; import org.netbeans.api.project.libraries.LibrariesCustomizer; +import org.netbeans.spi.project.support.ant.VariablesSupport; import org.netbeans.spi.project.ui.support.ProjectChooser; -import org.openide.awt.Mnemonics; import org.openide.filesystems.FileUtil; import org.openide.util.NbBundle; import org.openide.util.Utilities; @@ -180,6 +179,8 @@ LibrariesCustomizer.showCustomizer(null, model.getProjectLibraryManager()); } else if (or.getType() == BrokenReferencesModel.REF_TYPE_PLATFORM) { PlatformsCustomizer.showCustomizer(null); + } else if (or.getType() == BrokenReferencesModel.REF_TYPE_VARIABLE) { + VariablesSupport.showVariablesCustomizer(); } else { JFileChooser chooser; if (or.getType() == BrokenReferencesModel.REF_TYPE_PROJECT) { diff --git a/java.project/src/org/netbeans/modules/java/project/BrokenReferencesModel.java b/java.project/src/org/netbeans/modules/java/project/BrokenReferencesModel.java --- a/java.project/src/org/netbeans/modules/java/project/BrokenReferencesModel.java +++ b/java.project/src/org/netbeans/modules/java/project/BrokenReferencesModel.java @@ -115,6 +115,9 @@ case REF_TYPE_FILE: bundleID = "LBL_BrokenLinksCustomizer_BrokenFileReference"; break; + case REF_TYPE_VARIABLE: + bundleID = "LBL_BrokenLinksCustomizer_BrokenVariable"; + break; case REF_TYPE_PLATFORM: bundleID = "LBL_BrokenLinksCustomizer_BrokenPlatform"; break; @@ -140,6 +143,9 @@ break; case REF_TYPE_FILE: bundleID = "LBL_BrokenLinksCustomizer_BrokenFileReferenceDesc"; + break; + case REF_TYPE_VARIABLE: + bundleID = "LBL_BrokenLinksCustomizer_BrokenVariableReferenceDesc"; break; case REF_TYPE_PLATFORM: bundleID = "LBL_BrokenLinksCustomizer_BrokenPlatformDesc"; @@ -189,7 +195,7 @@ // references which could not be evaluated for (String v : vals) { // we are checking only: project reference, file reference, library reference - if (!(v.startsWith("${file.reference.") || v.startsWith("${project.") || v.startsWith("${libs."))) { + if (!(v.startsWith("${file.reference.") || v.startsWith("${project.") || v.startsWith("${libs.") || v.startsWith("${var."))) { all.append(v); continue; } @@ -201,6 +207,8 @@ int type = REF_TYPE_LIBRARY; if (v.startsWith("${file.reference")) { type = REF_TYPE_FILE; + } else if (v.startsWith("${var")) { + type = REF_TYPE_VARIABLE; } String val = v.substring(2, v.length() - 1); set.add(new OneReference(type, val, true)); @@ -433,6 +441,7 @@ public static final int REF_TYPE_LIBRARY = 3; public static final int REF_TYPE_PLATFORM = 4; public static final int REF_TYPE_LIBRARY_CONTENT = 5; + public static final int REF_TYPE_VARIABLE = 6; public static class OneReference { @@ -469,6 +478,9 @@ case REF_TYPE_PLATFORM: return ID; + case REF_TYPE_VARIABLE: + return ID.substring(4, ID.indexOf("}")); + default: assert false; return ID; diff --git a/java.project/src/org/netbeans/modules/java/project/Bundle.properties b/java.project/src/org/netbeans/modules/java/project/Bundle.properties --- a/java.project/src/org/netbeans/modules/java/project/Bundle.properties +++ b/java.project/src/org/netbeans/modules/java/project/Bundle.properties @@ -75,6 +75,7 @@ LBL_BrokenLinksCustomizer_List=Reference &Problems: LBL_BrokenLinksCustomizer_BrokenPlatform="{0}" platform could not be found LBL_BrokenLinksCustomizer_BrokenLibrary="{0}" library could not be found +LBL_BrokenLinksCustomizer_BrokenVariable="{0}" variable could not be found LBL_BrokenLinksCustomizer_BrokenFileReference="{0}" file/folder could not be found LBL_BrokenLinksCustomizer_BrokenProjectReference="{0}" project could not be found LBL_BrokenLinksCustomizer_BrokenPlatformDesc=\ @@ -95,6 +96,10 @@ Problem: The project uses the file/folder called "{0}", but \ this file/folder was not found.\n\ Solution: Click Resolve and locate the missing file/folder. +LBL_BrokenLinksCustomizer_BrokenVariableReferenceDesc=\ + Problem: The project uses the variable called "{0}", but \ + this variable was not found.\n\ + Solution: Click Resolve and setup this varaible there. LBL_BrokenLinksCustomizer_BrokenProjectReferenceDesc=\ Problem: The project classpath includes a reference to the project \ called "{0}", but this project was not found.\n\ 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-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/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,12 @@ RelativizeFilePathCustomizer.title=Adding Artifact to Project RelativizeFilePathCustomizer.jLabel1.text=How to Reference File {0}? ACSD_FileChooserAccessory_NA=N/A +VariablesPanel.editButton.text=Edit +VariablesPanel.removeButton.text=Remove +VariablesPanel.addButton.text=Add +VariablePanel.errorLabel.text= +VariablePanel.nameTextField.text= +VariablePanel.jLabel2.text=Location: +VariablePanel.jLabel1.text=Name: +VariablePanel.browseButton.text=Browse +VariablePanel.locationTextField.text= 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,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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,177 @@ +/* + * VariableCustomizer.java + * + * Created on 4 June 2008, 14:42 + */ + +package org.netbeans.modules.project.ant; + +import java.io.File; +import javax.swing.JFileChooser; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import org.netbeans.api.project.ProjectUtils; +import org.netbeans.spi.project.support.ant.PropertyUtils; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.filesystems.FileUtil; + +/** + * + * @author david + */ +public class VariablePanel extends javax.swing.JPanel implements DocumentListener { + + private VariablesModel model; + private DialogDescriptor dd; + + /** Creates new form VariableCustomizer */ + public VariablePanel(VariablesModel model) { + this.model = model; + initComponents(); + 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 + + nameTextField.setText(org.openide.util.NbBundle.getMessage(VariablePanel.class, "VariablePanel.nameTextField.text")); // NOI18N + + locationTextField.setText(org.openide.util.NbBundle.getMessage(VariablePanel.class, "VariablePanel.locationTextField.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.openide.util.NbBundle.getMessage(VariablePanel.class, "VariablePanel.errorLabel.text")); // NOI18N + + 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() + .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) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + +private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed + JFileChooser chooser = new JFileChooser(); + FileUtil.preventFileChooserSymlinkTraversal(chooser, null); + chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); + chooser.setMultiSelectionEnabled(false); + chooser.setDialogTitle("Choose a 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 ="Valid name must be set"; + } else if (model.find(nameTextField.getText()) != null) { + error = "Variable with this name already exists"; + } else if (locationTextField.getText().length() == 0 || + !new File(locationTextField.getText()).exists()) { + error = "Valid location must be set"; + } else if (!PropertyUtils.isUsablePropertyName(nameTextField.getText())) { + error = "Not a valid variable name"; + } else if (model.contains(nameTextField.getText())) { + error = "Variable with this name already exists"; + } + dd.setValid(error == null); + errorLabel.setText(error == null ? "" : error); + } + + 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,76 @@ +/* + * 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.actions.CallableSystemAction; + + + + +public class VariablesCustomizerAction extends CallableSystemAction { + + public VariablesCustomizerAction () { + putValue("noIconInMenu", Boolean.TRUE); // NOI18N + } + + public void performAction() { + showCustomizer(); + } + + public String getName() { + return "Variables"; + } + + public HelpCtx getHelpCtx() { + return HelpCtx.DEFAULT_HELP; + } + + 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,126 @@ +/* + * 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.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.netbeans.spi.project.support.ant.EditableProperties; +import org.netbeans.spi.project.support.ant.PropertyUtils; + +/** + * + * @author david + */ +public class VariablesModel { + + private static final String VARIABLE_PREFIX = "var."; + + private List vars; + + VariablesModel() { + init(); + } + + public List getVariables() { + return vars; + } + + public Variable find(String name) { + for (Variable v : vars) { + if (v.getName().equals(name)) { + return v; + } + } + return null; + } + + private void init() { + vars = new ArrayList(); + EditableProperties ep = PropertyUtils.getGlobalProperties(); + for (Map.Entry entry : ep.entrySet()) { + if (entry.getKey().startsWith(VARIABLE_PREFIX)) { + vars.add(new Variable(entry.getKey().substring(VARIABLE_PREFIX.length()), new File(entry.getValue()))); + } + } + } + + public boolean contains(String name) { + return vars.contains(new Variable(name, null)); + } + + public void add(String name, File location) { + assert !contains(name) : name; + vars.add(new Variable(name, location)); + } + + + 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(); + } + + } + +} 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,73 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
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,273 @@ +/* + * VariablesPanel.java + * + * Created on 4 June 2008, 13:26 + */ + +package org.netbeans.modules.project.ant; + +import java.awt.BorderLayout; +import java.awt.Dialog; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +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.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataFolder; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.lookup.Lookups; + +/** + * + * @author david + */ +public class VariablesPanel extends javax.swing.JPanel implements ExplorerManager.Provider { + + private final ExplorerManager explorer; + private boolean showItems; + private VariablesModel model; + + /** Creates new form VariablesPanel */ + public VariablesPanel(boolean showItems) { + this.showItems = showItems; + model = new VariablesModel(); + initComponents(); + tree.setRootVisible(false); + explorer = new ExplorerManager(); + } + + public static void showVariablesCustomizer() { + VariablesPanel l = new VariablesPanel(false); + l.showDialog(new ArrayList(), new ArrayList()); + } + + public static boolean showItemChooser(List selectedFiles, List selectedFilesAsFiles) { + VariablesPanel l = new VariablesPanel(true); + return l.showDialog(selectedFiles, selectedFilesAsFiles); + } + + private boolean showDialog(List selectedFiles, List selectedFilesAsFiles) { + JPanel inset = new JPanel(new BorderLayout()); + inset.setBorder(new EmptyBorder(12,12,0,12)); + inset.add(this); + String title; + String buttonLabel; + if (showItems) { + title = "Add JAR/Folder"; + buttonLabel = "Add"; + } else { + title = "Manage Variables"; + buttonLabel = "OK"; + } + DialogDescriptor dd = new DialogDescriptor(inset, title); + dd.setModal(true); + final JButton add = new JButton(buttonLabel); + add.setEnabled(false); + add.setDefaultCapable(true); + explorer.addPropertyChangeListener(new PropertyChangeListener() { + public void propertyChange(PropertyChangeEvent evt) { + add.setEnabled(showItems ? explorer.getSelectedNodes().length > 0 : true); + } + }); + dd.setOptions(new Object[] {add, NotifyDescriptor.CANCEL_OPTION}); + dd.setClosingOptions(new Object[] {add, NotifyDescriptor.CANCEL_OPTION}); + if (DialogDisplayer.getDefault().notify(dd) == add) { + selectedFiles.addAll(Arrays.asList(getSelectedLibraries())); + selectedFilesAsFiles.addAll(Arrays.asList(getSelectedLibrariesAsFiles())); + return true; + } else { + return false; + } + } + + private File[] getSelectedLibrariesAsFiles() { + List s = new ArrayList(); + StringBuffer sb = new StringBuffer(); + for (Node n : explorer.getSelectedNodes()) { + FileObject fo = n.getLookup().lookup(FileObject.class); + Variable var = n.getLookup().lookup(Variable.class); + if (fo != null) { + s.add(FileUtil.toFile(fo)); + } else if (var != null){ + s.add(var.getValue()); + } + } + return s.toArray(new File[s.size()]); + } + + private String[] getSelectedLibraries() { + List s = new ArrayList(); + StringBuffer sb = new StringBuffer(); + for (Node n : explorer.getSelectedNodes()) { + FileObject fo = n.getLookup().lookup(FileObject.class); + Variable var = n.getLookup().lookup(Variable.class); + if (fo != null) { + s.add(getVariableBasedName(n)); + } else if (var != null){ + s.add(var.getName()); + } + } + return s.toArray(new String[s.size()]); + } + + private String getVariableBasedName(Node n) { + StringBuffer sb = new StringBuffer(); + FileObject fo = n.getLookup().lookup(FileObject.class); + Variable var = n.getLookup().lookup(Variable.class); + if (fo != null) { + return getVariableBasedName(n.getParentNode()) + "/" + fo.getNameExt(); + } else { + assert var != null; + return "${var."+var.getName()+"}"; + } + } + + + + private void setRootNode() { + explorer.setRootContext(new AbstractNode(new VariableChildren(model.getVariables()))); +// tree.expandAll(); +// try { +// if (explorer.getRootContext().getChildren().getNodes(true).length > 0) { +// explorer.setSelectedNodes(new Node[] {explorer.getRootContext().getChildren().getNodes(true)[0]}); +// } +// } catch (PropertyVetoException x) { +// Exceptions.printStackTrace(x); +// } +// /* XXX Nothing seems to work to scroll to top; how is it done? +// tree.getViewport().setViewPosition(new Point()); +// tree.getViewport().scrollRectToVisible(new Rectangle(0, 0, 1, 1)); +// */ + 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 + + 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, 276, 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); + DialogDescriptor dd = new DialogDescriptor (p, "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 +// TODO add your handling code here: +}//GEN-LAST:event_removeButtonActionPerformed + + + // 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 VariableChildren(List vars) { + setKeys(vars); + } + + protected Node[] createNodes(Variable var) { + Children ch = Children.LEAF; + if (showItems) { + FileObject fo = FileUtil.toFileObject(var.getValue()); + assert fo.isFolder(); + DataFolder df = DataFolder.findFolder(fo); + ch = df.createNodeChildren(null); + //df.getNodeDelegate().cloneNode().getChildren(); + } + AbstractNode n = new AbstractNode(ch, Lookups.singleton(var)); + n.setName(var.getName()); + n.setDisplayName(var.getName() + " ("+var.getValue().getPath()+")"); + n.setShortDescription(var.getName() + " ("+var.getValue().getPath()+")"); + // TODO: + n.setIconBaseWithExtension("org/netbeans/modules/project/libraries/resources/libraries.gif"); // NOI18N + return new Node[] {n}; + } + + } + +} 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/VariablesSupport.java b/project.ant/src/org/netbeans/spi/project/support/ant/VariablesSupport.java new file mode 100644 --- /dev/null +++ b/project.ant/src/org/netbeans/spi/project/support/ant/VariablesSupport.java @@ -0,0 +1,60 @@ +/* + * 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; + +import java.io.File; +import java.util.List; +import org.netbeans.modules.project.ant.VariablesPanel; + +/** + * + * @author david + */ +public class VariablesSupport { + + public static void showVariablesCustomizer() { + VariablesPanel.showVariablesCustomizer(); + } + + public static boolean showItemChooser(List selectedFiles, List selectedFilesAsFiles) { + return VariablesPanel.showItemChooser(selectedFiles, selectedFilesAsFiles); + } + +}