Search in sources :

Example 6 with BranchInfo

use of org.archicontribs.modelrepository.grafico.BranchInfo in project archi-modelrepository-plugin by archi-contribs.

the class ModelRepositoryTreeViewer method updateStatusCache.

/**
 * Update the status cache
 */
private void updateStatusCache(List<IArchiRepository> repos) {
    cache = new Hashtable<IArchiRepository, StatusCache>();
    for (IArchiRepository repo : repos) {
        try {
            BranchInfo branchInfo = repo.getBranchStatus().getCurrentLocalBranch();
            if (branchInfo != null) {
                // This can be null!!
                StatusCache sc = new StatusCache(branchInfo, repo.hasLocalChanges());
                cache.put(repo, sc);
            }
        } catch (IOException | GitAPIException ex) {
            ex.printStackTrace();
            // $NON-NLS-1$
            ModelRepositoryPlugin.INSTANCE.log(IStatus.ERROR, "Error getting Model Repository Status", ex);
        }
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) IOException(java.io.IOException)

Example 7 with BranchInfo

use of org.archicontribs.modelrepository.grafico.BranchInfo in project archi-modelrepository-plugin by archi-contribs.

the class RepoInfoSection method handleSelection.

@Override
protected void handleSelection(IStructuredSelection selection) {
    if (selection.getFirstElement() instanceof IArchiRepository) {
        fArchiRepo = (IArchiRepository) selection.getFirstElement();
        try {
            fFile = fArchiRepo.getLocalRepositoryFolder().getAbsolutePath();
            fTextFile.setText(fFile);
            fURL = fArchiRepo.getOnlineRepositoryURL();
            fTextURL.setText(StringUtils.safeString(fURL));
            // $NON-NLS-1$
            fBranch = "";
            BranchStatus status = fArchiRepo.getBranchStatus();
            if (status != null) {
                BranchInfo branchInfo = status.getCurrentLocalBranch();
                if (branchInfo != null) {
                    fBranch = branchInfo.getShortName();
                }
            }
            fTextCurrentBranch.setText(StringUtils.safeString(fBranch));
        } catch (IOException | GitAPIException ex) {
            ex.printStackTrace();
        }
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) IArchiRepository(org.archicontribs.modelrepository.grafico.IArchiRepository) BranchStatus(org.archicontribs.modelrepository.grafico.BranchStatus) IOException(java.io.IOException)

Example 8 with BranchInfo

use of org.archicontribs.modelrepository.grafico.BranchInfo in project archi-modelrepository-plugin by archi-contribs.

the class HistoryView method createInfoSection.

private void createInfoSection(Composite parent) {
    Composite mainComp = new Composite(parent, SWT.NONE);
    mainComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout layout = new GridLayout(3, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    mainComp.setLayout(layout);
    // Repository name
    fRepoLabel = new Label(mainComp, SWT.NONE);
    fRepoLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fRepoLabel.setText(Messages.HistoryView_0);
    // Branches
    Label label = new Label(mainComp, SWT.NONE);
    label.setText(Messages.HistoryView_2);
    fBranchesViewer = new BranchesViewer(mainComp);
    GridData gd = new GridData(SWT.END);
    fBranchesViewer.getControl().setLayoutData(gd);
    /*
         * Listen to Branch Selections and forward on to History Viewer
         */
    fBranchesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            BranchInfo branchInfo = (BranchInfo) event.getStructuredSelection().getFirstElement();
            getHistoryViewer().setSelectedBranch(branchInfo);
            updateActions();
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 9 with BranchInfo

use of org.archicontribs.modelrepository.grafico.BranchInfo in project archi-modelrepository-plugin by archi-contribs.

the class CommitDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    setMessage(Messages.CommitDialog_1, IMessageProvider.INFORMATION);
    setTitleImage(IModelRepositoryImages.ImageFactory.getImage(IModelRepositoryImages.BANNER_COMMIT));
    Composite area = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(area, SWT.NONE);
    container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    GridLayout layout = new GridLayout(2, false);
    container.setLayout(layout);
    // Repo and branch
    // $NON-NLS-1$
    String shortBranchName = "unknown";
    try {
        BranchStatus status = fRepository.getBranchStatus();
        if (status != null) {
            BranchInfo branchInfo = status.getCurrentLocalBranch();
            if (branchInfo != null) {
                shortBranchName = branchInfo.getShortName();
            }
        }
    } catch (IOException | GitAPIException ex) {
        ex.printStackTrace();
    }
    Label label = new Label(container, SWT.NONE);
    label.setText(Messages.CommitDialog_6);
    label = new Label(container, SWT.NONE);
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // $NON-NLS-1$ //$NON-NLS-2$
    label.setText(fRepository.getName() + " [" + shortBranchName + "]");
    // User name & email
    // $NON-NLS-1$
    String userName = "";
    // $NON-NLS-1$
    String userEmail = "";
    try {
        PersonIdent result = fRepository.getUserDetails();
        userName = result.getName();
        userEmail = result.getEmailAddress();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    label = new Label(container, SWT.NONE);
    label.setText(Messages.CommitDialog_2);
    fTextUserName = UIUtils.createSingleTextControl(container, SWT.BORDER, false);
    fTextUserName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fTextUserName.setText(userName);
    label = new Label(container, SWT.NONE);
    label.setText(Messages.CommitDialog_3);
    fTextUserEmail = UIUtils.createSingleTextControl(container, SWT.BORDER, false);
    fTextUserEmail.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    fTextUserEmail.setText(userEmail);
    label = new Label(container, SWT.NONE);
    label.setText(Messages.CommitDialog_4);
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    label.setLayoutData(gd);
    fTextCommitMessage = new Text(container, SWT.BORDER | SWT.V_SCROLL | SWT.WRAP | SWT.MULTI);
    gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    fTextCommitMessage.setLayoutData(gd);
    // TODO: After Archi 4.7 remove this code and use
    // UIUtils.applyTraverseListener(fTextCommitMessage, SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_RETURN);
    fTextCommitMessage.addTraverseListener((e) -> {
        // Ctrl + Enter
        if (e.detail == SWT.TRAVERSE_RETURN && (e.stateMask & SWT.MOD1) != 0) {
            e.doit = true;
        } else // Tabs and other SWT.TRAVERSE_* flags
        if (e.detail == SWT.TRAVERSE_TAB_NEXT || e.detail == SWT.TRAVERSE_TAB_PREVIOUS) {
            e.doit = true;
        }
    });
    fAmendLastCommitCheckbox = new Button(container, SWT.CHECK);
    fAmendLastCommitCheckbox.setText(Messages.CommitDialog_5);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fAmendLastCommitCheckbox.setLayoutData(gd);
    try {
        fAmendLastCommitCheckbox.setEnabled(isAmendAllowed());
    } catch (IOException | GitAPIException ex) {
        fAmendLastCommitCheckbox.setEnabled(false);
        ex.printStackTrace();
    }
    if (!StringUtils.isSet(userName)) {
        fTextUserName.setFocus();
    } else if (!StringUtils.isSet(userEmail)) {
        fTextUserEmail.setFocus();
    } else {
        fTextCommitMessage.setFocus();
    }
    return area;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GridLayout(org.eclipse.swt.layout.GridLayout) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) BranchStatus(org.archicontribs.modelrepository.grafico.BranchStatus)

Example 10 with BranchInfo

use of org.archicontribs.modelrepository.grafico.BranchInfo in project archi-modelrepository-plugin by archi-contribs.

the class DeleteBranchAction method run.

@Override
public void run() {
    if (!shouldBeEnabled()) {
        return;
    }
    // Keep a local reference in case of a notification event changing the current branch selection in the UI
    BranchInfo branchInfo = fBranchInfo;
    boolean response = MessageDialog.openConfirm(fWindow.getShell(), Messages.DeleteBranchAction_0, NLS.bind(Messages.DeleteBranchAction_1, branchInfo.getShortName()));
    if (!response) {
        return;
    }
    try {
        // If the branch has a remote ref or is remote we should delete that too
        boolean deleteRemote = branchInfo.hasRemoteRef() || branchInfo.isRemote();
        if (deleteRemote) {
            // Check primary key set
            if (!EncryptedCredentialsStorage.checkPrimaryKeySet()) {
                return;
            }
            // Get for this before opening the progress dialog
            // UsernamePassword will be null if using SSH
            UsernamePassword npw = getUsernamePassword();
            // User cancelled on HTTP
            if (npw == null && GraficoUtils.isHTTP(getRepository().getOnlineRepositoryURL())) {
                return;
            }
            Exception[] exception = new Exception[1];
            PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor pm) {
                    try {
                        // Update Proxy
                        ProxyAuthenticator.update();
                        pm.beginTask(Messages.DeleteBranchAction_2, IProgressMonitor.UNKNOWN);
                        deleteBranchAndPush(branchInfo, npw);
                    } catch (Exception ex) {
                        exception[0] = ex;
                    } finally {
                        // Clear Proxy
                        ProxyAuthenticator.clear();
                    }
                }
            });
            if (exception[0] != null) {
                throw exception[0];
            }
        } else {
            deleteLocalBranch(branchInfo);
        }
    } catch (GeneralSecurityException ex) {
        displayCredentialsErrorDialog(ex);
    } catch (Exception ex) {
        displayErrorDialog(Messages.DeleteBranchAction_0, ex);
    } finally {
        // Notify listeners
        notifyChangeListeners(IRepositoryListener.BRANCHES_CHANGED);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) GeneralSecurityException(java.security.GeneralSecurityException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) GeneralSecurityException(java.security.GeneralSecurityException) UsernamePassword(org.archicontribs.modelrepository.authentication.UsernamePassword) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

BranchInfo (org.archicontribs.modelrepository.grafico.BranchInfo)12 IOException (java.io.IOException)9 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)9 IArchimateModel (com.archimatetool.model.IArchimateModel)3 GeneralSecurityException (java.security.GeneralSecurityException)3 BranchStatus (org.archicontribs.modelrepository.grafico.BranchStatus)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 UsernamePassword (org.archicontribs.modelrepository.authentication.UsernamePassword)2 IArchiRepository (org.archicontribs.modelrepository.grafico.IArchiRepository)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 CanceledException (org.eclipse.jgit.api.errors.CanceledException)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Label (org.eclipse.swt.widgets.Label)2 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1