Package net.sphene.goim.rcp.views

Source Code of net.sphene.goim.rcp.views.ContactListView

/*
* 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.views;

import net.sphene.goim.rcp.GOIMPlugin;
import net.sphene.goim.rcp.beans.GOIMAccount;
import net.sphene.goim.rcp.beans.GOIMAccountList;
import net.sphene.goim.rcp.extensionpoints.GameExtensionPoint;
import net.sphene.goim.rcp.extensionpoints.IContactListView;
import net.sphene.goim.rcp.ui.ContactList;
import net.sphene.goim.rcp.ui.GOIMIcons;
import net.sphene.goim.rcp.xmpp.StatusChangedEvent;
import net.sphene.libs.SpheneListener;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.ViewPart;

public class ContactListView extends ViewPart implements IContactListView {
  public static final String ID = "net.sphene.goim.rcp.views.contactlist";
  ContactList contactList;
 
  GOIMAccountList accountList;
  GOIMAccount account;

  /**
   * This is a callback that will allow us to create the viewer and initialize
   * it.
   */
  public void createPartControl(Composite parent) {
    //parent.setLayout(new GridLayout());
    contactList = new ContactList(parent,SWT.NONE,this);
    GameExtensionPoint.getGameExtensions();
    //list.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
    if(accountList != null)
      contactList.initWithAccountList(accountList);
    else if(account != null)
      contactList.initWithAccount(account);
    else
      contactList.initWithout();
//    contactList.addListener(SWT.Dispose,new Listener() {
//      public void handleEvent(Event event) {
//        closeContactList();
//      } });
  }

  /**
   * Passing the focus request to the viewer's control.
   */
  public void setFocus() {
  }

  @Override
  public void init(IViewSite site, IMemento memento) throws PartInitException {
    super.init(site, memento);
    System.out.println("ContactListView.init...");
    if(memento != null) {
      Integer handleListInt = memento.getInteger("handleslist");
      if(handleListInt == null) return;
      boolean handlesList = (handleListInt==1?true:false);
      if(handlesList)
        accountList = GOIMPlugin.getPreferenceObject(GOIMAccountList.class);
      else {
        String accountName = memento.getString("account");
        if(accountName != null)
          account = GOIMPlugin.getAccountList().getByName(accountName);
      }
    }
  }

  @Override
  public void saveState(IMemento memento) {
    super.saveState(memento);
    boolean handlesList = contactList.managesAllAccounts();
    memento.putInteger("handleslist",(handlesList?1:0));
    if(!handlesList && contactList.getAccount() != null)
      memento.putString("account",contactList.getAccount().name);
  }

  public void initWithAccountList(GOIMAccountList list) {
    contactList.initWithAccountList(list);
  }

  public void initWithAccount(final GOIMAccount account) {
    setPartName("GOIM: " + account.name);
    account.xmpp.ownPresenceChanged.addListener(new SpheneListener<StatusChangedEvent>() {
      public void handleEvent(StatusChangedEvent event) {
        setTitleImage(GOIMIcons.getImageForPresence(null,account.xmpp.getOwnPresence()));
      } });
    setTitleImage(GOIMIcons.getImageForPresence(null,account.xmpp.getOwnPresence()));
    contactList.initWithAccount(account);
  }

  public void closeContactList() {
    contactList.closeContactList();
    getViewSite().getPage().hideView(this);
  }

  public Shell getShell() {
    return getViewSite().getShell();
  }

  public GOIMAccountList getAccountList() {
    return contactList.getAccountList();
  }

  public GOIMAccount getActiveAccount() {
    return contactList.getActiveAccount();
  }

  public Menu getActiveAccountContextMenu(GOIMAccount activeAccount) {
    return contactList.getActiveAccountContextMenu(activeAccount);
  }
}
TOP

Related Classes of net.sphene.goim.rcp.views.ContactListView

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.