blob: ff2370f59e2517fbc08d5b9cf719a937ef4f3c5c [file] [log] [blame]
package org.eclipse.stem.ui.graphgenerators.adapters.graphgeneratorpropertyeditor;
/*******************************************************************************
* Copyright (c) 2008 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.stem.core.STEMURI;
import org.eclipse.stem.core.common.Identifiable;
import org.eclipse.stem.core.graph.Graph;
import org.eclipse.stem.definitions.lattice.impl.LatticeGeneratorUtilityImpl;
import org.eclipse.stem.graphgenerators.GraphGenerator;
import org.eclipse.stem.graphgenerators.GraphgeneratorsPackage;
import org.eclipse.stem.graphgenerators.LatticeGraphGenerator;
import org.eclipse.stem.graphgenerators.MigrationEdgeGraphGenerator;
import org.eclipse.stem.graphgenerators.PajekNetGraphGenerator;
import org.eclipse.stem.graphgenerators.PlateCarreeGlobeGraphGenerator;
import org.eclipse.stem.graphgenerators.ShapefileGraphGenerator;
import org.eclipse.stem.graphgenerators.ShapefileType;
import org.eclipse.stem.graphgenerators.SquareLatticeGraphGenerator;
import org.eclipse.stem.graphgenerators.impl.Reader;
import org.eclipse.stem.ui.editors.GenericPropertyEditor;
import org.eclipse.stem.ui.graphgenerators.wizards.Messages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
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.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class GraphGeneratorPropertyEditor extends GenericPropertyEditor
implements SelectionListener, ModifyListener {
private List<String> shapefiles;
private List<ShapefileType> shapefileTypes;
private List<String> regionIDs;
private List<String> roadIDs;
private List<String> roadClasses;
private List<String> migrationIDs;
private List<String> migrationPopulations;
private List<String> migrationRates;
private String selectedDir;
private List<String> columnNames;
private List<List<String>> data;
private Button shapeButton;
private org.eclipse.swt.widgets.List shapeFileList;
private Group typeGroup;
private Button regionButton;
private Button roadButton;
private Button migrationButton;
private Button showDataButton;
private Group dataGroup;
private Text regionIDText;
private Combo regionIDCombo;
private Text roadIDText;
private Combo roadIDCombo;
private Text roadClassText;
private Combo roadClassCombo;
private Text migrationIDText;
private Combo migrationIDCombo;
private Text migrationPopulationText;
private Combo migrationPopulationCombo;
private Text migrationRateText;
private Combo migrationRateCombo;
public GraphGeneratorPropertyEditor(Composite parent, int style,
IProject project) {
super(parent, style, project);
}
/**
* Create the composite
*
* @param parent
* @param style
* @param projectValidator
*/
public GraphGeneratorPropertyEditor(final Composite parent,
final int style, final GraphGenerator graphGenerator,
final ModifyListener projectValidator, IProject project) {
super(parent, style, (Identifiable) graphGenerator, projectValidator,
project);
if (graphGenerator instanceof ShapefileGraphGenerator) {
shapefiles = new ArrayList<String>();
shapefileTypes = new ArrayList<ShapefileType>();
regionIDs = new ArrayList<String>();
roadIDs = new ArrayList<String>();
roadClasses = new ArrayList<String>();
migrationIDs = new ArrayList<String>();
migrationPopulations = new ArrayList<String>();
migrationRates = new ArrayList<String>();
shapeButton = new Button(this, SWT.PUSH);
shapeButton.setText(Messages.getString("selectShapefiles"));
shapeButton.addSelectionListener(this);
shapeFileList = new org.eclipse.swt.widgets.List(this, SWT.SINGLE
| SWT.V_SCROLL | SWT.BORDER);
shapeFileList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true, 3, 1));
shapeFileList.addSelectionListener(this);
}
}
/**
* @param graphGenerator
* the {@link GraphGenerator} instance to populate.
*/
public Graph getGraph(final GraphGenerator graphGenerator) {
if (graphGenerator instanceof LatticeGraphGenerator) {
LatticeGraphGenerator lattice = (LatticeGraphGenerator) graphGenerator;
EAttribute nearest = GraphgeneratorsPackage.Literals.LATTICE_GRAPH_GENERATOR__USE_NEAREST_NEIGHBORS;
EAttribute nextNearest = GraphgeneratorsPackage.Literals.LATTICE_GRAPH_GENERATOR__USE_NEXT_NEAREST_NEIGHBORS;
EAttribute periodic = GraphgeneratorsPackage.Literals.LATTICE_GRAPH_GENERATOR__PERIODIC_BOUNDARIES;
lattice.setUseNearestNeighbors(booleanMap.get(nearest)
.getSelection());
lattice.setUseNextNearestNeighbors(booleanMap.get(nextNearest)
.getSelection());
lattice.setPeriodicBoundaries(booleanMap.get(periodic)
.getSelection());
}
if (graphGenerator instanceof SquareLatticeGraphGenerator) {
SquareLatticeGraphGenerator squareLattice = (SquareLatticeGraphGenerator) graphGenerator;
EAttribute xSize = GraphgeneratorsPackage.Literals.SQUARE_LATTICE_GRAPH_GENERATOR__XSIZE;
EAttribute ySize = GraphgeneratorsPackage.Literals.SQUARE_LATTICE_GRAPH_GENERATOR__YSIZE;
EAttribute area = GraphgeneratorsPackage.Literals.SQUARE_LATTICE_GRAPH_GENERATOR__AREA;
squareLattice.setXSize(Integer.parseInt(map.get(xSize).getText()));
squareLattice.setYSize(Integer.parseInt(map.get(ySize).getText()));
squareLattice.setArea(Double.parseDouble(map.get(area).getText()));
}
if (graphGenerator instanceof PlateCarreeGlobeGraphGenerator) {
PlateCarreeGlobeGraphGenerator plateCarree = (PlateCarreeGlobeGraphGenerator) graphGenerator;
EAttribute angularStep = GraphgeneratorsPackage.Literals.PLATE_CARREE_GLOBE_GRAPH_GENERATOR__ANGULAR_STEP;
EAttribute radius = GraphgeneratorsPackage.Literals.PLATE_CARREE_GLOBE_GRAPH_GENERATOR__RADIUS;
plateCarree.setAngularStep(Integer.parseInt(map.get(angularStep)
.getText()));
plateCarree
.setRadius(Double.parseDouble(map.get(radius).getText()));
}
if (graphGenerator instanceof MigrationEdgeGraphGenerator) {
MigrationEdgeGraphGenerator migrationEdge = (MigrationEdgeGraphGenerator) graphGenerator;
EAttribute rate = GraphgeneratorsPackage.Literals.MIGRATION_EDGE_GRAPH_GENERATOR__MIGRATION_RATE;
EAttribute population = GraphgeneratorsPackage.Literals.MIGRATION_EDGE_GRAPH_GENERATOR__POPULATION;
String populationString = map.get(population).getText().trim();
EAttribute location = GraphgeneratorsPackage.Literals.MIGRATION_EDGE_GRAPH_GENERATOR__LOCATION;
String locationString = map.get(location).getText().trim();
migrationEdge.setMigrationRate(Double.parseDouble(map.get(rate)
.getText()));
migrationEdge.setProject(project);
if (!populationString.isEmpty()) {
migrationEdge.setPopulation(populationString);
}
if (!locationString.isEmpty()) {
migrationEdge.setLocation(STEMURI.createURI(locationString));
}
}
if (graphGenerator instanceof PajekNetGraphGenerator) {
PajekNetGraphGenerator pajek = (PajekNetGraphGenerator) graphGenerator;
EAttribute area = GraphgeneratorsPackage.Literals.PAJEK_NET_GRAPH_GENERATOR__AREA;
EAttribute scaling = GraphgeneratorsPackage.Literals.PAJEK_NET_GRAPH_GENERATOR__SCALING_FACTOR;
EAttribute fit = GraphgeneratorsPackage.Literals.PAJEK_NET_GRAPH_GENERATOR__FIT;
EAttribute enforce = GraphgeneratorsPackage.Literals.PAJEK_NET_GRAPH_GENERATOR__ENFORCE_CONTAINMENT;
EAttribute file = GraphgeneratorsPackage.Literals.PAJEK_NET_GRAPH_GENERATOR__DATA_FILE_NET;
String fileString = map.get(file).getText().trim();
EAttribute container = GraphgeneratorsPackage.Literals.PAJEK_NET_GRAPH_GENERATOR__CONTAINER;
String containerString = map.get(container).getText().trim();
pajek.setArea(Double.parseDouble(map.get(area).getText()));
pajek.setScalingFactor(Double.parseDouble(map.get(scaling)
.getText()));
pajek.setFit(booleanMap.get(fit).getSelection());
pajek.setEnforceContainment(booleanMap.get(enforce).getSelection());
pajek.setProject(project);
if (!fileString.isEmpty()) {
pajek.setDataFile_net(fileString);
}
if (!containerString.isEmpty()) {
pajek.setContainer(STEMURI.createURI(containerString));
}
}
if (graphGenerator instanceof ShapefileGraphGenerator) {
ShapefileGraphGenerator shapefile = (ShapefileGraphGenerator) graphGenerator;
shapefile.getShapefiles().clear();
shapefile.getShapefiles().addAll(shapefiles);
shapefile.getShapefileTypes().clear();
shapefile.getShapefileTypes().addAll(shapefileTypes);
shapefile.getRegionIDs().clear();
shapefile.getRegionIDs().addAll(regionIDs);
shapefile.getRoadIDs().clear();
shapefile.getRoadIDs().addAll(roadIDs);
shapefile.getRoadClasses().clear();
shapefile.getRoadClasses().addAll(roadClasses);
shapefile.getMigrationIDs().clear();
shapefile.getMigrationIDs().addAll(migrationIDs);
shapefile.getMigrationPopulations().clear();
shapefile.getMigrationPopulations().addAll(migrationPopulations);
shapefile.getMigrationRates().clear();
shapefile.getMigrationRates().addAll(migrationRates);
}
return graphGenerator.getGraph();
}
/**
* @return <code>true</code> if the contents are valid, <code>false</code>
* otherwise.
*/
@Override
public boolean validate() {
boolean retValue = true;
if (retValue) {
// Yes
final Text text = map
.get(GraphgeneratorsPackage.Literals.SQUARE_LATTICE_GRAPH_GENERATOR__XSIZE);
if (text != null) {
// Yes
retValue = !text.getText().equals(""); //$NON-NLS-1$
// nothing?
if (!retValue) {
// Yes
errorMessage = Messages.getString("NGGWizErr1"); //$NON-NLS-1$
} // if
else {
// No
// Is it a valid value?
retValue = isValidIntValue(text.getText(), 1);
if (!retValue) {
// No
errorMessage = Messages.getString("NGGWizErr2"); //$NON-NLS-1$
} // if
}
} // if text != null
} // if Transmission Rate
if (retValue) {
// Yes
final Text text = map
.get(GraphgeneratorsPackage.Literals.SQUARE_LATTICE_GRAPH_GENERATOR__YSIZE);
if (text != null) {
// Yes
retValue = !text.getText().equals(""); //$NON-NLS-1$
// nothing?
if (!retValue) {
// Yes
errorMessage = Messages.getString("NGGWizErr3"); //$NON-NLS-1$
} // if
else {
// No
// Is it a valid value?
retValue = isValidIntValue(text.getText(), 1);
if (!retValue) {
// No
errorMessage = Messages.getString("NGGWizErr4"); //$NON-NLS-1$
} // if
}
} // if text != null
} //
if (retValue) {
// Yes
final Text text = map
.get(GraphgeneratorsPackage.Literals.SQUARE_LATTICE_GRAPH_GENERATOR__AREA);
if (text != null) {
// Yes
retValue = !text.getText().equals(""); //$NON-NLS-1$
// nothing?
if (!retValue) {
// Yes
errorMessage = Messages.getString("NGGWizErr8"); //$NON-NLS-1$
} // if
else {
// No
// Is it a valid value?
retValue = isValidValue(text.getText(), 0);
if (!retValue) {
// No
errorMessage = Messages.getString("NGGWizErr9"); //$NON-NLS-1$
} // if
}
} // if text != null
} // if Non-Linearity Coefficient
if (retValue) {
// Yes
Text text = map
.get(GraphgeneratorsPackage.Literals.SQUARE_LATTICE_GRAPH_GENERATOR__XSIZE);
if (text != null) {
int xsize = Integer.parseInt(text.getText());
text = map
.get(GraphgeneratorsPackage.Literals.SQUARE_LATTICE_GRAPH_GENERATOR__YSIZE);
int ysize = Integer.parseInt(text.getText());
text = map
.get(GraphgeneratorsPackage.Literals.SQUARE_LATTICE_GRAPH_GENERATOR__AREA);
double area = Double.parseDouble(text.getText());
double scale = Math.sqrt(area);
if (xsize * scale / LatticeGeneratorUtilityImpl.KM_PER_DEG_LON > 360.0
|| ysize * scale
/ LatticeGeneratorUtilityImpl.KM_PER_DEG_LAT > 180.0) {
retValue = false;
// Yes
errorMessage = Messages.getString("NGGWizErr10"); //$NON-NLS-1$
}
}
}
if (retValue) {
final Text text = map
.get(GraphgeneratorsPackage.Literals.MIGRATION_EDGE_GRAPH_GENERATOR__POPULATION);
if (text != null) {
// Yes
retValue = !text.getText().equals(""); //$NON-NLS-1$
// nothing?
if (!retValue) {
// Yes
errorMessage = Messages.getString("NGGWizErr5"); //$NON-NLS-1$
} // if
}
}
if (retValue) {
final Text text = map
.get(GraphgeneratorsPackage.Literals.PLATE_CARREE_GLOBE_GRAPH_GENERATOR__ANGULAR_STEP);
// Is it a valid value?
if (text != null) {
retValue = isValidIntValue(text.getText(), 1);
if (!retValue) {
// No
errorMessage = Messages.getString("NGGWizErr11"); //$NON-NLS-1$
} // if
}
}
if (retValue) {
final Text text = map
.get(GraphgeneratorsPackage.Literals.PLATE_CARREE_GLOBE_GRAPH_GENERATOR__RADIUS);
// Is it a valid value?
if (text != null) {
retValue = isValidDoubleValue(text.getText(), 1);
if (!retValue) {
// No
errorMessage = Messages.getString("NGGWizErr12"); //$NON-NLS-1$
} // if
}
}
if (retValue) {
final Text text = map
.get(GraphgeneratorsPackage.Literals.MIGRATION_EDGE_GRAPH_GENERATOR__POPULATION);
if (text != null) {
// Yes
retValue = !text.getText().equals(""); //$NON-NLS-1$
// nothing?
if (!retValue) {
// Yes
errorMessage = Messages.getString("NGGWizErr5"); //$NON-NLS-1$
} // if
}
}
if (retValue) {
final Text text = map
.get(GraphgeneratorsPackage.Literals.MIGRATION_EDGE_GRAPH_GENERATOR__MIGRATION_RATE);
if (text != null) {
// Yes
try {
double rate = Double.parseDouble(text.getText());
if (rate < 0.0) {
retValue = false;
errorMessage = Messages.getString("NGGWizErr7");
}
} catch (Exception e) {
retValue = false;
errorMessage = Messages.getString("NGGWizErr6");
}
retValue = !text.getText().equals(""); //$NON-NLS-1$
// nothing?
if (!retValue) {
// Yes
errorMessage = Messages.getString("NGGWizErr5"); //$NON-NLS-1$
} // if
}
}
if (retValue) {
final Text text = map
.get(GraphgeneratorsPackage.Literals.PAJEK_NET_GRAPH_GENERATOR__DATA_FILE_NET);
if (text != null) {
// Yes
File file = new File(text.getText());
retValue = file != null && !file.isDirectory() && file.exists();
if (!retValue)
errorMessage = Messages.getString("NGGWizErr13");
}
}
if (retValue) {
final Text text = map
.get(GraphgeneratorsPackage.Literals.PAJEK_NET_GRAPH_GENERATOR__AREA);
if (text != null) {
retValue = text.getText().length() > 0; //$NON-NLS-1$
// nothing?
if (!retValue) {
errorMessage = Messages.getString("NGGWizErr14"); //$NON-NLS-1$
} // if
else {
try {
double rate = Double.parseDouble(text.getText());
if (rate < 0.0) {
retValue = false;
errorMessage = Messages.getString("NGGWizErr9");
}
} catch (Exception e) {
retValue = false;
errorMessage = Messages.getString("NGGWizErr9");
}
}
}
}
return retValue;
}
/**
* @param feature
* @return <code>true</code> if the feature is a dublin core feature that is
* specified by a user.
*/
@Override
protected boolean isUserSpecifiedProperty(EStructuralFeature feature) {
boolean retValue = false;
EClass containingClass = feature.getEContainingClass();
if (containingClass.getEPackage() == GraphgeneratorsPackage.eINSTANCE) {
retValue = true;
}
// If the "shapefile" type, then we'll specify it ourself.
if (containingClass == GraphgeneratorsPackage.Literals.SHAPEFILE_GRAPH_GENERATOR) {
retValue = false;
}
return retValue;
}
@Override
public void widgetSelected(SelectionEvent e) {
if (e.getSource() == shapeButton) {
FileDialog fileDialog_shp = new FileDialog(new Shell(), SWT.MULTI);
fileDialog_shp.setFilterPath(selectedDir);
fileDialog_shp.setFilterExtensions(new String[] { "*.shp" });
if (fileDialog_shp.open() != null) {
selectedDir = fileDialog_shp.getFilterPath();
shapeFileList.removeAll();
shapefiles.clear();
shapefileTypes.clear();
regionIDs.clear();
roadIDs.clear();
roadClasses.clear();
migrationIDs.clear();
migrationPopulations.clear();
migrationRates.clear();
for (String fName : fileDialog_shp.getFileNames()) {
shapeFileList.add(fName);
shapefiles
.add(fileDialog_shp.getFilterPath() + "/" + fName);
shapefileTypes.add(ShapefileType.REGION_FILE);
regionIDs.add("");
roadIDs.add("");
roadClasses.add("");
migrationIDs.add("");
migrationPopulations.add("");
migrationRates.add("");
}
if (dataGroup != null) {
dataGroup.dispose();
}
if (showDataButton != null) {
showDataButton.dispose();
}
if (typeGroup != null) {
typeGroup.dispose();
}
updateUI();
}
} else if (e.getSource() == shapeFileList) {
int selection = shapeFileList.getSelectionIndex();
if (dataGroup != null) {
dataGroup.dispose();
}
if (showDataButton != null) {
showDataButton.dispose();
}
if (typeGroup != null) {
typeGroup.dispose();
}
if (selection != -1) {
updateDBFData();
showDataButton = new Button(this, SWT.PUSH);
showDataButton.setText(Messages.getString("showData"));
showDataButton.addSelectionListener(this);
typeGroup = new Group(this, SWT.NONE);
typeGroup.setText(Messages.getString("shapefileType"));
typeGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false,
false, 3, 1));
typeGroup.setLayout(new GridLayout(3, true));
regionButton = new Button(typeGroup, SWT.RADIO);
regionButton.setText(Messages.getString("regionsType"));
regionButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
regionButton.addSelectionListener(this);
roadButton = new Button(typeGroup, SWT.RADIO);
roadButton.setText(Messages.getString("roadsType"));
roadButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
roadButton.addSelectionListener(this);
migrationButton = new Button(typeGroup, SWT.RADIO);
migrationButton.setText(Messages.getString("migrationType"));
migrationButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
migrationButton.addSelectionListener(this);
if (shapefileTypes.get(selection) == ShapefileType.REGION_FILE) {
regionButton.setSelection(true);
createRegionComposite();
} else if (shapefileTypes.get(selection) == ShapefileType.ROAD_FILE) {
roadButton.setSelection(true);
createRoadComposite();
} else if (shapefileTypes.get(selection) == ShapefileType.MIGRATION_FILE) {
migrationButton.setSelection(true);
createMigrationComposite();
}
}
updateUI();
} else if (e.getSource() == showDataButton) {
new TableDialog(this.getShell(), "", columnNames, data);
} else if (e.getSource() == regionButton) {
if (dataGroup != null) {
dataGroup.dispose();
}
shapefileTypes.set(shapeFileList.getSelectionIndex(),
ShapefileType.REGION_FILE);
createRegionComposite();
updateUI();
} else if (e.getSource() == roadButton) {
if (dataGroup != null) {
dataGroup.dispose();
}
shapefileTypes.set(shapeFileList.getSelectionIndex(),
ShapefileType.ROAD_FILE);
createRoadComposite();
updateUI();
} else if (e.getSource() == migrationButton) {
if (dataGroup != null) {
dataGroup.dispose();
}
shapefileTypes.set(shapeFileList.getSelectionIndex(),
ShapefileType.MIGRATION_FILE);
createMigrationComposite();
updateUI();
} else if (e.getSource() == regionIDCombo) {
String regionID = "column:"
+ columnNames.get(regionIDCombo.getSelectionIndex());
regionIDText.setText(regionID);
regionIDs.set(shapeFileList.getSelectionIndex(), regionID);
} else if (e.getSource() == roadIDCombo) {
String roadID = "column:"
+ columnNames.get(roadIDCombo.getSelectionIndex());
roadIDText.setText(roadID);
roadIDs.set(shapeFileList.getSelectionIndex(), roadID);
} else if (e.getSource() == roadClassCombo) {
String roadClass = "column:"
+ columnNames.get(roadClassCombo.getSelectionIndex());
roadClassText.setText(roadClass);
roadClasses.set(shapeFileList.getSelectionIndex(), roadClass);
} else if (e.getSource() == migrationIDCombo) {
String migrationID = "column:"
+ columnNames.get(migrationIDCombo.getSelectionIndex());
migrationIDText.setText(migrationID);
migrationIDs.set(shapeFileList.getSelectionIndex(), migrationID);
} else if (e.getSource() == migrationPopulationCombo) {
String migrationPopulation = "column:"
+ columnNames.get(migrationPopulationCombo
.getSelectionIndex());
migrationPopulationText.setText(migrationPopulation);
migrationPopulations.set(shapeFileList.getSelectionIndex(),
migrationPopulation);
} else if (e.getSource() == migrationRateCombo) {
String migrationRate = "column:"
+ columnNames.get(migrationRateCombo.getSelectionIndex());
migrationRateText.setText(migrationRate);
migrationRates
.set(shapeFileList.getSelectionIndex(), migrationRate);
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
@Override
public void modifyText(ModifyEvent e) {
if (e.getSource() == roadClassText) {
int column = getColumnIndex(roadClassText.getText());
roadClasses.set(shapeFileList.getSelectionIndex(),
roadClassText.getText());
if (column == -1) {
roadClassCombo.removeAll();
roadClassCombo.setItems(columnNames.toArray(new String[0]));
} else {
roadClassCombo.select(column);
}
} else if (e.getSource() == migrationPopulationText) {
int column = getColumnIndex(migrationPopulationText.getText());
migrationPopulations.set(shapeFileList.getSelectionIndex(),
migrationPopulationText.getText());
if (column == -1) {
migrationPopulationCombo.removeAll();
migrationPopulationCombo.setItems(columnNames
.toArray(new String[0]));
} else {
migrationPopulationCombo.select(column);
}
} else if (e.getSource() == migrationRateText) {
int column = getColumnIndex(migrationRateText.getText());
migrationRates.set(shapeFileList.getSelectionIndex(),
migrationRateText.getText());
if (column == -1) {
migrationRateCombo.removeAll();
migrationRateCombo.setItems(columnNames.toArray(new String[0]));
} else {
migrationRateCombo.select(column);
}
}
}
private void createRegionComposite() {
int selection = shapeFileList.getSelectionIndex();
Label regionIDLabel;
Label regionIDColumnLabel;
dataGroup = new Group(this, SWT.NONE);
dataGroup.setText("Data");
dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false,
3, 1));
dataGroup.setLayout(new GridLayout(4, true));
regionIDLabel = new Label(dataGroup, SWT.NONE);
regionIDLabel.setText(Messages.getString("regionID") + ":");
regionIDLabel
.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
regionIDText = new Text(dataGroup, SWT.BORDER);
regionIDText.setText(regionIDs.get(selection));
regionIDText.setEditable(false);
regionIDText
.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
regionIDColumnLabel = new Label(dataGroup, SWT.NONE);
regionIDColumnLabel.setText(Messages.getString("selectColumn") + ":");
regionIDColumnLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
regionIDCombo = new Combo(dataGroup, SWT.READ_ONLY);
regionIDCombo.setItems(columnNames.toArray(new String[0]));
regionIDCombo.addSelectionListener(this);
regionIDCombo
.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
int regionIDIndex = getColumnIndex(regionIDs.get(selection));
if (regionIDIndex != -1) {
regionIDCombo.select(regionIDIndex);
}
}
private void createRoadComposite() {
int selection = shapeFileList.getSelectionIndex();
Label roadIDLabel;
Label roadIDColumnLabel;
Label roadClassLabel;
Label roadClassColumnLabel;
dataGroup = new Group(this, SWT.NONE);
dataGroup.setText("Data");
dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false,
3, 1));
dataGroup.setLayout(new GridLayout(4, true));
roadIDLabel = new Label(dataGroup, SWT.NONE);
roadIDLabel.setText(Messages.getString("roadID") + ":");
roadIDLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
roadIDText = new Text(dataGroup, SWT.BORDER);
roadIDText.setText(roadIDs.get(selection));
roadIDText.setEditable(false);
roadIDText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
roadIDColumnLabel = new Label(dataGroup, SWT.NONE);
roadIDColumnLabel.setText(Messages.getString("selectColumn") + ":");
roadIDColumnLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
roadIDCombo = new Combo(dataGroup, SWT.READ_ONLY);
roadIDCombo.setItems(columnNames.toArray(new String[0]));
roadIDCombo.addSelectionListener(this);
roadIDCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
roadClassLabel = new Label(dataGroup, SWT.NONE);
roadClassLabel.setText(Messages.getString("roadClass") + ":");
roadClassLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
roadClassText = new Text(dataGroup, SWT.BORDER);
roadClassText.setText(roadClasses.get(selection));
roadClassText.addModifyListener(this);
roadClassText
.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
roadClassColumnLabel = new Label(dataGroup, SWT.NONE);
roadClassColumnLabel.setText(Messages.getString("selectColumn") + ":");
roadClassColumnLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
roadClassCombo = new Combo(dataGroup, SWT.READ_ONLY);
roadClassCombo.setItems(columnNames.toArray(new String[0]));
roadClassCombo.addSelectionListener(this);
roadClassCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
int roadIDIndex = getColumnIndex(roadIDs.get(selection));
int roadClassIndex = getColumnIndex(roadClasses.get(selection));
if (roadIDIndex != -1) {
roadIDCombo.select(roadIDIndex);
}
if (roadClassIndex != -1) {
roadClassCombo.select(roadClassIndex);
}
}
private void createMigrationComposite() {
int selection = shapeFileList.getSelectionIndex();
Label migrationIDLabel;
Label migrationIDColumnLabel;
Label migrationPopulationLabel;
Label migrationPopulationColumnLabel;
Label migrationRateLabel;
Label migrationRateColumnLabel;
dataGroup = new Group(this, SWT.NONE);
dataGroup.setText("Data");
dataGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false,
3, 1));
dataGroup.setLayout(new GridLayout(4, true));
migrationIDLabel = new Label(dataGroup, SWT.NONE);
migrationIDLabel.setText(Messages.getString("migrationID") + ":");
migrationIDLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
migrationIDText = new Text(dataGroup, SWT.BORDER);
migrationIDText.setText(migrationIDs.get(selection));
migrationIDText.setEditable(false);
migrationIDText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
migrationIDColumnLabel = new Label(dataGroup, SWT.NONE);
migrationIDColumnLabel
.setText(Messages.getString("selectColumn") + ":");
migrationIDColumnLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
migrationIDCombo = new Combo(dataGroup, SWT.READ_ONLY);
migrationIDCombo.setItems(columnNames.toArray(new String[0]));
migrationIDCombo.addSelectionListener(this);
migrationIDCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
migrationPopulationLabel = new Label(dataGroup, SWT.NONE);
migrationPopulationLabel.setText(Messages.getString("migrationPopulation") + ":");
migrationPopulationLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
migrationPopulationText = new Text(dataGroup, SWT.BORDER);
migrationPopulationText.setText(migrationPopulations.get(selection));
migrationPopulationText.addModifyListener(this);
migrationPopulationText.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
migrationPopulationColumnLabel = new Label(dataGroup, SWT.NONE);
migrationPopulationColumnLabel.setText(Messages
.getString("selectColumn") + ":");
migrationPopulationColumnLabel.setLayoutData(new GridData(SWT.FILL,
SWT.FILL, true, true));
migrationPopulationCombo = new Combo(dataGroup, SWT.READ_ONLY);
migrationPopulationCombo.setItems(columnNames.toArray(new String[0]));
migrationPopulationCombo.addSelectionListener(this);
migrationPopulationCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
migrationRateLabel = new Label(dataGroup, SWT.NONE);
migrationRateLabel.setText(Messages.getString("migrationRate") + ":");
migrationRateLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
migrationRateText = new Text(dataGroup, SWT.BORDER);
migrationRateText.setText(migrationRates.get(selection));
migrationRateText.addModifyListener(this);
migrationRateText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
migrationRateColumnLabel = new Label(dataGroup, SWT.NONE);
migrationRateColumnLabel.setText(Messages.getString("selectColumn")
+ ":");
migrationRateColumnLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, true));
migrationRateCombo = new Combo(dataGroup, SWT.READ_ONLY);
migrationRateCombo.setItems(columnNames.toArray(new String[0]));
migrationRateCombo.addSelectionListener(this);
migrationRateCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
int migrationIDIndex = getColumnIndex(migrationIDs.get(selection));
int migrationPopulationIndex = getColumnIndex(migrationPopulations
.get(selection));
int migrationRateIndex = getColumnIndex(migrationRates.get(selection));
if (migrationIDIndex != -1) {
migrationIDCombo.select(migrationIDIndex);
}
if (migrationPopulationIndex != -1) {
migrationPopulationCombo.select(migrationPopulationIndex);
}
if (migrationRateIndex != -1) {
migrationRateCombo.select(migrationRateIndex);
}
}
private void updateUI() {
pack();
getParent().layout();
getParent().getParent().getParent().layout();
}
private void updateDBFData() {
try {
Reader reader = new Reader(shapefiles.get(shapeFileList
.getSelectionIndex()));
columnNames = reader.getColumnNames();
data = reader.getData();
} catch (IOException ex) {
ex.printStackTrace();
}
}
private int getColumnIndex(String s) {
if (!s.startsWith("column:")) {
return -1;
}
s = s.replaceFirst("column:", "");
return columnNames.indexOf(s);
}
} // GraphGeneratorPropertyEditor