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();
}
}
});
}
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);
}
Aggregations