Skip to content

Commit

Permalink
save auto login state
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Melcher committed Jan 5, 2022
1 parent ef6d890 commit 28e271d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,41 @@ public class PasswordModelProvider {

private static Preferences prefsUi = InstanceScope.INSTANCE
.getNode("de.persosim.driver.connector.ui");

private static final String AUTO_LOGIN = "AUTO_LOGIN";
private static Preferences nodePassword = prefsUi.node("nodePwd");

private List<String> pins;
private boolean sort = true;
private String autoLogin = null;

public boolean getSort() {
return sort;
}

public String getAutoLogin() {
return autoLogin;
}

public void saveAutoLogin(String pin) {
this.autoLogin = pin;
prefsUi.put(AUTO_LOGIN, pin);
prefsUiFlush();
}

public void removeAutoLogin() {
autoLogin = null;
prefsUi.remove(AUTO_LOGIN);
prefsUiFlush();
}

public void setSort(boolean sort) {
this.sort = sort;
}

private PasswordModelProvider() {
pins = getPinsFromPrefs();
autoLogin = prefsUi.get(AUTO_LOGIN, null);
}

public static PasswordModelProvider getInstance() {
Expand Down Expand Up @@ -114,12 +134,7 @@ public void save(String userPin, String type, int index) {

}

try {
prefsUi.flush();
} catch (BackingStoreException e) {
log(getClass(), "could not save the password in the preferences file", LogLevel.ERROR);
e.printStackTrace();
}
prefsUiFlush();
}

public void deletePinsFromPrefs() {
Expand All @@ -144,4 +159,13 @@ public void deletePinsFromPrefs() {
}
getPinsFromPrefs();
}

private void prefsUiFlush() {
try {
prefsUi.flush();
} catch (BackingStoreException e) {
log(getClass(), "could not save the password in the preferences file", LogLevel.ERROR);
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ public void widgetSelected(SelectionEvent e) {

if (checkAutoLogin.getSelection()) {

passwordModelProvider.saveAutoLogin(viewer.getSelection().toString().replaceAll("\\D+", ""));

tablePwdManagement.setEnabled(false);
autologin = true;
pressedKeys.clear();
Expand All @@ -251,6 +253,7 @@ public void widgetSelected(SelectionEvent e) {

else {

passwordModelProvider.removeAutoLogin();
tablePwdManagement.setEnabled(true);
autologin = false;
txtOutput.setText("");
Expand All @@ -273,7 +276,7 @@ public void widgetDefaultSelected(SelectionEvent e) {




restoreAutoLoginState();


tablePwdManagement.setVisible(true);
Expand All @@ -289,6 +292,26 @@ private void placeholderColumn(Composite parent) {
label.setLayoutData(gd);
}

private void restoreAutoLoginState() {
String pin = passwordModelProvider.getAutoLogin();
if(pin != null)
{
checkAutoLogin.setEnabled(true);
checkAutoLogin.setSelection(true);
checkAutoLogin.setText("AutoLogin: [" + pin + "]");
tablePwdManagement.setEnabled(false);
autologin = true;
pressedKeys.clear();
char[] entries = pin.toCharArray();
for (int i = 0; i < entries.length; i++) {
char entry = entries[i];
setButton(String.valueOf(entry));
}

setButton("OK");
}
}

private TableViewer createPasswordTableViewer(Composite parent) {
viewer = new TableViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);

Expand All @@ -315,7 +338,6 @@ public String getText(Object element) {


viewer.setContentProvider(new ArrayContentProvider());

viewer.setInput(passwordModelProvider.getPins());
final Menu popupTable = new Menu(viewer.getTable());

Expand Down

0 comments on commit 28e271d

Please sign in to comment.