Search in sources :

Example 1 with BranchStatus

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

the class BranchesViewer method doSetInput.

void doSetInput(IArchiRepository archiRepo) {
    // Get BranchStatus
    BranchStatus branchStatus = null;
    try {
        branchStatus = archiRepo.getBranchStatus();
    } catch (IOException | GitAPIException ex) {
        ex.printStackTrace();
    }
    setInput(branchStatus);
    // Set selection to current branch
    if (branchStatus != null) {
        BranchInfo branchInfo = branchStatus.getCurrentLocalBranch();
        if (branchInfo != null) {
            setSelection(new StructuredSelection(branchInfo));
        }
    }
    // And relayout
    getControl().getParent().layout();
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) BranchStatus(org.archicontribs.modelrepository.grafico.BranchStatus) IOException(java.io.IOException)

Example 2 with BranchStatus

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

the class HistoryTableViewer method doSetInput.

public void doSetInput(IArchiRepository archiRepo) {
    // Get BranchStatus and currentLocalBranch
    try {
        BranchStatus branchStatus = archiRepo.getBranchStatus();
        if (branchStatus != null) {
            fSelectedBranch = branchStatus.getCurrentLocalBranch();
        }
    } catch (IOException | GitAPIException ex) {
        ex.printStackTrace();
    }
    setInput(archiRepo);
    // Do the Layout kludge
    ((UpdatingTableColumnLayout) getTable().getParent().getLayout()).doRelayout();
// Select first row
// Object element = getElementAt(0);
// if(element != null) {
// setSelection(new StructuredSelection(element), true);
// }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BranchStatus(org.archicontribs.modelrepository.grafico.BranchStatus) IOException(java.io.IOException) UpdatingTableColumnLayout(com.archimatetool.editor.ui.components.UpdatingTableColumnLayout)

Example 3 with BranchStatus

use of org.archicontribs.modelrepository.grafico.BranchStatus 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 4 with BranchStatus

use of org.archicontribs.modelrepository.grafico.BranchStatus 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 5 with BranchStatus

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

the class RefreshModelAction method pull.

protected int pull(UsernamePassword npw, ProgressMonitorDialog pmDialog) throws IOException, GitAPIException {
    PullResult pullResult = null;
    pmDialog.getProgressMonitor().subTask(Messages.RefreshModelAction_6);
    // update dialog
    Display.getCurrent().readAndDispatch();
    try {
        pullResult = getRepository().pullFromRemote(npw, new ProgressMonitorWrapper(pmDialog.getProgressMonitor()));
    } catch (Exception ex) {
        // So quietly absorb this and return OK
        if (ex instanceof RefNotAdvertisedException) {
            return PULL_STATUS_OK;
        }
        throw ex;
    }
    // Check for tracking updates
    FetchResult fetchResult = pullResult.getFetchResult();
    boolean newTrackingRefUpdates = fetchResult != null && !fetchResult.getTrackingRefUpdates().isEmpty();
    // Merge is already up to date...
    if (pullResult.getMergeResult().getMergeStatus() == MergeStatus.ALREADY_UP_TO_DATE) {
        // Check if any tracked refs were updated
        if (newTrackingRefUpdates) {
            return PULL_STATUS_OK;
        }
        return PULL_STATUS_UP_TO_DATE;
    }
    pmDialog.getProgressMonitor().subTask(Messages.RefreshModelAction_7);
    BranchStatus branchStatus = getRepository().getBranchStatus();
    // Setup the Graphico Model Loader
    GraficoModelLoader loader = new GraficoModelLoader(getRepository());
    // Merge failure
    if (!pullResult.isSuccessful() && pullResult.getMergeResult().getMergeStatus() == MergeStatus.CONFLICTING) {
        // Get the remote ref name
        String remoteRef = branchStatus.getCurrentRemoteBranch().getFullName();
        // Try to handle the merge conflict
        MergeConflictHandler handler = new MergeConflictHandler(pullResult.getMergeResult(), remoteRef, getRepository(), fWindow.getShell());
        try {
            handler.init(pmDialog.getProgressMonitor());
        } catch (IOException | GitAPIException ex) {
            // Clean up
            handler.resetToLocalState();
            if (ex instanceof CanceledException) {
                return PULL_STATUS_MERGE_CANCEL;
            }
            throw ex;
        }
        String dialogMessage = NLS.bind(Messages.RefreshModelAction_4, branchStatus.getCurrentLocalBranch().getShortName());
        pmDialog.getShell().setVisible(false);
        boolean result = handler.openConflictsDialog(dialogMessage);
        pmDialog.getShell().setVisible(true);
        if (result) {
            handler.merge();
        } else // User cancelled - we assume they committed all changes so we can reset
        {
            handler.resetToLocalState();
            return PULL_STATUS_MERGE_CANCEL;
        }
        // We now have to check if model can be reloaded
        pmDialog.getProgressMonitor().subTask(Messages.RefreshModelAction_8);
        // Reload the model from the Grafico XML files
        try {
            loader.loadModel();
        } catch (IOException ex) {
            // Clean up
            handler.resetToLocalState();
            throw ex;
        }
    } else {
        // Reload the model from the Grafico XML files
        pmDialog.getProgressMonitor().subTask(Messages.RefreshModelAction_8);
        loader.loadModel();
    }
    // Do a commit if needed
    if (getRepository().hasChangesToCommit()) {
        pmDialog.getProgressMonitor().subTask(Messages.RefreshModelAction_9);
        String commitMessage = NLS.bind(Messages.RefreshModelAction_1, branchStatus.getCurrentLocalBranch().getShortName());
        // Did we restore any missing objects?
        String restoredObjects = loader.getRestoredObjectsAsString();
        // Add to commit message
        if (restoredObjects != null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            commitMessage += "\n\n" + Messages.RefreshModelAction_3 + "\n" + restoredObjects;
        }
        // TODO - not sure if amend should be false or true here?
        getRepository().commitChanges(commitMessage, false);
    }
    return PULL_STATUS_OK;
}
Also used : CanceledException(org.eclipse.jgit.api.errors.CanceledException) FetchResult(org.eclipse.jgit.transport.FetchResult) MergeConflictHandler(org.archicontribs.modelrepository.merge.MergeConflictHandler) IOException(java.io.IOException) PullResult(org.eclipse.jgit.api.PullResult) RefNotAdvertisedException(org.eclipse.jgit.api.errors.RefNotAdvertisedException) GeneralSecurityException(java.security.GeneralSecurityException) CanceledException(org.eclipse.jgit.api.errors.CanceledException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RefNotAdvertisedException(org.eclipse.jgit.api.errors.RefNotAdvertisedException) GraficoModelLoader(org.archicontribs.modelrepository.grafico.GraficoModelLoader) BranchStatus(org.archicontribs.modelrepository.grafico.BranchStatus)

Aggregations

IOException (java.io.IOException)5 BranchStatus (org.archicontribs.modelrepository.grafico.BranchStatus)5 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)5 BranchInfo (org.archicontribs.modelrepository.grafico.BranchInfo)3 UpdatingTableColumnLayout (com.archimatetool.editor.ui.components.UpdatingTableColumnLayout)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 GraficoModelLoader (org.archicontribs.modelrepository.grafico.GraficoModelLoader)1 IArchiRepository (org.archicontribs.modelrepository.grafico.IArchiRepository)1 MergeConflictHandler (org.archicontribs.modelrepository.merge.MergeConflictHandler)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 PullResult (org.eclipse.jgit.api.PullResult)1 CanceledException (org.eclipse.jgit.api.errors.CanceledException)1 RefNotAdvertisedException (org.eclipse.jgit.api.errors.RefNotAdvertisedException)1 PersonIdent (org.eclipse.jgit.lib.PersonIdent)1 FetchResult (org.eclipse.jgit.transport.FetchResult)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