diff options
Diffstat (limited to 'src/net/java/sip/communicator/plugin/googletalkaccregwizz')
2 files changed, 72 insertions, 162 deletions
diff --git a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/FirstWizardPage.java b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/FirstWizardPage.java index 58b8a5b..b069e12 100644 --- a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/FirstWizardPage.java +++ b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/FirstWizardPage.java @@ -26,8 +26,7 @@ import net.java.sip.communicator.util.swing.*; */
public class FirstWizardPage
extends TransparentPanel
- implements WizardPage,
- DocumentListener
+ implements WizardPage
{
private static final Logger logger = Logger
.getLogger(FirstWizardPage.class);
@@ -36,7 +35,8 @@ public class FirstWizardPage public static final String USER_NAME_EXAMPLE = "Ex: johnsmith@gmail.com";
- private JPanel userIDPassPanel = new TransparentPanel(new BorderLayout(10, 10));
+ private JPanel userIDPassPanel
+ = new TransparentPanel(new BorderLayout(10, 10));
private JPanel labelsPanel = new TransparentPanel();
@@ -48,9 +48,6 @@ public class FirstWizardPage private JLabel passLabel
= new JLabel(Resources.getString("service.gui.PASSWORD"));
- private JLabel existingAccountLabel = new JLabel(Resources
- .getString("service.gui.EXISTING_ACCOUNT_ERROR"));
-
private JPanel emptyPanel = new TransparentPanel();
private JLabel userIDExampleLabel = new JLabel(USER_NAME_EXAMPLE);
@@ -76,11 +73,6 @@ public class FirstWizardPage = new SIPCommCheckBox(Resources
.getString("plugin.jabberaccregwizz.ENABLE_KEEP_ALIVE"));
- private JCheckBox enableAdvOpButton = new SIPCommCheckBox(
- Resources.getString(
- "plugin.jabberaccregwizz.OVERRIDE_SERVER_DEFAULT_OPTIONS"),
- false);
-
private JLabel resourceLabel
= new JLabel(Resources.getString("plugin.jabberaccregwizz.RESOURCE"));
@@ -122,6 +114,8 @@ public class FirstWizardPage private boolean isCommitted = false;
+ private boolean isServerOverridden = false;
+
/**
* Creates an instance of <tt>FirstWizardPage</tt>.
*
@@ -158,10 +152,26 @@ public class FirstWizardPage this.userIDPassPanel.setOpaque(false);
this.emptyPanel.setOpaque(false);
- this.userIDField.getDocument().addDocumentListener(this);
- this.rememberPassBox.setSelected(true);
+ this.userIDField.getDocument().addDocumentListener(new DocumentListener()
+ {
+ public void insertUpdate(DocumentEvent evt)
+ {
+ setNextButtonAccordingToUserIDAndResource();
- this.existingAccountLabel.setForeground(Color.RED);
+ setServerFieldAccordingToUserID();
+ }
+
+ public void removeUpdate(DocumentEvent evt)
+ {
+ setNextButtonAccordingToUserIDAndResource();
+
+ setServerFieldAccordingToUserID();
+ }
+
+ public void changedUpdate(DocumentEvent evt) {}
+ });
+
+ this.rememberPassBox.setSelected(true);
this.userIDExampleLabel.setForeground(Color.GRAY);
this.userIDExampleLabel.setFont(userIDExampleLabel.getFont()
@@ -187,39 +197,6 @@ public class FirstWizardPage mainPanel.add(userIDPassPanel);
- serverField.setEnabled(false);
- portField.setEnabled(false);
- resourceField.setEnabled(false);
- priorityField.setEnabled(false);
-
- enableAdvOpButton.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent evt)
- {
- // Perform action
- JCheckBox cb = (JCheckBox) evt.getSource();
-
- if (!wizard.isModification())
- serverField.setEnabled(cb.isSelected());
-
- portField.setEnabled(cb.isSelected());
- resourceField.setEnabled(cb.isSelected());
- priorityField.setEnabled(cb.isSelected());
-
- if(!cb.isSelected())
- {
- setServerFieldAccordingToUserID();
-
- portField.setText(
- GoogleTalkAccountRegistration.DEFAULT_PORT);
- resourceField.setText(
- GoogleTalkAccountRegistration.DEFAULT_RESOURCE);
- priorityField.setText(
- GoogleTalkAccountRegistration.DEFAULT_PRIORITY);
- }
- }
- });
-
portField.getDocument().addDocumentListener(new DocumentListener()
{
public void changedUpdate(DocumentEvent evt)
@@ -264,9 +241,9 @@ public class FirstWizardPage valuesAdvOpPanel.add(resourceField);
valuesAdvOpPanel.add(priorityField);
- JPanel checkBoxesPanel = new TransparentPanel(new GridLayout(0, 1, 10, 10));
+ JPanel checkBoxesPanel
+ = new TransparentPanel(new GridLayout(0, 1, 10, 10));
checkBoxesPanel.add(sendKeepAliveBox);
- checkBoxesPanel.add(enableAdvOpButton);
advancedOpPanel.add(checkBoxesPanel, BorderLayout.NORTH);
advancedOpPanel.add(labelsAdvOpPanel, BorderLayout.WEST);
@@ -369,36 +346,24 @@ public class FirstWizardPage */
public void commitPage()
{
- String userID = userIDField.getText();
+ GoogleTalkAccountRegistration registration = wizard.getRegistration();
- if (!wizard.isModification() && isExistingAccount(userID))
- {
- nextPageIdentifier = FIRST_PAGE_IDENTIFIER;
- userIDPassPanel.add(existingAccountLabel, BorderLayout.NORTH);
- this.revalidate();
- }
- else
- {
- nextPageIdentifier = SUMMARY_PAGE_IDENTIFIER;
- userIDPassPanel.remove(existingAccountLabel);
+ registration.setUserID(userIDField.getText());
+ registration.setPassword(new String(passField.getPassword()));
+ registration.setRememberPassword(rememberPassBox.isSelected());
- GoogleTalkAccountRegistration registration = wizard.getRegistration();
+ registration.setServerAddress(serverField.getText());
+ registration.setSendKeepAlive(sendKeepAliveBox.isSelected());
+ registration.setResource(resourceField.getText());
- registration.setUserID(userIDField.getText());
- registration.setPassword(new String(passField.getPassword()));
- registration.setRememberPassword(rememberPassBox.isSelected());
+ if (portField.getText() != null)
+ registration.setPort(Integer.parseInt(portField.getText()));
- registration.setServerAddress(serverField.getText());
- registration.setSendKeepAlive(sendKeepAliveBox.isSelected());
- registration.setResource(resourceField.getText());
+ if (priorityField.getText() != null)
+ registration.setPriority(
+ Integer.parseInt(priorityField.getText()));
- if (portField.getText() != null)
- registration.setPort(Integer.parseInt(portField.getText()));
-
- if (priorityField.getText() != null)
- registration.setPriority(
- Integer.parseInt(priorityField.getText()));
- }
+ nextPageIdentifier = SUMMARY_PAGE_IDENTIFIER;
isCommitted = true;
}
@@ -422,38 +387,6 @@ public class FirstWizardPage }
}
- /**
- * Handles the <tt>DocumentEvent</tt> triggered when user types in the
- * UserID field. Enables or disables the "Next" wizard button according to
- * whether the UserID field is empty.
- *
- * @param evt the document event that has triggered this method call.
- */
- public void insertUpdate(DocumentEvent evt)
- {
- this.setNextButtonAccordingToUserIDAndResource();
-
- this.setServerFieldAccordingToUserID();
- }
-
- /**
- * Handles the <tt>DocumentEvent</tt> triggered when user deletes letters
- * from the User ID field. Enables or disables the "Next" wizard button
- * according to whether the User ID field is empty.
- *
- * @param evt the document event that has triggered this method call.
- */
- public void removeUpdate(DocumentEvent evt)
- {
- this.setNextButtonAccordingToUserIDAndResource();
-
- this.setServerFieldAccordingToUserID();
- }
-
- public void changedUpdate(DocumentEvent evt)
- {
- }
-
public void pageHiding()
{
}
@@ -516,21 +449,9 @@ public class FirstWizardPage priorityField.setText(priority);
- if (!serverPort.equals(GoogleTalkAccountRegistration.DEFAULT_PORT)
- || !resource.equals(GoogleTalkAccountRegistration.DEFAULT_RESOURCE)
- || !priority.equals(GoogleTalkAccountRegistration.DEFAULT_PRIORITY))
- {
- enableAdvOpButton.setSelected(true);
-
- // The server field should stay disabled in modification mode,
- // because the user should not be able to change anything concerning
- // the account identifier and server name is part of it.
- serverField.setEnabled(false);
+ this.isServerOverridden = accountID.getAccountPropertyBoolean(
+ ProtocolProviderFactory.IS_SERVER_OVERRIDDEN, false);
- portField.setEnabled(true);
- resourceField.setEnabled(true);
- priorityField.setEnabled(true);
- }
}
/**
@@ -539,7 +460,7 @@ public class FirstWizardPage */
private void setServerFieldAccordingToUserID()
{
- if (!enableAdvOpButton.isSelected())
+ if (!wizard.isModification() || !isServerOverridden)
{
String userId = userIDField.getText();
@@ -564,32 +485,6 @@ public class FirstWizardPage }
}
- /**
- * Checks if the accountName corresponds to an already existing account.
- *
- * @param accountName the name of the account to check
- * @return TRUE if an account with the specified name already exists, FALSE -
- * otherwise.
- */
- private boolean isExistingAccount(String accountName)
- {
- ProtocolProviderFactory factory = GoogleTalkAccRegWizzActivator
- .getGoogleTalkProtocolProviderFactory();
-
- ArrayList registeredAccounts = factory.getRegisteredAccounts();
-
- for (int i = 0; i < registeredAccounts.size(); i++)
- {
- AccountID accountID = (AccountID) registeredAccounts.get(i);
-
- if (accountName.equalsIgnoreCase(accountID.getUserID()))
- {
- return true;
- }
- }
- return false;
- }
-
public Object getSimpleForm()
{
return userIDPassPanel;
diff --git a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/GoogleTalkAccountRegistrationWizard.java b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/GoogleTalkAccountRegistrationWizard.java index ef656a7..7249d3e 100644 --- a/src/net/java/sip/communicator/plugin/googletalkaccregwizz/GoogleTalkAccountRegistrationWizard.java +++ b/src/net/java/sip/communicator/plugin/googletalkaccregwizz/GoogleTalkAccountRegistrationWizard.java @@ -11,6 +11,7 @@ import java.util.*; import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
+import net.java.sip.communicator.util.*;
import org.osgi.framework.*;
@@ -24,6 +25,9 @@ import org.osgi.framework.*; public class GoogleTalkAccountRegistrationWizard
implements AccountRegistrationWizard
{
+ private final Logger logger
+ = Logger.getLogger(GoogleTalkAccountRegistrationWizard.class);
+
private static final String GOOGLE_USER_SUFFIX = "gmail.com";
private static final String GOOGLE_CONNECT_SRV = "talk.google.com";
@@ -156,19 +160,20 @@ public class GoogleTalkAccountRegistrationWizard * @return ProtocolProviderService
*/
public ProtocolProviderService signin()
+ throws OperationFailedException
{
- if (!firstWizardPage.isCommitted())
- firstWizardPage.commitPage();
+ firstWizardPage.commitPage();
return signin( registration.getUserID(),
registration.getPassword());
}
public ProtocolProviderService signin(String userName, String password)
+ throws OperationFailedException
{
- firstWizardPage = null;
ProtocolProviderFactory factory
- = GoogleTalkAccRegWizzActivator.getGoogleTalkProtocolProviderFactory();
+ = GoogleTalkAccRegWizzActivator
+ .getGoogleTalkProtocolProviderFactory();
return this.installAccount(factory,
userName,
@@ -188,8 +193,10 @@ public class GoogleTalkAccountRegistrationWizard ProtocolProviderFactory providerFactory,
String userName,
String passwd)
+ throws OperationFailedException
{
- Hashtable accountProperties = new Hashtable();
+ Hashtable<String, String> accountProperties
+ = new Hashtable<String, String>();
/* Make the account use the resources specific to Google Talk. */
accountProperties.put(ProtocolProviderFactory.PROTOCOL, PROTOCOL);
@@ -209,11 +216,17 @@ public class GoogleTalkAccountRegistrationWizard if (registration.getServerAddress() != null)
{
serverName = registration.getServerAddress();
+
+ if (userName.indexOf(serverName) < 0)
+ accountProperties.put(
+ ProtocolProviderFactory.IS_SERVER_OVERRIDDEN,
+ Boolean.toString(true));
}
else
{
serverName = getServerFromUserName(userName);
}
+
accountProperties.put(ProtocolProviderFactory.SERVER_ADDRESS,
serverName);
@@ -248,19 +261,21 @@ public class GoogleTalkAccountRegistrationWizard GoogleTalkAccRegWizzActivator.bundleContext
.getService(serRef);
}
- catch (IllegalArgumentException exc)
+ catch (IllegalStateException exc)
{
- GoogleTalkAccRegWizzActivator.getUIService().getPopupDialog()
- .showMessagePopupDialog(exc.getMessage(),
- Resources.getString("service.gui.ERROR"),
- PopupDialog.ERROR_MESSAGE);
+ logger.warn(exc.getMessage());
+
+ throw new OperationFailedException(
+ "Account already exists.",
+ OperationFailedException.IDENTIFICATION_CONFLICT);
}
- catch (IllegalStateException exc)
+ catch (Exception exc)
{
- GoogleTalkAccRegWizzActivator.getUIService().getPopupDialog()
- .showMessagePopupDialog(exc.getMessage(),
- Resources.getString("service.gui.ERROR"),
- PopupDialog.ERROR_MESSAGE);
+ logger.warn(exc.getMessage());
+
+ throw new OperationFailedException(
+ "Failed to add account",
+ OperationFailedException.GENERAL_ERROR);
}
return protocolProvider;
|