/*
* 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.GOIMPlugin;
import net.sphene.goim.rcp.beans.GOIMAbstractListEvent;
import net.sphene.goim.rcp.beans.GOIMAccount;
import net.sphene.goim.rcp.beans.GOIMAccountList;
import net.sphene.libs.SpheneEvent;
import net.sphene.libs.SpheneListener;
import org.eclipse.swt.SWT;
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.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
public class GOIMPreferencePageGUI extends Composite {
private Table profileTable = null;
private Composite profileChangeButtons = null;
private Button profileCreateButton = null;
private Button profileEdit = null;
private Button profileRemove = null;
private Group group = null;
private GOIMAccountList accountList;
private SpheneListener<SpheneEvent> accountChangeListener;
public GOIMPreferencePageGUI(Composite parent, int style) {
super(parent, style);
initialize();
fillData();
}
private void initialize() {
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
this.setLayout(gridLayout);
createGroup();
setSize(new org.eclipse.swt.graphics.Point(300,323));
}
protected void fillData() {
accountList = GOIMPlugin.getAccountList();
for(GOIMAccount acc : accountList) {
addAccountToTable(acc);
}
accountList.changeListenerList.addListener(accountChangeListener = new SpheneListener<SpheneEvent>(){
public void handleEvent(SpheneEvent sevent) {
GOIMAbstractListEvent event = (GOIMAbstractListEvent)sevent;
if(event.type == GOIMAbstractListEvent.TYPE_ADD) {
addAccountToTable((GOIMAccount)event.source);
new GOIMPreferencePageEditAccount((GOIMAccount)event.source,getShell());
} else {
for(TableItem item : profileTable.getItems()) {
if(item.getData("account").equals(event.source)) {
if(event.type == GOIMAbstractListEvent.TYPE_DEL) {
item.dispose();
} else if(event.type == GOIMAbstractListEvent.TYPE_EDIT) {
setAccountFields(item,(GOIMAccount)event.source);
}
break;
}
}
}
}});
this.addListener(SWT.Dispose,new Listener() {
public void handleEvent(Event event) {
accountList.changeListenerList.removeListener(accountChangeListener);
accountChangeListener = null;
}});
}
protected void addAccountToTable(GOIMAccount acc) {
TableItem item = new TableItem(profileTable,SWT.NULL);
setAccountFields(item,acc);
item.setData("account",acc);
}
protected void setAccountFields(TableItem item, GOIMAccount acc) {
item.setText(new String[] { acc.name, acc.jid });
}
/**
* This method initializes profileTable
*
*/
private void createProfileTable() {
GridData gridData1 = new org.eclipse.swt.layout.GridData();
gridData1.verticalSpan = 2;
gridData1.verticalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData1.grabExcessHorizontalSpace = true;
gridData1.grabExcessVerticalSpace = true;
gridData1.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
profileTable = new Table(group, SWT.FULL_SELECTION);
profileTable.setHeaderVisible(true);
profileTable.setLayoutData(gridData1);
profileTable.setLinesVisible(true);
TableColumn profileTableName = new TableColumn(profileTable, SWT.NONE);
profileTableName.setWidth(90);
profileTableName.setText("Name");
TableColumn profileTableJID = new TableColumn(profileTable, SWT.NONE);
profileTableJID.setWidth(90);
profileTableJID.setText("JID");
}
/**
* This method initializes profileChangeButtons
*
*/
private void createProfileChangeButtons() {
GridData gridData5 = new org.eclipse.swt.layout.GridData();
gridData5.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData5.verticalAlignment = 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.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;
profileChangeButtons = new Composite(group, SWT.NONE);
profileChangeButtons.setLayout(new GridLayout());
profileChangeButtons.setLayoutData(gridData5);
profileCreateButton = new Button(profileChangeButtons, SWT.NONE);
profileCreateButton.setText("Create");
profileCreateButton.setLayoutData(gridData3);
profileCreateButton
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
new GOIMPreferencePageCreateAccount(profileCreateButton.getShell());
}
});
profileEdit = new Button(profileChangeButtons, SWT.NONE);
profileEdit.setText("Edit");
profileEdit.setLayoutData(gridData2);
profileEdit.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
TableItem[] items = profileTable.getSelection();
if(items == null || items.length < 1) return;
new GOIMPreferencePageEditAccount((GOIMAccount)items[0].getData("account"),profileEdit.getShell());
}
});
profileRemove = new Button(profileChangeButtons, SWT.NONE);
profileRemove.setText("Remove");
profileRemove.setLayoutData(gridData4);
profileRemove
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
TableItem[] items = profileTable.getSelection();
if(items == null || items.length < 1) return;
accountList.remove(items[0].getData("account"));
}
});
}
/**
* This method initializes group
*
*/
private void createGroup() {
GridLayout gridLayout1 = new GridLayout();
gridLayout1.numColumns = 2;
GridData gridData = new org.eclipse.swt.layout.GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData.verticalAlignment = org.eclipse.swt.layout.GridData.FILL;
gridData.grabExcessVerticalSpace = true;
group = new Group(this, SWT.NONE);
group.setText("Accounts");
createProfileTable();
group.setLayoutData(gridData);
group.setLayout(gridLayout1);
createProfileChangeButtons();
}
} // @jve:decl-index=0:visual-constraint="10,10"