Package de.innovationgate.eclipse.wgadesigner.wizards

Source Code of de.innovationgate.eclipse.wgadesigner.wizards.ExportWGAPluginRemoteServerPage

/*******************************************************************************
* 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.wizards;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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.TableItem;
import org.eclipse.swt.widgets.Text;

import de.innovationgate.eclipse.utils.BeanListStore;
import de.innovationgate.eclipse.utils.ui.EditableTableControl;
import de.innovationgate.eclipse.utils.ui.ValidatedWizardPage;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.dialogs.AddWGARemoteServerDialog;
import de.innovationgate.eclipse.wgadesigner.models.WGARemoteServer;
import de.innovationgate.eclipse.wgadesigner.models.WGARemoteServersModel;
import de.innovationgate.eclipse.wgadesigner.preferences.PreferenceConstants;
import de.innovationgate.utils.WGUtils;
import de.innovationgate.wga.model.WGADesignConfigurationModel;

public class ExportWGAPluginRemoteServerPage extends ValidatedWizardPage implements SelectionListener {

  BeanListStore<WGARemoteServer> _serverstore = WGADesignerPlugin.getDefault().getWGARemoteServerStore();
  private EditableTableControl<WGARemoteServer> _tableControl;
  private WGARemoteServersModel _remoteServerModel;

 
  private Text _txtBuild;
  private int _build;
  private WGADesignConfigurationModel _model;

  protected ExportWGAPluginRemoteServerPage(WGADesignConfigurationModel model) {
    super("Export WGA Plugin");
    _model = model;

    setPageComplete(false);
    setTitle("Export WGA Plugin");
    setDescription("This wizard exports a WGA Plugin to WGA-Servers.");
  }

  public void createControl(Composite parent) {
   
   
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    composite.setLayout(layout);
   
 

    Label lblFolder = new Label(composite, SWT.None);
    lblFolder.setText("Plugin folder:");
    Label lblPath = new Label(composite, SWT.None);
    lblPath.setText(_model.getDesignDirectory());
   
   
   

    Label lblBuild = new Label(composite, SWT.None);
    lblBuild.setText("Build:");

    _txtBuild = new Text(composite, SWT.BORDER);
    _txtBuild.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    _txtBuild.setText(Integer.toString(_model.getPluginBuild()));       
    _txtBuild.addModifyListener(this);
   
   
   
    new Label(composite, SWT.None);
   
    Label label = new Label(composite, SWT.NULL);
    label.setText("Select target server(s)");   
    GridData g = new GridData(GridData.FILL_HORIZONTAL);
    g.horizontalSpan = 2;
    label.setLayoutData(g);
   
   
   

    _tableControl = new EditableTableControl<WGARemoteServer>(composite, SWT.NONE, SWT.BORDER | SWT.MULTI |SWT.FULL_SELECTION);
    _tableControl.setLayoutData(new GridData(GridData.FILL_BOTH));

    String[] columnNames = new String[] { "Servername", "URL" };

    _remoteServerModel = new WGARemoteServersModel(_serverstore.getBeans())
   

    _tableControl.init(columnNames, _remoteServerModel);

    _tableControl.getButton(EditableTableControl.BUTTON_ADD).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
      public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
        handleAdd();
        validate();
      }

    });

    _tableControl.getButton(EditableTableControl.BUTTON_REMOVE).addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
      public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
        handleRemove();
        validate();
      }
    });

    _tableControl.getTable().addSelectionListener(this);

    g = new GridData(GridData.FILL_HORIZONTAL|GridData.FILL_VERTICAL);
    g.horizontalSpan = 2;

    _tableControl.setLayoutData(g);


   
    String lastSelectedRemoteServers = WGADesignerPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.LAST_SELECTED_REMOTEESERVERS+"_"+_model.getPluginUniqueName());
   
    List<String> serverNames = WGUtils.deserializeCollection(lastSelectedRemoteServers, ",");     
   
    for(int i =0; i<_tableControl.getModel().getBeans().size();i++){
      if(serverNames.contains(_tableControl.getModel().getBeans().get(i).getName())){
        _tableControl.getTable().select(i);
      }     
    }
    setControl(composite);
    performValidation();
  }
 
 

  private void handleAdd() {
    AddWGARemoteServerDialog addDialog = new AddWGARemoteServerDialog(getShell(),_remoteServerModel);
    addDialog.open();

    if (addDialog.getReturnCode() == Dialog.OK) {
      _remoteServerModel.add(addDialog.getServer());
      try {
        _serverstore.flush();
      } catch (IOException e) {
        WGADesignerPlugin.getDefault().logInfo("Unable to write to remoteserverstore ", e);
      }
    }
  }
 

 
  public List<WGARemoteServer> getSelectedServers() {
    List<WGARemoteServer> servers = new ArrayList<WGARemoteServer>();
    for(TableItem item : _tableControl.getTable().getSelection()){
      servers.add((WGARemoteServer) item.getData());
    }
    return servers;
  }

  public int getBuild() {
    return _build;
  }

  private void handleRemove() {
    if (_tableControl.getTable().getSelectionCount() > 0) {
      WGARemoteServer remoteserver = (WGARemoteServer) _tableControl.getTable().getSelection()[0].getData();
      _remoteServerModel.remove(remoteserver);
    }
  }

  @Override
  public void computeResponse() {
    _build = Integer.parseInt(_txtBuild.getText());   
  }

  @Override
  public List<IStatus> validate() {
    List<IStatus> messages = new ArrayList<IStatus>();
    if (!(_tableControl.getTable().getSelectionCount() > 0)) {
      messages.add(new Status(IStatus.ERROR, WGADesignerPlugin.PLUGIN_ID, "Please select a server."));
    } else if (_txtBuild.getText().trim().equals("")) {
      messages.add(new Status(IStatus.ERROR, WGADesignerPlugin.PLUGIN_ID, "Please specify a buildnumber."));     
    }   
    return messages;
  }

  public void widgetDefaultSelected(SelectionEvent e) {
    performValidation();   
  }

  public void widgetSelected(SelectionEvent e) {
    performValidation();
  }

}
TOP

Related Classes of de.innovationgate.eclipse.wgadesigner.wizards.ExportWGAPluginRemoteServerPage

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.