/*
* Gamers Own Instant Messenger
* Copyright (C) 2005-2006 Herbert Poul (kahless@sphene.net)
* http://goim.sphene.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package net.sphene.goim.rcp.ui.preferences;
import net.sphene.goim.rcp.beans.GOIMAccount;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.jivesoftware.smack.util.StringUtils;
public class GOIMPreferencePageEditAccount {
private Shell sShell = null; // @jve:decl-index=0:visual-constraint="10,10"
private TabFolder tabFolder = null;
private Composite editAccountParent = null;
private Composite composite = null;
private Label lblAccountName = null;
private Text accountName = null;
private Label lblJabberID = null;
private Text jabberID = null;
private Label lblPassword = null;
private Text password = null;
@SuppressWarnings("unused")
private Label label = null;
private Button saveButton = null;
private GOIMAccount account;
private Label lblResource = null;
private Text resource = null;
private Label lblResourcePriority = null;
private Text resourcePriority = null;
private Shell parent;
private Button useCustomHost = null;
private Text customHost;
private Composite customComposite = null;
private Label labelCustomPort = null;
private Text customPort = null;
private Button useSSL = null;
private Button autoConnect;
public GOIMPreferencePageEditAccount() {
this(null,(Shell)null);
}
public GOIMPreferencePageEditAccount(GOIMAccount account, Shell parent) {
this.parent = parent;
createSShell();
sShell.open();
this.account = account;
fillWithData();
}
public GOIMPreferencePageEditAccount(GOIMAccount account, Composite parent, boolean onlyCreateEditAccount, boolean noSaveButton) {
editAccountParent = parent;
createComposite();
}
public void fillWithData() {
accountName.setText(account.name);
jabberID.setText(account.jid);
password.setText(account.password);
resource.setText(account.resource);
useSSL.setSelection(account.useSSL);
resourcePriority.setText(Integer.toString(account.resourcePriority));
useCustomHost.setSelection(account.customHost != null);
customHost.setEnabled(useCustomHost.getSelection());
customPort.setEnabled(useCustomHost.getSelection());
customHost.setText(account.getServer());
customPort.setText(Integer.toString(account.getPort()));
autoConnect.setSelection(account.autoConnect);
}
/**
* This method initializes sShell
*/
private void createSShell() {
if(parent == null)
sShell = new Shell();
else
sShell = new Shell(parent,SWT.APPLICATION_MODAL | SWT.SHELL_TRIM);
sShell.setText("Edit Account");
sShell.setLayout(new FillLayout());
createTabFolder();
sShell.setSize(new org.eclipse.swt.graphics.Point(412,264));
sShell.pack();
}
/**
* This method initializes tabFolder
*
*/
private void createTabFolder() {
editAccountParent = tabFolder = new TabFolder(sShell, SWT.NONE);
createComposite();
TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setText("Account");
tabItem.setControl(composite);
}
/**
* This method initializes composite
*
*/
private void createComposite() {
GridData gridData61 = new org.eclipse.swt.layout.GridData();
gridData61.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData61.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
gridData61.grabExcessHorizontalSpace = true;
GridData gridData51 = new org.eclipse.swt.layout.GridData();
gridData51.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData51.grabExcessHorizontalSpace = true;
gridData51.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
GridData gridData41 = new org.eclipse.swt.layout.GridData();
gridData41.horizontalSpan = 2;
gridData41.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
gridData41.horizontalAlignment = org.eclipse.swt.layout.GridData.CENTER;
GridLayout gridLayout3 = new GridLayout();
gridLayout3.numColumns = 3;
gridLayout3.marginHeight = 0;
gridLayout3.marginWidth = 0;
GridData gridData11 = new org.eclipse.swt.layout.GridData();
gridData11.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData11.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
gridData11.grabExcessHorizontalSpace = true;
GridData gridData31 = new org.eclipse.swt.layout.GridData();
gridData31.grabExcessHorizontalSpace = true;
gridData31.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
gridData31.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
GridData gridData21 = new org.eclipse.swt.layout.GridData();
gridData21.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData21.grabExcessHorizontalSpace = true;
gridData21.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
GridData gridData6 = new org.eclipse.swt.layout.GridData();
gridData6.horizontalAlignment = org.eclipse.swt.layout.GridData.CENTER;
gridData6.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
GridData gridData5 = new org.eclipse.swt.layout.GridData();
gridData5.grabExcessHorizontalSpace = false;
gridData5.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
gridData5.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
GridData gridData4 = new org.eclipse.swt.layout.GridData();
gridData4.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData4.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
GridData gridData3 = new org.eclipse.swt.layout.GridData();
gridData3.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData3.grabExcessHorizontalSpace = false;
gridData3.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
GridData gridData2 = new org.eclipse.swt.layout.GridData();
gridData2.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData2.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
GridData gridData1 = new org.eclipse.swt.layout.GridData();
gridData1.grabExcessHorizontalSpace = true;
gridData1.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
gridData1.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
GridData gridData = new org.eclipse.swt.layout.GridData();
gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = org.eclipse.swt.layout.GridData.CENTER;
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
gridLayout.makeColumnsEqualWidth = true;
composite = new Composite(editAccountParent, SWT.NONE);
composite.setLayout(gridLayout);
lblAccountName = new Label(composite, SWT.NONE);
lblAccountName.setText("Account Name");
lblAccountName.setLayoutData(gridData1);
accountName = new Text(composite, SWT.BORDER);
accountName.setEditable(false);
accountName.setEnabled(false);
accountName.setLayoutData(gridData);
lblJabberID = new Label(composite, SWT.NONE);
lblJabberID.setText("Jabber ID");
lblJabberID.setLayoutData(gridData5);
jabberID = new Text(composite, SWT.BORDER);
jabberID.setLayoutData(gridData2);
useSSL = new Button(composite, SWT.CHECK);
useSSL.setText("Use SSL Connection");
useSSL.setLayoutData(gridData41);
useSSL.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
if(!useCustomHost.getSelection())
customPort.setText(Integer.toString(useSSL.getSelection() ? GOIMAccount.DEFAULT_PORT_SSL : GOIMAccount.DEFAULT_PORT));
}
});
jabberID.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
if(!useCustomHost.getSelection())
customHost.setText(StringUtils.parseServer(jabberID.getText()));
}
});
useCustomHost = new Button(composite, SWT.CHECK);
useCustomHost.setText("Connect to Custom Host");
useCustomHost
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
customHost.setEnabled(useCustomHost.getSelection());
customPort.setEnabled(useCustomHost.getSelection());
if(!useCustomHost.getSelection()) {
customHost.setText(StringUtils.parseServer(jabberID.getText()));
customPort.setText(Integer.toString(useSSL.getSelection() ? GOIMAccount.DEFAULT_PORT_SSL : GOIMAccount.DEFAULT_PORT));
}
}
});
customComposite = new Composite(composite, SWT.NULL);
customComposite.setLayout(gridLayout3);
customComposite.setLayoutData(gridData51);
customHost = new Text(customComposite, SWT.BORDER);
customHost.setLayoutData(gridData11);
labelCustomPort = new Label(customComposite, SWT.NONE);
labelCustomPort.setText(":");
customPort = new Text(customComposite, SWT.BORDER);
customPort.setLayoutData(gridData61);
lblPassword = new Label(composite, SWT.NONE);
lblPassword.setText("Password");
lblPassword.setLayoutData(gridData4);
password = new Text(composite, SWT.BORDER);
password.setEchoChar('*');
password.setLayoutData(gridData3);
lblResource = new Label(composite, SWT.NONE);
lblResource.setText("Resource");
resource = new Text(composite, SWT.BORDER);
resource.setLayoutData(gridData21);
lblResourcePriority = new Label(composite, SWT.NONE);
lblResourcePriority.setText("Resource Priority");
resourcePriority = new Text(composite, SWT.BORDER | SWT.RIGHT);
resourcePriority.setLayoutData(gridData31);
autoConnect = new Button(composite, SWT.CHECK);
autoConnect.setText("Automatically connect when starting GOIM");
autoConnect.setLayoutData(new GridData(SWT.FILL,SWT.CENTER,true,false,2,1));
label = new Label(composite, SWT.NONE);
saveButton = new Button(composite, SWT.NONE);
saveButton.setText("Save Account");
saveButton.setLayoutData(gridData6);
saveButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
account.name = accountName.getText();
account.jid = jabberID.getText();
account.password = password.getText();
account.resource = resource.getText();
account.resourcePriority = Integer.parseInt(resourcePriority.getText());
account.useSSL = useSSL.getSelection();
account.customPort = Integer.parseInt(customPort.getText());
if(useCustomHost.getSelection())
account.customHost = customHost.getText();
else
account.customHost = null;
account.autoConnect = autoConnect.getSelection();
account.fireChangeEvent();
sShell.close();
}
});
}
}