for (String selected : selectionResult)
{
//search among all sourceAddedCompartments
for (int j = 0 ; j < sourceAddedCompartments.size() ; j++)
{
Compartment compartment = sourceAddedCompartments.get(j);
//if corresponding compartment is found
if (selected != null &&
selected.equals(compartment.getName()))
{
//remove compartment from sourceAddedCompartments ArrayList
sourceAddedCompartments.remove(j);
//remove compartment name from source compartment list
entityList.remove(selected);
}
}
}
}
});
//Target add button
targetAddButton = new Button(shell, SWT.NONE);
targetAddButton.setText("Add...");
gridData = new GridData(GridData.END, GridData.BEGINNING, true, false);
gridData.minimumWidth = 100;
gridData.horizontalIndent = 5;
targetAddButton.setLayoutData(gridData);
targetAddButton.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent arg0)
{
//new addCompartmentDialog
AddCompartmentDialog addCompartment =
new AddCompartmentDialog(new Shell(), allCompartments);
//open dialog
boolean addPressed = addCompartment.open();
//if add button is pressed
if (addPressed)
{
//for each selected compartment
for (Compartment compartment :
addCompartment.getSelectedCompartments())
{
//check if compartment has been added before
if (!previouslyAdded(compartment, targetAddedCompartments))
{
//add compartment name to target compartment list
targetCompartmentList.add(compartment.getName());
//add compartment to targetAddedCompartments ArrayList
targetAddedCompartments.add(compartment);
}
}
}
}
});
//Target remove button
targetRemoveButton = new Button(shell, SWT.NONE);
targetRemoveButton.setText("Remove");
gridData = new GridData(GridData.BEGINNING, GridData.BEGINNING,
true, false);
gridData.horizontalIndent = 5;
gridData.minimumWidth = 100;
targetRemoveButton.setLayoutData(gridData);
targetRemoveButton.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(SelectionEvent arg0)
{
String[] selectionResult = targetCompartmentList.getSelection();
//for each selected string
for (String selected : selectionResult)
{
//search among all targetAddedCompartments
for (int j = 0 ; j < targetAddedCompartments.size() ; j++)
{
Compartment compartment = targetAddedCompartments.get(j);
//if corresponding compartment is found
if (selected != null &&
selected.equals(compartment.getName()))
{
//remove compartment from targetAddedCompartments ArrayList
targetAddedCompartments.remove(j);
//remove compartment name from target compartment list