This is an automated email from the ASF dual-hosted git repository. ebakke pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
commit 5a34cc3b6c84411258263e532a7b516548834e6c Author: Eirik Bakke <eba...@ultorg.com> AuthorDate: Mon Feb 3 13:57:51 2020 -0500 In the Database module, refactor the 'Add Connection' wizard to avoid depending on hardcoded wizard panel indexes. --- .../db/explorer/dlg/AddConnectionWizard.java | 51 ++++++++++++---------- .../explorer/dlg/ChoosingConnectionNamePanel.java | 7 ++- .../db/explorer/dlg/ChoosingDriverPanel.java | 6 ++- .../db/explorer/dlg/ChoosingSchemaPanel.java | 9 +++- .../modules/db/explorer/dlg/ConnectionPanel.java | 9 ++-- 5 files changed, 52 insertions(+), 30 deletions(-) diff --git a/ide/db/src/org/netbeans/modules/db/explorer/dlg/AddConnectionWizard.java b/ide/db/src/org/netbeans/modules/db/explorer/dlg/AddConnectionWizard.java index b71769c..e6c4f0d 100644 --- a/ide/db/src/org/netbeans/modules/db/explorer/dlg/AddConnectionWizard.java +++ b/ide/db/src/org/netbeans/modules/db/explorer/dlg/AddConnectionWizard.java @@ -21,6 +21,8 @@ package org.netbeans.modules.db.explorer.dlg; import java.awt.Dialog; import java.net.URL; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -60,12 +62,11 @@ public class AddConnectionWizard extends ConnectionDialogMediator implements Wiz private final String pwd; private final String databaseUrl; private final String user; + private final WizardDescriptor wd; private DatabaseConnection connection; private List<String> schemas = null; private String currentSchema; private JDBCDriver jdbcDriver; - private boolean increase = false; - private WizardDescriptor wd; private AddConnectionWizard(JDBCDriver driver, String databaseUrl, String user, String password) { this.databaseUrl = databaseUrl; @@ -123,30 +124,41 @@ public class AddConnectionWizard extends ConnectionDialogMediator implements Wiz */ private WizardDescriptor.Panel<AddConnectionWizard>[] getPanels() { if (panels == null) { + boolean skipDriverSelection = false; if (jdbcDriver != null) { URL[] jars = jdbcDriver.getURLs(); if (jars != null && jars.length > 0) { FileObject jarFO = URLMapper.findFileObject(jars[0]); if (jarFO != null && jarFO.isValid()) { this.allPrivilegedFileNames.add(jarFO.getNameExt()); - this.increase = true; + skipDriverSelection = true; } } } - driverPanel = new ChoosingDriverPanel(jdbcDriver); - panels = new Panel[] { - driverPanel, - new ConnectionPanel(), - new ChoosingSchemaPanel(), - new ChoosingConnectionNamePanel() - }; - steps = new String[panels.length]; - steps = new String[] { - NbBundle.getMessage(AddConnectionWizard.class, "ChoosingDriverUI.Name"), // NOI18N - NbBundle.getMessage(AddConnectionWizard.class, "ConnectionPanel.Name"), // NOI18N - NbBundle.getMessage(AddConnectionWizard.class, "ChoosingSchemaPanel.Name"), // NOI18N - NbBundle.getMessage(AddConnectionWizard.class, "ChooseConnectionNamePanel.Name"), // NOI18N - }; + List<Panel> toPanels = new ArrayList<>(); + List<String> toSteps = new ArrayList<>(); + int stepIndex = 0; + + if (!skipDriverSelection) { + toPanels.add(new ChoosingDriverPanel(jdbcDriver, stepIndex)); + toSteps.add(NbBundle.getMessage(AddConnectionWizard.class, "ChoosingDriverUI.Name")); // NOI18N + stepIndex++; + } + + toPanels.add(new ConnectionPanel(stepIndex)); + toSteps.add(NbBundle.getMessage(AddConnectionWizard.class, "ConnectionPanel.Name")); // NOI18N + stepIndex++; + + toPanels.add(new ChoosingSchemaPanel(stepIndex)); + toSteps.add(NbBundle.getMessage(AddConnectionWizard.class, "ChoosingSchemaPanel.Name")); // NOI18N + stepIndex++; + + toPanels.add(new ChoosingConnectionNamePanel(stepIndex)); + toSteps.add(NbBundle.getMessage(AddConnectionWizard.class, "ChooseConnectionNamePanel.Name")); // NOI18N + stepIndex++; + + panels = toPanels.toArray(new Panel[stepIndex]); + steps = toSteps.toArray(new String[stepIndex]); } return panels; } @@ -155,11 +167,6 @@ public class AddConnectionWizard extends ConnectionDialogMediator implements Wiz public WizardDescriptor.Panel<AddConnectionWizard> current() { // init panels first getPanels(); - if (increase) { - index++; - increase = false; - } - return getPanels()[index]; } diff --git a/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingConnectionNamePanel.java b/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingConnectionNamePanel.java index 669a130..2013d26 100644 --- a/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingConnectionNamePanel.java +++ b/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingConnectionNamePanel.java @@ -30,6 +30,7 @@ import org.openide.util.HelpCtx; public class ChoosingConnectionNamePanel implements AddConnectionWizard.Panel { + private final int stepIndex; /** * The visual component that displays this panel. If you need to access the * component from this class, just use getComponent(). @@ -39,6 +40,10 @@ public class ChoosingConnectionNamePanel implements AddConnectionWizard.Panel { private static HelpCtx CHOOSING_SCHEMA_PANEL_HELPCTX = new HelpCtx(ChoosingConnectionNamePanel.class); private boolean blockEventListener = false; + public ChoosingConnectionNamePanel(int stepIndex) { + this.stepIndex = stepIndex; + } + // Get the visual component for the panel. In this template, the component // is kept separate. This can be more efficient: if the wizard is created // but never displayed, or not all panels are displayed, it is better to @@ -51,7 +56,7 @@ public class ChoosingConnectionNamePanel implements AddConnectionWizard.Panel { } assert pw != null : "ChoosingConnectionNamePanel must be initialized."; component = new ConnectionNamePanel(pw, pw.getDatabaseConnection().getDisplayName()); - component.setName(pw.getSteps()[3]); + component.setName(pw.getSteps()[stepIndex]); component.addPropertyChangeListener(ConnectionNamePanel.PROP_CONNECTION_NAME, new PropertyChangeListener() { @Override diff --git a/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingDriverPanel.java b/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingDriverPanel.java index 8a6f6b0..cba768d 100644 --- a/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingDriverPanel.java +++ b/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingDriverPanel.java @@ -31,10 +31,12 @@ import org.openide.util.HelpCtx; public class ChoosingDriverPanel implements AddConnectionWizard.Panel { + private final int stepIndex; private AddConnectionWizard pw; - public ChoosingDriverPanel(JDBCDriver driver) { + public ChoosingDriverPanel(JDBCDriver driver, int stepIndex) { this.driver = driver; + this.stepIndex = stepIndex; } /** @@ -56,7 +58,7 @@ public class ChoosingDriverPanel implements AddConnectionWizard.Panel { } component = new ChoosingDriverUI(this, driver, pw); JComponent jc = (JComponent) component; - jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0); + jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, stepIndex); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, pw.getSteps()); jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, Boolean.TRUE); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, Boolean.FALSE); diff --git a/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingSchemaPanel.java b/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingSchemaPanel.java index d4de3fe..3b2bc7a 100644 --- a/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingSchemaPanel.java +++ b/ide/db/src/org/netbeans/modules/db/explorer/dlg/ChoosingSchemaPanel.java @@ -25,6 +25,7 @@ import org.openide.util.HelpCtx; public class ChoosingSchemaPanel implements AddConnectionWizard.Panel, WizardDescriptor.FinishablePanel<AddConnectionWizard> { + private final int stepIndex; /** * The visual component that displays this panel. If you need to access the * component from this class, just use getComponent(). @@ -33,6 +34,10 @@ public class ChoosingSchemaPanel implements AddConnectionWizard.Panel, WizardDes private AddConnectionWizard pw; private static HelpCtx CHOOSING_SCHEMA_PANEL_HELPCTX = new HelpCtx(ChoosingSchemaPanel.class); + public ChoosingSchemaPanel(int stepIndex) { + this.stepIndex = stepIndex; + } + // Get the visual component for the panel. In this template, the component // is kept separate. This can be more efficient: if the wizard is created // but never displayed, or not all panels are displayed, it is better to @@ -46,12 +51,12 @@ public class ChoosingSchemaPanel implements AddConnectionWizard.Panel, WizardDes assert pw != null : "ChoosingSchemaPanel must be initialized."; component = new SchemaPanel(pw, pw.getDatabaseConnection()); component.setSchemas(pw.getSchemas(), pw.getCurrentSchema()); - component.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 2); + component.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, stepIndex); component.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, pw.getSteps()); component.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, Boolean.TRUE); component.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, Boolean.FALSE); component.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, Boolean.FALSE); - component.setName(pw.getSteps()[2]); + component.setName(pw.getSteps()[stepIndex]); } return component; } diff --git a/ide/db/src/org/netbeans/modules/db/explorer/dlg/ConnectionPanel.java b/ide/db/src/org/netbeans/modules/db/explorer/dlg/ConnectionPanel.java index a01f8ee..020141d 100644 --- a/ide/db/src/org/netbeans/modules/db/explorer/dlg/ConnectionPanel.java +++ b/ide/db/src/org/netbeans/modules/db/explorer/dlg/ConnectionPanel.java @@ -45,12 +45,15 @@ import org.openide.util.NbBundle; public class ConnectionPanel implements AddConnectionWizard.Panel, WizardDescriptor.AsynchronousValidatingPanel<AddConnectionWizard>, WizardDescriptor.FinishablePanel<AddConnectionWizard> { + private final int stepIndex; private DatabaseConnection databaseConnection; private JDBCDriver drv; private JDBCDriver oldDriver; private static HelpCtx CONNECTION_PANEL_HELPCTX = new HelpCtx(ConnectionPanel.class); - public ConnectionPanel() {} + public ConnectionPanel(int stepIndex) { + this.stepIndex = stepIndex; + } /** * The visual component that displays this panel. If you need to access the * component from this class, just use getComponent(). @@ -78,12 +81,12 @@ public class ConnectionPanel implements AddConnectionWizard.Panel, WizardDescrip component = new NewConnectionPanel(pw, this, drv.getClassName(), databaseConnection); oldDriver = drv; JComponent jc = (JComponent) component; - jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 1); + jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, stepIndex); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, pw.getSteps()); jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, Boolean.TRUE); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, Boolean.FALSE); jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, Boolean.FALSE); - component.setName(pw.getSteps()[1]); + component.setName(pw.getSteps()[stepIndex]); fireChangeEvent(); component.checkValid(); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists