Package org.apache.wicket.extensions.markup.html.tree

Examples of org.apache.wicket.extensions.markup.html.tree.LinkTree


   * Page constructor
   *
   */
  public SimpleTreePage()
  {
    tree = new LinkTree("tree", createTreeModel());
    add(tree);
    tree.getTreeState().collapseAll();
  }
View Full Code Here


    @SuppressWarnings("serial")
    public OrganizeGlobalsPage() {
        TreeModel treeModel = createTreeModel();

        final LinkTree tree = new LinkTree("tree", treeModel)
        {
            @Override
            protected void onNodeLinkClicked(Object node, BaseTree tree, AjaxRequestTarget target) {
                DefaultMutableTreeNode mnode = (DefaultMutableTreeNode) node;
                if (!mnode.isLeaf()) {
                    return;
                }
                Global global = (Global) mnode.getUserObject();
                globalName = global.getName();
                className = global.getClassname();
                target.add(nameField);
                target.add(classNameField);
            }

        };
        tree.getTreeState().expandAll();

        add(tree);

        Form<Object> form = new Form<Object>("editForm", new CompoundPropertyModel<Object>(this));

        submitButton = new AjaxButton("submitButton", form) {

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {

                if (globalName == null || globalName.equals("") || className == null || className.equals("")) {
                    String message = new StringResourceModel("emptyError", this, null).getString();
                    error(message);
                    target.add(feedbackPanel);
                    return;
                }

                try {
                    ruleManager.addGlobal(className, globalName);
                    String message = new StringResourceModel("insertedGlobal", this, null).getString();
                    info(globalName + " " + message);
                    LOGGER.info("successfully inserted global " + globalName);
                } catch (RuleBaseException e) {
                    LOGGER.debug("error while inserting global " + globalName, e);
                    String temp = ruleManager.getGlobalType(globalName);
                    try {
                        // it comes here if the global already exists
                        ruleManager.removeGlobal(globalName);
                        ruleManager.addGlobal(className, globalName);
                        String message = new StringResourceModel("updatedGlobal", this, null).getString();
                        info(globalName + " " + message);
                    } catch (RuleBaseException ex) {
                        LOGGER.debug("error while updating global " + globalName, e);
                        // it restores the old value if the new value for global is invalid
                        ruleManager.removeGlobal(globalName);
                        ruleManager.addGlobal(temp, globalName);
                        String message = new StringResourceModel("savingError", this, null).getString();
                        error(globalName + " " + message + "\n" + ex.getLocalizedMessage());
                    }
                }
                tree.setModelObject(createTreeModel());
                globalName = "";
                className = "";

                target.add(nameField);
                target.add(classNameField);
                target.add(tree);
                target.add(feedbackPanel);
            }

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                LOGGER.warn("Error during handling submitButton submit");
            }

        };
        submitButton.setOutputMarkupId(true);
        form.add(submitButton);

        deleteButton = new AjaxButton("deleteButton", form) {

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                String temp = ruleManager.getGlobalType(globalName);
                try {
                    ruleManager.removeGlobal(globalName);
                    String message = new StringResourceModel("deletedGlobal", this, null).getString();
                    info(globalName + " " + message);
                    LOGGER.info("successfully deleted global " + globalName);
                } catch (RuleBaseException e) {
                    LOGGER.debug("error while deleting global " + globalName, e);
                    if (e.getMessage().startsWith("Rule Compilation error")) {
                        ruleManager.addGlobal(temp, globalName);
                        String message = new StringResourceModel("deletingError", this, null).getString();
                        error(globalName + " " + message + "\n" + e.getLocalizedMessage());
                    } else {
                        String message = new StringResourceModel("notExistingError", this, null).getString();
                        error(globalName + " " + message);
                    }
                    target.add(feedbackPanel);
                    return;
                }
                tree.setModelObject(createTreeModel());

                globalName = "";
                className = "";

                target.add(feedbackPanel);
View Full Code Here

        tester.assertComponent("editForm:globalName", TextField.class);
        tester.assertComponent("editForm:className", TextField.class);
        tester.assertComponent("editForm:submitButton", AjaxButton.class);
        tester.assertComponent("editForm:deleteButton", AjaxButton.class);

        LinkTree tree = (LinkTree) tester.getComponentFromLastRenderedPage("tree");
        assertEquals(globals.size(), tree.getModelObject().getChildCount(tree.getModelObject().getRoot()));
    }
View Full Code Here

        FormTester formTester = tester.newFormTester("editForm");
        formTester.setValue("globalName", "test");
        formTester.setValue("className", "test");
        formTester.submit("submitButton");

        LinkTree tree = (LinkTree) tester.getComponentFromLastRenderedPage("tree");
        assertEquals(globals.size(), tree.getModelObject().getChildCount(tree.getModelObject().getRoot()));
    }
View Full Code Here

        FormTester formTester = tester.newFormTester("editForm");
        formTester.setValue("globalName", "glob4");
        formTester.setValue("className", "aaaa.bbbb.fff");
        formTester.submit("submitButton");

        LinkTree tree = (LinkTree) tester.getComponentFromLastRenderedPage("tree");
        assertEquals(globals.size(), tree.getModelObject().getChildCount(tree.getModelObject().getRoot()));
    }
View Full Code Here

        FormTester formTester = tester.newFormTester("editForm");
        formTester.setValue("globalName", "glob4");
        formTester.setValue("className", "aaaa.bbbb.fff");
        formTester.submit("deleteButton");

        LinkTree tree = (LinkTree) tester.getComponentFromLastRenderedPage("tree");
        assertEquals(globals.size(), tree.getModelObject().getChildCount(tree.getModelObject().getRoot()));
    }
View Full Code Here

        FormTester formTester = tester.newFormTester("editForm");
        formTester.setValue("globalName", "test");
        formTester.setValue("className", "test");
        formTester.submit("deleteButton");

        LinkTree tree = (LinkTree) tester.getComponentFromLastRenderedPage("tree");
        assertEquals(globals.size(), tree.getModelObject().getChildCount(tree.getModelObject().getRoot()));
    }
View Full Code Here

        tester.assertComponent("editForm", Form.class);
        tester.assertComponent("editForm:importName", TextField.class);
        tester.assertComponent("editForm:submitButton", AjaxButton.class);
        tester.assertComponent("editForm:deleteButton", AjaxButton.class);

        LinkTree tree = (LinkTree) tester.getComponentFromLastRenderedPage("tree");
        assertEquals(imports.size(), tree.getModelObject().getChildCount(tree.getModelObject().getRoot()));
    }
View Full Code Here

    public void testAddNewImport_shouldAddImport() throws Exception {
        FormTester formTester = tester.newFormTester("editForm");
        formTester.setValue("importName", "aaaa.bbbb.fff");
        formTester.submit("submitButton");

        LinkTree tree = (LinkTree) tester.getComponentFromLastRenderedPage("tree");
        assertEquals(imports.size(), tree.getModelObject().getChildCount(tree.getModelObject().getRoot()));
    }
View Full Code Here

    public void testDeleteImport_shouldDeleteImport() throws Exception {
        FormTester formTester = tester.newFormTester("editForm");
        formTester.setValue("importName", "aaaa.bbbb.fff");
        formTester.submit("deleteButton");

        LinkTree tree = (LinkTree) tester.getComponentFromLastRenderedPage("tree");
        assertEquals(imports.size(), tree.getModelObject().getChildCount(tree.getModelObject().getRoot()));
    }
View Full Code Here

TOP

Related Classes of org.apache.wicket.extensions.markup.html.tree.LinkTree

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.