Author: tchemit Date: 2008-04-27 08:39:02 +0000 (Sun, 27 Apr 2008) New Revision: 635 Added: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ConnexionConfigUIHandler.java Removed: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ConfigUIHandler.java Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/ConnexionConfigUI.java trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/ShowConfigAction.java trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/TestConnexionAction.java Log: renommage ConfigUI en ConnexionConfigUI Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/ConnexionConfigUI.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/ConnexionConfigUI.java 2008-04-27 08:38:39 UTC (rev 634) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/ConnexionConfigUI.java 2008-04-27 08:39:02 UTC (rev 635) @@ -18,7 +18,7 @@ import org.codelutin.ui.FormElement; import org.codelutin.util.FileUtil; import org.codelutin.vcs.type.VCSConnexionMode; -import org.codelutin.vcs.ui.handler.ConfigUIHandler; +import org.codelutin.vcs.ui.handler.ConnexionConfigUIHandler; import org.codelutin.vcs.ui.util.ui.AbstractUI; import javax.swing.AbstractButton; @@ -34,7 +34,7 @@ import java.util.Arrays; /** @author chemit */ -public abstract class ConnexionConfigUI extends AbstractUI<ConfigUIHandler> { +public abstract class ConnexionConfigUI extends AbstractUI<ConnexionConfigUIHandler> { public enum Element implements FormElement<ConnexionConfigUI> { connexion, Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java 2008-04-27 08:38:39 UTC (rev 634) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/VCSUIFactory.java 2008-04-27 08:39:02 UTC (rev 635) @@ -26,7 +26,7 @@ import org.codelutin.vcs.VCSConnexionConfig; import org.codelutin.vcs.VCSFactory; import org.codelutin.vcs.ui.handler.ChangelogUIHandler; -import org.codelutin.vcs.ui.handler.ConfigUIHandler; +import org.codelutin.vcs.ui.handler.ConnexionConfigUIHandler; import org.codelutin.vcs.ui.handler.ConfirmUIHandler; import org.codelutin.vcs.ui.handler.DiffUIHandler; import org.codelutin.vcs.ui.handler.IdentityUIHandler; @@ -59,7 +59,7 @@ public static final DialogUIDef<DiffUIModel, DiffUI, DiffUIHandler> DIFF_UI; public static final DialogUIDef<ChangelogUIModel, ChangelogUI, ChangelogUIHandler> CHANGELOG_UI; public static final DialogUIDef<ConfirmUIModel, ConfirmUI, ConfirmUIHandler> CONFIRM_UI; - public static final DialogUIDef<ConnexionConfigUIModel, ConnexionConfigUI, ConfigUIHandler> CONFIG_UI; + public static final DialogUIDef<ConnexionConfigUIModel, ConnexionConfigUI, ConnexionConfigUIHandler> CONFIG_UI; public static final DialogUIDef<GenerateSshKeyUIModel, GenerateSshKeyUI, GenerateSshKeyUIHandler> GENERATE_SHH_KEY_UI; public static final DialogUIDef<IdentityUIModel, IdentityUI, IdentityUIHandler> IDENTITY_UI; public static final DialogUIDef<TestUIModel, TestUI, TestUIHandler> TEST_UI; @@ -132,7 +132,7 @@ n_("lutinvcs.action.show.confirmui"), n_("lutinvcs.action.show.confirmui.tip"), n_("lutinvcs.confirmui.title")); - CONFIG_UI = newDef(ConfigUIHandler.class, ConnexionConfigUI.class, ConnexionConfigUIModel.class, + CONFIG_UI = newDef(ConnexionConfigUIHandler.class, ConnexionConfigUI.class, ConnexionConfigUIModel.class, n_("lutinvcs.action.show.configui"), n_("lutinvcs.action.show.configui.tip"), n_("lutinvcs.configui.title")); Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/ShowConfigAction.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/ShowConfigAction.java 2008-04-27 08:38:39 UTC (rev 634) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/ShowConfigAction.java 2008-04-27 08:39:02 UTC (rev 635) @@ -17,14 +17,14 @@ import org.codelutin.ui.DialogUIHandler; import org.codelutin.vcs.ui.ConnexionConfigUI; import org.codelutin.vcs.ui.VCSUIFactory; -import org.codelutin.vcs.ui.handler.ConfigUIHandler; +import org.codelutin.vcs.ui.handler.ConnexionConfigUIHandler; import org.codelutin.vcs.ui.model.ConnexionConfigUIModel; import org.codelutin.vcs.ui.util.AbstractVCSShowUIAction; import java.awt.event.ActionEvent; /** @author chemit */ -public class ShowConfigAction extends AbstractVCSShowUIAction<ConnexionConfigUIModel, ConnexionConfigUI, ConfigUIHandler, DialogUIHandler<?, ?>> { +public class ShowConfigAction extends AbstractVCSShowUIAction<ConnexionConfigUIModel, ConnexionConfigUI, ConnexionConfigUIHandler, DialogUIHandler<?, ?>> { private static final long serialVersionUID = 1L; Modified: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/TestConnexionAction.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/TestConnexionAction.java 2008-04-27 08:38:39 UTC (rev 634) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/action/TestConnexionAction.java 2008-04-27 08:39:02 UTC (rev 635) @@ -20,14 +20,14 @@ import org.codelutin.vcs.VCSException; import org.codelutin.vcs.VCSFactory; import org.codelutin.vcs.ui.ConnexionConfigUI; -import org.codelutin.vcs.ui.handler.ConfigUIHandler; +import org.codelutin.vcs.ui.handler.ConnexionConfigUIHandler; import javax.swing.JOptionPane; import static javax.swing.JOptionPane.ERROR_MESSAGE; import static javax.swing.JOptionPane.INFORMATION_MESSAGE; /** @author chemit */ -public class TestConnexionAction extends org.codelutin.ui.AbstractUIAction<org.codelutin.vcs.ui.handler.ConfigUIHandler> { +public class TestConnexionAction extends org.codelutin.ui.AbstractUIAction<ConnexionConfigUIHandler> { private static final long serialVersionUID = 1L; @@ -41,7 +41,7 @@ public void actionPerformed(java.awt.event.ActionEvent e) { checkInit(); - ConfigUIHandler uiHandler = getHandler(); + ConnexionConfigUIHandler uiHandler = getHandler(); VCSConnexionConfig config = uiHandler.getConfig(); VCSConnexion connexion = VCSFactory.newConnexion(config); ConnexionConfigUI ui = uiHandler.getUi(); Deleted: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ConfigUIHandler.java =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ConfigUIHandler.java 2008-04-27 08:38:39 UTC (rev 634) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ConfigUIHandler.java 2008-04-27 08:39:02 UTC (rev 635) @@ -1,288 +0,0 @@ -/** - * ##% Copyright (C) 2008 Code Lutin, Tony Chemit - * This program is free software; you - * can redistribute it and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. This program is - * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU General Public License for more details. You - * should have received a copy of the GNU General Public License along with this - * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - * - Suite 330, Boston, MA 02111-1307, USA. - * ##% - */ -package org.codelutin.vcs.ui.handler; - -import org.codelutin.vcs.VCSConnexionConfig; -import org.codelutin.vcs.type.VCSConnexionMode; -import org.codelutin.vcs.ui.ConnexionConfigUI; -import org.codelutin.vcs.ui.ConnexionConfigUI.Element; -import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.login; -import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.nopassphrase; -import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.passphrase; -import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.password; -import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.privateKeyFile; -import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.sshLogin; -import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.values; -import org.codelutin.vcs.ui.model.ConnexionConfigUIModel; -import org.codelutin.vcs.ui.util.handler.AbstractUIHandler; - -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; -import javax.swing.text.JTextComponent; -import java.awt.Color; -import java.beans.PropertyChangeEvent; -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** @author chemit */ -public class ConfigUIHandler extends AbstractUIHandler<ConnexionConfigUIModel, ConnexionConfigUI> { - - protected List<Element> errors; - - - public ConfigUIHandler(ConnexionConfigUI ui, VCSConnexionConfig config) { - super(ui, new ConnexionConfigUIModel(), config); - ui.setHandler(this); - errors = new ArrayList<Element>(); - } - - public void init() { - super.init(); - ConnexionConfigUI ui = getUi(); - JPanel connexionPanel = ui.getConnexionPanel(); - connexionPanel.add(ui.getAnonymousPanel(), VCSConnexionMode.ANONYMOUS.name()); - connexionPanel.add(ui.getPasswordPanel(), VCSConnexionMode.PASSWORD.name()); - connexionPanel.add(ui.getSshPanel(), VCSConnexionMode.SSH.name()); - } - - public void propertyChange(PropertyChangeEvent evt) { - if (log.isDebugEnabled()) { - log.debug(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); - } - String action = evt.getPropertyName(); - - if (ConnexionConfigUIModel.CONFIG_PROPERTY_CHANGED.equals(action)) { - // update ui with model values, - populateUI((ConnexionConfigUIModel) evt.getNewValue()); - doCheck(null); - return; - } - if (ConnexionConfigUIModel.MODE_PROPERTY_CHANGED.equals(action)) { - updateUI((VCSConnexionMode) evt.getNewValue()); - doCheck(null); - return; - } - - if (ConnexionConfigUIModel.MODIFIED_PROPERTY_CHANGED.equals(action)) { - Boolean newValue = (Boolean) evt.getNewValue(); - boolean modified = newValue != null && newValue; - getUi().getReset().setEnabled(modified); - getUi().getTestConnection().setEnabled(modified && isConfigValid()); - return; - } - - if (ConnexionConfigUIModel.CONNEXION_STATE_PROPERTY_CHANGED.equals(action)) { - Boolean newValue = (Boolean) evt.getNewValue(); - boolean validConnexion = newValue != null && newValue; - getUi().getOk().setEnabled(validConnexion); - getUi().getTestConnection().setEnabled(!validConnexion); - return; - } - throw new IllegalStateException("unimplemented property changed : " + evt + " for " + this); - } - - public synchronized List<Element> validateModel(Element element) { - errors.clear(); - ConnexionConfigUI ui = getUi(); - if (element != null) { - // compute modifed - setModified(element, ui); - } - switch (getModel().getMode()) { - case ANONYMOUS: - // nothing to validate - break; - case PASSWORD: - // login + password not empty - checkData(ui.getLogin(), login); - checkData(ui.getPassword().getPassword().length == 0, password); - break; - case SSH: - // login + private key exists - checkData(ui.getSshLogin(), sshLogin); - String s = ui.getPrivateKeyFile().getText(); - File file = new File(s); - checkData(s.isEmpty() || !file.exists(), privateKeyFile); - if (ui.getElementValue(nopassphrase).equals("false")) { - // check it there is a pass-phrase - checkData(ui.getPassphrase().getPassword().length == 0, passphrase); - } else { - errors.remove(passphrase); - } - break; - } - return errors; - } - - public void setModified(Element element, ConnexionConfigUI ui) { - boolean modify = false; - ConnexionConfigUIModel model = getModel(); - - String value = ui.getElementValue(element); - - switch (element) { - case connexion: - modify = model.getMode() != model.getConfig().getMode(); - break; - case login: - modify = !model.getConfig().getUserName().equals(value); - break; - case sshLogin: - modify = !model.getConfig().getUserName().equals(value); - break; - case nopassphrase: - boolean b = ui.getNoPassPhrase().isSelected(); - modify = (model.getConfig().getPassphrase() != null && !model.getConfig().getPassphrase().isEmpty()) == b; - if (!b) { - model.removeModified(passphrase); - } else { - char[] password = ui.getPassphrase().getPassword(); - boolean modify2; - if (model.getConfig().getPassphrase() == null || model.getConfig().getPassphrase().isEmpty()) { - modify2 = password.length == 0; - } else { - modify2 = model.getConfig().getPassphrase().equals(Arrays.toString(password)); - } - if (modify2) { - model.addModified(passphrase); - } - } - break; - case password: - modify = !model.getConfig().getPassphrase().equals(Arrays.toString(ui.getPassword().getPassword())); - break; - case privateKeyFile: - modify = !model.getConfig().getKeyFile().getAbsolutePath().equals(value); - break; - case passphrase: - modify = !model.getConfig().getPassphrase().equals(value); - break; - } - if (modify) { - model.addModified(element); - // reset connexion state - model.setConnexionState(null); - } else if (model.getModifieds().contains(element)) { - model.removeModified(element); - // reset connexion state - model.setConnexionState(null); - } - } - - public void doCheck(Element element) { - List<Element> errors = validateModel(element); - updateUI(errors); - } - - public boolean isConfigValid() { - return errors.isEmpty() && getModel().isConnexionState(); - } - - public void reset() { - getModel().reset(); - } - - protected void populateUI(ConnexionConfigUIModel model) { - ConnexionConfigUI ui = getUi(); - VCSConnexionConfig config = model.getConfig(); - switch (config.getMode()) { - case ANONYMOUS: - break; - case PASSWORD: - ui.getLogin().setText(config.getUserName()); - ui.getPassword().setText(config.getPassphrase() == null ? "" : config.getPassphrase()); - break; - case SSH: - ui.getSshLogin().setText(config.getUserName()); - ui.getNoPassPhrase().setSelected(config.isNoPassPhrase()); - ui.getPrivateKeyFile().setText(config.getKeyFile() == null ? "" : config.getKeyFile().getAbsolutePath()); - ui.getPassphrase().setText(config.getPassphrase() == null ? "" : config.getPassphrase()); - break; - } - ui.getTestConnection().setEnabled(true); - } - - protected void updateUI(final VCSConnexionMode mode) { - ConnexionConfigUI ui = getUi(); - //getModel().removeModified(sshLogin, nopassphrase, passphrase, privateKeyFile, login, password); - switch (mode) { - case ANONYMOUS: - ui.getConnexionModeAnonymous().setSelected(true); - break; - case PASSWORD: - ui.getConnexionModePassword().setSelected(true); - setModified(login, ui); - setModified(password, ui); - break; - case SSH: - setModified(sshLogin, ui); - setModified(nopassphrase, ui); - setModified(passphrase, ui); - setModified(privateKeyFile, ui); - ui.getConnexionModeSsh().setSelected(true); - break; - } - SwingUtilities.invokeLater(new Runnable() { - public void run() { - getUi().getConnexionPanelLayout().show(getUi().getConnexionPanel(), mode.name()); - getUi().pack(); - } - }); - } - - protected void updateUI(List<Element> errors) { - ConnexionConfigUI ui = getUi(); - boolean valid = isConfigValid(); - ui.getOk().setEnabled(valid && getModel().isModified()); - //ui.getTestConnection().setEnabled(valid); - ui.getGenerateKey().setEnabled(getModel().getMode() == VCSConnexionMode.SSH && !errors.contains(sshLogin) && !errors.contains(passphrase)); - for (Element element : values()) { - setLabelColor(errors, element); - } - } - - protected void checkData(JTextComponent component, Element errorName) { - if (component.getText().isEmpty()) { - errors.add(errorName); - } - } - - protected void checkData(boolean notValid, Element errorName) { - if (notValid) { - errors.add(errorName); - } - } - - protected void setLabelColor(List<Element> errors, Element element) { - JComponent component = getUi().getElementLabel(element); - if (component != null && component.isVisible()) { - component.setForeground(errors.contains(element) ? Color.red : Color.black); - } - } - - public void save() { - if (!getModel().isModified()) { - log.warn("nothing to save"); - } - for (Element element : getModel().getModifieds()) { - String value = getUi().getElementValue(element); - getModel().save(element, value); - log.info("save " + element); - } - } -} \ No newline at end of file Copied: trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ConnexionConfigUIHandler.java (from rev 633, trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ConfigUIHandler.java) =================================================================== --- trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ConnexionConfigUIHandler.java (rev 0) +++ trunk/lutinvcs/ui/common/src/main/java/org/codelutin/vcs/ui/handler/ConnexionConfigUIHandler.java 2008-04-27 08:39:02 UTC (rev 635) @@ -0,0 +1,288 @@ +/** + * ##% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * ##% + */ +package org.codelutin.vcs.ui.handler; + +import org.codelutin.vcs.VCSConnexionConfig; +import org.codelutin.vcs.type.VCSConnexionMode; +import org.codelutin.vcs.ui.ConnexionConfigUI; +import org.codelutin.vcs.ui.ConnexionConfigUI.Element; +import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.login; +import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.nopassphrase; +import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.passphrase; +import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.password; +import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.privateKeyFile; +import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.sshLogin; +import static org.codelutin.vcs.ui.ConnexionConfigUI.Element.values; +import org.codelutin.vcs.ui.model.ConnexionConfigUIModel; +import org.codelutin.vcs.ui.util.handler.AbstractUIHandler; + +import javax.swing.JComponent; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.text.JTextComponent; +import java.awt.Color; +import java.beans.PropertyChangeEvent; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** @author chemit */ +public class ConnexionConfigUIHandler extends AbstractUIHandler<ConnexionConfigUIModel, ConnexionConfigUI> { + + protected List<Element> errors; + + + public ConnexionConfigUIHandler(ConnexionConfigUI ui, VCSConnexionConfig config) { + super(ui, new ConnexionConfigUIModel(), config); + ui.setHandler(this); + errors = new ArrayList<Element>(); + } + + public void init() { + super.init(); + ConnexionConfigUI ui = getUi(); + JPanel connexionPanel = ui.getConnexionPanel(); + connexionPanel.add(ui.getAnonymousPanel(), VCSConnexionMode.ANONYMOUS.name()); + connexionPanel.add(ui.getPasswordPanel(), VCSConnexionMode.PASSWORD.name()); + connexionPanel.add(ui.getSshPanel(), VCSConnexionMode.SSH.name()); + } + + public void propertyChange(PropertyChangeEvent evt) { + if (log.isDebugEnabled()) { + log.debug(evt.getPropertyName() + " old:" + evt.getOldValue() + ", new:" + evt.getNewValue()); + } + String action = evt.getPropertyName(); + + if (ConnexionConfigUIModel.CONFIG_PROPERTY_CHANGED.equals(action)) { + // update ui with model values, + populateUI((ConnexionConfigUIModel) evt.getNewValue()); + doCheck(null); + return; + } + if (ConnexionConfigUIModel.MODE_PROPERTY_CHANGED.equals(action)) { + updateUI((VCSConnexionMode) evt.getNewValue()); + doCheck(null); + return; + } + + if (ConnexionConfigUIModel.MODIFIED_PROPERTY_CHANGED.equals(action)) { + Boolean newValue = (Boolean) evt.getNewValue(); + boolean modified = newValue != null && newValue; + getUi().getReset().setEnabled(modified); + getUi().getTestConnection().setEnabled(modified && isConfigValid()); + return; + } + + if (ConnexionConfigUIModel.CONNEXION_STATE_PROPERTY_CHANGED.equals(action)) { + Boolean newValue = (Boolean) evt.getNewValue(); + boolean validConnexion = newValue != null && newValue; + getUi().getOk().setEnabled(validConnexion); + getUi().getTestConnection().setEnabled(!validConnexion); + return; + } + throw new IllegalStateException("unimplemented property changed : " + evt + " for " + this); + } + + public synchronized List<Element> validateModel(Element element) { + errors.clear(); + ConnexionConfigUI ui = getUi(); + if (element != null) { + // compute modifed + setModified(element, ui); + } + switch (getModel().getMode()) { + case ANONYMOUS: + // nothing to validate + break; + case PASSWORD: + // login + password not empty + checkData(ui.getLogin(), login); + checkData(ui.getPassword().getPassword().length == 0, password); + break; + case SSH: + // login + private key exists + checkData(ui.getSshLogin(), sshLogin); + String s = ui.getPrivateKeyFile().getText(); + File file = new File(s); + checkData(s.isEmpty() || !file.exists(), privateKeyFile); + if (ui.getElementValue(nopassphrase).equals("false")) { + // check it there is a pass-phrase + checkData(ui.getPassphrase().getPassword().length == 0, passphrase); + } else { + errors.remove(passphrase); + } + break; + } + return errors; + } + + public void setModified(Element element, ConnexionConfigUI ui) { + boolean modify = false; + ConnexionConfigUIModel model = getModel(); + + String value = ui.getElementValue(element); + + switch (element) { + case connexion: + modify = model.getMode() != model.getConfig().getMode(); + break; + case login: + modify = !model.getConfig().getUserName().equals(value); + break; + case sshLogin: + modify = !model.getConfig().getUserName().equals(value); + break; + case nopassphrase: + boolean b = ui.getNoPassPhrase().isSelected(); + modify = (model.getConfig().getPassphrase() != null && !model.getConfig().getPassphrase().isEmpty()) == b; + if (!b) { + model.removeModified(passphrase); + } else { + char[] password = ui.getPassphrase().getPassword(); + boolean modify2; + if (model.getConfig().getPassphrase() == null || model.getConfig().getPassphrase().isEmpty()) { + modify2 = password.length == 0; + } else { + modify2 = model.getConfig().getPassphrase().equals(Arrays.toString(password)); + } + if (modify2) { + model.addModified(passphrase); + } + } + break; + case password: + modify = !model.getConfig().getPassphrase().equals(Arrays.toString(ui.getPassword().getPassword())); + break; + case privateKeyFile: + modify = !model.getConfig().getKeyFile().getAbsolutePath().equals(value); + break; + case passphrase: + modify = !model.getConfig().getPassphrase().equals(value); + break; + } + if (modify) { + model.addModified(element); + // reset connexion state + model.setConnexionState(null); + } else if (model.getModifieds().contains(element)) { + model.removeModified(element); + // reset connexion state + model.setConnexionState(null); + } + } + + public void doCheck(Element element) { + List<Element> errors = validateModel(element); + updateUI(errors); + } + + public boolean isConfigValid() { + return errors.isEmpty() && getModel().isConnexionState(); + } + + public void reset() { + getModel().reset(); + } + + protected void populateUI(ConnexionConfigUIModel model) { + ConnexionConfigUI ui = getUi(); + VCSConnexionConfig config = model.getConfig(); + switch (config.getMode()) { + case ANONYMOUS: + break; + case PASSWORD: + ui.getLogin().setText(config.getUserName()); + ui.getPassword().setText(config.getPassphrase() == null ? "" : config.getPassphrase()); + break; + case SSH: + ui.getSshLogin().setText(config.getUserName()); + ui.getNoPassPhrase().setSelected(config.isNoPassPhrase()); + ui.getPrivateKeyFile().setText(config.getKeyFile() == null ? "" : config.getKeyFile().getAbsolutePath()); + ui.getPassphrase().setText(config.getPassphrase() == null ? "" : config.getPassphrase()); + break; + } + ui.getTestConnection().setEnabled(true); + } + + protected void updateUI(final VCSConnexionMode mode) { + ConnexionConfigUI ui = getUi(); + //getModel().removeModified(sshLogin, nopassphrase, passphrase, privateKeyFile, login, password); + switch (mode) { + case ANONYMOUS: + ui.getConnexionModeAnonymous().setSelected(true); + break; + case PASSWORD: + ui.getConnexionModePassword().setSelected(true); + setModified(login, ui); + setModified(password, ui); + break; + case SSH: + setModified(sshLogin, ui); + setModified(nopassphrase, ui); + setModified(passphrase, ui); + setModified(privateKeyFile, ui); + ui.getConnexionModeSsh().setSelected(true); + break; + } + SwingUtilities.invokeLater(new Runnable() { + public void run() { + getUi().getConnexionPanelLayout().show(getUi().getConnexionPanel(), mode.name()); + getUi().pack(); + } + }); + } + + protected void updateUI(List<Element> errors) { + ConnexionConfigUI ui = getUi(); + boolean valid = isConfigValid(); + ui.getOk().setEnabled(valid && getModel().isModified()); + //ui.getTestConnection().setEnabled(valid); + ui.getGenerateKey().setEnabled(getModel().getMode() == VCSConnexionMode.SSH && !errors.contains(sshLogin) && !errors.contains(passphrase)); + for (Element element : values()) { + setLabelColor(errors, element); + } + } + + protected void checkData(JTextComponent component, Element errorName) { + if (component.getText().isEmpty()) { + errors.add(errorName); + } + } + + protected void checkData(boolean notValid, Element errorName) { + if (notValid) { + errors.add(errorName); + } + } + + protected void setLabelColor(List<Element> errors, Element element) { + JComponent component = getUi().getElementLabel(element); + if (component != null && component.isVisible()) { + component.setForeground(errors.contains(element) ? Color.red : Color.black); + } + } + + public void save() { + if (!getModel().isModified()) { + log.warn("nothing to save"); + } + for (Element element : getModel().getModifieds()) { + String value = getUi().getElementValue(element); + getModel().save(element, value); + log.info("save " + element); + } + } +} \ No newline at end of file
participants (1)
-
tchemit@users.labs.libre-entreprise.org