Package net.sphene.goim.rcp.ui.actions

Source Code of net.sphene.goim.rcp.ui.actions.LaunchGameContribution

/*
* File    : LaunchGameContribution.java
* Created : 02.04.2006
* By      : kahless
*
* GOIM - Gamers Own Instant Messenger
* Copyright (C) 2005-2006 Herbert Poul
*              (JabberId: kahless@sphene.net / Email: herbert.poul@gmail.com)
* 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.actions;

import net.sphene.goim.rcp.beans.GOIMGameItem;
import net.sphene.goim.rcp.beans.GOIMGameList;
import net.sphene.libs.SpheneEvent;
import net.sphene.libs.SpheneListener;

import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.widgets.Menu;

/**
* Menu contribution items for launching games.
*
* @author kahless
*/
public class LaunchGameContribution extends ContributionItem {
  IAction[] actions;
  private GOIMGameList gameList;
 
  public LaunchGameContribution(GOIMGameList gameList) {
    super();
    this.gameList = gameList;
    gameList.changeListenerList.addListener(new SpheneListener<SpheneEvent>() {
      public void handleEvent(SpheneEvent event) {
        actions = null;
      }
    });
  }

  /* (non-Javadoc)
   * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
   */
  @Override
  public void fill(Menu menu, int index) {
    ActionContributionItem[] items = getContributionItems();
    for(ActionContributionItem item : items) {
      item.fill(menu,index++);
    }
  }

  protected ActionContributionItem[] getContributionItems() {
    if(actions == null) {
      int i = 0;
      actions = new IAction[gameList.size()];
      for(GOIMGameItem game : gameList) {
        actions[i++] = new LaunchGameAction(game);
      }
    }
    ActionContributionItem[] items = new ActionContributionItem[actions.length];
    int i = 0;
    for(IAction action : actions) {
      items[i++] = new ActionContributionItem(action);
    }
    return items;
  }
}
TOP

Related Classes of net.sphene.goim.rcp.ui.actions.LaunchGameContribution

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.