/*******************************************************************************
* 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.util.ArrayList;
import java.util.Iterator;
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.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import de.innovationgate.eclipse.utils.ui.ValidatedWizardPage;
import de.innovationgate.eclipse.wgadesigner.WGADesignerPlugin;
import de.innovationgate.eclipse.wgadesigner.models.WGARemoteServer;
import de.innovationgate.wga.model.WGADesignConfigurationModel;
public class ExportWGAPluginRemoteUploadPage extends ValidatedWizardPage {
private Table _table;
protected ExportWGAPluginRemoteUploadPage(WGADesignConfigurationModel model) {
super("Export WGA Plugin");
setTitle("Export WGA Plugin");
setDescription("The plugin '"+ model.getPluginUniqueName()+"' will be exported to the following server(s)" );
}
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
composite.setLayout(layout);
Color bg = getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
GridData tblLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
_table = new Table(composite, SWT.FULL_SELECTION | SWT.BORDER );
_table.setHeaderVisible(true);
TableColumn column1 = new TableColumn(_table, SWT.FILL);
column1.setText("Name");
TableColumn column2 = new TableColumn(_table, SWT.FILL);
column2.setText("URL");
TableColumn column3 = new TableColumn(_table, SWT.FILL);
column3.setText("Status");
_table.setLayoutData(tblLayoutData);
_table.setBackground(bg);
_table.setEnabled(true);
setControl(composite);
performValidation();
}
public void init(List<WGARemoteServer> servers) {
_table.removeAll();
Iterator<WGARemoteServer> it = servers.iterator();
while (it.hasNext()) {
WGARemoteServer currentServer = it.next();
TableItem item = new TableItem(_table, SWT.NONE);
item.setText(new String[] { currentServer.getName(), currentServer.getUrl().toString(), "" });
item.setData(currentServer);
}
for(TableColumn current : _table.getColumns()){
current.pack();
}
performValidation();
}
@Override
public void computeResponse() {
// TODO Auto-generated method stub
}
@Override
public List<IStatus> validate() {
List<IStatus> messages = new ArrayList<IStatus>();
TableItem[] items = _table.getItems();
for (TableItem item : items) {
WGARemoteServer server = (WGARemoteServer) item.getData();
// try to connect to server
try {
server.connectToServer();
item.setImage(2, WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_REMOTESERVER_REACHABLE));
} catch (Exception e) {
item.setImage(2, WGADesignerPlugin.getDefault().getImageRegistry().get(WGADesignerPlugin.IMAGE_REMOTESERVER_UNREACHABLE));
messages.add(new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "Unable to connect to server '" + server.getName() + "'.", e));
}
}
return messages;
}
}