Search in sources :

Example 1 with CredentialVariablesDialog

use of org.knime.workbench.ui.masterkey.CredentialVariablesDialog in project knime-core by knime.

the class OpenCredentialVariablesDialogAction method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    super.run();
    // get workflow
    final WorkflowManager wf = getWorkflow();
    // open the dialog
    final Display d = Display.getDefault();
    // run in UI thread
    d.asyncExec(new Runnable() {

        @Override
        public void run() {
            CredentialsStore store = wf.getCredentialsStore();
            CredentialVariablesDialog dialog = new CredentialVariablesDialog(d.getActiveShell(), store, wf.getName());
            if (dialog.open() == Window.OK) {
                for (String name : store.listNames()) {
                    store.remove(name);
                }
                List<Credentials> credentials = dialog.getCredentials();
                for (Credentials cred : credentials) {
                    store.add(cred);
                }
            }
        }
    });
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) CredentialsStore(org.knime.core.node.workflow.CredentialsStore) CredentialVariablesDialog(org.knime.workbench.ui.masterkey.CredentialVariablesDialog) List(java.util.List) Credentials(org.knime.core.node.workflow.Credentials) Display(org.eclipse.swt.widgets.Display)

Example 2 with CredentialVariablesDialog

use of org.knime.workbench.ui.masterkey.CredentialVariablesDialog in project knime-core by knime.

the class GUIWorkflowLoadHelper method loadCredentials.

/**
 * {@inheritDoc}
 */
@Override
public List<Credentials> loadCredentials(final List<Credentials> credentialsList) {
    // set the ones that were already prompted for into the result list ... don't prompt them again
    final List<Credentials> newCredentialsList = new ArrayList<Credentials>();
    final List<Credentials> credentialsToBePromptedList = new ArrayList<Credentials>();
    for (Credentials c : credentialsList) {
        Credentials updatedCredentials = m_promptedCredentials.get(c.getName());
        if (updatedCredentials != null) {
            newCredentialsList.add(updatedCredentials);
        } else {
            credentialsToBePromptedList.add(c);
        }
    }
    // prompt for details for the credentials that haven't been prompted for
    if (!credentialsToBePromptedList.isEmpty()) {
        // run sync'ly in UI thread
        m_display.syncExec(new Runnable() {

            @Override
            public void run() {
                CredentialVariablesDialog dialog = new CredentialVariablesDialog(m_display.getActiveShell(), credentialsToBePromptedList, m_workflowName);
                if (dialog.open() == Window.OK) {
                    List<Credentials> updateCredentialsList = dialog.getCredentials();
                    newCredentialsList.addAll(updateCredentialsList);
                    updateCredentialsList.stream().filter(c -> StringUtils.isNotEmpty(c.getPassword())).forEach(c -> m_promptedCredentials.put(c.getName(), c));
                } else {
                    newCredentialsList.addAll(credentialsToBePromptedList);
                }
            }
        });
    }
    return newCredentialsList;
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) KNIMEConstants(org.knime.core.node.KNIMEConstants) LoadVersion(org.knime.core.node.workflow.FileWorkflowPersistor.LoadVersion) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) HashMap(java.util.HashMap) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) Display(org.eclipse.swt.widgets.Display) CredentialVariablesDialog(org.knime.workbench.ui.masterkey.CredentialVariablesDialog) AtomicReference(java.util.concurrent.atomic.AtomicReference) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File) PreferenceConstants(org.knime.workbench.ui.preferences.PreferenceConstants) ArrayList(java.util.ArrayList) Version(org.knime.core.util.Version) List(java.util.List) Window(org.eclipse.jface.window.Window) Map(java.util.Map) SWT(org.eclipse.swt.SWT) Credentials(org.knime.core.node.workflow.Credentials) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) KNIMEUIPlugin(org.knime.workbench.ui.KNIMEUIPlugin) URI(java.net.URI) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) WorkflowLoadHelper(org.knime.core.node.workflow.WorkflowLoadHelper) ArrayList(java.util.ArrayList) CredentialVariablesDialog(org.knime.workbench.ui.masterkey.CredentialVariablesDialog) ArrayList(java.util.ArrayList) List(java.util.List) Credentials(org.knime.core.node.workflow.Credentials)

Aggregations

List (java.util.List)2 Display (org.eclipse.swt.widgets.Display)2 Credentials (org.knime.core.node.workflow.Credentials)2 CredentialVariablesDialog (org.knime.workbench.ui.masterkey.CredentialVariablesDialog)2 File (java.io.File)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 StringUtils (org.apache.commons.lang3.StringUtils)1 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 Window (org.eclipse.jface.window.Window)1 SWT (org.eclipse.swt.SWT)1 KNIMEConstants (org.knime.core.node.KNIMEConstants)1 CredentialsStore (org.knime.core.node.workflow.CredentialsStore)1 LoadVersion (org.knime.core.node.workflow.FileWorkflowPersistor.LoadVersion)1