use of org.bndtools.templating.jgit.GithubRepoDetailsDTO in project bndtools by bndtools.
the class GitHubRepoDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
setTitle(title);
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
container.setLayout(new GridLayout(2, false));
Label lblRepo = new Label(container, SWT.NONE);
lblRepo.setText("Repository Name:");
txtRepository = new Text(container, SWT.BORDER);
txtRepository.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
txtRepository.setMessage("username/repository");
if (repository != null)
txtRepository.setText(repository);
new Label(container, SWT.NONE).setText("Branch:");
txtBranch = new Text(container, SWT.BORDER);
txtBranch.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
txtBranch.setMessage("default branch");
if (branch != null)
txtBranch.setText(branch);
ControlDecoration branchDecor = new ControlDecoration(txtBranch, SWT.LEFT, container);
branchDecor.setDescriptionText("Specify the branch, tag or commit ID you would like to clone from the\nrepository. We use the default branch specified in GitHub settings.");
branchDecor.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
branchDecor.setShowHover(true);
final Button btnValidate = new Button(container, SWT.PUSH);
btnValidate.setText("Validate");
btnValidate.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1));
ModifyListener modifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent ev) {
if (!txtRepository.getText().trim().equals(repository)) {
isValidated = false;
repository = txtRepository.getText().trim();
}
branch = txtBranch.getText().trim();
updateButtons();
}
};
txtRepository.addModifyListener(modifyListener);
txtBranch.addModifyListener(modifyListener);
btnValidate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setMessage(null, IMessageProvider.INFORMATION);
try {
if (repository == null || repository.isEmpty())
throw new GitHubValidationException("No repository name specified");
if (repository.contains(":/"))
throw new GitHubValidationException("Specify GitHub repositories as username/repository");
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
final GithubRepoDetailsDTO dto = new GitHub(cache, executor).loadRepoDetails(repository).getValue();
final URI cloneUri = URI.create(dto.clone_url);
btnValidate.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
setMessage(String.format("Validated! Clone URL is '%s'. Default branch 'origin/%s'", cloneUri, dto.default_branch), IMessageProvider.INFORMATION);
isValidated = true;
updateButtons();
}
});
} catch (InvocationTargetException e) {
throw e;
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
};
ProgressRunner.execute(false, runnable, new ProgressMonitorDialog(getParentShell()), btnValidate.getDisplay());
setErrorMessage(null);
} catch (InvocationTargetException ex) {
Throwable t = ex.getCause();
if (t instanceof FileNotFoundException)
setErrorMessage("Could not find the requested repository");
else
setErrorMessage(t.getClass().getSimpleName() + ": " + t.getMessage());
} catch (GitHubValidationException ex) {
setErrorMessage(ex.getMessage());
} catch (Exception ex) {
setErrorMessage(ex.getClass().getSimpleName() + ": " + ex.getMessage());
}
}
});
return area;
}
Aggregations