diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/EnterPasswordComponent.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/EnterPasswordComponent.java index 05469f3bf8f5..68aebf6feea9 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/EnterPasswordComponent.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/EnterPasswordComponent.java @@ -17,7 +17,6 @@ package com.intellij.ide.passwordSafe.impl.providers.masterKey; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.ui.ValidationInfo; -import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import java.util.function.Function; @@ -30,24 +29,15 @@ public class EnterPasswordComponent extends PasswordComponentBase { private final Function myPasswordConsumer; public EnterPasswordComponent(@NotNull Function passwordConsumer) { - super("Enter"); - myPasswordConsumer = passwordConsumer; - myPromptLabel.setText("
Master password is required to unlock the password database to convert it to a new format."); - UIUtil.setEnabled(myNewPasswordPanel, false, true); - myNewPasswordPanel.setVisible(false); + myPromptLabel.setText("Master password is required to convert saved password."); if (ApplicationManager.getApplication().isUnitTestMode()) { myPasswordField.setText("pass"); } } - @Override - public ValidationInfo doValidate() { - return null; - } - @Override public ValidationInfo apply() { // enter password — only and only old key, so, we use EncryptionUtil.genPasswordKey diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterPasswordDialog.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterPasswordDialog.java index 3f7b52470185..eac7989e2edb 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterPasswordDialog.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterPasswordDialog.java @@ -18,78 +18,40 @@ package com.intellij.ide.passwordSafe.impl.providers.masterKey; import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.ValidationInfo; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.util.ArrayUtil; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.awt.*; -import java.awt.event.ActionEvent; -import java.util.List; -/** - * The dialog used to prompt for the master password to the password database - */ public class MasterPasswordDialog extends DialogWrapper { private final static int NUMBER_OF_RETRIES = 5; - private final JPanel myRootPanel = new JPanel(new CardLayout()); - private final List myComponents = ContainerUtil.newArrayList(); - private final DialogWrapperAction myCardAction; + private final JPanel myRootPanel; + private final PasswordComponentBase myComponent; private int myRetriesCount; public MasterPasswordDialog(@NotNull PasswordComponentBase component) { super(false); + myComponent = component; setResizable(false); - myComponents.add(component); - myRootPanel.add(component.getComponent(), component.getTitle()); - myCardAction = new DialogWrapperAction("") { - @Override - protected void doAction(ActionEvent e) { - show(getNextComponent(getSelectedComponent())); - } - }; - show(myComponents.get(0)); + myRootPanel = component.getComponent(); + setTitle("Password Manager Database Updated"); + getOKAction().putValue(Action.NAME, "Convert"); + getCancelAction().putValue(Action.NAME, "Clear Passwords"); init(); } @Nullable @Override public JComponent getPreferredFocusedComponent() { - return getSelectedComponent().getPreferredFocusedComponent(); + return myComponent.getPreferredFocusedComponent(); } @Nullable @Override protected String getHelpId() { - return getSelectedComponent().getHelpId(); - } - - private CardLayout getLayout() { - return (CardLayout)myRootPanel.getLayout(); - } - - private PasswordComponentBase getSelectedComponent() { - for (PasswordComponentBase component : myComponents) { - if (component.getComponent().isVisible()) return component; - } - throw new AssertionError("no visible components"); - } - - @NotNull - private PasswordComponentBase getNextComponent(@NotNull PasswordComponentBase component) { - int idx = myComponents.indexOf(component); - int next = idx < myComponents.size() - 1 ? idx + 1 : 0; - return myComponents.get(next); - } - - private void show(@NotNull PasswordComponentBase component) { - setTitle(component.getTitle() + " Master Password"); - getLayout().show(myRootPanel, component.getTitle()); - myCardAction.putValue(Action.NAME, getNextComponent(component).getTitle() + "..."); - component.getPreferredFocusedComponent().requestFocus(); + return myComponent.getHelpId(); } @Override @@ -97,29 +59,9 @@ public class MasterPasswordDialog extends DialogWrapper { return myRootPanel; } - @NotNull - @Override - protected Action[] createActions() { - Action[] result = { - getHelpAction(), - getOKAction(), - getCancelAction()}; - if (myComponents.size() > 1) { - return ArrayUtil.append(result, myCardAction); - } - return result; - } - - @Nullable - @Override - protected ValidationInfo doValidate() { - return getSelectedComponent().doValidate(); - } - @Override public void doOKAction() { - PasswordComponentBase component = getSelectedComponent(); - ValidationInfo info = component.apply(); + ValidationInfo info = myComponent.apply(); if (info == null) { super.doOKAction(); } diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.form b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.form index f088f62aa219..105475bbd005 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.form +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.form @@ -31,7 +31,7 @@ - + @@ -41,50 +41,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.java index ca3a8ceb8759..bdd1398129bd 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/PasswordComponentBase.java @@ -18,32 +18,23 @@ package com.intellij.ide.passwordSafe.impl.providers.masterKey; import com.intellij.icons.AllIcons; import com.intellij.openapi.ui.ValidationInfo; import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.util.Arrays; /** * @author gregsh */ public abstract class PasswordComponentBase { - private final String myTitle; - private JPanel myRootPanel; private JLabel myIconLabel; protected JLabel myPromptLabel; protected JPanel myPasswordPanel; - protected JPanel myNewPasswordPanel; protected JPasswordField myPasswordField; - protected JPasswordField myNewPasswordField; - protected JPasswordField myConfirmPasswordField; protected JLabel myPasswordLabel; - protected JLabel myNewPasswordLabel; - public PasswordComponentBase(@NotNull String title) { - myTitle = title; + public PasswordComponentBase() { myIconLabel.setText(""); myIconLabel.setIcon(AllIcons.General.PasswordLock); myIconLabel.setDisabledIcon(AllIcons.General.PasswordLock); @@ -51,25 +42,12 @@ public abstract class PasswordComponentBase { myPromptLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL)); } - public JComponent getComponent() { + public JPanel getComponent() { return myRootPanel; } public JComponent getPreferredFocusedComponent() { - if (myPasswordField.isEnabled()) return myPasswordField; - else if (myNewPasswordField.isEnabled()) return myNewPasswordField; - throw new AssertionError("no visible fields found"); - } - - public String getTitle() { - return myTitle; - } - - public ValidationInfo doValidate() { - if (myNewPasswordField.isEnabled() && !Arrays.equals(myNewPasswordField.getPassword(), myConfirmPasswordField.getPassword())) { - return new ValidationInfo("New passwords do not match", myConfirmPasswordField); - } - return null; + return myPasswordField; } @Nullable