List of usage examples for com.vaadin.event Action Action
public Action(String caption)
From source file:com.cavisson.gui.dashboard.components.calender.BeanItemContainerTestUI.java
License:Apache License
/** * Creates a table with some actions/*from w w w . ja va 2s . c om*/ * * @return */ private Table createTable() { Table table = new Table(); table.setSizeFull(); table.addActionHandler(new Action.Handler() { private final Action ADD = new Action("Add event"); private final Action EDIT = new Action("Edit event"); private final Action REMOVE = new Action("Remove event"); @Override public void handleAction(Action action, Object sender, Object target) { if (action == ADD) { BasicEvent event = new BasicEvent(); event.setStart(new Date(100, 1, 1)); event.setEnd(new Date(100, 1, 1)); editEvent(event); } else if (action == EDIT) { editEvent((BasicEvent) target); } else if (action == REMOVE) { events.removeItem(target); } } @Override public Action[] getActions(Object target, Object sender) { if (target == null) { return new Action[] { ADD }; } else { return new Action[] { EDIT, REMOVE }; } } }); return table; }
From source file:com.cavisson.gui.dashboard.components.calender.CalendarActionsUI.java
License:Apache License
@SuppressWarnings("deprecation") @Override/*from www. ja v a 2s .c o m*/ protected void init(VaadinRequest request) { GridLayout content = new GridLayout(1, 2); content.setSizeFull(); setContent(content); final Calendar calendar = new Calendar(); calendar.setLocale(new Locale("fi", "FI")); calendar.setSizeFull(); calendar.setStartDate(new Date(100, 1, 1)); calendar.setEndDate(new Date(100, 2, 1)); calendar.addActionHandler(new Action.Handler() { public final Action NEW_EVENT = new Action("Add event"); public final Action EDIT_EVENT = new Action("Edit event"); public final Action REMOVE_EVENT = new Action("Remove event"); /* * (non-Javadoc) * * @see * com.vaadin.event.Action.Handler#handleAction(com.vaadin.event * .Action, java.lang.Object, java.lang.Object) */ @Override public void handleAction(Action action, Object sender, Object target) { Date date = (Date) target; if (action == NEW_EVENT) { BasicEvent event = new BasicEvent("New event", "Hello world", date, date); calendar.addEvent(event); } } /* * (non-Javadoc) * * @see com.vaadin.event.Action.Handler#getActions(java.lang.Object, * java.lang.Object) */ @Override public Action[] getActions(Object target, Object sender) { CalendarDateRange date = (CalendarDateRange) target; java.util.Calendar cal = java.util.Calendar.getInstance(); cal.set(2000, 1, 1, 12, 0, 0); if (date.inRange(cal.getTime())) { return new Action[] { NEW_EVENT, }; } cal.add(java.util.Calendar.DAY_OF_WEEK, 1); if (date.inRange(cal.getTime())) { return new Action[] { REMOVE_EVENT }; } return null; } }); content.addComponent(calendar); content.addComponent(new Button("Set week view", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { calendar.setEndDate(new Date(100, 1, 7)); } })); content.setRowExpandRatio(0, 1); }
From source file:com.expressui.core.view.menu.ActionContextMenu.java
License:Open Source License
/** * Adds action to the context menu./*from ww w .j a v a 2s . c om*/ * * @param caption caption to display in context menu item * @param target target object to invoke when user selects action * @param methodName target method to invoke when user selects action */ public void addAction(String caption, Object target, String methodName) { Action action = new Action(uiMessageSource.getMessage(caption)); MethodDelegate methodDelegate = new MethodDelegate(target, methodName); ContextMenuAction contextMenuAction = new ContextMenuAction(action, methodDelegate); actions.put(caption, contextMenuAction); }
From source file:com.garyclayburg.vconsole.VConsole.java
License:Open Source License
private Table createUserTable(BeanContainer<String, User> userBeanContainer) { final Collection[] selectedRows = new Collection[1]; final Table userTable = new Table(); userTable.setSizeFull();/*from w ww . j a va2 s.co m*/ userTable.setSelectable(true); userTable.setMultiSelect(false); userTable.setImmediate(true); userTable.setContainerDataSource(userBeanContainer); userTable.addItemClickListener(new ItemClickEvent.ItemClickListener() { @Override public void itemClick(ItemClickEvent event) { Collection<?> itemPropertyIds = event.getItem().getItemPropertyIds(); log.info("properties clicked: " + itemPropertyIds); log.info("multiple select? " + selectedRows[0]); } }); userTable.addValueChangeListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { // selectedRows[0] = (Collection) userTable.getValue(); log.info("selected: " + userTable.getValue()); } }); userTable.addActionHandler(new Action.Handler() { @Override public Action[] getActions(Object target, Object sender) { Table selectedUserTable = (Table) sender; Item item = selectedUserTable.getItem(selectedUserTable.getValue()); Action[] actions = new Action[0]; if (item instanceof BeanItem) { log.debug("create right-click menu items"); // if (target == null){ //create actions for item user clicked on Item targetItem = selectedUserTable.getItem(target); if (targetItem != null) { User targetUser = (User) ((BeanItem) targetItem).getBean(); if (targetUser != null) { Set<String> allEntitledTargets = attributeService.getEntitledTargets(targetUser); Set<Action> entitledTargetActions = new HashSet<>(); for (String targetName : allEntitledTargets) { final Action action = new Action(targetName); entitledTargetActions.add(action); } actions = entitledTargetActions.toArray(new Action[entitledTargetActions.size()]); log.debug("right-click actions for user {}: {}", target, entitledTargetActions); } } } else { log.debug("Cannot create right-click menu items"); } return actions; } @Override public void handleAction(Action action, Object sender, Object target) { if (action != null) { Table selectedUserTable = (Table) sender; selectedUserTable.getValue(); Item item = selectedUserTable.getItem(selectedUserTable.getValue()); if (item instanceof BeanItem) { log.debug("create target window"); User user = (User) ((BeanItem) item).getBean(); targetWindows.showTargetWindow(user, action.getCaption()); } else { log.debug("Cannot create window"); } } else { Window multiWindow = new Window("multi-user myAD attributes"); UI.getCurrent().addWindow(multiWindow); Label stuff = new Label("2 users here " + selectedRows[0] + " "); multiWindow.setContent(stuff); } } }); userTable.setVisibleColumns("firstname", "lastname"); return userTable; }
From source file:com.ocs.dynamo.ui.composite.table.CustomTreeTable.java
License:Apache License
/** * Constructs the right-click menu/* w ww. j a v a2 s .c om*/ * * @param parentCollection */ protected void constructActionMenu(final List<V> parentCollection) { final Action copyPreviousAction = new Action(messageService.getMessage("ocs.copy.previous.column")); final Action clearColumnAction = new Action(messageService.getMessage("ocs.clear.column")); final Action fillColumnAction = new Action(messageService.getMessage("ocs.fill.column")); final List<Action> actions = new ArrayList<>(); if (!isViewMode() && isEditAllowed()) { actions.addAll(Lists.newArrayList(copyPreviousAction, fillColumnAction, clearColumnAction)); } actions.addAll(getAdditionalActions()); this.addActionHandler(new Action.Handler() { @Override public Action[] getActions(Object target, Object sender) { return actions.toArray(new Action[0]); } @Override @SuppressWarnings("unused") public void handleAction(Action action, Object sender, Object target) { if (!StringUtils.isEmpty(clickedColumn) && isRightClickable(clickedColumn)) { propagateChanges = false; if (action == fillColumnAction) { // fill all cells in column with the same value String targetRow = (String) target; Number value = (Number) getItem(targetRow).getItemProperty(clickedColumn).getValue(); int i = 0; for (V v : parentCollection) { for (U u : getRowCollection(v)) { if (!targetRow.equals(PREFIX_CHILDROW + i)) { CustomTreeTable.this.handleChange(PREFIX_CHILDROW + i, clickedColumn, value == null ? null : convertToString(toBigDecimal(value), clickedColumn)); } i++; } } } else if (action == copyPreviousAction) { // copy all values from the previous row String previousColumnId = getPreviousColumnId(clickedColumn); copyValue(previousColumnId, clickedColumn); } else if (action == clearColumnAction) { // empty the entire row int i = 0; for (V v : parentCollection) { for (U u : getRowCollection(v)) { CustomTreeTable.this.handleChange(PREFIX_CHILDROW + i, clickedColumn, null); i++; } } } else { // custom action handling handleAdditionalAction(action, sender, target); } propagateChanges = true; } clickedColumn = null; } }); // add export functionality addActionHandler( new TableExportActionHandler(UI.getCurrent(), messageService, null, getReportTitle(), true, null)); }
From source file:com.ocs.dynamo.ui.composite.table.export.TableExportActionHandler.java
License:Apache License
/** * Constructor//from ww w . j av a2 s .c o m * * @param ui * the current UI object * @param messageService * the message service * @param columnIds * the IDs of the columsn to export * @param reportTitle * the title of the report * @param totalsRow */ public TableExportActionHandler(UI ui, MessageService messageService, List<String> columnIds, String reportTitle, boolean totalsRow, CustomCellStyleGenerator cellStyleGenerator) { this.messageService = messageService; this.columnIds = columnIds; this.cellStyleGenerator = cellStyleGenerator; // try to get message from message bundle this.reportTitle = messageService.getMessageNoDefault(reportTitle); if (this.reportTitle == null) { // if that fails, use the title itself this.reportTitle = reportTitle; } this.ui = ui; this.totalsRow = totalsRow; actionExport = new Action(messageService.getMessage("ocs.export")); }
From source file:com.ocs.dynamo.ui.composite.table.ModelBasedTreeTable.java
License:Apache License
/** * @param container//w w w.j a va 2s . c o m * @param entityModelFactory * @param messageService */ @SuppressWarnings("unchecked") public ModelBasedTreeTable(ModelBasedHierarchicalContainer<T> container, EntityModelFactory entityModelFactory) { super("", container); this.messageService = ServiceLocator.getMessageService(); this.entityModelFactory = entityModelFactory; EntityModel<T> rootEntityModel = (EntityModel<T>) container.getHierarchicalDefinition(0).getEntityModel(); TableUtils.defaultInitialization(this); setCaption(rootEntityModel.getDisplayName()); // add a custom field factory that takes care of special cases and // validation this.setTableFieldFactory(container.new HierarchicalFieldFactory(container, messageService)); generateColumns(container, rootEntityModel); actionExpandAll = new Action(messageService.getMessage("ocs.expandAll")); actionHideAll = new Action(messageService.getMessage("ocs.hideAll")); addActionHandler(this); addActionHandler(new TableExportActionHandler(UI.getCurrent(), entityModelFactory, getEntityModels(), messageService, rootEntityModel.getDisplayName(), null, true, null)); }
From source file:com.purebred.core.view.menu.ActionContextMenu.java
License:Open Source License
public void addAction(String caption, Object target, String methodName) { Action action = new Action(uiMessageSource.getMessage(caption)); MethodDelegate methodDelegate = new MethodDelegate(target, methodName); ContextMenuAction contextMenuAction = new ContextMenuAction(action, methodDelegate); actions.put(caption, contextMenuAction); }
From source file:com.tripoin.util.ui.calendar.BeanItemContainerTestUI.java
License:Apache License
/** * Creates a table with some actions//from w w w . j a v a 2s .c om * * @return */ private Table createTable() { Table table = new Table(); table.setSizeFull(); table.addActionHandler(new Action.Handler() { /** * */ private static final long serialVersionUID = 6803702453578851522L; private final Action ADD = new Action("Add event"); private final Action EDIT = new Action("Edit event"); private final Action REMOVE = new Action("Remove event"); @SuppressWarnings("deprecation") @Override public void handleAction(Action action, Object sender, Object target) { if (action == ADD) { BasicEvent event = new BasicEvent(); event.setStart(new Date(100, 1, 1)); event.setEnd(new Date(100, 1, 1)); editEvent(event); } else if (action == EDIT) { editEvent((BasicEvent) target); } else if (action == REMOVE) { events.removeItem(target); } } @Override public Action[] getActions(Object target, Object sender) { if (target == null) { return new Action[] { ADD }; } else { return new Action[] { EDIT, REMOVE }; } } }); return table; }
From source file:com.tripoin.util.ui.calendar.CalendarActionsUI.java
License:Apache License
@SuppressWarnings("deprecation") @Override//from ww w . j a va2 s. c o m protected void init(VaadinRequest request) { GridLayout content = new GridLayout(1, 2); content.setSizeFull(); setContent(content); final Calendar calendar = new Calendar(); calendar.setLocale(new Locale("fi", "FI")); calendar.setSizeFull(); calendar.setStartDate(new Date(100, 1, 1)); calendar.setEndDate(new Date(100, 2, 1)); calendar.addActionHandler(new Action.Handler() { /** * */ private static final long serialVersionUID = -9176166330213062162L; public final Action NEW_EVENT = new Action("Add event"); @SuppressWarnings("unused") public final Action EDIT_EVENT = new Action("Edit event"); public final Action REMOVE_EVENT = new Action("Remove event"); /* * (non-Javadoc) * * @see * com.vaadin.event.Action.Handler#handleAction(com.vaadin.event * .Action, java.lang.Object, java.lang.Object) */ @Override public void handleAction(Action action, Object sender, Object target) { Date date = (Date) target; if (action == NEW_EVENT) { BasicEvent event = new BasicEvent("New event", "Hello world", date, date); calendar.addEvent(event); } } /* * (non-Javadoc) * * @see com.vaadin.event.Action.Handler#getActions(java.lang.Object, * java.lang.Object) */ @Override public Action[] getActions(Object target, Object sender) { CalendarDateRange date = (CalendarDateRange) target; java.util.Calendar cal = java.util.Calendar.getInstance(); cal.set(2000, 1, 1, 12, 0, 0); if (date.inRange(cal.getTime())) { return new Action[] { NEW_EVENT, }; } cal.add(java.util.Calendar.DAY_OF_WEEK, 1); if (date.inRange(cal.getTime())) { return new Action[] { REMOVE_EVENT }; } return null; } }); content.addComponent(calendar); content.addComponent(new Button("Set week view", new Button.ClickListener() { /** * */ private static final long serialVersionUID = -9193155583440680362L; @Override public void buttonClick(ClickEvent event) { calendar.setEndDate(new Date(100, 1, 7)); } })); content.setRowExpandRatio(0, 1); }