Search in sources :

Example 1 with UsernamePassword

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;
}
Also used : SimpleCredentialsStorage(org.archicontribs.modelrepository.authentication.SimpleCredentialsStorage) IOException(java.io.IOException) File(java.io.File) UserNamePasswordDialog(org.archicontribs.modelrepository.dialogs.UserNamePasswordDialog) UsernamePassword(org.archicontribs.modelrepository.authentication.UsernamePassword)

Example 2 with UsernamePassword

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();
            }
        }
    });
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel) UsernamePassword(org.archicontribs.modelrepository.authentication.UsernamePassword)

Aggregations

IOException (java.io.IOException)2 UsernamePassword (org.archicontribs.modelrepository.authentication.UsernamePassword)2 IArchimateModel (com.archimatetool.model.IArchimateModel)1 File (java.io.File)1 SimpleCredentialsStorage (org.archicontribs.modelrepository.authentication.SimpleCredentialsStorage)1 UserNamePasswordDialog (org.archicontribs.modelrepository.dialogs.UserNamePasswordDialog)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1