Package de.innovationgate.eclipse.wgadesigner.team

Source Code of de.innovationgate.eclipse.wgadesigner.team.WGARemoteServerSynchronizationWizard

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.wgadesigner.team;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.synchronize.ISynchronizeManager;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipant;
import org.eclipse.team.ui.synchronize.ISynchronizeView;

import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.actions.StartWGARuntime;
import de.innovationgate.eclipse.wgadesigner.editors.helpers.WGADeployment;
import de.innovationgate.eclipse.wgadesigner.models.WGARemoteServer;
import de.innovationgate.eclipse.wgadesigner.models.WGARuntimeConfigurationModel;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntime;
import de.innovationgate.eclipse.wgadesigner.tomcat.TomcatUtils;
import de.innovationgate.wgaservices.types.Version;


public class WGARemoteServerSynchronizationWizard extends Wizard {

  private WGARuntime _runtime;
  private ChooseWGARuntimePage _chooseRuntimePage;
  private RemoteLocationPage _remoteLocationPage;

  public WGARemoteServerSynchronizationWizard() {
    super();
    init(null);
  }

  public WGARemoteServerSynchronizationWizard(WGARuntime runtime) {
    super();
    init(runtime);
  }

 
  private void init(WGARuntime runtime) {
    _runtime = runtime;
    setWindowTitle("Synchronize WGA runtime with a remote server");
    setNeedsProgressMonitor(true);
   
    if (_runtime == null) {
      _chooseRuntimePage = new ChooseWGARuntimePage();
      addPage(_chooseRuntimePage);
    }
    _remoteLocationPage = new RemoteLocationPage();
    _remoteLocationPage.setRuntime(_runtime);
    addPage(_remoteLocationPage);
  }
 
  @Override
  public boolean performFinish() {
    // save location in runtime config
    try {
      WGARuntimeConfigurationModel model = new WGARuntimeConfigurationModel();
      model.init(_runtime);
      if (model.getRemoteLocation() == null || !model.getRemoteLocation().equals(_remoteLocationPage.getLocation())) {
        model.setRemoteLocation(_remoteLocationPage.getLocation());
        model.saveChanges()
      }
    } catch (Exception e) {
      // ignore
    }     
     
   

   
    WGARemoteServer server = _remoteLocationPage.getRemoteServer();
    try {
      server.connectToServer();     

    } catch (Exception e) {
      WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getShell(), "Server connection failed.", "Unable to connect to WGA server '" + server.getUrl().toString() + "'.", e);
      return false;
    }
   
      // check local and remote runtime version
        de.innovationgate.wga.common.beans.csconfig.v1.Version localWGAVersion =  null;
        WGADeployment deployment = WGADesignerPlugin.getDefault().getWGADeploymentManager().getDeployment(_runtime.getWGADistributionName());
        if (deployment != null) {
            localWGAVersion = deployment.getWGAVersion();
        }
   
        Version remoteWGAVersion = null;
        try {            
            remoteWGAVersion = server.getServices().getWGAVersion(server.getSession());
        }
        catch (Exception e) {
            // this might happen if server version is < 5.3
        }
       
        if (localWGAVersion.isAtLeast(5, 3)) {
            if (remoteWGAVersion == null || !remoteWGAVersion.isAtLeast(5, 3)) {
                MessageDialog.openWarning(getShell(), "Synchronization warning", "The remote server version is too low (< 5.3) to support all synchronization features. Synchronization will only affect designs but not plugins.");  
            } else if (remoteWGAVersion != null && remoteWGAVersion.isAtLeast(5, 3) && !TomcatUtils.getInstance().isRunning(_runtime)) {
                boolean startRuntime = MessageDialog.openConfirm(getShell(), "Synchronization warning", "To provide all synchronization features local runtime need to be started. Start runtime now?.");
                if (startRuntime) {
                    StartWGARuntime.call(_runtime, true);
                }
            }
        }

        try {
      WGARemoteServerSynchronizationParticipant participant = new WGARemoteServerSynchronizationParticipant(server, _runtime);
      ISynchronizeManager manager = TeamUI.getSynchronizeManager();
      manager.addSynchronizeParticipants(new ISynchronizeParticipant[] {participant});
      ISynchronizeView view = manager.showSynchronizeViewInActivePage();
      view.display(participant);
      return true;
    } catch (Throwable e) {
      WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getShell(), "Unable to initialize synchronization", "Unable to initialize synchronization with WGA server '" + server.getUrl().toString() + "'.", e);
      return false;
    }
  }

  @Override
  public IWizardPage getNextPage(IWizardPage page) {
    IWizardPage nextPage =  super.getNextPage(page);
    if (page == _chooseRuntimePage) {
      _runtime = _chooseRuntimePage.getRuntime();
    }
    if (nextPage == _remoteLocationPage) {
      _remoteLocationPage.setRuntime(_runtime);
    }
    return nextPage;
  }

}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.team.WGARemoteServerSynchronizationWizard

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.