Java tutorial
/* * Copyright (c) 2008-2016 Haulmont. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.haulmont.cuba.web.toolkit.ui; import com.haulmont.cuba.web.toolkit.ui.client.cssactionslayout.CubaCssActionsLayoutState; import com.vaadin.event.Action; import com.vaadin.event.ActionManager; import com.vaadin.event.ShortcutListener; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.shared.ui.MarginInfo; import com.vaadin.ui.CssLayout; import com.vaadin.ui.Layout; import com.vaadin.ui.LegacyComponent; import java.util.Map; /** * CssLayout with separate action manager for shortcuts */ public class CubaCssActionsLayout extends CssLayout implements Action.Container, LegacyComponent, Layout.MarginHandler, Layout.SpacingHandler { protected ActionManager actionManager; @Override protected CubaCssActionsLayoutState getState() { return (CubaCssActionsLayoutState) super.getState(); } @Override public void addActionHandler(Action.Handler actionHandler) { getActionManager().addActionHandler(actionHandler); markAsDirty(); } @Override public void removeActionHandler(Action.Handler actionHandler) { if (actionManager != null) { actionManager.removeActionHandler(actionHandler); markAsDirty(); } } @Override public void addShortcutListener(ShortcutListener listener) { getActionManager().addAction(listener); } @Override public void removeShortcutListener(ShortcutListener listener) { getActionManager().removeAction(listener); } @Override protected ActionManager getActionManager() { if (actionManager == null) { actionManager = new ActionManager(this); } return actionManager; } @Override public void paintContent(PaintTarget target) throws PaintException { if (actionManager != null) { actionManager.paintActions(null, target); } } @Override public void changeVariables(Object source, Map<String, Object> variables) { if (actionManager != null) { actionManager.handleActions(variables, this); } } @Override public void setMargin(boolean enabled) { setMargin(new MarginInfo(enabled)); } @Override public void setMargin(MarginInfo marginInfo) { getState().marginsBitmask = marginInfo.getBitMask(); } @Override public MarginInfo getMargin() { return new MarginInfo(getState().marginsBitmask); } @Override public void setSpacing(boolean enabled) { getState().spacing = enabled; } @Override public boolean isSpacing() { return getState().spacing; } }