public void widgetSelected(SelectionEvent event) {
ConstraintDialog cdialog = new ConstraintDialog(getShell());
cdialog.create();
if (cdialog.open() == Window.OK) {
RutaRuleListConstraint newConstraint = new RutaRuleListConstraint(cdialog.getRule(),
cdialog.getDescription());
ConstraintData newConstraintData = new ConstraintData(newConstraint);
constraintList.add(newConstraintData);
tableViewer.setInput(constraintList);
tableViewer.refresh();
}
}
});
// Complex Constraint Button now used for GEConstraints
constraintButtonTMComplex = new Button(this, SWT.PUSH | SWT.CENTER);
FormData ConstraintButtonTMComplexData = new FormData();
ConstraintButtonTMComplexData.width = 25;
ConstraintButtonTMComplexData.height = 25;
ConstraintButtonTMComplexData.top = new FormAttachment(constraintButtonRutaList, 10);
ConstraintButtonTMComplexData.right = new FormAttachment(100, -5);
constraintButtonTMComplex.setLayoutData(ConstraintButtonTMComplexData);
Image addTableIcon = getImage("tmAdd");
constraintButtonTMComplex.setImage(addTableIcon);
constraintButtonTMComplex.setToolTipText("Add an Annotation-Distribution Constraint");
constraintButtonTMComplex.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
ConstraintDialog cdialog = new ConstraintDialog(getShell());
cdialog.create();
if (cdialog.open() == Window.OK) {
RutaGEConstraint newConstraint = new RutaGEConstraint(cdialog.getRule(), cdialog
.getDescription());
ConstraintData newConstraintData = new ConstraintData(newConstraint);
constraintList.add(newConstraintData);
tableViewer.setInput(constraintList);
tableViewer.refresh();
}
}
});
// Constraint Edit Button
constraintButconJava = new Button(this, SWT.PUSH | SWT.CENTER);
FormData ConstraintButtonJavaData = new FormData();
ConstraintButtonJavaData.width = 25;
ConstraintButtonJavaData.height = 25;
ConstraintButtonJavaData.top = new FormAttachment(constraintButtonTMComplex, 10);
ConstraintButtonJavaData.right = new FormAttachment(100, -5);
constraintButconJava.setLayoutData(ConstraintButtonJavaData);
Image addJavaIcon = getImage("cupAdd");
constraintButconJava.setImage(addJavaIcon);
constraintButconJava.setToolTipText("Add Java Constraint");
constraintRemoveButton = new Button(this, SWT.PUSH | SWT.CENTER);
FormData ConstraintRemoveData = new FormData();
ConstraintRemoveData.width = 25;
ConstraintRemoveData.height = 25;
ConstraintRemoveData.top = new FormAttachment(constraintButconJava, 10);
ConstraintRemoveData.right = new FormAttachment(100, -5);
constraintRemoveButton.setLayoutData(ConstraintRemoveData);
Image addRemoveIcon = getImage("delete");
constraintRemoveButton.setImage(addRemoveIcon);
constraintRemoveButton.setToolTipText("Remove Selected Constraints");
constraintRemoveButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
int[] indices = table.getSelectionIndices();
for (int i = indices.length - 1; i >= 0; i--) {
constraintList.remove(indices[i]);
}
tableViewer.setSelection(new StructuredSelection());
editor.getEditor().dispose();
tableViewer.setInput(constraintList);
tableViewer.refresh();
}
});
tableViewer = new TableViewer(this, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL
| SWT.FULL_SELECTION);
contentProvider = new ConstraintSelectTableContentProvider();
labelProvider = new ConstraintSelectTableLabelProvider();
tableViewer.setContentProvider(contentProvider);
tableViewer.setLabelProvider(labelProvider);
table = tableViewer.getTable();
FormData tableFormData = new FormData();
tableFormData.top = new FormAttachment(0, 10);
tableFormData.left = new FormAttachment(0, 10);
tableFormData.right = new FormAttachment(constraintButtonRuta, -10);
tableFormData.bottom = new FormAttachment(100, 0);
table.setLayoutData(tableFormData);
table.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
// if (((e.stateMask & SWT.CTRL) == SWT.CTRL) && (e.keyCode == 'c')) {
// String output = "";
// TableItem[] items = table.getSelection();
// for (TableItem item : items) {
// ConstraintData data = (ConstraintData) item.getData();
// output = output + data.getConstraint().getData() + "\n";
// }
// clipboard.setContents(new Object[] { output },
// new Transfer[] { TextTransfer.getInstance() });
// }
}
public void keyReleased(KeyEvent arg0) {
}
});
tableViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
if (selection.isEmpty()) {
return;
}
Object element = selection.getFirstElement();
if (element instanceof ConstraintData) {
ConstraintData data = (ConstraintData) element;
IRutaConstraint constraint = data.getConstraint();
if (constraint instanceof SimpleRutaRuleConstraint) {
ConstraintDialog cdialog = new ConstraintDialog(getShell());
cdialog.create((SimpleRutaRuleConstraint) constraint);
if (cdialog.open() == Window.OK) {
SimpleRutaRuleConstraint newConstraint = new SimpleRutaRuleConstraint(cdialog
.getRule(), cdialog.getDescription());
data.setConstraint(newConstraint);
tableViewer.setInput(constraintList);
tableViewer.refresh();
}
}
if (constraint instanceof RutaRuleListConstraint) {
ConstraintDialog cdialog = new ConstraintDialog(getShell());
cdialog.create((RutaRuleListConstraint) constraint);
if (cdialog.open() == Window.OK) {
RutaRuleListConstraint newConstraint = new RutaRuleListConstraint(cdialog.getRule(),
cdialog.getDescription());
data.setConstraint(newConstraint);
tableViewer.setInput(constraintList);
tableViewer.refresh();
}