summaryrefslogtreecommitdiff
path: root/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java')
-rw-r--r--java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java69
1 files changed, 62 insertions, 7 deletions
diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java
index dd9e792912..5eb9d9a168 100644
--- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java
+++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/actions/ReconnectServer.java
@@ -34,12 +34,15 @@ import org.apache.qpid.management.ui.views.TreeObject;
import org.apache.qpid.management.ui.views.ViewUtility;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
@@ -96,17 +99,34 @@ public class ReconnectServer extends AbstractAction implements IWorkbenchWindowA
// Create the login popup fot th user to enter usernaem and password
private void createLoginPopup()
{
+ final Shell appShell = _window.getShell();
+
Display display = Display.getCurrent();
final Shell shell = new Shell(display, SWT.BORDER | SWT.CLOSE);
shell.setText(_title);
shell.setImage(ApplicationRegistry.getImage(CONSOLE_IMAGE));
shell.setLayout(new GridLayout());
- int x = display.getBounds().width;
- int y = display.getBounds().height;
- shell.setBounds(x/3, y/3, 350, 200);
-
- createWidgets(shell);
+ createWidgets(shell);
+ shell.pack();
+
+ //get current size dialog, and application window size and location
+ int appWidth = appShell.getBounds().width;
+ int appHeight = appShell.getBounds().height;
+ int appLocX = appShell.getBounds().x;
+ int appLocY = appShell.getBounds().y;
+ int currentShellWidth = shell.getSize().x;
+ int currentShellHeight = shell.getSize().y;
+
+ //default sizes for the dialog
+ int minShellWidth = 350;
+ int minShellHeight= 200;
+ //ensure this is large enough, increase it if its not
+ int newShellWidth = currentShellWidth > minShellWidth ? currentShellWidth : minShellWidth;
+ int newShellHeight = currentShellHeight > minShellHeight ? currentShellHeight : minShellHeight;
+
+ //set the final size and centre the dialog within the app window
+ shell.setBounds((appWidth - newShellWidth)/2 + appLocX, (appHeight - newShellHeight)/2 + appLocY, newShellWidth, newShellHeight);
shell.open();
_window.getShell().setEnabled(false);
@@ -155,11 +175,27 @@ public class ReconnectServer extends AbstractAction implements IWorkbenchWindowA
textPwd.setText("");
textPwd.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+ //Get the text widgets
+ Control[] widgets = composite.getChildren();
+ for (int i=0; i < widgets.length; i++)
+ {
+ widgets[i].addKeyListener(new KeyAdapter()
+ {
+ public void keyPressed(KeyEvent event)
+ {
+ if (event.character == SWT.ESC)
+ {
+ //Escape key acts as cancel on all widgets
+ shell.dispose();
+ }
+ }
+ });
+ }
+
Composite buttonsComposite = new Composite(composite, SWT.NONE);
buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
buttonsComposite.setLayout(new GridLayout(2, true));
-
final Button connectButton = new Button(buttonsComposite, SWT.PUSH | SWT.CENTER);
connectButton.setText(Constants.BUTTON_CONNECT);
GridData gridData = new GridData (SWT.TRAIL, SWT.BOTTOM, true, true);
@@ -203,7 +239,26 @@ public class ReconnectServer extends AbstractAction implements IWorkbenchWindowA
{
shell.dispose();
}
- });
+ });
+
+ //Get the ok/cancel button widgets and add a new key listener
+ widgets = buttonsComposite.getChildren();
+ for (int i=0; i < widgets.length; i++)
+ {
+ widgets[i].addKeyListener(new KeyAdapter()
+ {
+ public void keyPressed(KeyEvent event)
+ {
+ if (event.character == SWT.ESC)
+ {
+ //Escape key acts as cancel on all widgets
+ shell.dispose();
+ }
+ }
+ });
+ }
+
+ shell.setDefaultButton(connectButton);
}
}