Example usage for org.apache.wicket.ajax.markup.html AjaxLink AjaxLink

List of usage examples for org.apache.wicket.ajax.markup.html AjaxLink AjaxLink

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.markup.html AjaxLink AjaxLink.

Prototype

public AjaxLink(final String id) 

Source Link

Document

Construct.

Usage

From source file:eu.uqasar.web.dashboard.widget.projectqualitychart.ProjectQualityChartSettingsPanel.java

License:Apache License

public ProjectQualityChartSettingsPanel(String id, IModel<ProjectQualityChartWidget> model) {
    super(id, model);

    setOutputMarkupPlaceholderTag(true);

    Form<Widget> form = new Form<>("form");

    // Get the project from the settings
    projectName = getModelObject().getSettings().get("project");

    // DropDown select for Projects
    TreeNodeService treeNodeService = null;
    try {/*from  www .j a va  2s  .c  om*/
        InitialContext ic = new InitialContext();
        treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");
        projects = treeNodeService.getAllProjectsOfLoggedInUser();
        if (projects != null && projects.size() != 0) {
            if (projectName == null || projectName.isEmpty()) {
                projectName = projects.get(0).getName();
            }
        }
        project = treeNodeService.getProjectByName(projectName);
    } catch (NamingException e) {
        e.printStackTrace();
    }
    DropDownChoice<Project> projectChoice = new DropDownChoice<>("project",
            new PropertyModel<Project>(this, "project"), projects);
    form.add(projectChoice);

    // Field for the chart type
    chartType = getModelObject().getSettings().get("chartType");
    DropDownChoice<String> choice = new DropDownChoice<>("chartType",
            new PropertyModel<String>(this, "chartType"), ProjectQualityChartWidget.TYPES);
    form.add(choice);

    form.add(new AjaxSubmitLink("submit") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (project != null) {
                getModelObject().getSettings().put("chartType", chartType);
                getModelObject().getSettings().put("project", project.getName());
                Dashboard dashboard = findParent(DashboardPanel.class).getDashboard();
                DbDashboard dbdb = (DbDashboard) dashboard;
                WidgetPanel widgetPanel = findParent(WidgetPanel.class);
                ProjectQualityChartWidgetView widgetView = (ProjectQualityChartWidgetView) widgetPanel
                        .getWidgetView();
                target.add(widgetView);
                hideSettingPanel(target);

                // Do not save the default dashboard
                if (dbdb.getId() != null && dbdb.getId() != 0) {
                    dashboardContext.getDashboardPersiter().save(dashboard);
                    PageParameters params = new PageParameters();
                    params.add("id", dbdb.getId());
                    setResponsePage(DashboardViewPage.class, params);
                }
            }
        }

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

    });
    form.add(new AjaxLink<Void>("cancel") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            hideSettingPanel(target);
        }

    });

    add(form);
}

From source file:eu.uqasar.web.dashboard.widget.reportingwidget.ReportingSettingsPanel.java

License:Apache License

public ReportingSettingsPanel(String id, IModel<ReportingWidget> model) {
    super(id, model);

    setOutputMarkupPlaceholderTag(true);

    final ReportingWidget qualityWidget = model.getObject();

    Form<Widget> form = new Form<>("form");

    cube = getModelObject().getSettings().get("cube");
    if (cube == null) {
        cube = "jira";
    }/* ww w.  ja va  2s. com*/
    selectedAdditionalRule = getModelObject().getSettings().get("selectedAdditionalRule");
    selectedRule = getModelObject().getSettings().get("selectedRule");

    chartType = getModelObject().getSettings().get("chartType");
    if (chartType == null) {
        chartType = ReportingWidget.COLUMN_TYPE;
    }

    try {
        InitialContext ic = new InitialContext();
        dataService = (SonarDataService) ic.lookup("java:module/SonarDataService");
        projects = dataService.getSonarProjects();
    } catch (NamingException e) {
        e.printStackTrace();
    }

    // Add Rules and Additional Rules as DropDownList
    rulesMap = qualityWidget.getRulesMap(projects);

    // //Add selection of cubes for report generation.
    List<String> cubes = Arrays.asList("jira", "sonarcube");
    final DropDownChoice<String> selectedCubes = new DropDownChoice<>("cube",
            new PropertyModel<String>(this, "cube"), cubes);
    selectedCubes.setRequired(true);
    form.add(selectedCubes);

    // Field for the chart type
    chartType = getModelObject().getSettings().get("chartType");
    DropDownChoice<String> choice = new DropDownChoice<>("chartType",
            new PropertyModel<String>(this, "chartType"), ReportingWidget.TYPES);
    form.add(choice);

    // Create a void form for ListView and WebMarkupContainer
    Form<Void> formVoid = new Form<>("formVoid");
    ruleWebMrkUpContainer = new WebMarkupContainer("ruleContainer", new Model<Rule>());
    ruleWebMrkUpContainer.setOutputMarkupId(true);
    formVoid.add(ruleWebMrkUpContainer);

    ruleWebMrkUpContainer.add(rulesView = new ListView<Rule>("rulesListView", Model.ofList(proposedRules)) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onConfigure() {
            super.onConfigure();
            // update model
            rulesView.setModelObject(proposedRules);
        }

        @Override
        protected void populateItem(ListItem<Rule> item) {

            final Rule proposedRule = item.getModelObject();

            // //get dropdown list method will give two different lists..
            IModel<List<? extends String>> ruleChoices = new AbstractReadOnlyModel<List<? extends String>>() {
                /**
                 * 
                 */
                private static final long serialVersionUID = 1L;

                @Override
                public List<String> getObject() {
                    return new ArrayList<>(rulesMap.keySet());
                }

            };

            IModel<List<? extends String>> additionalRuleChoices = new AbstractReadOnlyModel<List<? extends String>>() {
                /**
                 * 
                 */
                private static final long serialVersionUID = 1L;

                @Override
                public List<String> getObject() {
                    List<String> models = rulesMap.get(proposedRule.getSelectedRule()); // very important
                    // System.out.println("selectedRule : " + proposedUser.getSelectedRule());
                    if (models == null) {
                        models = Collections.emptyList();
                    }
                    return models;
                }

            };

            item.add(rules = new DropDownChoice<>("rules",
                    new PropertyModel<String>(proposedRule, "selectedRule"), ruleChoices));
            rules.setOutputMarkupId(true);
            rules.setNullValid(true);
            rules.setRequired(true);
            rules.setMarkupId("rules" + item.getIndex()); // very important

            item.add(additionalRules = new DropDownChoice<>("additionalRules",
                    new PropertyModel<String>(proposedRule, "selectedAdditionalRule"), additionalRuleChoices));
            additionalRules.setOutputMarkupId(true);
            additionalRules.setMarkupId("additionalRules" + item.getIndex()); // very important
            additionalRules.setNullValid(true);
            additionalRules.setRequired(true);
            rules.add(new AjaxFormComponentUpdatingBehavior("onchange") { // very important
                /**
                * 
                */
                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    target.add(additionalRules);
                    target.add(rules);
                }
            });

            additionalRules.add(new AjaxFormComponentUpdatingBehavior("onchange") { // very important
                private static final long serialVersionUID = 1L;

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    target.add(additionalRules);
                    target.add(rules);
                }
            });
        }
    });

    AjaxSubmitLink addRuleButton = new AjaxSubmitLink("add.rule", formVoid) {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> formVoid) {
            // target.add(feedbackPanel);
            target.add(formVoid);
        }

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

            addNewRuleToList(target, formVoid);
        }
    };
    addRuleButton.add(new Label("button.add.save",
            new StringResourceModel("button.add.save", this, Model.of(proposedRules))));
    formVoid.add(addRuleButton);

    rulesView.setOutputMarkupId(true);
    form.add(formVoid);

    form.add(new AjaxSubmitLink("submit") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Dashboard dashboard = findParent(DashboardPanel.class).getDashboard();
            if (dashboard != null && dashboardContext != null) {

                // Here, create a url query based on selected Rule and Additional Rule from dynamic dropdown lists..
                urlToLoad = createRule();
                System.out.println(urlToLoad);
                getModelObject().getSettings().put("urlToLoad", urlToLoad);

                getModelObject().getSettings().put("cube", cube);
                getModelObject().getSettings().put("selectedAdditionalRule", selectedAdditionalRule);
                getModelObject().getSettings().put("selectedRule", selectedRule);
                getModelObject().getSettings().put("chartType", chartType);

                System.out.print("dashboard : " + dashboard);
                dashboardContext.getDashboardPersiter().save(dashboard);
                hideSettingPanel(target);

                WidgetPanel widgetPanel = findParent(WidgetPanel.class);
                ReportingWidget tasksWidget = (ReportingWidget) widgetPanel.getModelObject();
                tasksWidget.setTitle("Reporting Widget For " + cube + " cube");
                ReportingWidgetView widgetView = (ReportingWidgetView) widgetPanel.getWidgetView();
                target.add(widgetView);

                PageParameters params = new PageParameters();
                DbDashboard dbdb = (DbDashboard) dashboard;
                params.add("id", dbdb.getId());
                setResponsePage(DashboardViewPage.class, params);
            }
        }

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

    });

    form.add(new AjaxLink<Void>("cancel") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            hideSettingPanel(target);
        }
    });

    add(form);

}

From source file:eu.uqasar.web.dashboard.widget.sonarqualitywidget.SonarQualityWidgetSettingsPanel.java

License:Apache License

public SonarQualityWidgetSettingsPanel(String id, IModel<SonarQualityWidget> model) {
    super(id, model);

    setOutputMarkupPlaceholderTag(true);

    Form<Widget> form = new Form<>("form");
    project = getModelObject().getSettings().get("project");
    metric = getModelObject().getSettings().get("metric");
    individualMetric = getModelObject().getSettings().get("individualMetric");
    if (getModelObject().getSettings().get("period") != null) {
        timeInterval = getModelObject().getSettings().get("period");
    } else {/*  w  w  w  .  ja  v  a2 s.  c o m*/
        // if there is no selection of period then it should be the latest values 
        timeInterval = "Latest";
    }

    List<String> projects = new ArrayList<>();
    try {
        InitialContext ic = new InitialContext();
        dataService = (SonarDataService) ic.lookup("java:module/SonarDataService");
        projects = dataService.getSonarProjects();
    } catch (NamingException e) {
        e.printStackTrace();
    }

    form.add(new DropDownChoice<>("project", new PropertyModel<String>(this, "project"), projects));

    List<String> metricGroups = Arrays.asList("Code Lines related", "Complexity related", "Structure related",
            "Density related", "Test related");
    form.add(new DropDownChoice<>("metric", new PropertyModel<String>(this, "metric"), metricGroups));

    List<String> individualMetricGroups = UQasarUtil.getSonarMetricNames();
    DropDownChoice<String> dropDown = new DropDownChoice<>("individualMetric",
            new PropertyModel<String>(this, "individualMetric"), individualMetricGroups);
    dropDown.setNullValid(true);
    form.add(dropDown);

    form.add(new AjaxSubmitLink("submit") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Dashboard dashboard = findParent(DashboardPanel.class).getDashboard();
            if (project != null && dashboard != null) {
                getModelObject().getSettings().put("project", project);
                getModelObject().getSettings().put("metric", metric);
                getModelObject().getSettings().put("period", timeInterval);
                getModelObject().getSettings().put("individualMetric", individualMetric);
                hideSettingPanel(target);

                WidgetPanel widgetPanel = findParent(WidgetPanel.class);
                SonarQualityWidget tasksWidget = (SonarQualityWidget) widgetPanel.getModelObject();
                tasksWidget.setTitle("Source code quality in " + project);
                SonarQualityWidgetView widgetView = (SonarQualityWidgetView) widgetPanel.getWidgetView();
                target.add(widgetView);
                DbDashboard dbdb = (DbDashboard) dashboard;

                // Do not save the default dashboard
                if (dbdb.getId() != null && dbdb.getId() != 0) {
                    dashboardContext.getDashboardPersiter().save(dashboard);
                    PageParameters params = new PageParameters();
                    params.add("id", dbdb.getId());
                    setResponsePage(DashboardViewPage.class, params);
                }
            }
        }

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

    });

    // Period
    List<String> timeIntervals = Arrays.asList("Last Year", "Last 6 Months", "Last Month", "Last Week",
            "Latest");

    form.add(new DropDownChoice<>("time", new PropertyModel<String>(this, "timeInterval"), timeIntervals));

    form.add(new AjaxLink<Void>("cancel") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            hideSettingPanel(target);
        }
    });

    add(form);
}

From source file:eu.uqasar.web.dashboard.widget.tech_debt.TechDebtChartSettingsPanel.java

License:Apache License

public TechDebtChartSettingsPanel(String id, IModel<TechDebtChartWidget> model) {
    super(id, model);

    setOutputMarkupPlaceholderTag(true);

    Form<Widget> form = new Form<>("form");

    // Get the project from the settings
    projectName = getModelObject().getSettings().get("project");

    // DropDown select for Projects
    TreeNodeService treeNodeService = null;

    try {/*from w  w w. java  2 s  .c o m*/
        InitialContext ic = new InitialContext();
        treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");
        projects = treeNodeService.getAllProjectsOfLoggedInUser();
        if (projects != null && projects.size() != 0) {
            if (projectName == null || projectName.isEmpty()) {
                projectName = projects.get(0).getName();
            }
            project = treeNodeService.getProjectByName(projectName);
        }
    } catch (NamingException e) {
        e.printStackTrace();
    }
    DropDownChoice<Project> projectChoice = new DropDownChoice<>("project",
            new PropertyModel<Project>(this, "project"), projects);
    form.add(projectChoice);

    // Field for the chart type
    chartType = getModelObject().getSettings().get("chartType");
    DropDownChoice<String> choice = new DropDownChoice<>("chartType",
            new PropertyModel<String>(this, "chartType"), TechDebtChartWidget.TYPES);
    form.add(choice);

    form.add(new AjaxSubmitLink("submit") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            if (project != null) {
                getModelObject().getSettings().put("chartType", chartType);
                getModelObject().getSettings().put("project", project.getName());
                Dashboard dashboard = findParent(DashboardPanel.class).getDashboard();
                DbDashboard dbdb = (DbDashboard) dashboard;

                WidgetPanel widgetPanel = findParent(WidgetPanel.class);
                TechDebtChartWidgetView widgetView = (TechDebtChartWidgetView) widgetPanel.getWidgetView();
                target.add(widgetView);
                hideSettingPanel(target);

                // Do not save the default dashboard
                if (dbdb.getId() != null && dbdb.getId() != 0) {
                    dashboardContext.getDashboardPersiter().save(dashboard);
                    PageParameters params = new PageParameters();
                    params.add("id", dbdb.getId());
                    setResponsePage(DashboardViewPage.class, params);
                }
            }
        }

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

    });
    form.add(new AjaxLink<Void>("cancel") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            hideSettingPanel(target);
        }

    });

    add(form);
}

From source file:eu.uqasar.web.dashboard.widget.testlinkwidget.TestLinkSettingsPanel.java

License:Apache License

public TestLinkSettingsPanel(String id, IModel<TestLinkWidget> model) {
    super(id, model);

    setOutputMarkupPlaceholderTag(true);

    Form<Widget> form = new Form<>("form");
    project = getModelObject().getSettings().get("project");
    timeInterval = getModelObject().getSettings().get("period");
    individualMetric = getModelObject().getSettings().get("individualMetric");

    List<String> projects = new ArrayList<>();
    try {// w  w  w  .  j  a va 2 s .  c o  m
        InitialContext ic = new InitialContext();
        TestLinkDataService dataService = (TestLinkDataService) ic.lookup("java:module/TestLinkDataService");
        projects = dataService.getTestLinkProjects();
    } catch (NamingException e) {
        e.printStackTrace();
    }

    form.add(new DropDownChoice<>("project", new PropertyModel<String>(this, "project"), projects));

    List<String> individualMetricGroups = UQasarUtil.getTestLinkMetricNames();
    DropDownChoice<String> dropDown = new DropDownChoice<>("individualMetric",
            new PropertyModel<String>(this, "individualMetric"), individualMetricGroups);
    dropDown.setNullValid(true);
    form.add(dropDown);

    form.add(new AjaxSubmitLink("submit") {

        private static final long serialVersionUID = 1L;

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

            Dashboard dashboard = findParent(DashboardPanel.class).getDashboard();
            if (project != null && dashboard != null) {
                getModelObject().getSettings().put("project", project);
                getModelObject().getSettings().put("period", timeInterval);
                getModelObject().getSettings().put("individualMetric", individualMetric);

                DbDashboard dbdb = (DbDashboard) dashboard;
                hideSettingPanel(target);

                WidgetPanel widgetPanel = findParent(WidgetPanel.class);
                TestLinkWidget tasksWidget = (TestLinkWidget) widgetPanel.getModelObject();
                tasksWidget.setTitle("Source code quality in " + project);
                TestLinkWidgetView widgetView = (TestLinkWidgetView) widgetPanel.getWidgetView();
                target.add(widgetView);

                // Do not save the default dashboard
                if (dbdb.getId() != null && dbdb.getId() != 0) {
                    dashboardContext.getDashboardPersiter().save(dashboard);
                    PageParameters params = new PageParameters();
                    params.add("id", dbdb.getId());
                    setResponsePage(DashboardViewPage.class, params);
                }
            }
        }

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

    });

    // Period
    List<String> timeIntervals = Arrays.asList("Last Year", "Last 6 Months", "Last Month", "Last Week");
    form.add(new DropDownChoice<>("time", new PropertyModel<String>(this, "timeInterval"), timeIntervals));

    form.add(new AjaxLink<Void>("cancel") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            hideSettingPanel(target);
        }
    });

    add(form);
}

From source file:eu.uqasar.web.dashboard.widget.uqasardatavisualization.UqasarDataVisualizationSettingsPanel.java

License:Apache License

public UqasarDataVisualizationSettingsPanel(String id, IModel<UqasarDataVisualizationWidget> model) {
    super(id, model);

    setOutputMarkupPlaceholderTag(true);

    //Form and WMCs
    final Form<Widget> form = new Form<>("form");
    wmcGeneral = newWebMarkupContainer("wmcGeneral");
    form.add(wmcGeneral);/*  w w  w. java  2s.  co  m*/

    // Get the project from the settings
    projectName = getModelObject().getSettings().get("project");

    // DropDown select for Projects
    TreeNodeService treeNodeService = null;
    try {
        InitialContext ic = new InitialContext();
        treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");
        projects = treeNodeService.getAllProjectsOfLoggedInUser();
        if (projects != null && projects.size() != 0) {
            if (projectName == null || projectName.isEmpty()) {
                projectName = projects.get(0).getName();
            }
            project = treeNodeService.getProjectByName(projectName);
            recreateAllProjectTreeChildrenForProject(project);
        }
    } catch (NamingException e) {
        e.printStackTrace();
    }
    //project
    List<String> joinedQualityParameters = ListUtils.union(ListUtils.union(OBJS, INDIS), MTRX);
    qualityParameterChoice = new DropDownChoice<String>("qualityParams",
            new PropertyModel<String>(this, "qualityParams"), joinedQualityParameters) {
        @Override
        protected void appendOptionHtml(AppendingStringBuffer buffer, String choice, int index,
                String selected) {
            super.appendOptionHtml(buffer, choice, index, selected);

            if (UqasarDataVisualizationWidget.ALL.get(0).equals(choice)) {
                buffer.append("<optgroup label='Quality Objectives'></optgroup>");
            }

            int noOfObjs = OBJS.size();
            int noOfIndis = INDIS.size();

            if (index + 1 == noOfObjs && noOfObjs > 0) {
                buffer.append("<optgroup label='Quality Indicators'></optgroup>");
            }
            if (index + 1 == (noOfObjs + noOfIndis) && noOfIndis > 0) {
                buffer.append("<optgroup label='Metrics'></optgroup>");
            }

        }
    };
    qualityParameterChoice.setOutputMarkupId(true);
    wmcGeneral.add(qualityParameterChoice);

    // project
    projectChoice = new DropDownChoice<>("projects", new PropertyModel<Project>(this, "project"), projects);
    if (project != null) {
        projectChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                System.out.println(project);
                recreateAllProjectTreeChildrenForProject(project);
                qualityParameterChoice.setChoices(ListUtils.union(ListUtils.union(OBJS, INDIS), MTRX));
                target.add(qualityParameterChoice);
                target.add(wmcGeneral);

                target.add(form);
            }
        });

    }

    wmcGeneral.setOutputMarkupId(true);
    wmcGeneral.add(projectChoice);

    form.add(new AjaxSubmitLink("submit") {
        private static final long serialVersionUID = 1L;

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

            if (project != null) {
                getModelObject().getSettings().put("qualityParams", qualityParams);
                getModelObject().getSettings().put("project", project.getName());

                Dashboard dashboard = findParent(DashboardPanel.class).getDashboard();
                DbDashboard dbdb = (DbDashboard) dashboard;

                WidgetPanel widgetPanel = findParent(WidgetPanel.class);
                UqasarDataVisualizationWidgetView widgetView = (UqasarDataVisualizationWidgetView) widgetPanel
                        .getWidgetView();
                target.add(widgetPanel);
                hideSettingPanel(target);

                // Do not save the default dashboard
                if (dbdb.getId() != null && dbdb.getId() != 0) {
                    dashboardContext.getDashboardPersiter().save(dashboard);
                    PageParameters params = new PageParameters();
                    params.add("id", dbdb.getId());
                    setResponsePage(DashboardViewPage.class, params);
                }
            }
        }
    });
    form.add(new AjaxLink<Void>("cancel") {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            hideSettingPanel(target);
        }
    });

    add(form);
}

From source file:eu.uqasar.web.dashboard.widget.widgetforjira.WidgetForJIRASettingsPanel.java

License:Apache License

public WidgetForJIRASettingsPanel(final String id, IModel<WidgetForJira> model) {
    super(id, model);

    setOutputMarkupPlaceholderTag(true);

    final WidgetForJira tasksWidget = model.getObject();
    // Get the project from the settings
    if (tasksWidget.getSettings().get("project") != null) {
        chartType = tasksWidget.getSettings().get("chartType");
        projectName = tasksWidget.getSettings().get("project");
        timeInterval = tasksWidget.getSettings().get("timeInterval");
    } else {/*from w w w  .  j  ava2s .  c om*/
        // Otherwise use the first project of the existing ones
        chartType = "BAR";
        timeInterval = "Latest";
    }

    individualMetric = getModelObject().getSettings().get("individualMetric");
    // DropDown select for Projects
    TreeNodeService treeNodeService = null;
    try {
        InitialContext ic = new InitialContext();
        treeNodeService = (TreeNodeService) ic.lookup("java:module/TreeNodeService");
        projects = treeNodeService.getAllProjectsOfLoggedInUser();
        // Select the first project if no project is provided
        if (projects != null && projects.size() != 0) {
            if (projectName == null || projectName.isEmpty() && projects.size() != 0) {
                projectName = projects.get(0).getName();
            }
        }
        project = treeNodeService.getProjectByName(projectName);
    } catch (NamingException e) {
        e.printStackTrace();
    }

    Form<Widget> form = new Form<>("form");
    wmcGeneral = new WebMarkupContainer("wmcGeneral");
    form.add(wmcGeneral);

    chartType = getModelObject().getSettings().get("chartType");
    List<String> chartTypes = Arrays.asList("AREA", "BAR", "LINE", "COLUMN");
    List<String> timeIntervals = Arrays.asList("Last Year", "Last 6 Months", "Last Month", "Last Week",
            "Latest");

    wmcGeneral.add(new DropDownChoice<>("chartType", new PropertyModel<String>(this, "chartType"), chartTypes));

    wmcGeneral
            .add(new DropDownChoice<>("time", new PropertyModel<String>(this, "timeInterval"), timeIntervals));

    // project
    projectChoice = new DropDownChoice<>("project", new PropertyModel<Project>(this, "project"), projects);
    if (project != null) {
        projectChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
                System.out.println(project);

            }
        });

    }
    List<String> individualMetricGroups = UQasarUtil.getJiraMetricNames();
    DropDownChoice<String> dropDown = new DropDownChoice<>("individualMetric",
            new PropertyModel<String>(this, "individualMetric"), individualMetricGroups);
    dropDown.setNullValid(true);
    wmcGeneral.add(dropDown);
    wmcGeneral.setOutputMarkupId(true);
    wmcGeneral.add(projectChoice);
    form.add(new AjaxSubmitLink("submit") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Dashboard dashboard = findParent(DashboardPanel.class).getDashboard();
            if (project != null && dashboard != null) {
                getModelObject().getSettings().put("chartType", chartType);
                getModelObject().getSettings().put("project", project.getName());
                getModelObject().getSettings().put("timeInterval", timeInterval);
                getModelObject().getSettings().put("individualMetric", individualMetric);
                hideSettingPanel(target);

                DbDashboard dbdb = (DbDashboard) dashboard;
                // Do not save the default dashboard
                if (dbdb.getId() != null && dbdb.getId() != 0) {
                    dashboardContext.getDashboardPersiter().save(dashboard);
                    PageParameters params = new PageParameters();
                    params.add("id", dbdb.getId());
                    setResponsePage(DashboardViewPage.class, params);
                }
            }
        }

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

    });
    form.add(new AjaxLink<Void>("cancel") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            hideSettingPanel(target);
        }
    });

    add(form);
}

From source file:eu.uqasar.web.pages.analytic.AnalyticWorkbench.java

License:Apache License

private AjaxLink<Void> delAnalysis(final Analysis analysis) {
    return new AjaxLink<Void>("delete") {
        private static final long serialVersionUID = -2489881869944830108L;

        @Override/*w  w w.  j  a va2 s  .c om*/
        public void onClick(AjaxRequestTarget target) {
            analyticService.delete(analysis);
            target.add(analysisContainer);
        }
    };
}

From source file:eu.uqasar.web.pages.tree.projects.panels.ProjectViewPanel.java

License:Apache License

private AjaxLink saveSnapButton() {
    return new AjaxLink("saveSnapButton") {

        @Override/*from  w ww.j  a va2  s .  com*/
        public void onClick(AjaxRequestTarget target) {
            saveSnapshotModal.appendShowDialogJavaScript(target);
        }
    };
}

From source file:eu.uqasar.web.pages.tree.projects.panels.ProjectViewPanel.java

License:Apache License

private AjaxLink recoverSnapButton() {
    return new AjaxLink("recoverSnapButton") {

        @Override// ww w .  j av  a2s . c  om
        public void onClick(AjaxRequestTarget target) {
            recoverSnapshotModal.appendShowDialogJavaScript(target);
        }
    };
}