Search in sources :

Example 1 with GithubRepoDetailsDTO

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;
}
Also used : GitHubValidationException(org.bndtools.templating.jgit.GitHubValidationException) ModifyListener(org.eclipse.swt.events.ModifyListener) GitHub(org.bndtools.templating.jgit.GitHub) Label(org.eclipse.swt.widgets.Label) FileNotFoundException(java.io.FileNotFoundException) URI(java.net.URI) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Text(org.eclipse.swt.widgets.Text) InvocationTargetException(java.lang.reflect.InvocationTargetException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GitHubValidationException(org.bndtools.templating.jgit.GitHubValidationException) GithubRepoDetailsDTO(org.bndtools.templating.jgit.GithubRepoDetailsDTO) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GridData(org.eclipse.swt.layout.GridData)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 GitHub (org.bndtools.templating.jgit.GitHub)1 GitHubValidationException (org.bndtools.templating.jgit.GitHubValidationException)1 GithubRepoDetailsDTO (org.bndtools.templating.jgit.GithubRepoDetailsDTO)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 ControlDecoration (org.eclipse.jface.fieldassist.ControlDecoration)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1