use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.
the class DownloadBar method buildMenu.
@Override
public void buildMenu(Menu menu, MenuEvent menuEvent) {
// Queue
final MenuItem itemQueue = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemQueue, "MyTorrentsView.menu.queue");
Utils.setMenuItemImage(itemQueue, "start");
itemQueue.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
ManagerUtils.queue(download, splash);
}
});
itemQueue.setEnabled(ManagerUtils.isStartable(download));
// Stop
final MenuItem itemStop = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemStop, "MyTorrentsView.menu.stop");
Utils.setMenuItemImage(itemStop, "stop");
itemStop.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
ManagerUtils.stop(download, splash);
}
});
itemStop.setEnabled(ManagerUtils.isStopable(download));
new MenuItem(menu, SWT.SEPARATOR);
super.buildMenu(menu);
}
use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.
the class MenuBuildUtils method addCommunityChatMenu.
public static void addCommunityChatMenu(Menu menu) {
final Menu chat_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
final org.eclipse.swt.widgets.MenuItem chat_item = new org.eclipse.swt.widgets.MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(chat_item, MainMenuV3.MENU_ID_COMMUNITY_CHAT);
chat_item.setMenu(chat_menu);
chat_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
for (org.eclipse.swt.widgets.MenuItem mi : chat_menu.getItems()) {
mi.dispose();
}
if (!BuddyPluginUtils.isBetaChatAvailable()) {
return;
}
// BiglyBT
{
org.eclipse.swt.widgets.MenuItem chat_pub = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
Messages.setLanguageText(chat_pub, "label.public");
chat_pub.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
pub_chat_pending.set(true);
BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_PUBLIC, BuddyPluginBeta.COMMUNITY_CHAT_KEY, new BuddyPluginUtils.CreateChatCallback() {
@Override
public void complete(ChatInstance chat) {
pub_chat_pending.set(false);
}
});
}
});
if (pub_chat_pending.get()) {
chat_pub.setEnabled(false);
chat_pub.setText(chat_pub.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
if (BuddyPluginUtils.isBetaChatAnonAvailable()) {
org.eclipse.swt.widgets.MenuItem chat_priv = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
Messages.setLanguageText(chat_priv, "label.anon");
chat_priv.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
anon_chat_pending.set(true);
BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_I2P, BuddyPluginBeta.COMMUNITY_CHAT_KEY, new BuddyPluginUtils.CreateChatCallback() {
@Override
public void complete(ChatInstance chat) {
anon_chat_pending.set(false);
}
});
}
});
if (anon_chat_pending.get()) {
chat_priv.setEnabled(false);
chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
} else {
org.eclipse.swt.widgets.MenuItem chat_priv = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
chat_priv.setText(MessageText.getString("label.anon") + "...");
chat_priv.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
I2PHelpers.installI2PHelper(null, null, null);
}
});
if (I2PHelpers.isInstallingI2PHelper()) {
chat_priv.setEnabled(false);
chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
}
// country chat
final ChatInstance cc = BuddyPluginUtils.getCountryChat();
org.eclipse.swt.widgets.MenuItem chat_cc = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
if (cc != null) {
String cc_text = MessageText.getString("menu.your.country", new String[] { (String) cc.getUserData(BuddyPluginUtils.CK_CC) });
chat_cc.setText(cc_text);
chat_cc.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
try {
BuddyPluginUtils.getBetaPlugin().showChat(cc);
} catch (Throwable e) {
Debug.out(e);
}
}
});
} else {
String cc_text = MessageText.getString("menu.your.country", new String[] { "..." });
chat_cc.setText(cc_text);
chat_cc.setEnabled(false);
}
// language chat
final ChatInstance lang = BuddyPluginUtils.getLanguageChat();
org.eclipse.swt.widgets.MenuItem chat_lang = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
if (lang != null) {
String lang_text = MessageText.getString("menu.your.language", new String[] { (String) lang.getUserData(BuddyPluginUtils.CK_LANG) });
chat_lang.setText(lang_text);
chat_lang.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
try {
BuddyPluginUtils.getBetaPlugin().showChat(lang);
} catch (Throwable e) {
Debug.out(e);
}
}
});
} else {
String lang_text = MessageText.getString("menu.your.language", new String[] { "..." });
chat_lang.setText(lang_text);
chat_lang.setEnabled(false);
}
}
new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.SEPARATOR);
// Vuze
{
org.eclipse.swt.widgets.MenuItem chat_pub = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
chat_pub.setText(MessageText.getString("ConfigView.section.interface.legacy") + " " + MessageText.getString("label.public"));
chat_pub.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
pub_chat_pending.set(true);
BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_PUBLIC, BuddyPluginBeta.LEGACY_COMMUNITY_CHAT_KEY, new BuddyPluginUtils.CreateChatCallback() {
@Override
public void complete(ChatInstance chat) {
pub_chat_pending.set(false);
}
});
}
});
if (pub_chat_pending.get()) {
chat_pub.setEnabled(false);
chat_pub.setText(chat_pub.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
if (BuddyPluginUtils.isBetaChatAnonAvailable()) {
org.eclipse.swt.widgets.MenuItem chat_priv = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
chat_priv.setText(MessageText.getString("ConfigView.section.interface.legacy") + " " + MessageText.getString("label.anon"));
chat_priv.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
anon_chat_pending.set(true);
BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_I2P, BuddyPluginBeta.LEGACY_COMMUNITY_CHAT_KEY, new BuddyPluginUtils.CreateChatCallback() {
@Override
public void complete(ChatInstance chat) {
anon_chat_pending.set(false);
}
});
}
});
if (anon_chat_pending.get()) {
chat_priv.setEnabled(false);
chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
} else {
org.eclipse.swt.widgets.MenuItem chat_priv = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
chat_priv.setText(MessageText.getString("label.anon") + "...");
chat_priv.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
I2PHelpers.installI2PHelper(null, null, null);
}
});
if (I2PHelpers.isInstallingI2PHelper()) {
chat_priv.setEnabled(false);
chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
}
}
}
});
}
use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.
the class MenuBuildUtils method addPluginMenuItems.
/**
* Creates menu items inside the given menu based on the plugin API MenuItem
* instances provided. This method is provided mainly as a utility method to
* make it easier for menus to incorporate menu components specified by
* plugins.
*
* Usually, the list of array items will be extracted from a class like
* MenuItemManager or TableContextMenuManager, where plugins will usually
* register menu items they have created.
*
* @param items The list of plugin MenuItem to add
* @param parent The SWT Menu to add to.
* @param prev_was_separator Indicates if the previous item in the menu is
* a separator or not
* @param enable_items Indicates whether you want generated items to be
* enabled or not. If false, all items will be disabled. If true,
* then the items *may* be enabled, depending on how each MenuItem
* is configured.
* @param controller The callback object used by this method when creating the
* SWT menus (used for invoking fill and selection listeners).
*/
public static void addPluginMenuItems(MenuItem[] items, Menu parent, boolean prev_was_separator, final boolean enable_items, final PluginMenuController controller) {
for (int i = 0; i < items.length; i++) {
final MenuItemImpl az_menuitem = (MenuItemImpl) items[i];
controller.notifyFillListeners(az_menuitem);
if (!az_menuitem.isVisible()) {
continue;
}
final int style = az_menuitem.getStyle();
final int swt_style;
boolean this_is_separator = false;
// Do we have any children? If so, we override any manually defined
// style.
boolean is_container = false;
if (style == TableContextMenuItem.STYLE_MENU) {
swt_style = SWT.CASCADE;
is_container = true;
} else if (style == TableContextMenuItem.STYLE_PUSH) {
swt_style = SWT.PUSH;
} else if (style == TableContextMenuItem.STYLE_CHECK) {
swt_style = SWT.CHECK;
} else if (style == TableContextMenuItem.STYLE_RADIO) {
swt_style = SWT.RADIO;
} else if (style == TableContextMenuItem.STYLE_SEPARATOR) {
this_is_separator = true;
swt_style = SWT.SEPARATOR;
} else {
swt_style = SWT.PUSH;
}
// Skip contiguous separators
if (prev_was_separator && this_is_separator) {
continue;
}
// Skip trailing separator
if (this_is_separator && i == items.length - 1) {
continue;
}
prev_was_separator = this_is_separator;
final org.eclipse.swt.widgets.MenuItem menuItem = new org.eclipse.swt.widgets.MenuItem(parent, swt_style);
if (swt_style == SWT.SEPARATOR) {
continue;
}
if (enable_items) {
if (style == TableContextMenuItem.STYLE_CHECK || style == TableContextMenuItem.STYLE_RADIO) {
Boolean selection_value = (Boolean) az_menuitem.getData();
if (selection_value == null) {
throw new RuntimeException("MenuItem with resource name \"" + az_menuitem.getResourceKey() + "\" needs to have a boolean value entered via setData before being used!");
}
menuItem.setSelection(selection_value.booleanValue());
}
}
final Listener main_listener = controller.makeSelectionListener(az_menuitem);
menuItem.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
if (az_menuitem.getStyle() == MenuItem.STYLE_CHECK || az_menuitem.getStyle() == MenuItem.STYLE_RADIO) {
if (!menuItem.isDisposed()) {
az_menuitem.setData(Boolean.valueOf(menuItem.getSelection()));
}
}
main_listener.handleEvent(e);
}
});
if (is_container) {
Menu this_menu = new Menu(parent);
menuItem.setMenu(this_menu);
addMaintenanceListenerForMenu(this_menu, new MenuBuilder() {
@Override
public void buildMenu(Menu root_menu, MenuEvent menuEvent) {
controller.buildSubmenu(az_menuitem);
addPluginMenuItems(az_menuitem.getItems(), root_menu, false, enable_items, controller);
}
});
}
String custom_title = az_menuitem.getText();
menuItem.setText(custom_title);
Graphic g = az_menuitem.getGraphic();
if (g instanceof UISWTGraphic) {
Utils.setMenuItemImage(menuItem, ((UISWTGraphic) g).getImage());
} else if (g instanceof GraphicURI) {
Utils.setMenuItemImage(menuItem, ((GraphicURI) g).getURI().toString());
}
menuItem.setEnabled(enable_items && az_menuitem.isEnabled());
}
}
use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.
the class MenuBuildUtils method addChatMenu.
public static void addChatMenu(Menu menu, String menu_resource_key, final String chat_key) {
final Menu chat_menu = new Menu(menu.getShell(), SWT.DROP_DOWN);
final org.eclipse.swt.widgets.MenuItem chat_item = new org.eclipse.swt.widgets.MenuItem(menu, SWT.CASCADE);
Messages.setLanguageText(chat_item, menu_resource_key);
chat_item.setMenu(chat_menu);
chat_menu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
for (org.eclipse.swt.widgets.MenuItem mi : chat_menu.getItems()) {
mi.dispose();
}
if (!BuddyPluginUtils.isBetaChatAvailable()) {
return;
}
org.eclipse.swt.widgets.MenuItem chat_pub = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
Messages.setLanguageText(chat_pub, "label.public");
chat_pub.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
pub_chat_pending.set(true);
BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_PUBLIC, chat_key, new BuddyPluginUtils.CreateChatCallback() {
@Override
public void complete(ChatInstance chat) {
pub_chat_pending.set(false);
}
});
}
});
if (pub_chat_pending.get()) {
chat_pub.setEnabled(false);
chat_pub.setText(chat_pub.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
if (BuddyPluginUtils.isBetaChatAnonAvailable()) {
org.eclipse.swt.widgets.MenuItem chat_priv = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
Messages.setLanguageText(chat_priv, "label.anon");
chat_priv.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
anon_chat_pending.set(true);
BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_I2P, chat_key, new BuddyPluginUtils.CreateChatCallback() {
@Override
public void complete(ChatInstance chat) {
anon_chat_pending.set(false);
}
});
}
});
if (anon_chat_pending.get()) {
chat_priv.setEnabled(false);
chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
} else {
org.eclipse.swt.widgets.MenuItem chat_priv = new org.eclipse.swt.widgets.MenuItem(chat_menu, SWT.PUSH);
chat_priv.setText(MessageText.getString("label.anon") + "...");
chat_priv.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
I2PHelpers.installI2PHelper(null, null, null);
}
});
if (I2PHelpers.isInstallingI2PHelper()) {
chat_priv.setEnabled(false);
chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
}
}
}
});
}
use of org.eclipse.swt.events.MenuEvent in project BiglyBT by BiglySoftware.
the class SBC_ArchivedDownloadsView method fillMenu.
@Override
public void fillMenu(String sColumnName, Menu menu) {
List<Object> ds = tv.getSelectedDataSources();
final List<DownloadStub> dms = new ArrayList<>(ds.size());
for (Object o : ds) {
dms.add((DownloadStub) o);
}
boolean hasSelection = dms.size() > 0;
// Explore (or open containing folder)
final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
final MenuItem itemExplore = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemExplore, "MyTorrentsView.menu." + (use_open_containing_folder ? "open_parent_folder" : "explore"));
itemExplore.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (DownloadStub download : dms) {
ManagerUtils.open(new File(download.getSavePath()), use_open_containing_folder);
}
}
});
itemExplore.setEnabled(hasSelection);
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemRestore = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRestore, "MyTorrentsView.menu.restore");
itemRestore.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
ManagerUtils.restoreFromArchive(dms, false, null);
}
});
itemRestore.setEnabled(hasSelection);
final MenuItem itemRestoreAnd = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRestoreAnd, "MyTorrentsView.menu.restore.and");
itemRestoreAnd.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
ManagerUtils.restoreFromArchive(dms, false, new ArchiveCallback() {
private List<DownloadManager> targets = new ArrayList<>();
@Override
public void success(final DownloadStub source, final DownloadStub target) {
DownloadManager dm = PluginCoreUtils.unwrap((Download) target);
if (dm != null) {
targets.add(dm);
}
}
@Override
public void completed() {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (targets.size() == 0) {
return;
}
final Menu menu = new Menu(table_parent);
DownloadManager[] dm_list = targets.toArray(new DownloadManager[dms.size()]);
TorrentUtil.fillTorrentMenu(menu, dm_list, CoreFactory.getSingleton(), true, 0, tv);
menu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent e) {
}
@Override
public void menuHidden(MenuEvent e) {
Utils.execSWTThreadLater(1, new Runnable() {
@Override
public void run() {
menu.dispose();
}
});
}
});
menu.setVisible(true);
}
});
}
});
}
});
itemRestoreAnd.setEnabled(hasSelection);
new MenuItem(menu, SWT.SEPARATOR);
}
Aggregations