Package net.sphene.goim.rcp.ui

Source Code of net.sphene.goim.rcp.ui.AbstractContactList$HideOfflineContactsAction

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

import net.sphene.goim.rcp.GOIMPlugin;
import net.sphene.goim.rcp.beans.GOIMAccount;
import net.sphene.goim.rcp.extensionpoints.IAccountProvider;
import net.sphene.goim.rcp.ui.actions.ChangeStatusContribution;
import net.sphene.goim.rcp.ui.actions.account.AddContactAction;
import net.sphene.goim.rcp.ui.actions.account.EditVCardAction;
import net.sphene.goim.rcp.ui.actions.account.OpenServiceDiscoveryUIAction;
import net.sphene.goim.rcp.ui.actions.shortcuts.JoinGOIMMUCAction;
import net.sphene.goim.rcp.ui.actions.shortcuts.OpenSearchUIAction;
import net.sphene.goim.rcp.ui.menu.GOIMGlobalMenu;
import net.sphene.goim.rcp.ui.menu.GOIMMenuManager;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Menu;
import org.jivesoftware.smack.RosterEntry;

/**
* A very simple base class for Contact Lists. It just bundles a few things which might
* be useful for all Contact Lists. (not made userfriendly yet ;) .. just moved things
* here which i needed for {@link net.sphene.goim.rcp.ui.ContactList} as well as for
* {@link net.sphene.goim.rcp.simpleui.SimpleContactList} and didn't want to code
* twice.
* @author kahless
*/
public abstract class AbstractContactList extends Composite implements IAccountProvider {
  protected Menu contextMenu;
  protected Menu entryMenu;

  private GOIMAccount activeAccount;
  public GOIMAccount getActiveAccount() { return activeAccount; }
  protected void setActiveAccount(GOIMAccount account) {
    this.activeAccount = account;
    changeStatusContribution.setAccount(account);
  }
  protected RosterEntry selectedEntry;
  protected MenuManager contextMenuManager;
  private ChangeStatusContribution changeStatusContribution;
  private GOIMMenuManager actionsMenuManager;
  private MenuManager shortcutsMenuManager;

  public Menu getActiveAccountContextMenu(GOIMAccount activeAccount) {
    if(activeAccount != null) this.activeAccount = activeAccount;
    changeStatusContribution.setAccount(activeAccount);
    //updateCurrentContextMenu();
    return contextMenu;
  }
 
  public AbstractContactList(Composite parent, int style) {
    super(parent, style);
  }
 
  public abstract void setHideOfflineContacts(boolean hideOfflineContacts);
  public abstract boolean getHideOfflineContacts();

  protected void createMenu(Decorations parent) {
    contextMenuManager = new MenuManager();
    contextMenu = contextMenuManager.createContextMenu(parent);
    //contextMenu = new Menu(parent,SWT.POP_UP);
    MenuManager changeStatusManager = new MenuManager("Change Status");
    contextMenuManager.add(changeStatusManager);
    this.changeStatusContribution = new ChangeStatusContribution();
    this.changeStatusContribution.setAccount(activeAccount);
    changeStatusManager.add(changeStatusContribution);
   
    actionsMenuManager = new GOIMMenuManager("Actions");
    contextMenuManager.add(actionsMenuManager);
   
    actionsMenuManager.add(new AddContactAction(this));
    actionsMenuManager.add(new OpenServiceDiscoveryUIAction(this));
    actionsMenuManager.add(new EditVCardAction(this));
   
    shortcutsMenuManager = new MenuManager("Shortcuts");
    contextMenuManager.add(shortcutsMenuManager);
   
    shortcutsMenuManager.add(new OpenSearchUIAction(this,GOIMPlugin.defaultSearchService));
    shortcutsMenuManager.add(new JoinGOIMMUCAction(this,GOIMPlugin.defaultGOIMroom));

    contextMenuManager.add(new HideOfflineContactsAction(this));
   
    contextMenuManager.add(new Separator());
   
   
    GOIMGlobalMenu globalMenu = new GOIMGlobalMenu(contextMenuManager);
    globalMenu.createDefaultMenuItems(contextMenuManager);
   
    contextMenuManager.addMenuListener(new IMenuListener() {
      public void menuAboutToShow(IMenuManager manager) {
        updateCurrentContextMenu();
      }
    });
  }
  protected void updateCurrentContextMenu() {
    boolean isConnected = (activeAccount == null ? false : activeAccount.xmpp.isConnected());
    /*
    actionsItem.setEnabled(isConnected);
    shortcutsItem.setEnabled(isConnected);
   
    hideOfflineMenuItem.setSelection(getHideOfflineContacts());
    */
    actionsMenuManager.setVisible(isConnected);
    shortcutsMenuManager.setVisible(isConnected);
  }
 
 
  public static class HideOfflineContactsAction extends Action {
    private AbstractContactList contactList;

    public HideOfflineContactsAction(AbstractContactList contactList) {
      super("Hide Offline Contacts",Action.AS_CHECK_BOX);
      this.contactList = contactList;
      setChecked(contactList.getHideOfflineContacts());
    }

    @Override
    public void run() {
      contactList.setHideOfflineContacts(isChecked());
    }
   
  }
}
TOP

Related Classes of net.sphene.goim.rcp.ui.AbstractContactList$HideOfflineContactsAction

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.