public void widgetSelected(SelectionEvent e) {
try {
ApiEditor apiEditor = (ApiEditor) page.getEditor();
String newBindingName = StringUtils.findUnusedName("newBinding", apiEditor.getModel().getWo(), "getBinding");
Binding newBinding = apiEditor.getModel().getWo().createBinding(newBindingName);
viewer.refresh();
viewer.editElement(newBinding, 0);
managedForm.dirtyStateChanged();
} catch (Throwable tx) {
throw new RuntimeException("Failed to open .api file.", tx);
}
}
public void widgetDefaultSelected(SelectionEvent e) {
// nothing to do
}
});
Button removeButton = toolkit.createButton(buttonsGroup, "Remove", SWT.PUSH);
removeButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
try {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (!selection.isEmpty()) {
Iterator iterator = selection.iterator();
ApiEditor apiEditor = (ApiEditor) page.getEditor();
while (iterator.hasNext()) {
Binding binding = (Binding) iterator.next();
apiEditor.getModel().getWo().removeBinding(binding);
viewer.remove(binding);
}
managedForm.dirtyStateChanged();
}
} catch (Throwable tx) {
throw new RuntimeException("Failed to open .api file.", tx);
}
}
public void widgetDefaultSelected(SelectionEvent e) {
// nothing to do
}
});
bindingsSection.setClient(bindingsClient);
final SectionPart spart = new SectionPart(bindingsSection) {
@Override
public boolean isDirty() {
try {
return ((ApiEditor) page.getEditor()).getModel().isDirty();
} catch (ApiModelException e) {
return false;
}
}
};
managedForm.addPart(spart);
viewer = new TableViewer(bindingsTable);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
managedForm.fireSelectionChanged(spart, event.getSelection());
}
});
viewer.setContentProvider(new MasterContentProvider());
viewer.setSorter(new ViewerSorter());
viewer.setLabelProvider(new MasterLabelProvider() {
public String getColumnText(Object obj, int index) {
if (obj instanceof Binding) {
Binding binding = (Binding) obj;
return binding.getName();
}
return super.getColumnText(obj, index);
}
});