lkishalmi commented on code in PR #7605:
URL: https://github.com/apache/netbeans/pull/7605#discussion_r1690314818


##########
java/java.source/src/org/netbeans/modules/java/JavaNode.java:
##########
@@ -429,6 +385,147 @@ public String getValue() {
         }
     }
 
+    private static final class RunFileJDKProperty extends 
PropertySupport.ReadWrite<String> {
+
+        private final PropertyEditorSupport jdkPicker = new JDKPicker();
+        private final DataObject dObj;
+
+        public RunFileJDKProperty(DataObject dObj) {
+            super("runFileJDK", String.class, // NOI18N
+                  "JDK",
+                  "JDK used to run the file.");
+            this.dObj = dObj;
+        }
+
+        @Override
+        public String getValue() {
+            return dObj.getPrimaryFile().getAttribute(FILE_JDK) instanceof 
String args ? args : "";
+        }
+
+        @Override
+        public void setValue(String text) {
+            try {
+                dObj.getPrimaryFile().setAttribute(FILE_JDK, text);
+            } catch (IOException ex) {
+                LOG.log(Level.WARNING, "Java File does not exist : {0}", 
dObj.getPrimaryFile().getName()); //NOI18N
+            }
+        }
+
+        @Override
+        public PropertyEditor getPropertyEditor() {
+            return jdkPicker;
+        }
+
+        private static final class JDKPicker extends PropertyEditorSupport {
+
+            private final JComboBox jdkCombo = new JComboBox();
+            private final PropertyChangeListener modelUpdater = e -> 
initModel();
+
+            public JDKPicker() {
+                initModel();
+                jdkCombo.addActionListener(e -> 
super.setValue(jdkCombo.getSelectedItem()));
+                JavaPlatformManager jdkman = JavaPlatformManager.getDefault();
+                
jdkman.addPropertyChangeListener(WeakListeners.propertyChange(modelUpdater, 
jdkman));
+            }
+
+            private void initModel() {
+                String[] jdks = 
Stream.of(JavaPlatformManager.getDefault().getInstalledPlatforms())
+                        .filter(jdk -> 
isCompatible(jdk.getSpecification().getVersion()))
+                        .map(jdk -> jdk.getDisplayName())
+                        .sorted(Comparator.reverseOrder())
+                        .toArray(String[]::new);
+                jdkCombo.setModel(new DefaultComboBoxModel(jdks));
+            }
+
+            private static boolean isCompatible(SpecificationVersion 
jdkVerison) {
+                try {
+                    return Integer.parseInt(jdkVerison.toString()) >= 11;
+                } catch (NumberFormatException ignore) {}
+                return false;
+            }
+
+            @Override
+            public void setAsText(String text) throws IllegalArgumentException 
{
+                jdkCombo.setSelectedItem(text);
+            }
+
+            @Override
+            public void setValue(Object value) {
+                jdkCombo.setSelectedItem(value);
+                super.setValue(value);
+            }
+
+            @Override
+            public Component getCustomEditor() {
+                return jdkCombo;
+            }
+
+            @Override
+            public boolean supportsCustomEditor() {
+                return true;
+            }
+        }
+
+    }
+
+    private static final class RunFileArgumentsProperty extends 
PropertySupport.ReadWrite<String> {
+
+        private final DataObject dObj;
+
+        public RunFileArgumentsProperty(DataObject dObj) {
+            super("runFileArguments", String.class, // NOI18N
+                  "Arguments",
+                  "Arguments passed to the main method while running the 
file.");
+            this.dObj = dObj;
+        }
+
+        @Override
+        public String getValue() {
+            return dObj.getPrimaryFile().getAttribute(FILE_ARGUMENTS) 
instanceof String args ? args : "";
+        }
+
+        @Override
+        public void setValue(String o) {
+            try {
+                dObj.getPrimaryFile().setAttribute(FILE_ARGUMENTS, o);
+            } catch (IOException ex) {
+                LOG.log(Level.WARNING, "Java File does not exist : {0}", 
dObj.getPrimaryFile().getName()); //NOI18N
+            }
+        }
+    }
+
+    private static class RunFileVMOptionsProperty extends 
PropertySupport.ReadWrite<String> {
+
+        private final DataObject dObj;
+
+        public RunFileVMOptionsProperty(DataObject dObj) {
+            super("runFileVMOptions", String.class, // NOI18N
+                  "VM Options",
+                  "VM Options to be considered while running the file.");
+            this.dObj = dObj;
+        }
+
+        @Override
+        public String getValue() {
+            return dObj.getPrimaryFile().getAttribute(FILE_VM_OPTIONS) 
instanceof String opts ? opts : "";
+        }
+
+        @Override
+        public void setValue(String o) {
+            try {
+                dObj.getPrimaryFile().setAttribute(FILE_VM_OPTIONS, o);
+                // what is this for?
+                Source s = Source.create(dObj.getPrimaryFile());
+                ModificationResult result = 
ModificationResult.runModificationTask(List.of(s), new UserTask() {
+                    @Override public void run(ResultIterator resultIterator) {}
+                });
+                result.commit();

Review Comment:
   Well Squash them to one. One is the VM args, and the other is the args for 
the java file to be executed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to