com.vaadin.event.Action Java Examples

The following examples show how to use com.vaadin.event.Action. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Calendar.java    From calendar-component with Apache License 2.0 6 votes vote down vote up
private void setActionsForEachHalfHour(Map<CalendarDateRange, Set<Action>> actionMap,
                                       ZonedDateTime start, ZonedDateTime end, Action.Handler actionHandler) {

    ZonedDateTime actionTime = start;
    while (actionTime.isBefore(end)) {

        ZonedDateTime endTime = actionTime.plus(30, ChronoUnit.MINUTES);

        CalendarDateRange range = new CalendarDateRange(actionTime, endTime);

        Action[] actions = actionHandler.getActions(range, this);
        if (actions != null) {
            Set<Action> actionSet = new LinkedHashSet<>(Arrays.asList(actions));
            actionMap.put(range, actionSet);
        }

        actionTime = endTime;
    }
}
 
Example #2
Source File: CubaMainTabSheet.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void onTabContextMenu(int tabIndex) {
    Tab tab = getTab(tabIndex);
    if (tab != null) {
        Set<Action> actions = getActions(CubaMainTabSheet.this.getActionTarget(tab));

        if (!actions.isEmpty()) {
            actionMapper = new KeyMapper<>();

            List<ClientAction> actionsList = new ArrayList<>(actions.size());
            for (Action action : actions) {
                ClientAction clientAction = new ClientAction(action.getCaption());
                clientAction.setActionId(actionMapper.key(action));
                actionsList.add(clientAction);
            }

            ClientAction[] clientActions = actionsList.toArray(new ClientAction[actions.size()]);

            getRpcProxy(CubaMainTabSheetClientRpc.class).showTabContextMenu(tabIndex, clientActions);
        }
    }
}
 
Example #3
Source File: CubaMainTabSheet.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void performAction(int tabIndex, String actionKey) {
    Tab tab = getTab(tabIndex);
    if (tab != null) {
        if (actionMapper != null) {
            Action action = actionMapper.get(actionKey);
            Action.Handler[] handlers;

            if (actionHandlers != null) {
                handlers = actionHandlers.toArray(new Action.Handler[0]);
            } else {
                handlers = new Action.Handler[0];
            }

            for (Action.Handler handler : handlers) {
                handler.handleAction(action, this, CubaMainTabSheet.this.getActionTarget(tab));
            }

            // forget all painted actions after perform one
            actionMapper = null;
        }
    }
}
 
Example #4
Source File: WebDialogWindow.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public com.vaadin.event.Action[] getActions(Object target, Object sender) {
    if (!initialized) {
        Messages messages = beanLocator.get(Messages.NAME);

        saveSettingsAction = new com.vaadin.event.Action(messages.getMainMessage("actions.saveSettings"));
        restoreToDefaultsAction = new com.vaadin.event.Action(messages.getMainMessage("actions.restoreToDefaults"));
        analyzeAction = new com.vaadin.event.Action(messages.getMainMessage("actions.analyzeLayout"));

        initialized = true;
    }

    List<Action> actions = new ArrayList<>(3);

    ClientConfig clientConfig = getClientConfig();
    if (clientConfig.getManualScreenSettingsSaving()) {
        actions.add(saveSettingsAction);
        actions.add(restoreToDefaultsAction);
    }
    if (clientConfig.getLayoutAnalyzerEnabled()) {
        actions.add(analyzeAction);
    }

    return actions.toArray(new com.vaadin.event.Action[0]);
}
 
Example #5
Source File: MainTabSheetActionHandler.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void handleAction(Action action, Object sender, Object target) {
    TabSheetBehaviour tabSheetBehaviour = tabSheet.getTabSheetBehaviour();
    if (initialized) {
        if (closeCurrentTab == action) {
            tabSheetBehaviour.closeTab((com.vaadin.ui.Component) target);
        } else if (closeOtherTabs == action) {
            tabSheetBehaviour.closeOtherTabs((com.vaadin.ui.Component) target);
        } else if (closeAllTabs == action) {
            tabSheetBehaviour.closeAllTabs();
        } else if (showInfo == action) {
            showInfo(target);
        } else if (analyzeLayout == action) {
            analyzeLayout(target);
        } else if (saveSettings == action) {
            saveSettings(target);
        } else if (restoreToDefaults == action) {
            restoreToDefaults(target);
        }
    }
}
 
Example #6
Source File: CubaWindow.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void onWindowContextMenu() {
    Collection<Action> actions = getContextActions(CubaWindow.this);

    if (!actions.isEmpty()) {
        contextActionMapper = new KeyMapper<>();

        List<ClientAction> actionsList = new ArrayList<>(actions.size());
        for (Action action : actions) {
            ClientAction clientAction = new ClientAction(action.getCaption());
            clientAction.setActionId(contextActionMapper.key(action));
            actionsList.add(clientAction);
        }

        ClientAction[] clientActions = actionsList.toArray(new ClientAction[actions.size()]);

        getRpcProxy(CubaWindowClientRpc.class).showTabContextMenu(clientActions);
    }
}
 
Example #7
Source File: CalendarScreen.java    From sample-timesheets with Apache License 2.0 6 votes vote down vote up
@Override
public Action[] getActions(Object target, Object sender) {
    // The target should be a CalendarDateRage for the
    // entire day from midnight to midnight.
    if (!(target instanceof CalendarDateRange))
        return null;
    CalendarDateRange dateRange = (CalendarDateRange) target;

    // The sender is the Calendar object
    if (!(sender instanceof Calendar))
        return null;
    Calendar calendar = (Calendar) sender;

    // List all the events on the requested day
    List<CalendarEvent> events = calendar.getEvents(dateRange.getStart(), dateRange.getEnd());

    if (events.size() == 0)
        return new Action[]{addEventAction};
    else
        return new Action[]{addEventAction, copyEventAction, deleteEventAction};
}
 
Example #8
Source File: CubaWindow.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void performContextMenuAction(String actionKey) {
    if (contextActionMapper != null) {
        Action action = contextActionMapper.get(actionKey);
        Action.Handler[] handlers = contextActionHandlers.toArray(new Action.Handler[0]);
        for (Action.Handler handler : handlers) {
            handler.handleAction(action, this, CubaWindow.this);
        }

        // forget all painted actions after perform one
        contextActionMapper = null;
    }
}
 
Example #9
Source File: CubaWindow.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Collection<Action> getContextActions(Component actionTarget) {
    List<Action> actions = new ArrayList<>();
    if (contextActionHandlers != null) {
        for (Action.Handler handler : contextActionHandlers) {
            Action[] as = handler.getActions(actionTarget, this);
            if (as != null) {
                Collections.addAll(actions, as);
            }
        }
    }
    return actions;
}
 
Example #10
Source File: CubaMainTabSheet.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void addActionHandler(Action.Handler actionHandler) {
    if (actionHandlers == null) {
        actionHandlers = new LinkedHashSet<>();
    }
    actionHandlers.add(actionHandler);
}
 
Example #11
Source File: AbstractTableLayout.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void handleAction(final Action action, final Object sender, final Object target) {
    if (!selectAllAction.equals(action)) {
        return;
    }
    table.selectAll();
    publishEvent();
}
 
Example #12
Source File: CubaMainTabSheet.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Set<Action> getActions(Component actionTarget) {
    Set<Action> actions = new LinkedHashSet<>();
    if (actionHandlers != null) {
        for (Action.Handler handler : actionHandlers) {
            Action[] as = handler.getActions(actionTarget, this);
            if (as != null) {
                Collections.addAll(actions, as);
            }
        }
    }
    return actions;
}
 
Example #13
Source File: PIPSQLResolverEditorWindow.java    From XACML with MIT License 5 votes vote down vote up
@Override
public Action[] getActions(Object target, Object sender) {
	if (target == null) {
		return new Action[] {ADD_ATTRIBUTE};
	}
	return new Action[] {EDIT_ATTRIBUTE, CLONE_ATTRIBUTE, REMOVE_ATTRIBUTE};
}
 
Example #14
Source File: TableActionHandler.java    From jdal with Apache License 2.0 5 votes vote down vote up
@Override
public void handleAction(Action action, Object sender, Object target) {
	if (action instanceof Action.Handler) {
		((Action.Handler) action).handleAction(action, sender, target);
	}
	else if (action instanceof ButtonListener) {
		((ButtonListener) action).buttonClick(new ClickEvent((Component) sender) );
	}
	else {
		doHandleAction(action, sender, target);
	}
}
 
Example #15
Source File: Calendar.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
private void setActionsForDay(Map<CalendarDateRange, Set<Action>> actionMap,
                              ZonedDateTime start, ZonedDateTime end, Action.Handler actionHandler) {

    CalendarDateRange range = new CalendarDateRange(start, end);
    Action[] actions = actionHandler.getActions(range, this);
    if (actions != null) {
        Set<Action> actionSet = new LinkedHashSet<>(Arrays.asList(actions));
        actionMap.put(range, actionSet);
    }
}
 
Example #16
Source File: CubaTable.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintActions(PaintTarget target, Set<Action> actionSet) throws PaintException {
    super.paintActions(target, actionSet);

    if (shortcutActionManager != null) {
        shortcutActionManager.paintActions(null, target);
    }
}
 
Example #17
Source File: CubaGridLayout.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void removeActionHandler(Action.Handler actionHandler) {
    if (actionManager != null) {
        actionManager.removeActionHandler(actionHandler);
        markAsDirty();
    }
}
 
Example #18
Source File: CubaTreeTable.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void paintActions(PaintTarget target, Set<Action> actionSet) throws PaintException {
    super.paintActions(target, actionSet);

    if (shortcutActionManager != null) {
        shortcutActionManager.paintActions(null, target);
    }
}
 
Example #19
Source File: CubaCssActionsLayout.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void removeActionHandler(Action.Handler actionHandler) {
    if (actionManager != null) {
        actionManager.removeActionHandler(actionHandler);
        markAsDirty();
    }
}
 
Example #20
Source File: Calendar.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
private List<CalendarState.Action> createActionsList(Map<CalendarDateRange, Set<Action>> actionMap) {

        if (actionMap.isEmpty()) {
            return null;
        }

        List<CalendarState.Action> calendarActions = new ArrayList<>();

        for (Entry<CalendarDateRange, Set<Action>> entry : actionMap.entrySet()) {

            CalendarDateRange range = entry.getKey();

            for (Action action : entry.getValue()) {
                String key = actionMapper.key(action);
                CalendarState.Action calendarAction = new CalendarState.Action();
                calendarAction.actionKey = key;
                calendarAction.caption = action.getCaption();
                setResource(key, action.getIcon());
                calendarAction.iconKey = key;
                calendarAction.startDate = ACTION_DATE_TIME_FORMAT.format(range.getStart());
                calendarAction.endDate = ACTION_DATE_TIME_FORMAT.format(range.getEnd());
                calendarActions.add(calendarAction);
            }
        }

        return calendarActions;
    }
 
Example #21
Source File: CubaFoldersPane.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void perform(final Folder folder) {
    App.getInstance().getWindowManager().showOptionDialog(
            messages.getMainMessage("dialogs.Confirmation"),
            messages.getMainMessage("folders.removeFolderConfirmation"),
            Frame.MessageType.CONFIRMATION,
            new com.haulmont.cuba.gui.components.Action[]{
                    new DialogAction(Type.YES).withHandler(event -> {
                        removeFolder(folder);
                        refreshFolders();
                    }),
                    new DialogAction(Type.NO, Status.PRIMARY)
            }
    );
}
 
Example #22
Source File: Calendar.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
public void actionOnEmptyCell(String actionKey, CalDate startDate, CalDate endDate) {

    Action action = actionMapper.get(actionKey);

    for (Action.Handler ah : actionHandlers) {
        ah.handleAction(action, Calendar.this,
                ZonedDateTime.of(startDate.y, startDate.m, startDate.d,
                        startDate.t.h, startDate.t.m, startDate.t.s, 0, getZoneId()));
    }

}
 
Example #23
Source File: CubaOrderedActionsLayout.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void removeActionHandler(Action.Handler actionHandler) {
    if (actionManager != null) {
        actionManager.removeActionHandler(actionHandler);
        markAsDirty();
    }
}
 
Example #24
Source File: Calendar.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
public void actionOnItem(String actionKey, CalDate startDate, CalDate endDate, int itemIndex) {

    Action action = actionMapper.get(actionKey);

    for (Action.Handler ah : actionHandlers) {
        ah.handleAction(action, Calendar.this, items.get(itemIndex));
    }
}
 
Example #25
Source File: AbstractTableLayout.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public Action[] getActions(final Object target, final Object sender) {
    return new Action[] { selectAllAction };
}
 
Example #26
Source File: CubaTextField.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void removeActionHandler(Action.Handler actionHandler) {
    getActionManager().removeActionHandler(actionHandler);
}
 
Example #27
Source File: CalendarScreen.java    From sample-timesheets with Apache License 2.0 4 votes vote down vote up
@Override
public void handleAction(Action action, Object sender, Object target) {
    if (action == addEventAction) {
        // Check that the click was not done on an event
        if (target instanceof Date) {
            Date date = (Date) target;
            TimeEntry timeEntry = metadata.create(TimeEntry.class);
            timeEntry.setDate(date);
            editTimeEntry(timeEntry);
        } else {
            notifications.create()
                    .withType(Notifications.NotificationType.WARNING)
                    .withCaption(messages.getMessage(getClass(), "cantAddTimeEntry"))
                    .show();
        }
    } else if (action == copyEventAction) {
        // Check that the click was not done on an event
        if (target instanceof TimeEntryCalendarEventAdapter) {
            TimeEntry copiedEntry = metadata.getTools().copy(((TimeEntryCalendarEventAdapter) target).getTimeEntry());
            copiedEntry.setId(uuidSource.createUuid());
            copiedEntry.setStatus(TimeEntryStatus.NEW);

            CommitContext context = new CommitContext();
            context.getCommitInstances().add(copiedEntry);
            Set<Entity> entities = dataManager.commit(context);
            dataSource.changeEventTimeEntity((TimeEntry) entities.iterator().next());
        }
    } else if (action == deleteEventAction) {
        // Check if the action was clicked on top of an event
        if (target instanceof HolidayCalendarEventAdapter) {
            notifications.create()
                    .withType(Notifications.NotificationType.WARNING)
                    .withCaption(messages.getMessage(getClass(), "cantDeleteHoliday"))
                    .show();
        } else if (target instanceof TimeEntryCalendarEventAdapter) {
            TimeEntryCalendarEventAdapter event = (TimeEntryCalendarEventAdapter) target;
            new EventRemoveAction("eventRemove", dialogs, event).actionPerform(null);
        } else {
            notifications.create()
                    .withType(Notifications.NotificationType.WARNING)
                    .withCaption(messages.getMessage(getClass(), "cantDeleteTimeEntry"))
                    .show();
        }
    }
}
 
Example #28
Source File: CalendarScreen.java    From sample-timesheets with Apache License 2.0 4 votes vote down vote up
@Subscribe("showCommandLine")
public void onShowCommandLine(com.haulmont.cuba.gui.components.Action.ActionPerformedEvent event) {
    showCommandLine();
}
 
Example #29
Source File: CubaWindow.java    From cuba with Apache License 2.0 4 votes vote down vote up
public void addContextActionHandler(Action.Handler actionHandler) {
    contextActionHandlers.add(actionHandler);
}
 
Example #30
Source File: CubaWindow.java    From cuba with Apache License 2.0 4 votes vote down vote up
public void removeContextActionHandler(Action.Handler actionHandler) {
    contextActionHandlers.remove(actionHandler);
}