Search in sources :

Example 11 with BranchInfo

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

the class MergeBranchAction method doLocalMerge.

private void doLocalMerge(BranchInfo branchToMerge) throws IOException, GitAPIException {
    // Offer to save the model if open and dirty
    // We need to do this to keep grafico and temp files in sync
    IArchimateModel model = getRepository().locateModel();
    if (model != null && IEditorModelManager.INSTANCE.isModelDirty(model)) {
        if (!offerToSaveModel(model)) {
            return;
        }
    }
    // Do the Grafico Export first
    getRepository().exportModelToGraficoFiles();
    // Then offer to Commit
    if (getRepository().hasChangesToCommit()) {
        if (!offerToCommitChanges()) {
            return;
        }
    }
    // Do main action with PM dialog
    Display.getCurrent().asyncExec(new Runnable() {

        @Override
        public void run() {
            ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
            try {
                pmDialog.run(false, true, new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            monitor.beginTask(Messages.MergeBranchAction_11, -1);
                            // Store currentBranch first
                            BranchInfo currentBranch = getRepository().getBranchStatus().getCurrentLocalBranch();
                            merge(currentBranch, branchToMerge, pmDialog);
                        } catch (Exception ex) {
                            pmDialog.getShell().setVisible(false);
                            displayErrorDialog(Messages.MergeBranchAction_1, ex);
                        } finally {
                            try {
                                saveChecksumAndNotifyListeners();
                            } catch (IOException ex) {
                                ex.printStackTrace();
                            }
                        }
                    }
                });
            } catch (InvocationTargetException | InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    });
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel) 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) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 12 with BranchInfo

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

the class SwitchBranchAction 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;
    // Offer to save the model if open and dirty
    // We need to do this to keep grafico and temp files in sync
    IArchimateModel model = getRepository().locateModel();
    if (model != null && IEditorModelManager.INSTANCE.isModelDirty(model)) {
        int response = MessageDialog.open(MessageDialog.CONFIRM, fWindow.getShell(), Messages.AbstractModelAction_1, Messages.AbstractModelAction_2, SWT.NONE, Messages.SwitchBranchAction_2, Messages.SwitchBranchAction_3, Messages.SwitchBranchAction_4);
        // Cancel
        if (response == 2) {
            return;
        }
        // Save anyway
        try {
            IEditorModelManager.INSTANCE.saveModel(model);
        } catch (IOException ex) {
            displayErrorDialog(Messages.AbstractModelAction_1, ex);
            return;
        }
        // If "no" to save then don't commit
        if (response == 1) {
            try {
                // Abort changes by resetting to HEAD
                getRepository().resetToRef(IGraficoConstants.HEAD);
                // Switch branch
                switchBranch(branchInfo, !isBranchRefSameAsCurrentBranchRef(branchInfo));
                notifyChangeListeners(IRepositoryListener.BRANCHES_CHANGED);
                return;
            } catch (IOException | GitAPIException ex) {
                displayErrorDialog(Messages.SwitchBranchAction_0, ex);
            }
        }
    }
    boolean notifyHistoryChanged = false;
    try {
        // Do the Grafico Export first
        getRepository().exportModelToGraficoFiles();
        // If there are changes to commit...
        if (getRepository().hasChangesToCommit()) {
            // Ask user
            boolean doCommit = MessageDialog.openQuestion(fWindow.getShell(), Messages.SwitchBranchAction_0, Messages.SwitchBranchAction_1);
            // Commit dialog
            if (doCommit && !offerToCommitChanges()) {
                return;
            }
            // User chose "no" to commit so let's make sure we proceed
            boolean proceed = MessageDialog.openQuestion(fWindow.getShell(), Messages.SwitchBranchAction_0, Messages.SwitchBranchAction_5);
            if (!proceed) {
                return;
            }
            // Abort changes by resetting to HEAD
            getRepository().resetToRef(IGraficoConstants.HEAD);
            notifyHistoryChanged = true;
        }
        // Switch branch
        switchBranch(branchInfo, !isBranchRefSameAsCurrentBranchRef(branchInfo));
    } catch (Exception ex) {
        displayErrorDialog(Messages.SwitchBranchAction_0, ex);
    }
    // Notify listeners last because a new UI selection will trigger an updated BranchInfo here
    if (notifyHistoryChanged) {
        notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
    }
    notifyChangeListeners(IRepositoryListener.BRANCHES_CHANGED);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) BranchInfo(org.archicontribs.modelrepository.grafico.BranchInfo) IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException)

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