Example usage for org.apache.wicket Component getMetaData

List of usage examples for org.apache.wicket Component getMetaData

Introduction

In this page you can find the example usage for org.apache.wicket Component getMetaData.

Prototype

public final <M extends Serializable> M getMetaData(final MetaDataKey<M> key) 

Source Link

Document

Gets metadata for this component using the given key.

Usage

From source file:com.servoy.j2db.server.headlessclient.dataui.TooltipAttributeModifier.java

License:Open Source License

static String getToolTipForComponent(Component component) {
    String tooltip = null;// www .  j a va2 s . com
    if (component instanceof IComponent || component instanceof SortableCellViewHeader
            || component.getMetaData(TOOLTIP_METADATA) != null) {
        if (component instanceof IComponent) {
            tooltip = ((IComponent) component).getToolTipText();
        }
        if (component instanceof SortableCellViewHeader) {
            tooltip = ((SortableCellViewHeader) component).getToolTipText();
        }
        if (tooltip == null) {
            tooltip = (String) component.getMetaData(TOOLTIP_METADATA);
        }
        return tooltip;
    }
    return null;
}

From source file:eu.uqasar.auth.strategies.metadata.MetaDataAuthorizationStrategy.java

License:Apache License

/**
 * Authorizes the given roles to perform the given action on the given
 * component./*from w w w .  ja va 2  s  . c o m*/
 *
 * @param component The component that is subject to the authorization
 * @param action The action to authorize
 * @param roles The roles to authorize
 */
private static void authorize(final Component component, final Action action, final Role... roles) {
    ActionPermissions permissions = component.getMetaData(ACTION_PERMISSIONS);
    if (permissions == null) {
        permissions = new ActionPermissions();
        component.setMetaData(ACTION_PERMISSIONS, permissions);
    }
    permissions.authorize(action, roles);
}

From source file:eu.uqasar.auth.strategies.metadata.MetaDataAuthorizationStrategy.java

License:Apache License

/**
 * Grants permission to all roles to perform the given action on the given
 * component./*from  w  ww  . jav  a2s . c om*/
 *
 * @param component The component that is subject to the authorization
 * @param action The action to authorize
 */
private static void authorizeAll(final Component component, final Action action) {
    ActionPermissions permissions = component.getMetaData(ACTION_PERMISSIONS);
    if (permissions != null) {
        permissions.authorizeAll(action);
    }
}

From source file:eu.uqasar.auth.strategies.metadata.MetaDataAuthorizationStrategy.java

License:Apache License

/**
 * Removes permission for the given roles to perform the given action on the
 * given component. There is no danger in removing authorization by calling
 * this method. If the last authorization grant is removed for a given
 * action, the internal role Role.NoRole will automatically be added,
 * effectively denying access to all roles (if this was not done, all roles
 * would suddenly have access since no authorization is equivalent to full
 * access)./*  www. j  a v  a 2 s .  c  om*/
 *
 * @param component The component
 * @param action The action
 * @param roles The set of roles that are no longer allowed to perform the
 * given action
 */
private static void unauthorize(final Component component, final Action action, final Role... roles) {
    final ActionPermissions permissions = component.getMetaData(ACTION_PERMISSIONS);
    if (permissions != null) {
        permissions.unauthorize(action, roles);
    }
}

From source file:eu.uqasar.auth.strategies.metadata.MetaDataAuthorizationStrategy.java

License:Apache License

/**
 * Gets the roles for the given action/component combination.
 *
 * @param component the component//from   www .  j a v  a 2 s.  c  o  m
 * @param action the action
 * @return the roles for the action as defined with the given component
 */
private static EnumSet<Role> levelsAuthorizedToPerformAction(final Component component, final Action action) {
    final ActionPermissions permissions = component.getMetaData(ACTION_PERMISSIONS);
    if (permissions != null) {
        return permissions.rolesFor(action);
    }
    return null;
}

From source file:org.brixcms.plugin.hierarchical.admin.HierarchicalNodeManagerPanel.java

License:Apache License

@Override
protected void onBeforeRender() {
    if (get("createNodesContainer") == null) {
        WebMarkupContainer createNodesContainer = new WebMarkupContainer("createNodesContainer") {
            @Override/*from  w w  w.ja  v a  2 s.c o  m*/
            public boolean isVisible() {
                BrixNode folderNode = getNewNodeParent().getObject();
                return pluginLocator.getPlugin().canAddNodeChild(folderNode, Context.ADMINISTRATION);
            }
        };
        add(createNodesContainer);

        final NodeEditorPluginEntriesModel createNodesModel = new NodeEditorPluginEntriesModel(pluginLocator,
                getNewNodeParent());
        createNodesContainer.add(new ListView<NodeEditorPluginEntry>("createNodes", createNodesModel) {
            @Override
            protected void populateItem(final ListItem<NodeEditorPluginEntry> item) {
                Link<Void> link;
                item.add(link = new Link<Void>("link") {
                    @Override
                    public void onClick() {
                        NodeEditorPlugin plugin = item.getModelObject().getPlugin();
                        final Component currentEditor = getEditor();

                        // remember the last editor that is not a create
                        // node
                        // panel
                        if (lastEditor == null || currentEditor.getMetaData(EDITOR_NODE_TYPE) == null) {
                            lastEditor = currentEditor;
                        }
                        SimpleCallback goBack = new SimpleCallback() {
                            @Override
                            public void execute() {
                                setupEditor(lastEditor);
                            }
                        };
                        IModel<BrixNode> parent = getNewNodeParent(plugin.getNodeType());
                        Panel panel = plugin.newCreateNodePanel(EDITOR_ID, parent, goBack);
                        panel.setMetaData(EDITOR_NODE_TYPE, plugin.getNodeType());
                        setupEditor(panel);
                    }

                    @Override
                    protected void onComponentTag(ComponentTag tag) {
                        super.onComponentTag(tag);
                        NodeEditorPlugin plugin = item.getModelObject().getPlugin();
                        String editorNodeType = getEditor().getMetaData(EDITOR_NODE_TYPE);
                        if (plugin.getNodeType().equals(editorNodeType)) {
                            CharSequence klass = tag.getAttribute("class");
                            if (klass == null) {
                                klass = "active";
                            } else {
                                klass = klass + " active";
                            }
                            tag.put("class", klass);
                        }
                    }

                });
                IModel<BrixNode> parent = getNewNodeParent();
                NodeEditorPlugin plugin = item.getModelObject().getPlugin();
                link.add(new Label("label", plugin.newCreateNodeCaptionModel(parent)));
            }

        }.setReuseItems(false));

        editor = new WebMarkupContainer(EDITOR_ID);
        add(editor);
        setupDefaultEditor();
    }

    Workspace workspace = workspaceModel.getObject();

    BrixNode node = null;
    try {
        node = getModelObject();
    } catch (JcrException e) {
        if (e.getCause() instanceof ItemNotFoundException) {
            HierarchicalNodePlugin dataPlugin = pluginLocator.getPlugin();
            if (dataPlugin != null) {
                node = dataPlugin.getRootNode(workspace.getId());
                getModel().setObject(null);
                selectNode(node);
                setupDefaultEditor();
                tree.invalidateAll();
            }
        } else {
            throw (e);
        }
    }
    if (node != null) {
        String nodeWorkspaceName = node.getSession().getWorkspace().getName();
        if (!nodeWorkspaceName.equals(workspace.getId())) {
            // we have to either update node or workspace
            if (oldWorkspaceId != null && workspace.getId().equals(oldWorkspaceId)) {
                // the node changed, need to update the workspace
                Workspace newWorkspace = node.getBrix().getWorkspaceManager().getWorkspace(nodeWorkspaceName);
                workspaceModel.setObject(newWorkspace);
            } else {
                // the workspace has changed, update the node
                // 1 try to get node with same UUID, 2 try to get node with
                // same
                // path, 3 get root node
                JcrSession newSession = node.getBrix().getCurrentSession(workspace.getId());
                String uuid = node.getIdentifier();
                BrixNode newNode = JcrUtil.getNodeByUUID(newSession, uuid);
                if (newNode == null) {
                    String path = node.getPath();
                    if (newSession.getRootNode().hasNode(path.substring(1))) {
                        newNode = (BrixNode) newSession.getItem(path);
                    }
                }
                if (newNode == null) {
                    newNode = pluginLocator.getPlugin().getRootNode(workspaceModel.getObject().getId());
                }
                selectNode(newNode);
                tree.invalidateAll();
                tree.getTreeState().expandNode(((TreeModel) tree.getDefaultModelObject()).getRoot());
            }
        }
    }

    super.onBeforeRender();

    oldWorkspaceId = workspace.getId();

}

From source file:org.brixcms.plugin.site.admin.NodeManagerContainerPanel.java

License:Apache License

public NodeManagerContainerPanel(String id, IModel<Workspace> workspaceModel) {
    super(id, new BrixNodeModel(getRootNode(workspaceModel)));
    this.workspaceModel = workspaceModel;

    editor = new WebMarkupContainer(EDITOR_ID);
    add(editor);//ww w.  j  a  v  a  2  s .c  o m

    setupDefaultEditor();

    add(tree = new Tree("tree", new TreeModel()));

    WebMarkupContainer createNodesContainer = new WebMarkupContainer("createNodesContainer") {
        @Override
        public boolean isVisible() {
            BrixNode folderNode = getNewNodeParent().getObject();
            return SitePlugin.get().canAddNodeChild(folderNode, Context.ADMINISTRATION);
        }
    };
    add(createNodesContainer);

    createNodesContainer.add(new ListView<SiteNodePluginEntry>("createNodes", createNodesModel) {
        @Override
        protected void populateItem(final ListItem<SiteNodePluginEntry> item) {
            Link<Void> link;
            item.add(link = new Link<Void>("link") {
                @Override
                public void onClick() {
                    SiteNodePlugin plugin = item.getModelObject().getPlugin();
                    final Component currentEditor = getEditor();

                    // remember the last editor that is not a create node
                    // panel
                    if (lastEditor == null || currentEditor.getMetaData(EDITOR_NODE_TYPE) == null) {
                        lastEditor = currentEditor;
                    }
                    SimpleCallback goBack = new SimpleCallback() {
                        public void execute() {
                            setupEditor(lastEditor);
                        }
                    };
                    Panel panel = plugin.newCreateNodePanel(EDITOR_ID, getNewNodeParent(), goBack);
                    panel.setMetaData(EDITOR_NODE_TYPE, plugin.getNodeType());
                    setupEditor(panel);
                }

                @Override
                protected void onComponentTag(ComponentTag tag) {
                    super.onComponentTag(tag);
                    SiteNodePlugin plugin = item.getModelObject().getPlugin();
                    String editorNodeType = getEditor().getMetaData(EDITOR_NODE_TYPE);
                    if (plugin.getNodeType().equals(editorNodeType)) {
                        CharSequence klass = tag.getString("class");
                        if (klass == null) {
                            klass = "selected";
                        } else {
                            klass = klass + " selected";
                        }
                        tag.put("class", klass);
                    }
                }
            });
            item.add(new WebMarkupContainer("separator") {
                @Override
                public boolean isVisible() {
                    return item.getIndex() != createNodesModel.getObject().size() - 1;
                }
            });
            IModel<BrixNode> parent = getNewNodeParent();
            SiteNodePlugin plugin = item.getModelObject().getPlugin();
            link.add(new Label("label", plugin.newCreateNodeCaptionModel(parent)));
        }

    }.setReuseItems(false));
}

From source file:org.dcm4chee.web.common.secure.ExtendedSwarmStrategy.java

License:LGPL

private String buildHiveKey(Component component) {

    if (component == null)
        throw new SecurityException(this.getClass() + ": Specified component is null");

    MarkupContainer markupContainer = findLowestSecureContainer(component);
    String alias = SecureComponentHelper.alias(markupContainer.getClass());
    String relative = (String) component.getMetaData(new ComponentHiveKey(String.class));
    if (relative == null || "".equals(relative))
        return alias;
    else/*  www.  j a va2  s. c o  m*/
        return alias + ":" + relative;
}

From source file:org.opensingular.form.wicket.SValidationFeedbackHandler.java

License:Apache License

public static SValidationFeedbackHandler get(Component component) {
    return component.getMetaData(MDK);
}

From source file:org.opensingular.form.wicket.util.WicketFormUtils.java

License:Apache License

public static MarkupContainer getRootContainer(Component component) {
    return component.getMetaData(KEY_ROOT_CONTAINER);
}