Package net.sphene.goim.rcp.ui.wizard

Source Code of net.sphene.goim.rcp.ui.wizard.FirstStartWizard

/*
* File    : FirstStartWizard.java
* Created : 27.12.2005
* By      : kahless
*
* Gamer's Own Instant Messenger
* Copyright (C) 2005 Herbert Poul (kahless@sphene.net)
* http://goim.sphene.net
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
package net.sphene.goim.rcp.ui.wizard;

import java.lang.reflect.InvocationTargetException;

import net.sphene.goim.rcp.GOIMPlugin;
import net.sphene.goim.rcp.beans.GOIMAccount;
import net.sphene.goim.rcp.beans.GOIMAccountList;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.Wizard;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;

public class FirstStartWizard extends Wizard {

  WizardWelcomePage wizardWelcomePage;
  WizardCreateAccount wizardCreateAccount;
  WizardConfigureJabberAccount wizardConfigureJabberAccount;
  WizardConfigureGames wizardConfigureGames;
  private GOIMAccountList accountList;

  public FirstStartWizard() {
    super();
    setNeedsProgressMonitor(true);
    setWindowTitle("Welcome To GOIM !");
    wizardWelcomePage = new WizardWelcomePage(this);
    wizardCreateAccount = new WizardCreateAccount(this);
    wizardConfigureJabberAccount = new WizardConfigureJabberAccount();
    wizardConfigureGames = new WizardConfigureGames();
    addPage(wizardWelcomePage);
    addPage(wizardCreateAccount);
    addPage(wizardConfigureJabberAccount);
    addPage(wizardConfigureGames);
  }

  @Override
  public boolean canFinish() {
    if(wizardConfigureJabberAccount.canFlipToNextPage() &&
        wizardConfigureGames.isCurrentPage())
      return true;
    return false;
  }
  @Override
  public boolean performFinish() {
    final boolean registerNewUser = wizardCreateAccount.buttonCreateUser.getSelection();
    String accountName = wizardCreateAccount.txtAccountName.getText();
    accountList = GOIMPlugin.getAccountList();
    if(accountList.getByName(accountName) != null) {
      throw new RuntimeException("Account name already exists. Choose a different one.");
    }
    final GOIMAccount account = new GOIMAccount();
    account.name = accountName;
    account.jid = wizardConfigureJabberAccount.txtJabberId.getText();
    if(wizardConfigureJabberAccount.useCustomHost.getSelection()) {
      account.customHost = wizardConfigureJabberAccount.txtCustomHost.getText();
      account.customPort = Integer.parseInt(wizardConfigureJabberAccount.txtCustomPort.getText());
    }
    account.password = wizardConfigureJabberAccount.txtPassword.getText();
    account.resource = wizardConfigureJabberAccount.txtResource.getText();
    account.resourcePriority = wizardConfigureJabberAccount.spinnerResourcePriority.getSelection();
    account.useSSL = wizardConfigureJabberAccount.buttonUseSSL.getSelection();
    account.autoConnect = wizardConfigureJabberAccount.buttonAutoConnect.getSelection();
    try {
      getContainer().run(true,true,new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
          if(registerNewUser) {
            monitor.beginTask("Registering Jabber Account ...",4);
            monitor.worked(1);
            try {
              account.xmpp.tryRegister();
              accountList.add(account);
            } catch (final XMPPException e) {
              System.out.println("getxmpperror: " + e.getXMPPError());
              String msg = "Error during Registration.";
              if(e.getXMPPError() != null) {
                if(e.getXMPPError().getMessage() != null)
                  msg = msg + e.getXMPPError().getMessage();
                else if(e.getXMPPError().getCode() == 409)
                  msg = msg + " Username conflict (Username already in use)";
                else if(e.getXMPPError().getCode() == 406)
                  msg = msg + " Registration Failed (Some Required Information Not Provided. (This is a bug/missing feature - if this happens please post a bug report at http://goim.sphene.net )";
  //              getShell().getDisplay().asyncExec(new Runnable() { public void run() {
  //                new GOIMErrorDialog(getShell(),"Error registering account", "Error " + e.getXMPPError().getCode() + ": " + e.getXMPPError().getMessage(),new Status(IStatus.ERROR,GOIMPlugin.ID,IStatus.ERROR,"Error registering account: " + e.getXMPPError().getMessage(),e),IStatus.ERROR).open();
  //              }});
                monitor.setCanceled(true);
              }
              throw new RuntimeException(msg,e);
            }
          } else {
            accountList.add(account);
          }
          monitor.worked(1);
          account.xmpp.connect(Presence.Type.AVAILABLE,Presence.Mode.AVAILABLE);
          getShell().getDisplay().asyncExec(new Runnable() {public void run() {
            new SuccessfulConfiguration(account).open();
          }});
          monitor.done();
        } });
    } catch (Exception e) {
      // Remove account if it was not successful
      accountList.remove(account);
      e.printStackTrace();
      if(e instanceof InvocationTargetException)
        e = (Exception)((InvocationTargetException)e).getCause();
      throw new RuntimeException(e);
    }
    System.out.println("FINNISHED !!");
    return true;
  }

}
TOP

Related Classes of net.sphene.goim.rcp.ui.wizard.FirstStartWizard

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.