Package de.innovationgate.eclipse.wgadesigner.team

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

/*******************************************************************************
* 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 java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.team.core.TeamException;
import org.eclipse.team.ui.TeamUI;
import org.eclipse.team.ui.synchronize.ISynchronizeManager;
import org.eclipse.team.ui.synchronize.ISynchronizeParticipantReference;

import de.innovationgate.eclipse.utils.WorkbenchUtils;
import de.innovationgate.eclipse.utils.ui.ValidatedWizardPage;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.models.WGARemoteServer;
import de.innovationgate.eclipse.wgadesigner.natures.WGARuntime;

public class RemoteLocationPage extends ValidatedWizardPage {

  protected RemoteLocationPage() {
    super("Remote location for synchronization");
    setTitle("Remote location for synchronization");
  }

  public RemoteLocationPage(String title) {
        super(title);
        setTitle(title);     
  }
 
  private WGARuntime _runtime;

  private Text _txtRemoteLocation;
  private Text _txtUser;
  private Text _txtPassword;

  private WGARemoteServer _remoteServer;

  private URL _location;

  @Override
  public void computeResponse() {
   
    try {
      _location = new URL(_txtRemoteLocation.getText());
      _remoteServer = new WGARemoteServer(_runtime.getName(), _location, _txtUser.getText(), _txtPassword.getText());

    } catch (Exception e) {
      WorkbenchUtils.showErrorDialog(WGADesignerPlugin.getDefault(), getShell(), "Gathering remote location information failed", "Creation of remote location information failed.", e);
    }
  }

  @Override
  public List<IStatus> validate() {
    List<IStatus> messages = new ArrayList<IStatus>();
   
    if (_txtRemoteLocation != null && _txtRemoteLocation.getText().trim().length() <= 0) {
      messages.add(new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "Please specify the WGA server url."));
    } else {
      try {
        new URL(_txtRemoteLocation.getText());
      } catch (MalformedURLException e) {
        messages.add(new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "Invalid URL. '" + e.getMessage() + "'."));
      }
    }
    if (_txtUser.getText().trim().length() <= 0) {
      messages.add(new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "No user specified."));
    }
    if (_txtPassword.getText().trim().length() <= 0) {
      messages.add(new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "No password specified."));
    }
   
    return messages;
  }

  public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    container.setLayout(layout);
   
    Label label = new Label(container, SWT.NONE);
    label.setText("Remote location (root url to WGA server):");   
    _txtRemoteLocation = new Text(container, SWT.BORDER);
    _txtRemoteLocation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));   
   
    if (_runtime != null) {
      URL remoteLocation = _runtime.getConfiguration().getRemoteLocation();
      if (remoteLocation != null) {
        _txtRemoteLocation.setText(remoteLocation.toString());
      }
    }
   
    label = new Label(container, SWT.NONE);
    label.setText("User (must have administrative rights):");
    _txtUser = new Text(container, SWT.BORDER);
    _txtUser.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (_txtRemoteLocation.getText().trim().length() > 0) {
      _txtUser.setFocus();
    }
   
    label = new Label(container, SWT.NONE);
    label.setText("Password:");
    _txtPassword = new Text(container, SWT.BORDER | SWT.PASSWORD);
    _txtPassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
   

   
    _txtRemoteLocation.addModifyListener(this);
    _txtUser.addModifyListener(this);
    _txtPassword.addModifyListener(this);

    setControl(container);
    setPageComplete(false);
   
    if (_runtime != null) {
      try {
        // try to init user and password from existing participant
        ISynchronizeManager manager = TeamUI.getSynchronizeManager();
        ISynchronizeParticipantReference[] participantRefs = manager.getSynchronizeParticipants();
        for (ISynchronizeParticipantReference reference : participantRefs) {
          if (reference.getParticipant() != null && reference.getParticipant() instanceof WGARemoteServerSynchronizationParticipant) {
            WGARemoteServerSynchronizationParticipant participant = (WGARemoteServerSynchronizationParticipant) reference.getParticipant();
            if (participant.getRuntime() != null && participant.getRuntime().getName().equals(_runtime.getName())) {
              // init user and password from existing participant
              if (participant.getServer() != null) {
                _txtUser.setText(participant.getServer().getUser());
                _txtPassword.setText(participant.getServer().getPassword());
                _txtPassword.setFocus();
                _txtPassword.setSelection(_txtPassword.getText().length());               
              }
            }
          }
        }
      } catch (TeamException e) {
        WGADesignerPlugin.getDefault().logError("Unable to set default values for RemoteLocationPage.", e);
      }
    }
   
    //performValidation();
  }

  public WGARemoteServer getRemoteServer() {
    return _remoteServer;
  }

  public void setRuntime(WGARuntime runtime) {
    _runtime = runtime;
    if (runtime != null && runtime.getConfiguration().getRemoteLocation() != null && _txtRemoteLocation != null) {
      _txtRemoteLocation.setText(runtime.getConfiguration().getRemoteLocation().toString());
     

    }   
  }

  public URL getLocation() {
    return _location;
  }

}
TOP

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

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.