Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-09-19 01:17:06 -0400
committerEike Stepper2013-09-19 01:17:06 -0400
commitc1574d75a9bf1ff76a2a6a56edcda2e1dcad8d72 (patch)
tree8368fe178c9dd9848611902642241f047b12ff3c
parent0a166de53ef098b48cf3a173de3342acfd8112ce (diff)
downloadcdo-c1574d75a9bf1ff76a2a6a56edcda2e1dcad8d72.tar.gz
cdo-c1574d75a9bf1ff76a2a6a56edcda2e1dcad8d72.tar.xz
cdo-c1574d75a9bf1ff76a2a6a56edcda2e1dcad8d72.zip
[417560] [UI] Remember user names in CredentialsDialog
https://bugs.eclipse.org/bugs/show_bug.cgi?id=417560
-rw-r--r--plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF30
-rw-r--r--plugins/org.eclipse.net4j.util.ui/build.properties3
-rw-r--r--plugins/org.eclipse.net4j.util.ui/icons/credentials_wiz.gifbin0 -> 3335 bytes
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/CredentialsDialog.java106
-rw-r--r--plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/BaseDialog.java64
5 files changed, 173 insertions, 30 deletions
diff --git a/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF
index 77ab8f743c..d52c1d7a76 100644
--- a/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.util.ui/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.net4j.util.ui;singleton:=true
-Bundle-Version: 3.3.100.qualifier
+Bundle-Version: 3.4.0.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
@@ -15,17 +15,17 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.5.0,4.0.0)";visibility:=reexport,
org.eclipse.net4j.util;bundle-version="[3.0.0,4.0.0)";visibility:=reexport,
org.eclipse.net4j.ui.shared;bundle-version="[4.0.0,5.0.0)"
-Export-Package: org.eclipse.net4j.util.internal.ui;version="3.3.100";x-internal:=true,
- org.eclipse.net4j.util.internal.ui.actions;version="3.3.100";x-internal:=true,
- org.eclipse.net4j.util.internal.ui.bundle;version="3.3.100";x-internal:=true,
- org.eclipse.net4j.util.internal.ui.messages;version="3.3.100";x-internal:=true,
- org.eclipse.net4j.util.internal.ui.views;version="3.3.100";x-internal:=true,
- org.eclipse.net4j.util.ui;version="3.3.100",
- org.eclipse.net4j.util.ui.actions;version="3.3.100",
- org.eclipse.net4j.util.ui.container;version="3.3.100",
- org.eclipse.net4j.util.ui.dnd;version="3.3.100",
- org.eclipse.net4j.util.ui.prefs;version="3.3.100",
- org.eclipse.net4j.util.ui.proposals;version="3.3.100",
- org.eclipse.net4j.util.ui.security;version="3.3.100",
- org.eclipse.net4j.util.ui.views;version="3.3.100",
- org.eclipse.net4j.util.ui.widgets;version="3.3.100"
+Export-Package: org.eclipse.net4j.util.internal.ui;version="3.4.0";x-internal:=true,
+ org.eclipse.net4j.util.internal.ui.actions;version="3.4.0";x-internal:=true,
+ org.eclipse.net4j.util.internal.ui.bundle;version="3.4.0";x-internal:=true,
+ org.eclipse.net4j.util.internal.ui.messages;version="3.4.0";x-internal:=true,
+ org.eclipse.net4j.util.internal.ui.views;version="3.4.0";x-internal:=true,
+ org.eclipse.net4j.util.ui;version="3.4.0",
+ org.eclipse.net4j.util.ui.actions;version="3.4.0",
+ org.eclipse.net4j.util.ui.container;version="3.4.0",
+ org.eclipse.net4j.util.ui.dnd;version="3.4.0",
+ org.eclipse.net4j.util.ui.prefs;version="3.4.0",
+ org.eclipse.net4j.util.ui.proposals;version="3.4.0",
+ org.eclipse.net4j.util.ui.security;version="3.4.0",
+ org.eclipse.net4j.util.ui.views;version="3.4.0",
+ org.eclipse.net4j.util.ui.widgets;version="3.4.0"
diff --git a/plugins/org.eclipse.net4j.util.ui/build.properties b/plugins/org.eclipse.net4j.util.ui/build.properties
index da7c2b7d2d..d2ea48877b 100644
--- a/plugins/org.eclipse.net4j.util.ui/build.properties
+++ b/plugins/org.eclipse.net4j.util.ui/build.properties
@@ -17,7 +17,8 @@ bin.includes = META-INF/,\
about.html,\
copyright.txt,\
plugin.properties,\
- plugin.xml
+ plugin.xml,\
+ icons/
src.includes = about.html,\
copyright.txt
diff --git a/plugins/org.eclipse.net4j.util.ui/icons/credentials_wiz.gif b/plugins/org.eclipse.net4j.util.ui/icons/credentials_wiz.gif
new file mode 100644
index 0000000000..dc5a3202d7
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util.ui/icons/credentials_wiz.gif
Binary files differ
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/CredentialsDialog.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/CredentialsDialog.java
index 81fb77364e..5ca332b2f7 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/CredentialsDialog.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/security/CredentialsDialog.java
@@ -17,15 +17,22 @@ import org.eclipse.net4j.util.security.PasswordCredentials;
import org.eclipse.net4j.util.ui.UIUtil;
import org.eclipse.net4j.util.ui.widgets.BaseDialog;
+import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
/**
* @author Eike Stepper
* @since 2.0
@@ -42,7 +49,9 @@ public class CredentialsDialog extends BaseDialog<Viewer>
private final String realm;
- private Text userIDControl;
+ private final List<String> users;
+
+ private Control userIDControl;
private Text passwordControl;
@@ -58,8 +67,10 @@ public class CredentialsDialog extends BaseDialog<Viewer>
*/
public CredentialsDialog(Shell shell, String realm)
{
- super(shell, DEFAULT_SHELL_STYLE | SWT.APPLICATION_MODAL, TITLE, MESSAGE, OM.Activator.INSTANCE.getDialogSettings());
+ super(shell, DEFAULT_SHELL_STYLE | SWT.APPLICATION_MODAL, TITLE, MESSAGE, OM.Activator.INSTANCE.getDialogSettings(), OM
+ .getImageDescriptor("icons/credentials_wiz.gif"));
this.realm = realm;
+ users = loadUsers();
}
/**
@@ -70,6 +81,11 @@ public class CredentialsDialog extends BaseDialog<Viewer>
return realm;
}
+ public IPasswordCredentials getCredentials()
+ {
+ return credentials;
+ }
+
@Override
protected void configureShell(Shell newShell)
{
@@ -91,11 +107,6 @@ public class CredentialsDialog extends BaseDialog<Viewer>
}
}
- public IPasswordCredentials getCredentials()
- {
- return credentials;
- }
-
@Override
protected void createUI(Composite parent)
{
@@ -104,20 +115,97 @@ public class CredentialsDialog extends BaseDialog<Viewer>
composite.setLayout(new GridLayout(2, false));
new Label(composite, SWT.NONE).setText(Messages.getString("CredentialsDialog_2")); //$NON-NLS-1$
- userIDControl = new Text(composite, SWT.BORDER);
+ if (users.isEmpty())
+ {
+ userIDControl = new Text(composite, SWT.BORDER);
+ }
+ else
+ {
+ Combo combo = new Combo(composite, SWT.BORDER);
+ combo.setItems(users.toArray(new String[users.size()]));
+ combo.setText(users.get(0));
+
+ userIDControl = combo;
+ }
+
userIDControl.setLayoutData(UIUtil.createGridData(true, false));
new Label(composite, SWT.NONE).setText(Messages.getString("CredentialsDialog_3")); //$NON-NLS-1$
passwordControl = new Text(composite, SWT.BORDER | SWT.PASSWORD);
passwordControl.setLayoutData(UIUtil.createGridData(true, false));
+
+ if (userIDControl instanceof Combo)
+ {
+ passwordControl.setFocus();
+ }
}
@Override
protected void okPressed()
{
- String userID = userIDControl.getText();
+ String userID;
+ if (userIDControl instanceof Combo)
+ {
+ userID = ((Combo)userIDControl).getText();
+ }
+ else
+ {
+ userID = ((Text)userIDControl).getText();
+ }
+
String password = passwordControl.getText();
credentials = new PasswordCredentials(userID, password.toCharArray());
+
+ users.remove(userID);
+ users.add(0, userID);
+ saveUsers(users);
+
super.okPressed();
}
+
+ /**
+ * @since 3.4
+ */
+ protected List<String> loadUsers()
+ {
+ List<String> result = new ArrayList<String>();
+
+ IDialogSettings settings = getUsersSection();
+ String key = getRealmKey();
+
+ String[] users = settings.getArray(key);
+ if (users != null && users.length != 0)
+ {
+ result.addAll(Arrays.asList(users));
+ }
+
+ return result;
+ }
+
+ /**
+ * @since 3.4
+ */
+ protected void saveUsers(List<String> users)
+ {
+ IDialogSettings settings = getUsersSection();
+ String key = getRealmKey();
+
+ settings.put(key, users.toArray(new String[users.size()]));
+ }
+
+ private String getRealmKey()
+ {
+ String key = "realm";
+ if (realm != null)
+ {
+ key += realm;
+ }
+
+ return key;
+ }
+
+ private IDialogSettings getUsersSection()
+ {
+ return getDialogSettings("users");
+ }
}
diff --git a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/BaseDialog.java b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/BaseDialog.java
index bf7dda08ac..3603305ed3 100644
--- a/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/BaseDialog.java
+++ b/plugins/org.eclipse.net4j.util.ui/src/org/eclipse/net4j/util/ui/widgets/BaseDialog.java
@@ -15,8 +15,10 @@ import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
@@ -24,6 +26,7 @@ import org.eclipse.swt.widgets.Shell;
/**
* @author Eike Stepper
+ * @since 3.4
*/
public abstract class BaseDialog<VIEWER extends Viewer> extends TitleAreaDialog
{
@@ -33,19 +36,35 @@ public abstract class BaseDialog<VIEWER extends Viewer> extends TitleAreaDialog
private String message;
+ private Image image;
+
private IDialogSettings settings;
private VIEWER currentViewer;
private MenuManager contextMenu;
- public BaseDialog(Shell parentShell, int shellStyle, String title, String message, IDialogSettings settings)
+ /**
+ * @since 3.4
+ */
+ public BaseDialog(Shell parentShell, int shellStyle, String title, String message, IDialogSettings settings,
+ ImageDescriptor descriptor)
{
super(parentShell);
setShellStyle(shellStyle);
this.title = title;
this.message = message;
this.settings = settings;
+
+ if (descriptor != null)
+ {
+ image = descriptor.createImage(parentShell.getDisplay());
+ }
+ }
+
+ public BaseDialog(Shell parentShell, int shellStyle, String title, String message, IDialogSettings settings)
+ {
+ this(parentShell, DEFAULT_SHELL_STYLE, title, message, settings, null);
}
public BaseDialog(Shell parentShell, String title, String message, IDialogSettings settings)
@@ -64,8 +83,13 @@ public abstract class BaseDialog<VIEWER extends Viewer> extends TitleAreaDialog
protected Control createDialogArea(Composite parent)
{
Composite composite = (Composite)super.createDialogArea(parent);
+
setTitle(title);
setMessage(message);
+ if (image != null)
+ {
+ setTitleImage(image);
+ }
contextMenu = new MenuManager("#PopupMenu"); //$NON-NLS-1$
contextMenu.setRemoveAllWhenShown(true);
@@ -126,20 +150,50 @@ public abstract class BaseDialog<VIEWER extends Viewer> extends TitleAreaDialog
{
}
- @Override
- protected IDialogSettings getDialogBoundsSettings()
+ /**
+ * @since 3.4
+ */
+ protected IDialogSettings getDialogSettings()
{
+ return settings;
+ }
+
+ /**
+ * @since 3.4
+ */
+ protected IDialogSettings getDialogSettings(String sectionName)
+ {
+ IDialogSettings settings = getDialogSettings();
if (settings == null)
{
return null;
}
- IDialogSettings section = settings.getSection(title);
+ sectionName = getClass().getName() + "_" + sectionName;
+ IDialogSettings section = settings.getSection(sectionName);
if (section == null)
{
- section = settings.addNewSection(title);
+ section = settings.addNewSection(sectionName);
}
return section;
}
+
+ @Override
+ protected IDialogSettings getDialogBoundsSettings()
+ {
+ return getDialogSettings("bounds");
+ }
+
+ @Override
+ public boolean close()
+ {
+ if (image != null)
+ {
+ image.dispose();
+ image = null;
+ }
+
+ return super.close();
+ }
}

Back to the top