You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ge...@apache.org on 2018/05/10 07:52:37 UTC
[incubator-netbeans] branch master updated: [NETBEANS-648] Cannot
select "Source/Binary Format : 10" in a maven project (#495)
This is an automated email from the ASF dual-hosted git repository.
geertjan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new f4fb240 [NETBEANS-648] Cannot select "Source/Binary Format : 10" in a maven project (#495)
f4fb240 is described below
commit f4fb2405ce72059d0308cb1987c89d744dc91f79
Author: Junichi Yamamoto <ju...@gmail.com>
AuthorDate: Thu May 10 16:52:35 2018 +0900
[NETBEANS-648] Cannot select "Source/Binary Format : 10" in a maven project (#495)
* [NETBEANS-648] Cannot select "Source/Binary Format : 10" in a maven project
* Fix typo
---
.../modules/maven/customizer/CompilePanel.java | 25 +++-
.../maven/customizer/CompilePanelProvider.java | 6 +-
.../maven/customizer/CustomizerProviderImpl.java | 3 +-
.../MavenProjectPropertiesUiSupport.java | 91 +++++++++++++++
.../modules/maven/customizer/SourcesPanel.java | 130 ++++++++++++++++++++-
.../maven/customizer/SourcesPanelProvider.java | 3 +-
6 files changed, 241 insertions(+), 17 deletions(-)
diff --git a/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.java b/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.java
index 71948fa..5ba47d8 100644
--- a/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.java
+++ b/maven/src/org/netbeans/modules/maven/customizer/CompilePanel.java
@@ -92,11 +92,11 @@ public class CompilePanel extends javax.swing.JPanel implements HelpCtx.Provider
private Color origComPlatformFore;
/** Creates new form CompilePanel */
- public CompilePanel(ModelHandle2 handle, Project prj) {
+ public CompilePanel(ModelHandle2 handle, Project prj, MavenProjectPropertiesUiSupport uiSupport) {
initComponents();
this.handle = handle;
project = prj;
- comJavaPlatform.setModel(new PlatformsModel());
+ comJavaPlatform.setModel(uiSupport.getPlatformComboBoxModel());
comJavaPlatform.setRenderer(new PlatformsRenderer());
origComPlatformFore = comJavaPlatform.getForeground();
@@ -248,7 +248,7 @@ public class CompilePanel extends javax.swing.JPanel implements HelpCtx.Provider
};
// java platform updater
- new ComboBoxUpdater<Union2<JavaPlatform,String>>(comJavaPlatform, lblJavaPlatform) {
+ ComboBoxUpdater<Union2<JavaPlatform,String>> compleComboBoxUpdater = new ComboBoxUpdater<Union2<JavaPlatform,String>>(comJavaPlatform, lblJavaPlatform) {
private String modifiedValue;
private String DEFAULT_PLATFORM_VALUE = "@@DEFAU:T@@";
private ModelOperation<POMModel> operation = new ModelOperation<POMModel>() {
@@ -330,6 +330,10 @@ public class CompilePanel extends javax.swing.JPanel implements HelpCtx.Provider
}
}
};
+ // the selected item is not set until the compile panel is shown
+ // so, invoke these methods for setting it
+ compleComboBoxUpdater.ancestorAdded(null);
+ compleComboBoxUpdater.ancestorRemoved(null);
}
private Pair<String,JavaPlatform> getSelPlatform () {
@@ -543,12 +547,18 @@ public class CompilePanel extends javax.swing.JPanel implements HelpCtx.Provider
return null;
}
- private class PlatformsModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener {
+ static class PlatformsModel extends AbstractListModel implements ComboBoxModel, PropertyChangeListener {
+
+ private static final long serialVersionUID = 1L;
private List<Union2<JavaPlatform,String>> data;
private Union2<JavaPlatform,String> sel;
+ private final Project project;
+ private final ModelHandle2 handle;
- public PlatformsModel() {
+ public PlatformsModel(Project project, ModelHandle2 handle) {
+ this.project = project;
+ this.handle = handle;
JavaPlatformManager jpm = JavaPlatformManager.getDefault();
getPlatforms(jpm);
jpm.addPropertyChangeListener(WeakListeners.propertyChange(this, jpm));
@@ -616,6 +626,11 @@ public class CompilePanel extends javax.swing.JPanel implements HelpCtx.Provider
data = tmp;
}
+ private Pair<String, JavaPlatform> getSelPlatform() {
+ String platformId = project.getLookup().lookup(AuxiliaryProperties.class).
+ get(Constants.HINT_JDK_PLATFORM, true);
+ return Pair.of(platformId, BootClassPathImpl.getActivePlatform(platformId));
+ }
}
private class PlatformsRenderer extends JLabel implements ListCellRenderer, UIResource {
diff --git a/maven/src/org/netbeans/modules/maven/customizer/CompilePanelProvider.java b/maven/src/org/netbeans/modules/maven/customizer/CompilePanelProvider.java
index 4866a10..d7b27bf 100644
--- a/maven/src/org/netbeans/modules/maven/customizer/CompilePanelProvider.java
+++ b/maven/src/org/netbeans/modules/maven/customizer/CompilePanelProvider.java
@@ -19,7 +19,6 @@
package org.netbeans.modules.maven.customizer;
import javax.swing.JComponent;
-import org.netbeans.api.project.Project;
import org.netbeans.modules.maven.api.customizer.ModelHandle2;
import static org.netbeans.modules.maven.customizer.Bundle.*;
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
@@ -45,9 +44,8 @@ public class CompilePanelProvider implements ProjectCustomizer.CompositeCategory
@Override
public JComponent createComponent(Category category, Lookup context) {
- ModelHandle2 handle = context.lookup(ModelHandle2.class);
- Project prj = context.lookup(Project.class);
- return new CompilePanel(handle, prj);
+ MavenProjectPropertiesUiSupport uiSupport = context.lookup(MavenProjectPropertiesUiSupport.class);
+ return uiSupport.getCompilePanel();
}
}
diff --git a/maven/src/org/netbeans/modules/maven/customizer/CustomizerProviderImpl.java b/maven/src/org/netbeans/modules/maven/customizer/CustomizerProviderImpl.java
index 3118d3a..394de3e 100644
--- a/maven/src/org/netbeans/modules/maven/customizer/CustomizerProviderImpl.java
+++ b/maven/src/org/netbeans/modules/maven/customizer/CustomizerProviderImpl.java
@@ -150,7 +150,8 @@ public class CustomizerProviderImpl implements CustomizerProvider2 {
public void run() {
assert EventQueue.isDispatchThread();
OptionListener listener = new OptionListener();
- Lookup context = Lookups.fixed(new Object[] { project, handle, handle2});
+ MavenProjectPropertiesUiSupport uiSupport = new MavenProjectPropertiesUiSupport(handle2, project);
+ Lookup context = Lookups.fixed(new Object[] { project, handle, handle2, uiSupport});
Dialog dialog = ProjectCustomizer.createCustomizerDialog("Projects/org-netbeans-modules-maven/Customizer", //NOI18N
context,
preselectedCategory,
diff --git a/maven/src/org/netbeans/modules/maven/customizer/MavenProjectPropertiesUiSupport.java b/maven/src/org/netbeans/modules/maven/customizer/MavenProjectPropertiesUiSupport.java
new file mode 100644
index 0000000..9548e16
--- /dev/null
+++ b/maven/src/org/netbeans/modules/maven/customizer/MavenProjectPropertiesUiSupport.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.maven.customizer;
+
+import javax.swing.ComboBoxModel;
+import javax.swing.JComponent;
+import org.netbeans.api.java.queries.SourceLevelQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.maven.api.customizer.ModelHandle2;
+
+final class MavenProjectPropertiesUiSupport {
+
+ private final ModelHandle2 handle;
+ private final Project project;
+
+ private JComponent compilePanel;
+ private ComboBoxModel platformComboBoxModel;
+ private ComboBoxModel sourceLevelComboBoxModel;
+
+ public MavenProjectPropertiesUiSupport(ModelHandle2 handle, Project project) {
+ this.handle = handle;
+ this.project = project;
+ init();
+ }
+
+ private void init() {
+ setPlatformComboBoxModel(new CompilePanel.PlatformsModel(project, handle));
+ setCompilePanel(new CompilePanel(handle, project, this));
+ String sourceLevel = SourceLevelQuery.getSourceLevel(project.getProjectDirectory());
+ setSourceLevelComboBoxModel(new SourcesPanel.SourceLevelComboBoxModel(getPlatformComboBoxModel(), sourceLevel));
+ }
+
+ /**
+ * @return the compilePanel
+ */
+ public JComponent getCompilePanel() {
+ return compilePanel;
+ }
+
+ /**
+ * @param compilePanel the compilePanel to set
+ */
+ private void setCompilePanel(JComponent compilePanel) {
+ this.compilePanel = compilePanel;
+ }
+
+ /**
+ * @return the platformComboBoxModel
+ */
+ public ComboBoxModel getPlatformComboBoxModel() {
+ return platformComboBoxModel;
+ }
+
+ /**
+ * @param platformComboBoxModel the platformComboBoxModel to set
+ */
+ private void setPlatformComboBoxModel(ComboBoxModel platformComboBoxModel) {
+ this.platformComboBoxModel = platformComboBoxModel;
+ }
+
+ /**
+ * @return the sourceLevelComboBoxModel
+ */
+ public ComboBoxModel getSourceLevelComboBoxModel() {
+ return sourceLevelComboBoxModel;
+ }
+
+ /**
+ * @param sourceLevelComboBoxModel the sourceLevelComboBoxModel to set
+ */
+ private void setSourceLevelComboBoxModel(ComboBoxModel sourceLevelComboBoxModel) {
+ this.sourceLevelComboBoxModel = sourceLevelComboBoxModel;
+ }
+
+}
diff --git a/maven/src/org/netbeans/modules/maven/customizer/SourcesPanel.java b/maven/src/org/netbeans/modules/maven/customizer/SourcesPanel.java
index c189004..1dc2ad3 100644
--- a/maven/src/org/netbeans/modules/maven/customizer/SourcesPanel.java
+++ b/maven/src/org/netbeans/modules/maven/customizer/SourcesPanel.java
@@ -24,9 +24,16 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
import java.util.logging.Logger;
-import javax.swing.DefaultComboBoxModel;
+import javax.swing.AbstractListModel;
+import javax.swing.ComboBoxModel;
import javax.swing.JPanel;
+import javax.swing.event.ListDataEvent;
+import javax.swing.event.ListDataListener;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.java.platform.JavaPlatform;
import org.netbeans.api.java.queries.SourceLevelQuery;
import org.netbeans.modules.maven.NbMavenProjectImpl;
import org.netbeans.modules.maven.api.Constants;
@@ -45,7 +52,9 @@ import org.netbeans.modules.maven.options.MavenVersionSettings;
import org.netbeans.spi.project.ui.support.ProjectCustomizer;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
+import org.openide.modules.SpecificationVersion;
import org.openide.util.HelpCtx;
+import org.openide.util.Union2;
/**
* Customizer panel for setting source level and encoding.
@@ -161,7 +170,7 @@ public class SourcesPanel extends JPanel implements HelpCtx.Provider {
}
};
- public SourcesPanel( ModelHandle2 handle, NbMavenProjectImpl project ) {
+ public SourcesPanel( ModelHandle2 handle, NbMavenProjectImpl project, MavenProjectPropertiesUiSupport uiSupport) {
initComponents();
this.handle = handle;
FileObject projectFolder = project.getProjectDirectory();
@@ -171,9 +180,7 @@ public class SourcesPanel extends JPanel implements HelpCtx.Provider {
// XXX use ComboBoxUpdater to boldface the label when not an inherited default
comSourceLevel.setEditable(false);
sourceLevel = SourceLevelQuery.getSourceLevel(project.getProjectDirectory());
- comSourceLevel.setModel(new DefaultComboBoxModel(new String[] {
- "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "9" //NOI18N
- }));
+ comSourceLevel.setModel(uiSupport.getSourceLevelComboBoxModel());
comSourceLevel.setSelectedItem(sourceLevel);
String enc = project.getOriginalMavenProject().getProperties().getProperty(Constants.ENCODING_PROP);
@@ -403,5 +410,116 @@ public class SourcesPanel extends JPanel implements HelpCtx.Provider {
private javax.swing.JTextField txtSrc;
private javax.swing.JTextField txtTestSrc;
// End of variables declaration//GEN-END:variables
-
+
+ static final class SourceLevelComboBoxModel extends AbstractListModel<String> implements ComboBoxModel<String>, ListDataListener {
+
+ private final ComboBoxModel platformComboBoxModel;
+ private String selectedSourceLevel;
+ private String[] sourceLevelCache;
+
+ private static final SpecificationVersion MINIMAL_SOURCE_LEVEL = new SpecificationVersion("1.3"); // NOI18N
+ private static final long serialVersionUID = 1L;
+
+ public SourceLevelComboBoxModel(ComboBoxModel platformComboBoxModel, String selectedSourceLevel) {
+ this.platformComboBoxModel = platformComboBoxModel;
+ this.platformComboBoxModel.addListDataListener(this);
+ this.selectedSourceLevel = selectedSourceLevel;
+ }
+
+ @Override
+ public int getSize() {
+ String[] sourceLevels = getSourceLevels();
+ return sourceLevels.length;
+ }
+
+ @Override
+ public String getElementAt(int index) {
+ String[] sourceLevels = getSourceLevels();
+ assert index >= 0 && index < sourceLevels.length;
+ return sourceLevels[index];
+ }
+
+ @Override
+ public void setSelectedItem(Object obj) {
+ selectedSourceLevel = (obj == null ? null : (String) obj);
+ fireContentsChanged(this, 0, getSize());
+ }
+
+ @Override
+ public Object getSelectedItem() {
+ return selectedSourceLevel;
+ }
+
+ @Override
+ public void intervalAdded(ListDataEvent e) {
+ }
+
+ @Override
+ public void intervalRemoved(ListDataEvent e) {
+ }
+
+ @Override
+ public void contentsChanged(ListDataEvent e) {
+ resetCache();
+ }
+
+ private void resetCache() {
+ synchronized (this) {
+ sourceLevelCache = null;
+ }
+ fireContentsChanged(this, 0, getSize());
+ }
+
+ private synchronized String[] getSourceLevels() {
+ if (sourceLevelCache == null) {
+ Union2<JavaPlatform, String> union = (Union2<JavaPlatform, String>) platformComboBoxModel.getSelectedItem();
+ JavaPlatform platform = union.first();
+ List<String> sourceLevels = new ArrayList<>();
+ if (platform != null) {
+ SpecificationVersion version = platform.getSpecification().getVersion();
+ SpecificationVersion current = MINIMAL_SOURCE_LEVEL;
+ while (current.compareTo(version) <= 0) {
+ sourceLevels.add(current.toString());
+ current = incJavaSpecVersion(current);
+ }
+ }
+ sourceLevelCache = sourceLevels.toArray(new String[sourceLevels.size()]);
+ }
+ return sourceLevelCache;
+ }
+
+ }
+
+ private static SpecificationVersion incJavaSpecVersion(@NonNull final SpecificationVersion version) {
+ int major = major(version);
+ int minor = minor(version);
+ if (major == 1) {
+ if (minor == 8) {
+ major = minor + 1;
+ minor = -1;
+ } else {
+ minor += 1;
+ }
+ } else {
+ major += 1;
+ }
+ return minor == -1
+ ? new SpecificationVersion(Integer.toString(major))
+ : new SpecificationVersion(String.format(
+ "%d.%d", //NOI18N
+ major,
+ minor));
+ }
+
+ private static int minor(@NonNull final SpecificationVersion specVer) {
+ final String s = specVer.toString();
+ final int split = s.indexOf('.');
+ return split < 0 ? -1 : Integer.parseInt(s.substring(split + 1));
+ }
+
+ private static int major(@NonNull final SpecificationVersion specVer) {
+ final String s = specVer.toString();
+ final int split = s.indexOf('.');
+ return Integer.parseInt(split < 0 ? s : s.substring(0, split));
+ }
}
diff --git a/maven/src/org/netbeans/modules/maven/customizer/SourcesPanelProvider.java b/maven/src/org/netbeans/modules/maven/customizer/SourcesPanelProvider.java
index a3301cd..9601492 100644
--- a/maven/src/org/netbeans/modules/maven/customizer/SourcesPanelProvider.java
+++ b/maven/src/org/netbeans/modules/maven/customizer/SourcesPanelProvider.java
@@ -50,7 +50,8 @@ public class SourcesPanelProvider implements ProjectCustomizer.CompositeCategory
public JComponent createComponent(Category category, Lookup context) {
ModelHandle2 handle = context.lookup(ModelHandle2.class);
NbMavenProjectImpl project = context.lookup(NbMavenProjectImpl.class);
- return new SourcesPanel(handle, project);
+ MavenProjectPropertiesUiSupport uiSupport = context.lookup(MavenProjectPropertiesUiSupport.class);
+ return new SourcesPanel(handle, project, uiSupport);
}
@ProjectCustomizer.CompositeCategoryProvider.Registration(projectType="org-netbeans-modules-maven", position=1000, category="Formatting", categoryLabel="#LBL_CategoryFormatting")
--
To stop receiving notification emails like this one, please contact
geertjan@apache.org.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists