]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/auth/LoginDialog.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / auth / LoginDialog.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.ui.auth;\r
13 \r
14 import org.eclipse.jface.dialogs.IDialogSettings;\r
15 import org.eclipse.jface.dialogs.TrayDialog;\r
16 import org.eclipse.jface.layout.GridDataFactory;\r
17 import org.eclipse.swt.SWT;\r
18 import org.eclipse.swt.graphics.Point;\r
19 import org.eclipse.swt.widgets.Composite;\r
20 import org.eclipse.swt.widgets.Control;\r
21 import org.eclipse.swt.widgets.Shell;\r
22 import org.simantics.ui.auth.model.LoginModel;\r
23 \r
24 /**\r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public class LoginDialog extends TrayDialog {\r
28 \r
29     private static final String LOGIN_DIALOG = "LoginDialog"; //$NON-NLS-1$\r
30 \r
31     private IDialogSettings     dialogBoundsSettings;\r
32 \r
33     private LoginComposite      c;\r
34 \r
35     private final LoginModel          model;\r
36 \r
37     protected LoginDialog(Shell parentShell, IDialogSettings settings, LoginModel model) {\r
38         super(parentShell);\r
39         this.model = model;\r
40 \r
41         dialogBoundsSettings = settings.getSection(LOGIN_DIALOG);\r
42         if (dialogBoundsSettings == null)\r
43             dialogBoundsSettings = settings.addNewSection(LOGIN_DIALOG);\r
44     }\r
45 \r
46     @Override\r
47     protected int getShellStyle() {\r
48         return super.getShellStyle() /*| SWT.RESIZE */;\r
49     }\r
50 \r
51     @Override\r
52     protected void configureShell(Shell newShell) {\r
53         newShell.setText("Login - " + model.getServer().getName());\r
54         super.configureShell(newShell);\r
55     }\r
56 \r
57     @Override\r
58     protected Control createDialogArea(Composite parent) {\r
59         Composite composite = (Composite) super.createDialogArea(parent);\r
60 \r
61         c = new LoginComposite(composite, SWT.NONE, model);\r
62 \r
63         GridDataFactory.fillDefaults().grab(true, false).applyTo(c);\r
64 \r
65         applyDialogFont(composite);\r
66 \r
67         return composite;\r
68     }\r
69 \r
70     @Override\r
71     protected IDialogSettings getDialogBoundsSettings() {\r
72         return dialogBoundsSettings;\r
73     }\r
74 \r
75     @Override\r
76     protected Point getInitialSize() {\r
77         Point defaultSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true);\r
78         Point result = super.getInitialSize();\r
79         if (defaultSize.equals(result))\r
80             return new Point(400, 220);\r
81         return result;\r
82     }\r
83 \r
84     @Override\r
85     protected void createButtonsForButtonBar(Composite parent) {\r
86         super.createButtonsForButtonBar(parent);\r
87     }\r
88 \r
89 }\r