gd.widthHint = 100;
final ApiEditor apiEditor = (ApiEditor) this.getEditor();
boolean brokenApiFile = false;
String brokenMessage = null;
ApiModel apiModel = null;
try {
apiModel = apiEditor.getModel();
} catch (Throwable throwable) {
brokenApiFile = true;
ApieditorPlugin.getDefault().debug(throwable);
brokenMessage = StringUtils.getErrorMessage(throwable);
}
if (apiModel == null) {
if (brokenApiFile) {
Label brokenLabel = new Label(client, SWT.WRAP);
brokenLabel.setBackground(client.getBackground());
brokenLabel.setText(brokenMessage);
GridData labelData = new GridData(GridData.FILL_HORIZONTAL);
labelData.horizontalSpan = 2;
brokenLabel.setLayoutData(labelData);
}
Button createApiFileButton;
if (brokenApiFile) {
createApiFileButton = toolkit.createButton(client, "Recreate Api File", SWT.PUSH);
}
else {
createApiFileButton = toolkit.createButton(client, "Create Api File", SWT.PUSH);
}
gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
createApiFileButton.setLayoutData(gd);
createApiFileButton.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
FileEditorInput fileEditorInput = (FileEditorInput) apiEditor.getEditorInput();
try {
IFile file = fileEditorInput.getFile();
if (file.exists()) {
file.delete(false, null);
}
new ApiModel(file);
} catch (ApiModelException coreException) {
throw new RuntimeException("Failed to create .api file.", coreException);
} catch (CoreException coreException) {
throw new RuntimeException("Failed to delete existing .api file.", coreException);
}