@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); ArrayList<Insert> items = new ArrayList<>(); FragmentManager fm = getActivity().getSupportFragmentManager(); Insert insert; switch (item.getItemId()) { case R.id.menu_toggle_fav: adapter.toggleSelection(info.position); break; case R.id.menu_edit: insert = (Insert) adapter.getItem(info.position); InsertDialogFragment dialog = InsertDialogFragment.newInstance(insert); dialog.show(fm, ARG_EDIT_INSERT); break; case R.id.menu_delete: insert = (Insert) adapter.getItem(info.position); items.add(insert); DeleteInsertDialogFragment deleteDialog = DeleteInsertDialogFragment.newInstance(items); deleteDialog.show(fm, ARG_DELETE_INSERT); break; } return super.onContextItemSelected(item); }
public Special addItemToSpecial(Special special, MenuItem item, double price) throws PizzaException { if ((special == null) || !(parentSystem.getPizzaStore().getSpecials().contains(special)) || (item == null) || !(parentSystem.getPizzaStore().getMenu().getMenuItems().contains(item)) || (price < 0) || ((Double) price == null)) { throw new PizzaException( "Incorrect parameter addItemToSpecial(<" + special.getSpecialName() + ">:Special, <" + item.getDesc() + ">:MenuItem, <" + price + ">:double)"); } else { // Given good params and doesn't already have item if (special.getItem() == null) { item.setPrice(price); special.addItemToSpecial(item, price); return special; } // Given good params but already has item. Create new special, add // to specials else { Special temp = new Special(special.getSpecialName()); temp.addItemToSpecial(item, price); parentSystem.getPizzaStore().getSpecials().add(temp); return temp; } } }
@Override public boolean onContextItemSelected(MenuItem item) { final int position = ((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position; final ListView view = (ListView) getTabHost().getCurrentView(); final Bookmark bookmark = ((BookmarksAdapter) view.getAdapter()).getItem(position); switch (item.getItemId()) { case OPEN_ITEM_ID: gotoBookmark(bookmark); return true; case EDIT_ITEM_ID: final Intent intent = new Intent(this, BookmarkEditActivity.class); OrientationUtil.startActivityForResult(this, intent, 1); // TODO: implement return true; case DELETE_ITEM_ID: myCollection.deleteBookmark(bookmark); if (myThisBookAdapter != null) { myThisBookAdapter.remove(bookmark); } if (myAllBooksAdapter != null) { myAllBooksAdapter.remove(bookmark); } if (mySearchResultsAdapter != null) { mySearchResultsAdapter.remove(bookmark); } return true; } return super.onContextItemSelected(item); }
private void buildConnectContextMenu() { MenuItem createDb = new MenuItem("Create db..."); createDb.setOnAction(this::onCreateNewDb); MenuItem disconnect = new MenuItem("Disconnect"); disconnect.setOnAction(this::onDisconnectDb); connectContextMenu = new ContextMenu(createDb, disconnect); }
private static void createTree() { List<Menu> menuList = new MenuDAOImpl().getAllMenus(); Map<Menu, MenuItem> menuToMenuItemMap = new HashMap<Menu, MenuItem>(); for (Menu menu : menuList) { MenuItem menuItem = new MenuItem(); menuItem.setMenu(menu); menuToMenuItemMap.put(menu, menuItem); } MenuItem rootWrapper = new MenuItem(); for (Menu menu : menuList) { if (menu.getParent() == null) { rootWrapper.getChildMenus().add(menuToMenuItemMap.get(menu)); } else { menuToMenuItemMap.get(menu.getParent()).getChildMenus().add(menuToMenuItemMap.get(menu)); } } sortChildren(rootWrapper); root = rootWrapper.getChildMenus(); }
private void setContextMenuState( boolean deleteState, boolean selectState, boolean deselectState, boolean invertState) { deleteMenuItem.setDisable(!deleteState); selectMenuItem.setDisable(!selectState); deselectMenuItem.setDisable(!deselectState); invertMenuItem.setDisable(!invertState); }
@Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { // Handle select all/none first, and if it isn't those then don't do anything if we haven't // selected any items. if (item.getItemId() == R.id.action_select_all) { adapter.selectAll(); return true; } else if (item.getItemId() == R.id.action_select_none) { adapter.clearSelections(); return true; } else if (adapter.getSelectedItemCount() == 0) return true; // Handle actions. switch (item.getItemId()) { case R.id.action_tag: //noinspection unchecked TaggingActivity.start(this, adapter.getSelectedRealmObjects()); return true; case R.id.action_rate: int initialRating = adapter.getSelectedItemCount() == 1 ? ((RBook) adapter.getSelectedRealmObjects().get(0)).rating : 0; Dialogs.ratingDialog(getContext(), initialRating); return true; case R.id.action_mark_as: Dialogs.markAsDialog(getActivity()); return true; case R.id.action_add_to_list: Dialogs.addToListDialogOrSnack(getActivity(), realm); return true; case R.id.action_re_import: Dialogs.simpleConfirmDialog( getContext(), R.string.title_re_import_books, R.string.prompt_re_import_books, R.string.action_re_import, R.id.action_re_import); return true; case R.id.action_remove: Dialogs.simpleConfirmDialog( getContext(), R.string.title_remove_books, R.string.prompt_remove_from_recents, R.string.action_remove, R.id.action_remove); return true; case R.id.action_delete: Dialogs.confirmCheckBoxDialog( getContext(), R.string.title_delete_books, R.string.prompt_delete_books, R.string.prompt_delete_from_device_too, R.string.action_delete, R.id.action_delete); return true; default: return false; } }
private static void sortChildren(MenuItem menuItem) { menuItem.sortChildren(); for (MenuItem child : menuItem.getChildMenus()) { sortChildren(child); } }
/** Called when one of the menu items is selected. */ public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); Utilities.LogInfo("Option item selected - " + String.valueOf(item.getTitle())); switch (itemId) { case R.id.mnuSettings: Intent settingsActivity = new Intent(getApplicationContext(), GpsSettingsActivity.class); startActivity(settingsActivity); break; case R.id.mnuOSM: UploadToOpenStreetMap(); break; case R.id.mnuDropBox: UploadToDropBox(); break; case R.id.mnuAnnotate: Annotate(); break; case R.id.mnuShare: Share(); break; case R.id.mnuEmailnow: EmailNow(); break; case R.id.mnuExit: loggingService.StopLogging(); loggingService.stopSelf(); finish(); break; } return false; }
@Test public void getUrl_noParams() { MenuItem menuItem = new MenuItem(); String id = "id"; menuItem.setId(id); assertEquals(new MenuItemToMolgenisUiMenuItemAdapter(menuItem).getUrl(), id); }
@Test public void getType_pluginType() { MenuItem menuItem = new MenuItem(); menuItem.setType(MenuItemType.PLUGIN); assertEquals( new MenuItemToMolgenisUiMenuItemAdapter(menuItem).getType(), MolgenisUiMenuItemType.PLUGIN); }
@Test public void getType_menuType() { MenuItem menuItem = new MenuItem(); menuItem.setType(MenuItemType.MENU); assertEquals( new MenuItemToMolgenisUiMenuItemAdapter(menuItem).getType(), MolgenisUiMenuItemType.MENU); }
@Test public void getName() { MenuItem menuItem = new MenuItem(); String name = "name"; menuItem.setLabel(name); assertEquals(new MenuItemToMolgenisUiMenuItemAdapter(menuItem).getName(), name); }
/** * @param session * @param i * @return */ private boolean checkVisibility(BBTSession session, MenuItem i) { if (session.getCurrentUser() == null) return false; // Super Admin shows everything if (session.getCurrentUser().isSuperAdmin()) return true; else if (session.getCurrentUser().isAdmin()) return !i.isSuperAdminOnly(); else return (!i.isAdminOnly() && !i.isSuperAdminOnly()); }
/** * Shows "call via" menu allowing user to selected from multiple providers. * * @param context the android context * @param v the View that will contain the popup menu. * @param destination target callee name. */ private static void showCallViaMenu(final Context context, View v, final String destination) { PopupMenu popup = new PopupMenu(context, v); Menu menu = popup.getMenu(); Iterator<ProtocolProviderService> registeredProviders = AccountUtils.getRegisteredProviders().iterator(); while (registeredProviders.hasNext()) { final ProtocolProviderService provider = registeredProviders.next(); String accountAddress = provider.getAccountID().getAccountAddress(); MenuItem menuItem = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, accountAddress); menuItem.setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { createCall(context, destination, provider); return false; } }); } popup.show(); }
/** Creates a Bukkit Inventory for a Menu class */ Inventory generateFreshMenu(Menu menu, Class clazz) { MenuInventory menuInv = (MenuInventory) clazz.getAnnotation(MenuInventory.class); Inventory inv = Bukkit.createInventory(null, menuInv.slots(), menuInv.name()); for (int i = 0; i < inv.getSize(); i++) inv.setItem(i, ItemUtils.annotationToItemStack(menuInv.filler())); for (Method m : loadedMenus.get(clazz)) { MenuItem menuItem = m.getAnnotation(MenuItem.class); ItemStack item = ItemUtils.annotationToItemStack(menuItem.item()); inv.setItem(menuItem.slot(), item); } if (clazz.isAnnotationPresent(IgnoreSlots.class)) { IgnoreSlots ignoreSlots = (IgnoreSlots) clazz.getAnnotation(IgnoreSlots.class); if (ignoreSlots.slots().length == ignoreSlots.items().length) for (int i = 0; i < ignoreSlots.slots().length; i++) inv.setItem( ignoreSlots.slots()[i], ItemUtils.annotationToItemStack(ignoreSlots.items()[i])); } for (Method m : loadedPreprocessors.get(clazz)) { try { m.invoke(menu, inv); } catch (IllegalAccessException e) { System.out.println("All @PreProcessor methods must be static!"); e.printStackTrace(); } catch (InvocationTargetException e) { System.out.println("All @PreProcessor methods must take 1 Inventory as a parameter!"); e.printStackTrace(); } } return inv; }
/** * Transform a list of {@code <menu-item>} elements into {@code MenuItem} objects. * * <p>This method loads the children recursively. * * @param nodes List of XML elements * @return List of MenuItem, note that MenuItem is complete, that is each MenuItem will contain * their children List */ public List<MenuItem> loadMenuItems(NodeList nodes) { List<MenuItem> items = new ArrayList<MenuItem>(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() != Node.ELEMENT_NODE || !MENU_ITEM_ELEMENT.equals(node.getNodeName())) { continue; } // create the MenuItem object MenuItem item = new MenuItem((Element) node); // recursively load children NodeList childNodes = node.getChildNodes(); if (childNodes.getLength() > 0) { List<MenuItem> childItems = loadMenuItems(childNodes); item.setChildren(childItems); } // add MenuItem to result list items.add(item); } return items; }
public View getView(int position, View convertView, ViewGroup parent) { View rowView = convertView; ViewHolder viewHolder; if (rowView == null) { LayoutInflater inflater = context.getLayoutInflater(); rowView = inflater.inflate(resourceId, null); viewHolder = new ViewHolder(); viewHolder.labelTv = (TextView) rowView.findViewById(R.id.sliding_menu_label); rowView.setTag(viewHolder); } else { viewHolder = (ViewHolder) rowView.getTag(); } MenuItem item = list.get(position); int iconResId = item.getIconResId(); if (iconResId != 0) { viewHolder.labelTv.setCompoundDrawablesWithIntrinsicBounds( context.getResources().getDrawable(iconResId), null, null, null); } viewHolder.labelTv.setText(item.getLabel()); return rowView; }
/** Lay out menu items */ public void positionMenuItems() { MenuItem item = getItem(0); item.setHorizontalCenter(x); item = getItem(1); item.setHorizontalCenter(x); }
/** @since 1.504 */ public ContextMenu add(String url, String icon, String text, boolean post) { if (text != null && icon != null && url != null) { MenuItem item = new MenuItem(url, icon, text); item.post = post; items.add(item); } return this; }
private MenuItem menuItem(String title, Runnable r) { MenuItem mi = new MenuItem(title); mi.setOnAction( event -> { r.run(); }); return mi; }
public void removeMenuItemByLabel(String text) { for (int i = 0; i < m_menuItems.size(); i++) { MenuItem m = (MenuItem) m_menuItems.elementAt(i); if (text.compareTo(m.toString()) == 0) { m_menuItems.removeElementAt(i); } } }
/** * Generate a copy to be used in the order. * * @param ncomment the comment for this item. * @return a copy of this item, with comment */ public final MenuItem getItem(final String ncomment) { MenuItem newItem = new MenuItem(id, name, desc, price); for (int i = 0; i < tags.size(); i++) { newItem.addTag(tags.get(i)); } newItem.setComment(comment); return newItem; }
void printMenu(Iterator iterator) { while (iterator.hasNext()) { MenuItem menuItem = (MenuItem) iterator.next(); System.out.print(menuItem.getName() + ", "); System.out.print(menuItem.getPrice() + " -- "); System.out.println(menuItem.getDescription()); } }
public static void main(String args[]) throws java.lang.Exception { Scanner scan = new Scanner(System.in); URL wsdlURL = LunchService_Service.WSDL_LOCATION; if (args.length > 0 && args[0] != null && !"".equals(args[0])) { File wsdlFile = new File(args[0]); try { if (wsdlFile.exists()) { wsdlURL = wsdlFile.toURI().toURL(); } else { wsdlURL = new URL(args[0]); } } catch (MalformedURLException e) { e.printStackTrace(); } } LunchService_Service ss = new LunchService_Service(wsdlURL, SERVICE_NAME); LunchService port = ss.getLunchServiceImplPort(); // Restaurant Getter System.out.println("Choose from the following restaurants"); java.util.List<generated.Restaurant> _getRestaurants__return = port.getRestaurants(); System.out.println("getRestaurants.result=" + _getRestaurants__return); // Restaurant Chooser int i = 0; for (Restaurant restaurant : _getRestaurants__return) { System.out.println(i++ + ". " + restaurant.getName()); } int restaurantChoice = Integer.parseInt(scan.nextLine()); Restaurant chosenRestaurant = _getRestaurants__return.get(restaurantChoice); // Menu Getter System.out.println("Choose one or more of the following menu items seperated by a comma"); generated.Restaurant _getMenu_restaurant = chosenRestaurant; generated.Menu _getMenu__return = port.getMenu(_getMenu_restaurant); System.out.println("getMenu.result=" + _getMenu__return); // Menu item Chooser int a = 0; for (MenuItem menuItem : _getMenu__return.getMenuItems()) { System.out.println(a++ + ". " + menuItem.getMenuString()); } String chosenMenuString = scan.nextLine(); String[] chosenMenuArray = chosenMenuString.split(","); List<MenuItem> chosenmenuItems = new ArrayList<>(); for (String s : chosenMenuArray) { chosenmenuItems.add(_getMenu__return.getMenuItems().get(Integer.parseInt(s))); } // Order Placer System.out.println("Invoking addOrder..."); generated.Restaurant _addOrder_restaurant = chosenRestaurant; java.util.List<generated.MenuItem> _addOrder_menuItems = chosenmenuItems; port.addOrder(_addOrder_restaurant, _addOrder_menuItems); System.exit(0); }
private static void addChildMenuItems( StringBuffer html, List<MenuItem> menuTree, String contextPath, boolean topLevel) { int topLevelCount = 0; for (MenuItem menuItem : menuTree) { Menu menu = menuItem.getMenu(); if (topLevel) { if (topLevelCount == 0) { html.append("\t<li id=\"nav-first\" >\n"); } else if (topLevelCount == menuTree.size() - 1) { html.append("\t<li id=\"nav-last\" >\n"); } else { html.append("\t<li>\n"); } topLevelCount++; } else { html.append("\t<li>\n"); } html.append("\t\t<a "); html.append("id=\""); html.append(menu.getElementId()); html.append("\" "); if (!GenericValidator.isBlankOrNull(menu.getLocalizedTooltip())) { html.append(" title=\""); html.append(menu.getLocalizedTooltip()); html.append("\" "); } if (menu.isOpenInNewWindow()) { html.append(" target=\"_blank\" "); } if (GenericValidator.isBlankOrNull(menu.getActionURL()) && GenericValidator.isBlankOrNull(menu.getClickAction())) { html.append(" class=\"no-link\" >"); } else { html.append(" href=\""); html.append(contextPath); html.append(menu.getActionURL()); html.append("\" >"); } html.append(menu.getLocalizedTitle()); html.append("</a>\n"); if (!menuItem.getChildMenus().isEmpty()) { html.append("<ul>\n"); addChildMenuItems(html, menuItem.getChildMenus(), contextPath, false); html.append("</ul>\n"); } html.append("\t</li>\n"); } }
@Test public void getUrl_params() { MenuItem menuItem = new MenuItem(); String id = "id"; menuItem.setId(id); String params = "a=b&c=d"; menuItem.setParams(params); assertEquals(new MenuItemToMolgenisUiMenuItemAdapter(menuItem).getUrl(), id + '?' + params); }
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); final MenuItem item = menu.add(0, 1, Menu.NONE, myResource.getResource("menu").getResource("search").getValue()); item.setOnMenuItemClickListener(this); item.setIcon(R.drawable.ic_menu_search); return true; }
public void refreshSubServersGUI(boolean clear) { if (subServersInventory == null) subServersInventory = plugin.getServer().createInventory(null, InventoryType.CHEST); if (clear) subServersInventory.clear(); for (MenuItem srv : subServers) { ItemStack is = getItemStackByMenuItem(srv); subServersInventory.setItem(srv.getSlot(), is); } }
public void onContextMenuShowing() { ObservableList<FileItem> selectedItems = tableView.getSelectionModel().getSelectedItems(); if (areAllItemsSelected(selectedItems)) { selectMenuItem.setDisable(true); } if (areAllItemsDeselected(selectedItems)) { deselectMenuItem.setDisable(true); } }