1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.ui.auth;
14 import org.eclipse.jface.layout.GridDataFactory;
15 import org.eclipse.jface.layout.GridLayoutFactory;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.FocusEvent;
18 import org.eclipse.swt.events.FocusListener;
19 import org.eclipse.swt.events.ModifyEvent;
20 import org.eclipse.swt.events.ModifyListener;
21 import org.eclipse.swt.events.SelectionAdapter;
22 import org.eclipse.swt.events.SelectionEvent;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Label;
26 import org.eclipse.swt.widgets.Text;
27 import org.simantics.ui.auth.model.LoginModel;
30 * @author Tuukka Lehtonen
32 public class LoginComposite extends Composite {
34 // private FormToolkit toolkit;
36 private LoginModel model;
38 public LoginComposite(Composite parent, int style, LoginModel m) {
43 // toolkit = new FormToolkit(parent.getDisplay());
45 Composite body = this;
46 GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(2).applyTo(body);
47 GridDataFactory.fillDefaults().grab(true, true).applyTo(body);
49 Label desc = new Label(this, 0);
50 desc.setText("Enter credentials for " + model.getServer().getInfo());
51 GridDataFactory.fillDefaults().span(2, 1).applyTo(desc);
53 // Label nameLabel = toolkit.createLabel(this, "User name:");
54 Label nameLabel = new Label(this, 0);
55 nameLabel.setText("&User name:");
56 GridDataFactory.fillDefaults().align(SWT.LEAD, SWT.CENTER).applyTo(nameLabel);
57 // final Text nameText = toolkit.createText(this, "", SWT.NONE);
58 final Text nameText = new Text(this, SWT.BORDER);
59 nameText.setText(model.getName());
60 GridDataFactory.fillDefaults().grab(true, false).applyTo(nameText);
62 // Label passwordLabel = toolkit.createLabel(this, "Password:");
63 Label passwordLabel = new Label(this, 0);
64 passwordLabel.setText("&Password:");
65 GridDataFactory.fillDefaults().align(SWT.LEAD, SWT.CENTER).applyTo(passwordLabel);
66 // final Text passwordText = toolkit.createText(this, "", SWT.NONE);
67 final Text passwordText = new Text(this, SWT.PASSWORD | SWT.BORDER);
68 passwordText.setText(model.getPassword());
69 GridDataFactory.fillDefaults().grab(true, false).applyTo(passwordText);
71 // final Button rememberButton = toolkit.createButton(this, "Remember Login", SWT.CHECK);
72 final Button rememberButton = new Button(this, SWT.CHECK);
73 rememberButton.setText("&Remember Login");
74 GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(rememberButton);
76 // Build the separator line
77 Label separator = new Label(this, SWT.HORIZONTAL | SWT.SEPARATOR);
78 GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BOTTOM).span(2, 1).grab(false, true).applyTo(separator);
80 nameText.addModifyListener(new ModifyListener() {
82 public void modifyText(ModifyEvent e) {
83 model.setName(nameText.getText());
86 passwordText.addModifyListener(new ModifyListener() {
88 public void modifyText(ModifyEvent e) {
89 model.setPassword(passwordText.getText());
92 rememberButton.addSelectionListener(new SelectionAdapter() {
94 public void widgetSelected(SelectionEvent e) {
95 model.setRemember(rememberButton.getSelection());
99 new FocusSelector(nameText);
100 new FocusSelector(passwordText);
103 static class FocusSelector implements FocusListener {
105 FocusSelector(Text text) {
107 text.addFocusListener(this);
110 public void focusGained(FocusEvent e) {
114 public void focusLost(FocusEvent e) {
115 text.setSelection(0);
120 public void dispose() {
122 // if (toolkit != null) {
123 // toolkit.dispose();