Example usage for org.apache.wicket.markup.html.panel Panel setMetaData

List of usage examples for org.apache.wicket.markup.html.panel Panel setMetaData

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.panel Panel setMetaData.

Prototype

public final <M extends Serializable> Component setMetaData(final MetaDataKey<M> key, final M object) 

Source Link

Document

Sets the metadata for this component using the given key.

Usage

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/*w ww  .ja  v a2  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);//w w  w. j ava  2 s  .  co 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));
}