use of org.archicontribs.modelrepository.authentication.UsernamePassword in project archi-modelrepository-plugin by archi-contribs.
the class AbstractModelAction method getUserNameAndPasswordFromCredentialsFileOrDialog.
/**
* Get user name and password from credentials file if prefs set or from dialog
* @param storageFileName
* @param shell
* @return the username and password, or null
*/
protected UsernamePassword getUserNameAndPasswordFromCredentialsFileOrDialog(Shell shell) {
boolean doStoreInCredentialsFile = ModelRepositoryPlugin.INSTANCE.getPreferenceStore().getBoolean(IPreferenceConstants.PREFS_STORE_REPO_CREDENTIALS);
SimpleCredentialsStorage scs = new SimpleCredentialsStorage(new File(getRepository().getLocalGitFolder(), IGraficoConstants.REPO_CREDENTIALS_FILE));
// Is it stored?
if (doStoreInCredentialsFile && scs.hasCredentialsFile()) {
try {
return new UsernamePassword(scs.getUsername(), scs.getPassword());
} catch (IOException ex) {
displayErrorDialog(Messages.AbstractModelAction_9, ex);
}
}
// Else ask the user
UserNamePasswordDialog dialog = new UserNamePasswordDialog(shell, scs);
if (dialog.open() == Window.OK) {
return new UsernamePassword(dialog.getUsername(), dialog.getPassword());
}
return null;
}
use of org.archicontribs.modelrepository.authentication.UsernamePassword in project archi-modelrepository-plugin by archi-contribs.
the class RefreshModelAction method run.
@Override
public void run() {
// 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
try {
getRepository().exportModelToGraficoFiles();
} catch (IOException ex) {
displayErrorDialog(Messages.RefreshModelAction_0, ex);
return;
}
// Then offer to Commit
try {
if (getRepository().hasChangesToCommit()) {
if (!offerToCommitChanges()) {
return;
}
notifyChangeListeners(IRepositoryListener.HISTORY_CHANGED);
}
} catch (IOException | GitAPIException ex) {
displayErrorDialog(Messages.RefreshModelAction_3, ex);
return;
}
// Get User Credentials first
UsernamePassword up = getUserNameAndPasswordFromCredentialsFileOrDialog(fWindow.getShell());
if (up == null) {
return;
}
// Proxy update
try {
ProxyAuthenticater.update(getRepository().getOnlineRepositoryURL());
} catch (IOException ex) {
displayErrorDialog(Messages.RefreshModelAction_0, ex);
return;
}
// Do main action with PM dialog
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
try {
ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(fWindow.getShell());
pmDialog.run(false, true, getHandler(up));
} catch (InvocationTargetException | InterruptedException ex) {
ex.printStackTrace();
}
}
});
}
Aggregations