public Component buildRelatedTableStep() throws Exception { VerticalLayout layout = new VerticalLayout(); FormLayout formLayout = new FormLayout(); formLayout.setSpacing(true); formLayout.setReadOnly(true); layout.addComponent(formLayout); if (ReportModelPool.findReportModelByCurrentUser(user) == null) { throw new Exception("Error occurs when initialing the related data"); } if (relateReportTables == null || relateReportTables.size() == 0) { relateReportTables = new ArrayList<ReportTable>(); for (ReportTable r : ReportModelPool.findReportModelByCurrentUser(user).getReportTables()) { if (r.getType() != null && r.getType().toString().equals(ReportConfiguration.ReportType.SubTable.toString())) { if (relateReportTables != null) { relateReportTables.add(r); } } } } ReportTableEditor editor = new ReportTableEditor( getRelateTableModel(), ReportConfiguration.ReportType.SubTable.toString()); formLayout.addComponent(editor); return layout; }
@Override public Component getContent() { try { if (user != null && ReportModelPool.findReportModelByCurrentUser(user) != null) { removeDuplciateRelateResult(); return buildRelatedTableStep(); } return null; } catch (Exception e) { e.printStackTrace(); } return null; }
public boolean clearDuplicateRelateColumnResult(ReportColumn reportColumn) { for (ReportColumn sReportColumn : ReportModelPool.findReportModelByCurrentUser(user).getSubTableSelectedColumns()) { if (sReportColumn .getColumnUseMode() .equals(ReportConfiguration.ReportColumnType.OutputColumn.toString())) { if (sReportColumn.getColumnName().equals(reportColumn.getColumnName()) && sReportColumn.getColumnLabel().equals(reportColumn.getColumnLabel())) { return false; } } } return true; }
@Override public void valueChange(ValueChangeEvent event) { rm = (ReportModel) box.getValue(); if (rm != null) { columnLayout.setVisible(true); columnLayout.setImmediate(true); reportColumnStepDesc.setVisible(true); List<ReportColumn> columnFields = rm.getReportTables().iterator().next().getReportColumns(); gridLayout.removeAllComponents(); gridLayout.requestRepaintAll(); gridLayout.setRows(columnFields.size()); gridLayout.setSpacing(true); for (final ReportColumn columnField : columnFields) { if (columnField.getColumnLabel() != null) { ReportColumnCard reportColumnCard = new ReportColumnCard(columnField) { @Override public void layoutClick(LayoutClickEvent event) { if (clearDuplicateRelateColumnResult(columnField)) { System.out.println( "User click related column: " + columnField.getColumnLabel()); ReportColumn reportColumn = new ReportColumn(); reportColumn.setColumnName(columnField.getColumnName()); reportColumn.setColumnLabel(columnField.getColumnLabel()); reportColumn.setColumnUseMode( ReportConfiguration.ReportColumnType.OutputColumn.toString()); if (ReportModelPool.findReportModelByCurrentUser(user) .getSubTableSelectedColumns() == null) { HashSet<ReportColumn> reportColumns = new HashSet<ReportColumn>(); reportColumns.add(reportColumn); ReportModelPool.findReportModelByCurrentUser(user) .setSubTableSelectedColumns(reportColumns); } else { ReportModelPool.findReportModelByCurrentUser(user) .getSubTableSelectedColumns() .add(reportColumn); } } } }; gridLayout.addComponent(reportColumnCard); } } this.addComponent(columnLayout); ReportTable selectSubReportTable = rm.getReportTables().iterator().next(); ReportModelPool.findReportModelByCurrentUser(user) .getReportTables() .add(selectSubReportTable); boolean removeStepflg = false; for (WizardStep step : w.getSteps()) { if (step.getCaption() != null) { if (step.getCaption().equals("Report Filter Step")) { removeStepflg = true; } } } if (removeStepflg) { w.removeStep("Report Filter Step"); } w.removeStep("Preview Step"); w.addStep(new ReportFilterStep(w, user), "Report Filter Step"); w.addStep(new PreviewStep(w, user), "Preview Step"); } }