#252306 Allow user to manage python platforms while choosing it
authorJulien Enselme <jenselme@netbeans.org>
Fri, 17 Jul 2015 22:21:56 +0200
changeset 18293811289685a83
parent 18292 62f0f25d267e
child 18294 28142955865a
#252306 Allow user to manage python platforms while choosing it
python.platform/nbproject/project.xml
python.project2/nbproject/project.xml
python.project2/src/org/netbeans/modules/python/project2/ui/PythonPlatformChooser.java
python.project2/src/org/netbeans/modules/python/project2/ui/Utils.java
     1.1 --- a/python.platform/nbproject/project.xml	Wed Jul 08 19:50:14 2015 +0200
     1.2 +++ b/python.platform/nbproject/project.xml	Fri Jul 17 22:21:56 2015 +0200
     1.3 @@ -91,7 +91,9 @@
     1.4                      </test-dependency>
     1.5                  </test-type>
     1.6              </test-dependencies>
     1.7 -            <public-packages/>
     1.8 +            <public-packages>
     1.9 +                <package>org.netbeans.modules.python.platform.panels</package>
    1.10 +            </public-packages>
    1.11          </data>
    1.12      </configuration>
    1.13  </project>
     2.1 --- a/python.project2/nbproject/project.xml	Wed Jul 08 19:50:14 2015 +0200
     2.2 +++ b/python.project2/nbproject/project.xml	Fri Jul 17 22:21:56 2015 +0200
     2.3 @@ -100,6 +100,14 @@
     2.4                      </run-dependency>
     2.5                  </dependency>
     2.6                  <dependency>
     2.7 +                    <code-name-base>org.netbeans.modules.python.platform</code-name-base>
     2.8 +                    <build-prerequisite/>
     2.9 +                    <compile-dependency/>
    2.10 +                    <run-dependency>
    2.11 +                        <specification-version>1.2</specification-version>
    2.12 +                    </run-dependency>
    2.13 +                </dependency>
    2.14 +                <dependency>
    2.15                      <code-name-base>org.netbeans.modules.queries</code-name-base>
    2.16                      <build-prerequisite/>
    2.17                      <compile-dependency/>
     3.1 --- a/python.project2/src/org/netbeans/modules/python/project2/ui/PythonPlatformChooser.java	Wed Jul 08 19:50:14 2015 +0200
     3.2 +++ b/python.project2/src/org/netbeans/modules/python/project2/ui/PythonPlatformChooser.java	Fri Jul 17 22:21:56 2015 +0200
     3.3 @@ -1,17 +1,20 @@
     3.4  /*
     3.5 - * MainClassChooser.java
     3.6 + * PythonPlatformChooser.java
     3.7   *
     3.8   * Created on July 01, 2015 18:23
     3.9   */
    3.10  
    3.11  package org.netbeans.modules.python.project2.ui;
    3.12  
    3.13 +import java.awt.event.ActionEvent;
    3.14 +import java.awt.event.ActionListener;
    3.15  import java.util.LinkedList;
    3.16  import java.util.List;
    3.17  import javax.swing.DefaultListModel;
    3.18  import javax.swing.JButton;
    3.19  import javax.swing.SwingUtilities;
    3.20  import org.netbeans.modules.python.api.PythonPlatformManager;
    3.21 +import org.netbeans.modules.python.platform.panels.PythonPlatformPanel;
    3.22  import org.openide.util.NbBundle;
    3.23  import org.openide.util.RequestProcessor;
    3.24  
    3.25 @@ -23,13 +26,16 @@
    3.26  final class PythonPlatformChooser extends javax.swing.JPanel {
    3.27  
    3.28      private final JButton okButton;
    3.29 +    private final JButton managePythonPlatformButton;
    3.30      private final static RequestProcessor RP = new RequestProcessor("PythonPlatformChooser");   //NOI18N
    3.31  
    3.32 -    PythonPlatformChooser (final JButton okButton) {
    3.33 +    PythonPlatformChooser (final JButton okButton, final JButton managePythonPlatformButton) {
    3.34          assert okButton != null;
    3.35          initComponents();
    3.36          this.okButton = okButton;
    3.37          this.okButton.setEnabled(false);
    3.38 +        this.managePythonPlatformButton = managePythonPlatformButton;
    3.39 +        this.managePythonPlatformButton.setEnabled(false);
    3.40          ((DefaultListModel)this.pythonPlatforms.getModel()).addElement(NbBundle.getMessage(PythonPlatformChooser.class, "PPC_TXT_PleaseWait"));
    3.41          RP.post(new Runnable() {
    3.42              @Override
    3.43 @@ -44,21 +50,35 @@
    3.44      }
    3.45  
    3.46  
    3.47 -    private void initData () {
    3.48 -        final List<String> data = new LinkedList<>(PythonPlatformManager.getInstance().getPlatformList());
    3.49 +    private void initData() {
    3.50          SwingUtilities.invokeLater(new Runnable() {
    3.51              @Override
    3.52              public void run() {
    3.53 -                DefaultListModel lm = (DefaultListModel)pythonPlatforms.getModel();
    3.54 -                lm.clear();
    3.55 -                for (String s : data) {
    3.56 -                    lm.addElement(s);
    3.57 -                }
    3.58 +                updatePlatformList();
    3.59                  okButton.setEnabled(true);
    3.60 +
    3.61 +                managePythonPlatformButton.addActionListener(new ActionListener() {
    3.62 +
    3.63 +                    @Override
    3.64 +                    public void actionPerformed(ActionEvent e) {
    3.65 +                        PythonPlatformPanel.showPlatformManager();
    3.66 +                        updatePlatformList();
    3.67 +                    }
    3.68 +                });
    3.69 +                managePythonPlatformButton.setEnabled(true);
    3.70              }
    3.71          });
    3.72      }
    3.73  
    3.74 +    private void updatePlatformList() {
    3.75 +        final List<String> data = new LinkedList<>(PythonPlatformManager.getInstance().getPlatformList());
    3.76 +        DefaultListModel lm = (DefaultListModel)pythonPlatforms.getModel();
    3.77 +        lm.clear();
    3.78 +        for (String s : data) {
    3.79 +            lm.addElement(s);
    3.80 +        }
    3.81 +    }
    3.82 +
    3.83      /** This method is called from within the constructor to
    3.84       * initialize the form.
    3.85       * WARNING: Do NOT modify this code. The content of this method is
     4.1 --- a/python.project2/src/org/netbeans/modules/python/project2/ui/Utils.java	Wed Jul 08 19:50:14 2015 +0200
     4.2 +++ b/python.project2/src/org/netbeans/modules/python/project2/ui/Utils.java	Fri Jul 17 22:21:56 2015 +0200
     4.3 @@ -1,31 +1,28 @@
     4.4  package org.netbeans.modules.python.project2.ui;
     4.5  
     4.6  import java.awt.Component;
     4.7 +import java.awt.event.ActionEvent;
     4.8 +import java.awt.event.ActionListener;
     4.9  import java.io.File;
    4.10 -import java.util.Iterator;
    4.11  import java.util.List;
    4.12  import javax.swing.ComboBoxModel;
    4.13  import javax.swing.DefaultComboBoxModel;
    4.14  import javax.swing.JButton;
    4.15  import javax.swing.JComponent;
    4.16 -import javax.swing.JFileChooser;
    4.17  import javax.swing.JList;
    4.18  import javax.swing.JTable;
    4.19  import javax.swing.ListCellRenderer;
    4.20  import javax.swing.table.DefaultTableCellRenderer;
    4.21  import javax.swing.table.DefaultTableModel;
    4.22 -import javax.swing.table.TableModel;
    4.23  import org.netbeans.modules.python.api.PythonPlatform;
    4.24  import org.netbeans.modules.python.api.PythonPlatformManager;
    4.25 +import org.netbeans.modules.python.platform.panels.PythonPlatformPanel;
    4.26  import org.netbeans.modules.python.project2.PythonProject2;
    4.27  import org.openide.DialogDescriptor;
    4.28  import org.openide.DialogDisplayer;
    4.29  import org.openide.awt.HtmlRenderer;
    4.30 -import org.openide.filesystems.FileObject;
    4.31 -import org.openide.filesystems.FileUtil;
    4.32  import org.openide.util.HelpCtx;
    4.33  import org.openide.util.NbBundle;
    4.34 -import org.openide.util.Pair;
    4.35  
    4.36  /**
    4.37   *
    4.38 @@ -47,14 +44,16 @@
    4.39          return null;
    4.40      }
    4.41  
    4.42 -    @NbBundle.Messages({"LBL_SelectPythonPlatform=Select Python Platform", "LBL_BrowsePythonPlatforms=Browse Python Platforms"})
    4.43 +    @NbBundle.Messages({"LBL_SelectPythonPlatform=Select Python Platform", "LBL_BrowsePythonPlatforms=Browse Python Platforms", "LBL_ManagePythonPlatform=Manage Python Platforms"})
    4.44      public static String choosePythonPlatform(PythonProject2 project) {
    4.45          final JButton okButton = new JButton (NbBundle.getMessage(Utils.class, "LBL_SelectPythonPlatform"));
    4.46 -        final PythonPlatformChooser ppc = new PythonPlatformChooser(okButton);
    4.47 -        final Object[] options = new Object[] {okButton, DialogDescriptor.CANCEL_OPTION};
    4.48 +        final JButton managePythonPlatformButton = new JButton(NbBundle.getMessage(Utils.class, "LBL_ManagePythonPlatform"));
    4.49 +        final PythonPlatformChooser ppc = new PythonPlatformChooser(okButton, managePythonPlatformButton);
    4.50 +        final Object[] options = new Object[] {okButton, managePythonPlatformButton, DialogDescriptor.CANCEL_OPTION};
    4.51 +        final Object[] closingOptions = new Object[] {okButton, DialogDescriptor.CANCEL_OPTION};
    4.52          final DialogDescriptor dd = new DialogDescriptor(ppc, NbBundle.getMessage(Utils.class, "LBL_BrowsePythonPlatforms"), true, options,
    4.53              okButton,DialogDescriptor.RIGHT_ALIGN, HelpCtx.DEFAULT_HELP, null);
    4.54 -        dd.setClosingOptions(options);
    4.55 +        dd.setClosingOptions(closingOptions);
    4.56          if (DialogDisplayer.getDefault().notify(dd) == okButton) {
    4.57              return ppc.getPythonPlatform();
    4.58          }