optHeaderComponentText = Optional.ofNullable(column.getHeaderComponent())
38 | .map(Component::getElement)
39 | .map(Element::getText);
40 | if(optHeaderComponentText.isPresent())
41 | {
42 | return optHeaderComponentText;
43 | }
44 |
45 | return Optional.ofNullable(column.getHeaderText());
46 | }
47 | catch(final Exception e)
48 | {
49 | return Optional.empty();
50 | }
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/WizardState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard;
17 |
18 | public interface WizardState
19 | {
20 | // just marker
21 | }
22 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/WizardStyles.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard;
17 |
18 | public final class WizardStyles
19 | {
20 | private WizardStyles()
21 | {
22 | // No impl
23 | }
24 |
25 | public static final String LOCATION = "./styles/wizard.css";
26 |
27 | // region WizardPanel
28 |
29 | public static final String WIZARD_PANEL = "wizard-panel";
30 |
31 | public static final String WIZARD_PANEL_TABS = WIZARD_PANEL + "-tabs";
32 |
33 | public static final String WIZARD_PANEL_CONTENT = WIZARD_PANEL + "-content";
34 |
35 | // endregion
36 | // region WizardButtonBar
37 |
38 | public static final String WIZARD_BUTTON_BAR = "wizard-button-bar";
39 |
40 | public static final String WIZARD_BUTTON_BAR_BTN_CANCEL = WIZARD_BUTTON_BAR + "-cancel";
41 | public static final String WIZARD_BUTTON_BAR_BTN_PREVIOUS = WIZARD_BUTTON_BAR + "-previous";
42 | public static final String WIZARD_BUTTON_BAR_BTN_NEXT = WIZARD_BUTTON_BAR + "-next";
43 | public static final String WIZARD_BUTTON_BAR_BTN_DONE = WIZARD_BUTTON_BAR + "-done";
44 |
45 | // endregion
46 | }
47 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/buttonbar/AbstractWizardButtonBar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard.buttonbar;
17 |
18 | import java.util.Objects;
19 | import java.util.function.Consumer;
20 | import java.util.function.Function;
21 | import java.util.stream.Stream;
22 |
23 | import com.vaadin.flow.component.Composite;
24 | import com.vaadin.flow.component.HasSize;
25 | import com.vaadin.flow.component.HasStyle;
26 | import com.vaadin.flow.component.button.Button;
27 | import com.vaadin.flow.component.button.ButtonVariant;
28 | import com.vaadin.flow.component.dependency.CssImport;
29 | import com.vaadin.flow.component.orderedlayout.FlexComponent;
30 | import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
31 | import com.vaadin.flow.shared.Registration;
32 |
33 | import software.xdev.vaadin.grid_exporter.components.wizard.WizardStyles;
34 | import software.xdev.vaadin.grid_exporter.components.wizard.panel.WizardPanelActions;
35 | import software.xdev.vaadin.grid_exporter.components.wizard.step.WizardStepState;
36 |
37 |
38 | @CssImport(WizardStyles.LOCATION)
39 | public abstract class AbstractWizardButtonBar> extends Composite
40 | implements HasSize, HasStyle
41 | {
42 | protected final Button btnCancel = new Button("Cancel");
43 | protected final Button btnPrevious = new Button("Back");
44 | protected final Button btnNext = new Button("Next");
45 | protected final Button btnDone = new Button("Done");
46 |
47 | protected final HorizontalLayout hlEndButtons = new HorizontalLayout();
48 |
49 | protected void init(final WizardPanelActions panel)
50 | {
51 | Objects.requireNonNull(panel);
52 |
53 | this.initUI();
54 | this.registerListeners(panel);
55 |
56 | // Set initial state
57 | this.updateFromStepState(new WizardStepState(0, 0));
58 | }
59 |
60 | protected void initUI()
61 | {
62 | this.btnCancel.addClassName(WizardStyles.WIZARD_BUTTON_BAR_BTN_CANCEL);
63 | this.btnPrevious.addClassName(WizardStyles.WIZARD_BUTTON_BAR_BTN_PREVIOUS);
64 | this.btnNext.addClassName(WizardStyles.WIZARD_BUTTON_BAR_BTN_NEXT);
65 | this.btnDone.addClassName(WizardStyles.WIZARD_BUTTON_BAR_BTN_DONE);
66 |
67 | Stream.of(this.btnCancel, this.btnPrevious, this.btnNext, this.btnDone)
68 | .forEach(btn -> btn.setDisableOnClick(true));
69 |
70 | Stream.of(this.btnNext, this.btnDone)
71 | .forEach(btn -> btn.addThemeVariants(ButtonVariant.LUMO_PRIMARY));
72 |
73 | this.hlEndButtons.setPadding(false);
74 | this.hlEndButtons.add(this.btnPrevious, this.btnNext, this.btnDone);
75 |
76 | this.getContent().addClassName(WizardStyles.WIZARD_BUTTON_BAR);
77 | this.getContent().setPadding(false);
78 | this.getContent().setWidthFull();
79 | this.getContent().setJustifyContentMode(FlexComponent.JustifyContentMode.BETWEEN);
80 | this.getContent().add(this.btnCancel, this.hlEndButtons);
81 | }
82 |
83 | protected void registerListeners(final WizardPanelActions panel)
84 | {
85 | this.addButtonClickEvent(this.getBtnPrevious(), panel::showPreviousStep);
86 | this.addButtonClickEvent(this.getBtnNext(), panel::showNextStep);
87 |
88 | panel.addStepStateChangedListener(this::updateFromStepState);
89 | }
90 |
91 | protected Registration addButtonClickEvent(final Button button, final Consumer isFromClientConsumer)
92 | {
93 | return button.addClickListener(ev ->
94 | {
95 | isFromClientConsumer.accept(ev.isFromClient());
96 | ev.getSource().setEnabled(true);
97 | });
98 | }
99 |
100 | protected void updateFromStepState(final WizardStepState stepState)
101 | {
102 | this.getBtnPrevious().setEnabled(!stepState.isFirstStep());
103 |
104 | this.getBtnNext().setVisible(!stepState.isLastStep());
105 | this.getBtnDone().setVisible(stepState.isLastStep());
106 | }
107 |
108 | // region Getter for Buttons
109 |
110 | public Button getBtnCancel()
111 | {
112 | return this.btnCancel;
113 | }
114 |
115 | public Button getBtnPrevious()
116 | {
117 | return this.btnPrevious;
118 | }
119 |
120 | public Button getBtnNext()
121 | {
122 | return this.btnNext;
123 | }
124 |
125 | public Button getBtnDone()
126 | {
127 | return this.btnDone;
128 | }
129 |
130 | // endregion
131 |
132 | public P configureButton(
133 | final Function selfButtonSupplier,
134 | final Consumer configureButtonAction)
135 | {
136 | configureButtonAction.accept(selfButtonSupplier.apply(this.self()));
137 | return this.self();
138 | }
139 |
140 | public P withButtonText(
141 | final Function selfButtonSupplier,
142 | final String text)
143 | {
144 | return this.configureButton(selfButtonSupplier, btn -> btn.setText(text));
145 | }
146 |
147 | public Registration addCancelClickListener(final Consumer isFromClientConsumer)
148 | {
149 | return this.addButtonClickEvent(this.getBtnCancel(), isFromClientConsumer);
150 | }
151 |
152 | public P withCancelClickListener(final Consumer isFromClientConsumer)
153 | {
154 | this.addCancelClickListener(isFromClientConsumer);
155 | return this.self();
156 | }
157 |
158 | public Registration addDoneClickListener(final Consumer isFromClientConsumer)
159 | {
160 | return this.addButtonClickEvent(this.getBtnDone(), isFromClientConsumer);
161 | }
162 |
163 | public P withDoneClickListener(final Consumer isFromClientConsumer)
164 | {
165 | this.addDoneClickListener(isFromClientConsumer);
166 | return this.self();
167 | }
168 |
169 | @SuppressWarnings("unchecked")
170 | protected P self()
171 | {
172 | return (P)this;
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/buttonbar/WizardButtonBar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard.buttonbar;
17 |
18 | import software.xdev.vaadin.grid_exporter.components.wizard.panel.WizardPanelActions;
19 |
20 |
21 | public class WizardButtonBar extends AbstractWizardButtonBar
22 | {
23 | public WizardButtonBar(final WizardPanelActions panel)
24 | {
25 | this.init(panel);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/buttonbar/WizardButtonBarWithAnchor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard.buttonbar;
17 |
18 | import com.vaadin.flow.component.html.Anchor;
19 |
20 | import software.xdev.vaadin.grid_exporter.components.wizard.panel.WizardPanelActions;
21 | import software.xdev.vaadin.grid_exporter.components.wizard.step.WizardStepState;
22 |
23 |
24 | public class WizardButtonBarWithAnchor extends AbstractWizardButtonBar
25 | {
26 | protected final Anchor anchorDone = new Anchor();
27 |
28 | public WizardButtonBarWithAnchor(final WizardPanelActions panel)
29 | {
30 | this.init(panel);
31 | }
32 |
33 | @Override
34 | protected void initUI()
35 | {
36 | super.initUI();
37 |
38 | this.hlEndButtons.remove(this.btnDone);
39 | this.hlEndButtons.add(this.anchorDone);
40 |
41 | this.btnDone.setDisableOnClick(false);
42 | this.anchorDone.add(this.btnDone);
43 | }
44 |
45 | @Override
46 | protected void updateFromStepState(final WizardStepState stepState)
47 | {
48 | super.updateFromStepState(stepState);
49 |
50 | this.getAnchorDone().setVisible(this.getBtnDone().isVisible());
51 | }
52 |
53 | public Anchor getAnchorDone()
54 | {
55 | return this.anchorDone;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/panel/WizardPanelActions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard.panel;
17 |
18 | import java.util.function.Consumer;
19 |
20 | import software.xdev.vaadin.grid_exporter.components.wizard.step.WizardStepState;
21 |
22 |
23 | public interface WizardPanelActions
24 | {
25 | void showFirstStep(final boolean isFromClient);
26 |
27 | void showPreviousStep(final boolean isFromClient);
28 |
29 | void showNextStep(final boolean isFromClient);
30 |
31 | void addStepStateChangedListener(final Consumer newStateConsumer);
32 | }
33 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/step/WizardPanelStepChangedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard.step;
17 |
18 | import java.util.Objects;
19 |
20 | import com.vaadin.flow.component.ComponentEvent;
21 |
22 | import software.xdev.vaadin.grid_exporter.components.wizard.WizardState;
23 | import software.xdev.vaadin.grid_exporter.components.wizard.panel.WizardPanel;
24 |
25 | @SuppressWarnings("java:S1948")
26 | public class WizardPanelStepChangedEvent extends ComponentEvent>
27 | {
28 | protected final WizardStepState stepState;
29 |
30 | public WizardPanelStepChangedEvent(
31 | final WizardStepState stepState,
32 | final WizardPanel source,
33 | final boolean fromClient)
34 | {
35 | super(source, fromClient);
36 | this.stepState = Objects.requireNonNull(stepState);
37 | }
38 |
39 | public WizardStepState getStepState()
40 | {
41 | return this.stepState;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/step/WizardStep.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard.step;
17 |
18 | import software.xdev.vaadin.grid_exporter.components.wizard.WizardState;
19 |
20 |
21 | public interface WizardStep
22 | {
23 | String getStepName();
24 |
25 | void setWizardState(S state);
26 |
27 | default void onEnterStep(final S state)
28 | {
29 | // optional
30 | }
31 |
32 | /**
33 | * Called when next is clicked and the current step is exited
34 | * @param state The current state
35 | * @return false
when the exit can't happen due to e.g. validation problems.
36 | */
37 | default boolean onProgress(final S state)
38 | {
39 | // optional
40 | return true;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/step/WizardStepComposite.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard.step;
17 |
18 | import com.vaadin.flow.component.Component;
19 | import com.vaadin.flow.component.Composite;
20 |
21 | import software.xdev.vaadin.grid_exporter.components.wizard.WizardState;
22 |
23 | @SuppressWarnings("java:S1948")
24 | public abstract class WizardStepComposite
25 | extends Composite
26 | implements WizardStep
27 | {
28 | protected String stepName = "";
29 | protected S state;
30 |
31 | protected WizardStepComposite()
32 | {
33 | this.setStepName(this.getClass().getSimpleName());
34 | }
35 |
36 | @Override
37 | public String getStepName()
38 | {
39 | return this.stepName;
40 | }
41 |
42 | public void setStepName(final String stepName)
43 | {
44 | this.stepName = stepName;
45 | }
46 |
47 | public S getWizardState()
48 | {
49 | return this.state;
50 | }
51 |
52 | @Override
53 | public void setWizardState(final S state)
54 | {
55 | this.state = state;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/components/wizard/step/WizardStepState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.components.wizard.step;
17 |
18 | public class WizardStepState
19 | {
20 | protected final int currentStep;
21 | protected final int totalSteps;
22 |
23 | public WizardStepState(final int currentStep, final int totalSteps)
24 | {
25 | if(totalSteps < 0)
26 | {
27 | throw new IllegalArgumentException("Total steps is invalid");
28 | }
29 | if(currentStep < 0 || currentStep > totalSteps)
30 | {
31 | throw new IllegalArgumentException("Current step is invalid");
32 | }
33 |
34 | this.currentStep = currentStep;
35 | this.totalSteps = totalSteps;
36 | }
37 |
38 | public int getCurrentStep()
39 | {
40 | return this.currentStep;
41 | }
42 |
43 | public int getTotalSteps()
44 | {
45 | return this.totalSteps;
46 | }
47 |
48 | public boolean isFirstStep()
49 | {
50 | return this.getCurrentStep() <= 1;
51 | }
52 |
53 | public boolean isLastStep()
54 | {
55 | return this.getCurrentStep() >= this.getTotalSteps();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/format/AbstractFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.format;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Arrays;
20 | import java.util.List;
21 | import java.util.Objects;
22 | import java.util.Optional;
23 | import java.util.function.Function;
24 |
25 | import software.xdev.vaadin.grid_exporter.Translator;
26 |
27 |
28 | public abstract class AbstractFormat implements Format
29 | {
30 | protected final String nameToDisplay;
31 | protected final String fileSuffix;
32 | protected final String mimeType;
33 | protected List>> configComponents =
34 | new ArrayList<>();
35 |
36 | protected AbstractFormat(
37 | final String nameToDisplay,
38 | final String fileSuffix,
39 | final String mimeType)
40 | {
41 | this.nameToDisplay = Objects.requireNonNull(nameToDisplay);
42 | this.fileSuffix = Objects.requireNonNull(fileSuffix);
43 | this.mimeType = Objects.requireNonNull(mimeType);
44 | }
45 |
46 | @SafeVarargs
47 | public final void withConfigComponents(
48 | final Function>... configComponents)
49 | {
50 | this.configComponents.addAll(Arrays.asList(configComponents));
51 | }
52 |
53 | @Override
54 | public String getFormatNameToDisplay()
55 | {
56 | return this.nameToDisplay;
57 | }
58 |
59 | @Override
60 | public String getFormatFilenameSuffix()
61 | {
62 | return this.fileSuffix;
63 | }
64 |
65 | @Override
66 | public String getMimeType()
67 | {
68 | return this.mimeType;
69 | }
70 |
71 | @Override
72 | public List>> getConfigComponents()
73 | {
74 | return this.configComponents;
75 | }
76 |
77 | protected Optional getConfigFrom(
78 | final List extends SpecificConfig> configs,
79 | final Class targetedConfigClass)
80 | {
81 | return configs.stream()
82 | .filter(targetedConfigClass::isInstance)
83 | .map(targetedConfigClass::cast)
84 | .findFirst();
85 | }
86 |
87 | protected Optional getValueFrom(
88 | final List extends SpecificConfig> configs,
89 | final Class targetedConfigClass,
90 | final Function mapper)
91 | {
92 | return this.getConfigFrom(configs, targetedConfigClass)
93 | .stream()
94 | .findFirst()
95 | .map(mapper);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/format/Format.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.format;
17 |
18 | import java.util.List;
19 | import java.util.function.Function;
20 |
21 | import software.xdev.vaadin.grid_exporter.Translator;
22 | import software.xdev.vaadin.grid_exporter.column.ColumnConfiguration;
23 | import software.xdev.vaadin.grid_exporter.grid.GridDataExtractor;
24 |
25 |
26 | /**
27 | * Defines a format to export grid data to.
28 | */
29 | public interface Format
30 | {
31 | String getFormatNameToDisplay();
32 |
33 | String getFormatFilenameSuffix();
34 |
35 | String getMimeType();
36 |
37 | // Either ignore a rawtype or a generic wildcard type warning
38 | @SuppressWarnings("java:S1452")
39 | List>> getConfigComponents();
40 |
41 | byte[] export(
42 | GridDataExtractor gridDataExtractor,
43 | List> columnsToExport,
44 | List extends SpecificConfig> configs);
45 | }
46 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/format/SpecificConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.format;
17 |
18 | public interface SpecificConfig
19 | {
20 | }
21 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/format/SpecificConfigComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.format;
17 |
18 | import java.util.Objects;
19 | import java.util.function.Supplier;
20 |
21 | import com.vaadin.flow.component.Composite;
22 | import com.vaadin.flow.component.formlayout.FormLayout;
23 | import com.vaadin.flow.data.binder.Binder;
24 |
25 | import software.xdev.vaadin.grid_exporter.Translator;
26 |
27 | @SuppressWarnings("java:S1948")
28 | public abstract class SpecificConfigComponent
29 | extends Composite
30 | implements Translator
31 | {
32 | protected Translator translator;
33 | protected Supplier newConfigSupplier;
34 | protected String header;
35 |
36 | protected Binder binder = new Binder<>();
37 |
38 | protected SpecificConfigComponent(
39 | final Translator translator,
40 | final Supplier newConfigSupplier,
41 | final String headerToTranslate)
42 | {
43 | this.setTranslator(translator);
44 | this.setNewConfigSupplier(newConfigSupplier);
45 | this.setHeaderAndTranslate(headerToTranslate);
46 |
47 | this.getContent().setResponsiveSteps(
48 | new FormLayout.ResponsiveStep("0", 1),
49 | new FormLayout.ResponsiveStep("400px", 2)
50 | );
51 | }
52 |
53 | protected void setTranslator(final Translator translator)
54 | {
55 | this.translator = Objects.requireNonNull(translator);
56 | }
57 |
58 | protected void setNewConfigSupplier(final Supplier newConfigSupplier)
59 | {
60 | this.newConfigSupplier = Objects.requireNonNull(newConfigSupplier);
61 | }
62 |
63 | protected void setHeader(final String header)
64 | {
65 | this.header = header;
66 | }
67 |
68 | protected void setHeaderAndTranslate(final String headerToTranslate)
69 | {
70 | this.setHeader(this.translate(headerToTranslate));
71 | }
72 |
73 | public Supplier getNewConfigSupplier()
74 | {
75 | return this.newConfigSupplier;
76 | }
77 |
78 | public String getHeader()
79 | {
80 | return this.header;
81 | }
82 |
83 | public void updateFrom(final T value)
84 | {
85 | this.binder.setBean(value);
86 | }
87 |
88 | public T getBean()
89 | {
90 | return this.binder.getBean();
91 | }
92 |
93 | public boolean isValid()
94 | {
95 | return this.binder.isValid();
96 | }
97 |
98 | @Override
99 | public String translate(final String key)
100 | {
101 | return this.translator != null ? this.translator.translate(key) : key;
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/grid/GridDataExtractor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.grid;
17 |
18 | import java.lang.reflect.Field;
19 | import java.lang.reflect.InvocationTargetException;
20 | import java.lang.reflect.Method;
21 | import java.util.List;
22 | import java.util.Objects;
23 | import java.util.stream.Stream;
24 |
25 | import com.vaadin.flow.component.grid.ColumnPathRenderer;
26 | import com.vaadin.flow.component.grid.Grid;
27 | import com.vaadin.flow.data.provider.Query;
28 | import com.vaadin.flow.data.renderer.BasicRenderer;
29 | import com.vaadin.flow.data.renderer.Renderer;
30 | import com.vaadin.flow.function.ValueProvider;
31 |
32 | import software.xdev.vaadin.grid_exporter.column.ColumnConfiguration;
33 |
34 |
35 | /**
36 | * Extracts the sorted and filtered data from a {@link Grid}.
37 | *
38 | * Be aware that this class uses reflection to achieve it's goals.
39 | *
40 | */
41 | @SuppressWarnings({"java:S3011", "unchecked"}) // Accessing non-public Vaadin fields
42 | public class GridDataExtractor
43 | {
44 | protected final Grid grid;
45 |
46 | public GridDataExtractor(final Grid grid)
47 | {
48 | this.grid = Objects.requireNonNull(grid);
49 | }
50 |
51 | public List> getSortedAndFilteredData(final List> columnsToExport)
52 | {
53 | return this.getSortedAndFilteredData(this.grid)
54 | .map(item -> columnsToExport.stream()
55 | .map(column -> this.getFormattedValue(column.getGridColumn(), item))
56 | .toList())
57 | .toList();
58 | }
59 |
60 | protected String getFormattedValue(final Grid.Column column, final T item)
61 | {
62 | try
63 | {
64 | final Renderer renderer = column.getRenderer();
65 | final ValueProvider valueProvider = this.getValueProvider(column);
66 | if(valueProvider != null)
67 | {
68 | final Method getValueFormatter = this.getValueFormatter(renderer);
69 | final Object value = valueProvider.apply(item);
70 | if(value != null && getValueFormatter != null)
71 | {
72 | return (String)getValueFormatter.invoke(renderer, value);
73 | }
74 | }
75 | else if(renderer instanceof ColumnPathRenderer)
76 | {
77 | final Field provider = ColumnPathRenderer.class.getDeclaredField("provider");
78 | provider.setAccessible(true);
79 | final ValueProvider valprov = (ValueProvider)provider.get(renderer);
80 | if(valprov != null)
81 | {
82 | return valprov.apply(item).toString();
83 | }
84 | }
85 | }
86 | catch(final IllegalAccessException | IllegalArgumentException | InvocationTargetException
87 | | NoSuchFieldException | SecurityException e)
88 | {
89 | // Something went wrong, but it's not our place to say what or why.
90 | }
91 | return null;
92 | }
93 |
94 | protected Method getValueFormatter(final R renderer)
95 | {
96 | for(final Method m : renderer.getClass().getDeclaredMethods())
97 | {
98 | if("getFormattedValue".equals(m.getName()))
99 | {
100 | m.setAccessible(true);
101 | return m;
102 | }
103 | }
104 | return null;
105 | }
106 |
107 | protected ValueProvider getValueProvider(final Grid.Column column)
108 | {
109 | final Renderer r = column.getRenderer();
110 | if(r instanceof BasicRenderer)
111 | {
112 | try
113 | {
114 | final Method getValueProvider = BasicRenderer.class.getDeclaredMethod("getValueProvider");
115 | getValueProvider.setAccessible(true);
116 | return (ValueProvider)getValueProvider.invoke(r);
117 | }
118 | catch(final IllegalAccessException | IllegalArgumentException | InvocationTargetException
119 | | NoSuchMethodException | SecurityException e)
120 | {
121 | // Something went wrong, but it's not our place to say what or why.
122 | }
123 | }
124 | return null;
125 | }
126 |
127 | protected Stream getSortedAndFilteredData(final Grid grid)
128 | {
129 | return grid.getDataProvider().fetch(
130 | new Query<>(
131 | 0,
132 | Integer.MAX_VALUE,
133 | grid.getSortOrder().stream()
134 | .flatMap(so -> so.getSorted().getSortOrder(so.getDirection()))
135 | .toList(),
136 | grid.getDataCommunicator().getInMemorySorting(),
137 | null));
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/DynamicExporter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper;
17 |
18 | import software.xdev.dynamicreports.jasper.base.export.AbstractJasperExporter;
19 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
20 | import software.xdev.dynamicreports.jasper.builder.export.AbstractJasperExporterBuilder;
21 | import software.xdev.dynamicreports.report.exception.DRException;
22 |
23 |
24 | @FunctionalInterface
25 | public interface DynamicExporter>
26 | {
27 | void export(JasperReportBuilder builder, B exportBuilder) throws DRException;
28 | }
29 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/JasperGridExporterProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper;
17 |
18 | import java.util.Arrays;
19 |
20 | import software.xdev.vaadin.grid_exporter.GridExporterProvider;
21 | import software.xdev.vaadin.grid_exporter.jasper.config.JasperConfigsLocalization;
22 | import software.xdev.vaadin.grid_exporter.jasper.format.CsvFormat;
23 | import software.xdev.vaadin.grid_exporter.jasper.format.DocxFormat;
24 | import software.xdev.vaadin.grid_exporter.jasper.format.HtmlFormat;
25 | import software.xdev.vaadin.grid_exporter.jasper.format.OdsFormat;
26 | import software.xdev.vaadin.grid_exporter.jasper.format.OdtFormat;
27 | import software.xdev.vaadin.grid_exporter.jasper.format.PdfFormat;
28 | import software.xdev.vaadin.grid_exporter.jasper.format.PptxFormat;
29 | import software.xdev.vaadin.grid_exporter.jasper.format.RtfFormat;
30 | import software.xdev.vaadin.grid_exporter.jasper.format.TextFormat;
31 | import software.xdev.vaadin.grid_exporter.jasper.format.XlsxFormat;
32 |
33 |
34 | public class JasperGridExporterProvider extends GridExporterProvider
35 | {
36 | public JasperGridExporterProvider()
37 | {
38 | super(
39 | JasperConfigsLocalization.DEFAULT_VALUES,
40 | Arrays.asList(
41 | new PdfFormat(),
42 | new XlsxFormat(),
43 | new CsvFormat(),
44 | new DocxFormat(),
45 | new HtmlFormat(),
46 | new OdsFormat(),
47 | new OdtFormat(),
48 | new PptxFormat(),
49 | new RtfFormat(),
50 | new TextFormat()
51 | ));
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/JasperGridReportStyles.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper;
17 |
18 | import java.awt.Color;
19 |
20 | import software.xdev.dynamicreports.report.builder.style.SimpleStyleBuilder;
21 | import software.xdev.dynamicreports.report.builder.style.StyleBuilder;
22 | import software.xdev.dynamicreports.report.builder.style.Styles;
23 | import software.xdev.dynamicreports.report.constant.HorizontalTextAlignment;
24 |
25 |
26 | public interface JasperGridReportStyles
27 | {
28 | StyleBuilder titleStyle();
29 |
30 | StyleBuilder footerStyle();
31 |
32 | StyleBuilder columnTitleStyle();
33 |
34 | StyleBuilder columnStyle();
35 |
36 | SimpleStyleBuilder columnStyleHighlighted();
37 |
38 | class Default implements JasperGridReportStyles
39 | {
40 | protected final StyleBuilder defaultStyle = Styles.style().setPadding(2);
41 | protected final StyleBuilder boldCenterStyle = Styles.style(this.defaultStyle)
42 | .bold()
43 | .setHorizontalTextAlignment(HorizontalTextAlignment.CENTER);
44 | protected final StyleBuilder columnTitle = Styles.style(this.boldCenterStyle)
45 | .setBorder(Styles.pen1Point()).setBackgroundColor(Color.LIGHT_GRAY);
46 | protected final StyleBuilder columnStyle = Styles.style(this.defaultStyle)
47 | .setBorder(Styles.pen1Point());
48 |
49 | @SuppressWarnings("checkstyle:MagicNumber")
50 | protected final SimpleStyleBuilder columnStyleHighlighted = Styles.simpleStyle()
51 | .setPadding(2)
52 | .setBackgroundColor(new Color(222, 222, 222)) // Extra light gray so that the data remains readable
53 | .setBorder(Styles.pen1Point());
54 |
55 | @Override
56 | public StyleBuilder titleStyle()
57 | {
58 | return this.boldCenterStyle;
59 | }
60 |
61 | @Override
62 | public StyleBuilder footerStyle()
63 | {
64 | return this.boldCenterStyle;
65 | }
66 |
67 | @Override
68 | public StyleBuilder columnTitleStyle()
69 | {
70 | return this.columnTitle;
71 | }
72 |
73 | @Override
74 | public StyleBuilder columnStyle()
75 | {
76 | return this.columnStyle;
77 | }
78 |
79 | @Override
80 | public SimpleStyleBuilder columnStyleHighlighted()
81 | {
82 | return this.columnStyleHighlighted;
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/JasperConfigsLocalization.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config;
17 |
18 | import static java.util.Map.entry;
19 |
20 | import java.util.Map;
21 |
22 |
23 | public final class JasperConfigsLocalization
24 | {
25 | private JasperConfigsLocalization()
26 | {
27 | // No impl
28 | }
29 |
30 | public static final String PREFIX = "gridexporter.jasperformats.";
31 |
32 | public static final String ENCODING = PREFIX + "encoding";
33 | public static final String WITH_BOM = PREFIX + "with_bom";
34 |
35 |
36 | public static final String HEADER = PREFIX + "header";
37 | public static final String EXPORT_HEADER = PREFIX + "export_header";
38 |
39 | public static final String HIGHLIGHTING = PREFIX + "highlighting";
40 | public static final String HIGHLIGHT_ROWS = PREFIX + "highlight_rows";
41 |
42 | public static final String PAGE = PREFIX + "page";
43 | public static final String FORMAT_PAGE_TYPE = PREFIX + "format_page_type";
44 | public static final String ORIENTATION = PREFIX + "orientation";
45 | public static final String ORIENTATION_PORTRAIT = ORIENTATION + ".portrait";
46 | public static final String ORIENTATION_LANDSCAPE = ORIENTATION + ".landscape";
47 | public static final String SHOW_PAGE_NUMBERS = PREFIX + "show_page_numbers";
48 | public static final String MARGIN = PREFIX + "margin";
49 |
50 | public static final String SEPARATOR = PREFIX + "separator";
51 |
52 | public static final String TITLE = PREFIX + "title";
53 |
54 | // Key, Default Value
55 | public static final Map DEFAULT_VALUES = Map.ofEntries(
56 | entry(ENCODING, "Encoding"),
57 | entry(WITH_BOM, "with BOM"),
58 | entry(HEADER, "Header"),
59 | entry(EXPORT_HEADER, "Export header"),
60 | entry(HIGHLIGHTING, "Highlighting"),
61 | entry(HIGHLIGHT_ROWS, "Highlight rows"),
62 | entry(PAGE, "Page"),
63 | entry(FORMAT_PAGE_TYPE, "Format / Page type"),
64 | entry(ORIENTATION, "Orientation"),
65 | entry(ORIENTATION_PORTRAIT, "Portrait"),
66 | entry(ORIENTATION_LANDSCAPE, "Landscape"),
67 | entry(SHOW_PAGE_NUMBERS, "Show page numbers"),
68 | entry(MARGIN, "Margin"),
69 | entry(SEPARATOR, "Separator"),
70 | entry(TITLE, "Title")
71 | );
72 | }
73 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/encoding/EncodingConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.encoding;
17 |
18 | import java.nio.charset.StandardCharsets;
19 | import java.util.Arrays;
20 | import java.util.List;
21 | import java.util.Objects;
22 |
23 | import software.xdev.vaadin.grid_exporter.format.SpecificConfig;
24 |
25 |
26 | public class EncodingConfig implements SpecificConfig
27 | {
28 | protected List available = Arrays.asList(
29 | new ExportEncoding(StandardCharsets.UTF_8, "\ufeff"),
30 | new ExportEncoding(StandardCharsets.ISO_8859_1)
31 | );
32 | protected ExportEncoding selected = this.available.get(0);
33 | protected boolean useBOM;
34 |
35 | public List getAvailable()
36 | {
37 | return this.available;
38 | }
39 |
40 | public void setAvailable(final List available)
41 | {
42 | this.available = Objects.requireNonNull(available);
43 | }
44 |
45 | public ExportEncoding getSelected()
46 | {
47 | return this.selected;
48 | }
49 |
50 | public void setSelected(final ExportEncoding selected)
51 | {
52 | this.selected = selected;
53 | }
54 |
55 | public boolean isUseBOM()
56 | {
57 | return this.useBOM;
58 | }
59 |
60 | public void setUseBOM(final boolean useBOM)
61 | {
62 | this.useBOM = useBOM;
63 | }
64 |
65 |
66 | public boolean supportsAndUseBOM()
67 | {
68 | return this.isUseBOM() && this.getSelected().hasBom();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/encoding/EncodingConfigComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.encoding;
17 |
18 | import com.vaadin.flow.component.checkbox.Checkbox;
19 | import com.vaadin.flow.component.combobox.ComboBox;
20 |
21 | import software.xdev.vaadin.grid_exporter.Translator;
22 | import software.xdev.vaadin.grid_exporter.format.SpecificConfigComponent;
23 | import software.xdev.vaadin.grid_exporter.jasper.config.JasperConfigsLocalization;
24 |
25 |
26 | public class EncodingConfigComponent extends SpecificConfigComponent
27 | {
28 | protected final ComboBox cbExportEncoding = new ComboBox<>();
29 | protected final Checkbox chbxUseBom = new Checkbox();
30 |
31 | public EncodingConfigComponent(final Translator translator)
32 | {
33 | super(translator, EncodingConfig::new, JasperConfigsLocalization.ENCODING);
34 |
35 | this.initUI();
36 |
37 | this.registerBindings();
38 | }
39 |
40 | protected void initUI()
41 | {
42 | this.cbExportEncoding.setItemLabelGenerator(ee -> ee.charset().name());
43 |
44 | this.chbxUseBom.setLabel(this.translate(JasperConfigsLocalization.WITH_BOM));
45 |
46 | this.getContent().add(this.cbExportEncoding, this.chbxUseBom);
47 | }
48 |
49 | protected void registerBindings()
50 | {
51 | this.binder.forField(this.cbExportEncoding)
52 | .asRequired()
53 | .bind(EncodingConfig::getSelected, EncodingConfig::setSelected);
54 |
55 | this.cbExportEncoding.addValueChangeListener(ev -> this.validateAndManageUseBOM(ev.getValue()));
56 |
57 | this.binder.forField(this.chbxUseBom)
58 | .bind(EncodingConfig::isUseBOM, EncodingConfig::setUseBOM);
59 | }
60 |
61 | protected void validateAndManageUseBOM(final ExportEncoding value)
62 | {
63 | if(value == null)
64 | {
65 | return;
66 | }
67 |
68 | this.chbxUseBom.setEnabled(value.hasBom());
69 | if(!value.hasBom())
70 | {
71 | this.chbxUseBom.setValue(false);
72 | }
73 | }
74 |
75 | @Override
76 | public void updateFrom(final EncodingConfig value)
77 | {
78 | this.cbExportEncoding.setItems(value.getAvailable());
79 |
80 | super.updateFrom(value);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/encoding/ExportEncoding.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.encoding;
17 |
18 | import java.nio.charset.Charset;
19 |
20 |
21 | public class ExportEncoding
22 | {
23 | protected final Charset charset;
24 | protected final String bom;
25 |
26 | public ExportEncoding(final Charset charset)
27 | {
28 | this(charset, null);
29 | }
30 |
31 | public ExportEncoding(final Charset charset, final String bom)
32 | {
33 | this.charset = charset;
34 | this.bom = bom;
35 | }
36 |
37 | public Charset charset()
38 | {
39 | return this.charset;
40 | }
41 |
42 | public String bom()
43 | {
44 | return this.bom;
45 | }
46 |
47 | public boolean hasBom()
48 | {
49 | return this.bom() != null;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/header/HeaderConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.header;
17 |
18 | import software.xdev.vaadin.grid_exporter.format.SpecificConfig;
19 |
20 |
21 | public class HeaderConfig implements SpecificConfig
22 | {
23 | protected boolean exportHeader;
24 |
25 | public HeaderConfig()
26 | {
27 | this(true);
28 | }
29 |
30 | public HeaderConfig(final boolean exportHeader)
31 | {
32 | this.exportHeader = exportHeader;
33 | }
34 |
35 | public boolean isExportHeader()
36 | {
37 | return this.exportHeader;
38 | }
39 |
40 | public void setExportHeader(final boolean exportHeader)
41 | {
42 | this.exportHeader = exportHeader;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/header/HeaderConfigComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.header;
17 |
18 | import com.vaadin.flow.component.checkbox.Checkbox;
19 |
20 | import software.xdev.vaadin.grid_exporter.Translator;
21 | import software.xdev.vaadin.grid_exporter.format.SpecificConfigComponent;
22 | import software.xdev.vaadin.grid_exporter.jasper.config.JasperConfigsLocalization;
23 |
24 |
25 | public class HeaderConfigComponent extends SpecificConfigComponent
26 | {
27 | protected final Checkbox chbxExportHeader = new Checkbox();
28 |
29 | public HeaderConfigComponent(final Translator translator, final boolean defaultExportHeaderValue)
30 | {
31 | super(translator, () -> new HeaderConfig(defaultExportHeaderValue), JasperConfigsLocalization.HEADER);
32 |
33 | this.initUI();
34 |
35 | this.registerBindings();
36 | }
37 |
38 | public HeaderConfigComponent(final Translator translator)
39 | {
40 | this(translator, true);
41 | }
42 |
43 | protected void initUI()
44 | {
45 | this.chbxExportHeader.setLabel(this.translate(JasperConfigsLocalization.EXPORT_HEADER));
46 |
47 | this.getContent().add(this.chbxExportHeader);
48 | }
49 |
50 | protected void registerBindings()
51 | {
52 | this.binder.forField(this.chbxExportHeader)
53 | .bind(HeaderConfig::isExportHeader, HeaderConfig::setExportHeader);
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/highlight/HighlightConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.highlight;
17 |
18 | import software.xdev.vaadin.grid_exporter.format.SpecificConfig;
19 |
20 |
21 | public class HighlightConfig implements SpecificConfig
22 | {
23 | protected boolean highlightOddRows;
24 |
25 | public boolean isHighlightOddRows()
26 | {
27 | return this.highlightOddRows;
28 | }
29 |
30 | public void setHighlightOddRows(final boolean highlightOddRows)
31 | {
32 | this.highlightOddRows = highlightOddRows;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/highlight/HighlightConfigComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.highlight;
17 |
18 | import com.vaadin.flow.component.checkbox.Checkbox;
19 |
20 | import software.xdev.vaadin.grid_exporter.Translator;
21 | import software.xdev.vaadin.grid_exporter.format.SpecificConfigComponent;
22 | import software.xdev.vaadin.grid_exporter.jasper.config.JasperConfigsLocalization;
23 |
24 |
25 | public class HighlightConfigComponent extends SpecificConfigComponent
26 | {
27 | protected final Checkbox chbxExportHeader = new Checkbox();
28 |
29 | public HighlightConfigComponent(final Translator translator)
30 | {
31 | super(translator, HighlightConfig::new, JasperConfigsLocalization.HIGHLIGHTING);
32 |
33 | this.initUI();
34 |
35 | this.registerBindings();
36 | }
37 |
38 | protected void initUI()
39 | {
40 | this.chbxExportHeader.setLabel(this.translate(JasperConfigsLocalization.HIGHLIGHT_ROWS));
41 |
42 | this.getContent().add(this.chbxExportHeader);
43 | }
44 |
45 | protected void registerBindings()
46 | {
47 | this.binder.forField(this.chbxExportHeader)
48 | .bind(HighlightConfig::isHighlightOddRows, HighlightConfig::setHighlightOddRows);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/page/PageConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.page;
17 |
18 | import java.util.Arrays;
19 | import java.util.List;
20 | import java.util.Objects;
21 |
22 | import software.xdev.dynamicreports.report.constant.PageOrientation;
23 | import software.xdev.dynamicreports.report.constant.PageType;
24 | import software.xdev.vaadin.grid_exporter.format.SpecificConfig;
25 |
26 |
27 | public class PageConfig implements SpecificConfig
28 | {
29 | public static final int PAGE_MARGIN_MIN = 0;
30 | public static final int PAGE_MARGIN_MAX = 1_000;
31 |
32 | protected List availablePageTypes = Arrays.asList(PageType.values());
33 | protected List availablePageOrientations = Arrays.asList(PageOrientation.values());
34 | protected PageType selectedPageType = PageType.A4;
35 | protected PageOrientation selectedPageOrientation = PageOrientation.PORTRAIT;
36 | protected boolean usePageNumbering;
37 | protected int pageMargin = 20;
38 |
39 | public List getAvailablePageTypes()
40 | {
41 | return this.availablePageTypes;
42 | }
43 |
44 | public void setAvailablePageTypes(final List availablePageTypes)
45 | {
46 | this.availablePageTypes = Objects.requireNonNull(availablePageTypes);
47 | }
48 |
49 | public List getAvailablePageOrientations()
50 | {
51 | return this.availablePageOrientations;
52 | }
53 |
54 | public void setAvailablePageOrientations(final List availablePageOrientations)
55 | {
56 | this.availablePageOrientations = Objects.requireNonNull(availablePageOrientations);
57 | }
58 |
59 | public PageType getSelectedPageType()
60 | {
61 | return this.selectedPageType;
62 | }
63 |
64 | public void setSelectedPageType(final PageType selectedPageType)
65 | {
66 | this.selectedPageType = Objects.requireNonNull(selectedPageType);
67 | }
68 |
69 | public PageOrientation getSelectedPageOrientation()
70 | {
71 | return this.selectedPageOrientation;
72 | }
73 |
74 | public void setSelectedPageOrientation(final PageOrientation selectedPageOrientation)
75 | {
76 | this.selectedPageOrientation = Objects.requireNonNull(selectedPageOrientation);
77 | }
78 |
79 | public boolean isUsePageNumbering()
80 | {
81 | return this.usePageNumbering;
82 | }
83 |
84 | public void setUsePageNumbering(final boolean usePageNumbering)
85 | {
86 | this.usePageNumbering = usePageNumbering;
87 | }
88 |
89 | public int getPageMargin()
90 | {
91 | return this.pageMargin;
92 | }
93 |
94 | public void setPageMargin(final int pageMargin)
95 | {
96 | if(pageMargin < PAGE_MARGIN_MIN || pageMargin > PAGE_MARGIN_MAX)
97 | {
98 | throw new IllegalArgumentException("Invalid pageMargin value");
99 | }
100 | this.pageMargin = pageMargin;
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/page/PageConfigComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.page;
17 |
18 | import com.vaadin.flow.component.checkbox.Checkbox;
19 | import com.vaadin.flow.component.combobox.ComboBox;
20 | import com.vaadin.flow.component.textfield.IntegerField;
21 |
22 | import software.xdev.dynamicreports.report.constant.PageOrientation;
23 | import software.xdev.dynamicreports.report.constant.PageType;
24 | import software.xdev.vaadin.grid_exporter.Translator;
25 | import software.xdev.vaadin.grid_exporter.format.SpecificConfigComponent;
26 | import software.xdev.vaadin.grid_exporter.jasper.config.JasperConfigsLocalization;
27 |
28 |
29 | public class PageConfigComponent extends SpecificConfigComponent
30 | {
31 | protected final ComboBox cbPageType = new ComboBox<>();
32 | protected final ComboBox cbPageOrientation = new ComboBox<>();
33 | protected final Checkbox chbxPageNumbering = new Checkbox();
34 | protected final IntegerField intfPageMargin = new IntegerField();
35 |
36 | public PageConfigComponent(final Translator translator)
37 | {
38 | super(translator, PageConfig::new, JasperConfigsLocalization.PAGE);
39 |
40 | this.initUIs();
41 |
42 | this.registerBindings();
43 | }
44 |
45 | protected void initUIs()
46 | {
47 | this.cbPageType.setLabel(this.translate(JasperConfigsLocalization.FORMAT_PAGE_TYPE));
48 | this.cbPageType.setItemLabelGenerator(PageType::name);
49 |
50 | this.cbPageOrientation.setLabel(this.translate(JasperConfigsLocalization.ORIENTATION));
51 | this.cbPageOrientation.setItemLabelGenerator(po ->
52 | this.translate(JasperConfigsLocalization.ORIENTATION + "." + po.name().toLowerCase()));
53 |
54 | this.chbxPageNumbering.setLabel(this.translate(JasperConfigsLocalization.SHOW_PAGE_NUMBERS));
55 |
56 | this.intfPageMargin.setLabel(this.translate(JasperConfigsLocalization.MARGIN));
57 | this.intfPageMargin.setStepButtonsVisible(true);
58 | this.intfPageMargin.setMin(PageConfig.PAGE_MARGIN_MIN);
59 | this.intfPageMargin.setMax(PageConfig.PAGE_MARGIN_MAX);
60 |
61 | this.getContent().add(this.cbPageType, this.cbPageOrientation, this.chbxPageNumbering, this.intfPageMargin);
62 | }
63 |
64 | protected void registerBindings()
65 | {
66 | this.binder.forField(this.cbPageType)
67 | .asRequired()
68 | .bind(PageConfig::getSelectedPageType, PageConfig::setSelectedPageType);
69 |
70 | this.binder.forField(this.cbPageOrientation)
71 | .asRequired()
72 | .bind(PageConfig::getSelectedPageOrientation, PageConfig::setSelectedPageOrientation);
73 |
74 | this.binder.forField(this.chbxPageNumbering)
75 | .bind(PageConfig::isUsePageNumbering, PageConfig::setUsePageNumbering);
76 |
77 | this.binder.forField(this.intfPageMargin)
78 | .asRequired()
79 | .bind(PageConfig::getPageMargin, PageConfig::setPageMargin);
80 | }
81 |
82 | @Override
83 | public void updateFrom(final PageConfig value)
84 | {
85 | this.cbPageType.setItems(value.getAvailablePageTypes());
86 |
87 | this.cbPageOrientation.setItems(value.getAvailablePageOrientations());
88 |
89 | super.updateFrom(value);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/separator/CSVSeparatorConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.separator;
17 |
18 | import java.util.Objects;
19 |
20 | import software.xdev.vaadin.grid_exporter.format.SpecificConfig;
21 |
22 |
23 | public class CSVSeparatorConfig implements SpecificConfig
24 | {
25 | protected String separator = ";";
26 |
27 | public String getSeparator()
28 | {
29 | return this.separator;
30 | }
31 |
32 | public void setSeparator(final String separator)
33 | {
34 | Objects.requireNonNull(separator);
35 | if(separator.isEmpty())
36 | {
37 | throw new IllegalArgumentException("Separator can't be empty");
38 | }
39 | this.separator = separator;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/separator/CSVSeparatorConfigComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.separator;
17 |
18 | import com.vaadin.flow.component.textfield.TextField;
19 |
20 | import software.xdev.vaadin.grid_exporter.Translator;
21 | import software.xdev.vaadin.grid_exporter.format.SpecificConfigComponent;
22 | import software.xdev.vaadin.grid_exporter.jasper.config.JasperConfigsLocalization;
23 |
24 |
25 | public class CSVSeparatorConfigComponent extends SpecificConfigComponent
26 | {
27 | protected final TextField txtSeparator = new TextField();
28 |
29 | public CSVSeparatorConfigComponent(final Translator translator)
30 | {
31 | super(translator, CSVSeparatorConfig::new, JasperConfigsLocalization.SEPARATOR);
32 |
33 | this.initUIs();
34 |
35 | this.registerBindings();
36 | }
37 |
38 | protected void initUIs()
39 | {
40 | this.getContent().add(this.txtSeparator);
41 | }
42 |
43 | protected void registerBindings()
44 | {
45 | this.binder.forField(this.txtSeparator)
46 | .asRequired()
47 | .bind(CSVSeparatorConfig::getSeparator, CSVSeparatorConfig::setSeparator);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/title/TitleConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.title;
17 |
18 | import java.util.Objects;
19 |
20 | import software.xdev.vaadin.grid_exporter.format.SpecificConfig;
21 |
22 |
23 | public class TitleConfig implements SpecificConfig
24 | {
25 | protected String title;
26 |
27 | public String getTitle()
28 | {
29 | return this.title;
30 | }
31 |
32 | public void setTitle(final String title)
33 | {
34 | this.title = Objects.requireNonNull(title);
35 | }
36 |
37 | public boolean notTitleEmpty()
38 | {
39 | return this.getTitle() != null && !this.getTitle().isBlank();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/config/title/TitleConfigComponent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.config.title;
17 |
18 | import com.vaadin.flow.component.textfield.TextField;
19 |
20 | import software.xdev.vaadin.grid_exporter.Translator;
21 | import software.xdev.vaadin.grid_exporter.format.SpecificConfigComponent;
22 | import software.xdev.vaadin.grid_exporter.jasper.config.JasperConfigsLocalization;
23 |
24 |
25 | public class TitleConfigComponent extends SpecificConfigComponent
26 | {
27 | protected final TextField txtTitle = new TextField();
28 |
29 | public TitleConfigComponent(final Translator translator)
30 | {
31 | super(translator, TitleConfig::new, JasperConfigsLocalization.TITLE);
32 |
33 | this.initUIs();
34 |
35 | this.registerBindings();
36 | }
37 |
38 | protected void initUIs()
39 | {
40 | this.getContent().add(this.txtTitle);
41 | }
42 |
43 | protected void registerBindings()
44 | {
45 | this.binder.forField(this.txtTitle)
46 | .bind(TitleConfig::getTitle, TitleConfig::setTitle);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/AbstractJasperReportSpreadsheetFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import java.io.OutputStream;
19 | import java.util.function.Function;
20 |
21 | import software.xdev.dynamicreports.jasper.base.export.AbstractJasperExporter;
22 | import software.xdev.dynamicreports.jasper.builder.export.AbstractJasperExporterBuilder;
23 | import software.xdev.vaadin.grid_exporter.jasper.DynamicExporter;
24 | import software.xdev.vaadin.grid_exporter.jasper.config.header.HeaderConfigComponent;
25 | import software.xdev.vaadin.grid_exporter.jasper.config.highlight.HighlightConfigComponent;
26 |
27 |
28 | public abstract class AbstractJasperReportSpreadsheetFormat>
30 | extends AbstractJasperReportFormat
31 | {
32 | protected AbstractJasperReportSpreadsheetFormat(
33 | final String nameToDisplay,
34 | final String fileSuffix,
35 | final String mimeType,
36 | final DynamicExporter jasperReportBuilderTo,
37 | final Function jasperExportBuilderSupplier)
38 | {
39 | super(
40 | nameToDisplay,
41 | fileSuffix,
42 | mimeType,
43 | false,
44 | true,
45 | jasperReportBuilderTo,
46 | jasperExportBuilderSupplier);
47 | this.withConfigComponents(
48 | HeaderConfigComponent::new,
49 | HighlightConfigComponent::new
50 | );
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/AbstractJasperReportWordProcessingFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import java.io.OutputStream;
19 | import java.util.function.Function;
20 |
21 | import software.xdev.dynamicreports.jasper.base.export.AbstractJasperExporter;
22 | import software.xdev.dynamicreports.jasper.builder.export.AbstractJasperExporterBuilder;
23 | import software.xdev.vaadin.grid_exporter.jasper.DynamicExporter;
24 | import software.xdev.vaadin.grid_exporter.jasper.config.header.HeaderConfigComponent;
25 | import software.xdev.vaadin.grid_exporter.jasper.config.highlight.HighlightConfigComponent;
26 | import software.xdev.vaadin.grid_exporter.jasper.config.page.PageConfigComponent;
27 | import software.xdev.vaadin.grid_exporter.jasper.config.title.TitleConfigComponent;
28 |
29 |
30 | public abstract class AbstractJasperReportWordProcessingFormat>
32 | extends AbstractJasperReportFormat
33 | {
34 | protected AbstractJasperReportWordProcessingFormat(
35 | final String nameToDisplay,
36 | final String fileSuffix,
37 | final String mimeType,
38 | final DynamicExporter jasperReportBuilderTo,
39 | final Function jasperExportBuilderSupplier)
40 | {
41 | super(
42 | nameToDisplay,
43 | fileSuffix,
44 | mimeType,
45 | true,
46 | true,
47 | jasperReportBuilderTo,
48 | jasperExportBuilderSupplier);
49 | this.withConfigComponents(
50 | TitleConfigComponent::new,
51 | HeaderConfigComponent::new,
52 | HighlightConfigComponent::new,
53 | PageConfigComponent::new
54 | );
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/CsvFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import java.util.List;
19 |
20 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
21 | import software.xdev.dynamicreports.jasper.builder.export.Exporters;
22 | import software.xdev.dynamicreports.jasper.builder.export.JasperCsvExporterBuilder;
23 | import software.xdev.vaadin.grid_exporter.format.SpecificConfig;
24 | import software.xdev.vaadin.grid_exporter.jasper.config.encoding.EncodingConfigComponent;
25 | import software.xdev.vaadin.grid_exporter.jasper.config.header.HeaderConfigComponent;
26 | import software.xdev.vaadin.grid_exporter.jasper.config.separator.CSVSeparatorConfig;
27 | import software.xdev.vaadin.grid_exporter.jasper.config.separator.CSVSeparatorConfigComponent;
28 |
29 |
30 | public class CsvFormat extends AbstractJasperReportFormat
31 | {
32 |
33 | public CsvFormat()
34 | {
35 | super(
36 | "CSV",
37 | "csv",
38 | "text/comma-separated-value",
39 | false,
40 | false,
41 | JasperReportBuilder::toCsv,
42 | Exporters::csvExporter
43 | );
44 | this.withConfigComponents(
45 | HeaderConfigComponent::new,
46 | CSVSeparatorConfigComponent::new,
47 | EncodingConfigComponent::new
48 | );
49 | }
50 |
51 | @Override
52 | protected void export(
53 | final JasperReportBuilder reportBuilder,
54 | final JasperCsvExporterBuilder exportBuilder,
55 | final List extends SpecificConfig> configs)
56 | {
57 | this.getValueFrom(configs, CSVSeparatorConfig.class, CSVSeparatorConfig::getSeparator)
58 | .ifPresent(exportBuilder::setFieldDelimiter);
59 |
60 | super.export(reportBuilder, exportBuilder, configs);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/DocxFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
19 | import software.xdev.dynamicreports.jasper.builder.export.Exporters;
20 | import software.xdev.dynamicreports.jasper.builder.export.JasperDocxExporterBuilder;
21 |
22 |
23 | public class DocxFormat extends AbstractJasperReportWordProcessingFormat
24 | {
25 | public DocxFormat()
26 | {
27 | super(
28 | "Word (docx)",
29 | "docx",
30 | "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
31 | JasperReportBuilder::toDocx,
32 | Exporters::docxExporter
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/HtmlFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
19 | import software.xdev.dynamicreports.jasper.builder.export.Exporters;
20 | import software.xdev.dynamicreports.jasper.builder.export.JasperHtmlExporterBuilder;
21 | import software.xdev.vaadin.grid_exporter.jasper.config.header.HeaderConfigComponent;
22 | import software.xdev.vaadin.grid_exporter.jasper.config.highlight.HighlightConfigComponent;
23 | import software.xdev.vaadin.grid_exporter.jasper.config.title.TitleConfigComponent;
24 |
25 |
26 | public class HtmlFormat extends AbstractJasperReportFormat
27 | {
28 | public HtmlFormat()
29 | {
30 | super(
31 | "HTML",
32 | "html",
33 | "text/html",
34 | false,
35 | true,
36 | JasperReportBuilder::toHtml,
37 | Exporters::htmlExporter
38 | );
39 | this.withConfigComponents(
40 | TitleConfigComponent::new,
41 | HeaderConfigComponent::new,
42 | HighlightConfigComponent::new
43 | );
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/OdsFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
19 | import software.xdev.dynamicreports.jasper.builder.export.Exporters;
20 | import software.xdev.dynamicreports.jasper.builder.export.JasperOdsExporterBuilder;
21 |
22 |
23 | public class OdsFormat extends AbstractJasperReportSpreadsheetFormat
24 | {
25 | public OdsFormat()
26 | {
27 | super(
28 | "Open Document Spreadsheet (ods)",
29 | "ods",
30 | "application/vnd.oasis.opendocument.spreadsheet",
31 | JasperReportBuilder::toOds,
32 | Exporters::odsExporter
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/OdtFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
19 | import software.xdev.dynamicreports.jasper.builder.export.Exporters;
20 | import software.xdev.dynamicreports.jasper.builder.export.JasperOdtExporterBuilder;
21 |
22 |
23 | public class OdtFormat extends AbstractJasperReportWordProcessingFormat
24 | {
25 | public OdtFormat()
26 | {
27 | super(
28 | "Open Document Text (odt)",
29 | "odt",
30 | "application/vnd.oasis.opendocument.text",
31 | JasperReportBuilder::toOdt,
32 | Exporters::odtExporter
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/PdfFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
19 | import software.xdev.dynamicreports.jasper.builder.export.Exporters;
20 | import software.xdev.dynamicreports.jasper.builder.export.JasperPdfExporterBuilder;
21 | import software.xdev.vaadin.grid_exporter.jasper.config.header.HeaderConfigComponent;
22 | import software.xdev.vaadin.grid_exporter.jasper.config.highlight.HighlightConfigComponent;
23 | import software.xdev.vaadin.grid_exporter.jasper.config.page.PageConfigComponent;
24 | import software.xdev.vaadin.grid_exporter.jasper.config.title.TitleConfigComponent;
25 |
26 |
27 | public class PdfFormat extends AbstractJasperReportFormat
28 | {
29 |
30 | public PdfFormat()
31 | {
32 | super(
33 | "PDF",
34 | "pdf",
35 | "application/pdf",
36 | true,
37 | true,
38 | JasperReportBuilder::toPdf,
39 | Exporters::pdfExporter
40 | );
41 | this.withConfigComponents(
42 | TitleConfigComponent::new,
43 | HeaderConfigComponent::new,
44 | HighlightConfigComponent::new,
45 | PageConfigComponent::new
46 | );
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/PptxFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
19 | import software.xdev.dynamicreports.jasper.builder.export.Exporters;
20 | import software.xdev.dynamicreports.jasper.builder.export.JasperPptxExporterBuilder;
21 | import software.xdev.vaadin.grid_exporter.jasper.config.header.HeaderConfigComponent;
22 | import software.xdev.vaadin.grid_exporter.jasper.config.highlight.HighlightConfigComponent;
23 | import software.xdev.vaadin.grid_exporter.jasper.config.page.PageConfigComponent;
24 | import software.xdev.vaadin.grid_exporter.jasper.config.title.TitleConfigComponent;
25 |
26 |
27 | public class PptxFormat extends AbstractJasperReportFormat
28 | {
29 | public PptxFormat()
30 | {
31 | super(
32 | "Powerpoint (pptx)",
33 | "pptx",
34 | "application/vnd.openxmlformats-officedocument.presentationml.presentation",
35 | true,
36 | true,
37 | JasperReportBuilder::toPptx,
38 | Exporters::pptxExporter
39 | );
40 | this.withConfigComponents(
41 | TitleConfigComponent::new,
42 | HeaderConfigComponent::new,
43 | HighlightConfigComponent::new,
44 | PageConfigComponent::new
45 | );
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/RtfFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
19 | import software.xdev.dynamicreports.jasper.builder.export.Exporters;
20 | import software.xdev.dynamicreports.jasper.builder.export.JasperRtfExporterBuilder;
21 | import software.xdev.vaadin.grid_exporter.jasper.config.header.HeaderConfigComponent;
22 | import software.xdev.vaadin.grid_exporter.jasper.config.page.PageConfigComponent;
23 | import software.xdev.vaadin.grid_exporter.jasper.config.title.TitleConfigComponent;
24 |
25 |
26 | public class RtfFormat extends AbstractJasperReportFormat
27 | {
28 | public RtfFormat()
29 | {
30 | super(
31 | "Rich Text",
32 | "rtf",
33 | "text/rtf",
34 | true,
35 | false,
36 | JasperReportBuilder::toRtf,
37 | Exporters::rtfExporter
38 | );
39 | this.withConfigComponents(
40 | TitleConfigComponent::new,
41 | // Don't export header by default because it's centered?
42 | translator -> new HeaderConfigComponent(translator, false),
43 | PageConfigComponent::new
44 | );
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/TextFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
19 | import software.xdev.dynamicreports.jasper.builder.export.Exporters;
20 | import software.xdev.dynamicreports.jasper.builder.export.JasperTextExporterBuilder;
21 | import software.xdev.vaadin.grid_exporter.jasper.config.header.HeaderConfigComponent;
22 |
23 |
24 | public class TextFormat extends AbstractJasperReportFormat
25 | {
26 | public TextFormat()
27 | {
28 | super(
29 | "Text",
30 | "txt",
31 | "text/plain",
32 | false,
33 | false,
34 | JasperReportBuilder::toText,
35 | Exporters::textExporter
36 | );
37 | this.withConfigComponents(
38 | HeaderConfigComponent::new
39 | );
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/jasper/format/XlsxFormat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.jasper.format;
17 |
18 | import software.xdev.dynamicreports.jasper.builder.JasperReportBuilder;
19 | import software.xdev.dynamicreports.jasper.builder.export.Exporters;
20 | import software.xdev.dynamicreports.jasper.builder.export.JasperXlsxExporterBuilder;
21 |
22 |
23 | public class XlsxFormat extends AbstractJasperReportSpreadsheetFormat
24 | {
25 | public XlsxFormat()
26 | {
27 | super(
28 | "Excel (xlsx)",
29 | "xlsx",
30 | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
31 | JasperReportBuilder::toXlsx,
32 | Exporters::xlsxExporter
33 | );
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/wizard/GridExporterWizard.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.wizard;
17 |
18 | import java.util.Objects;
19 |
20 | import com.vaadin.flow.component.button.Button;
21 | import com.vaadin.flow.component.button.ButtonVariant;
22 | import com.vaadin.flow.component.dialog.Dialog;
23 | import com.vaadin.flow.component.icon.VaadinIcon;
24 | import com.vaadin.flow.router.AfterNavigationEvent;
25 | import com.vaadin.flow.router.AfterNavigationObserver;
26 |
27 | import software.xdev.vaadin.grid_exporter.GridExportLocalizationConfig;
28 | import software.xdev.vaadin.grid_exporter.Translator;
29 | import software.xdev.vaadin.grid_exporter.components.wizard.buttonbar.WizardButtonBarWithAnchor;
30 | import software.xdev.vaadin.grid_exporter.components.wizard.panel.WizardPanel;
31 | import software.xdev.vaadin.grid_exporter.wizard.steps.FormatStep;
32 | import software.xdev.vaadin.grid_exporter.wizard.steps.GeneralStep;
33 | import software.xdev.vaadin.grid_exporter.wizard.steps.PreviewStep;
34 |
35 |
36 | @SuppressWarnings("java:S1948")
37 | public class GridExporterWizard extends Dialog implements AfterNavigationObserver, Translator
38 | {
39 | protected final Button closeButton = new Button(VaadinIcon.CLOSE.create());
40 | protected final WizardPanel> wizardPanel = new WizardPanel<>();
41 | protected final WizardButtonBarWithAnchor buttonBar = new WizardButtonBarWithAnchor(this.wizardPanel);
42 | protected final PreviewStep previewStep;
43 |
44 | protected final GridExportLocalizationConfig localizationConfig;
45 |
46 | public GridExporterWizard(
47 | final GridExporterWizardState initialState,
48 | final GridExportLocalizationConfig localizationConfig)
49 | {
50 | this.localizationConfig = Objects.requireNonNull(localizationConfig);
51 | // Needs to be done after setting localizationConfig
52 | this.previewStep = new PreviewStep<>(this);
53 |
54 | this.initUI();
55 | this.registerListeners();
56 |
57 | this.wizardPanel.setState(initialState);
58 | }
59 |
60 | protected void initUI()
61 | {
62 | this.setHeaderTitle(this.translate(GridExportLocalizationConfig.EXPORT_GRID));
63 | this.closeButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
64 | this.getHeader().add(this.closeButton);
65 |
66 | this.addStepsToWizardPanel();
67 | this.add(this.wizardPanel);
68 |
69 | this.buttonBar.withButtonText(
70 | WizardButtonBarWithAnchor::getBtnCancel,
71 | this.translate(GridExportLocalizationConfig.CANCEL));
72 | this.buttonBar.withButtonText(
73 | WizardButtonBarWithAnchor::getBtnPrevious,
74 | this.translate(GridExportLocalizationConfig.PREVIOUS));
75 | this.buttonBar.withButtonText(
76 | WizardButtonBarWithAnchor::getBtnNext,
77 | this.translate(GridExportLocalizationConfig.NEXT));
78 | this.buttonBar.withButtonText(
79 | WizardButtonBarWithAnchor::getBtnDone,
80 | this.translate(GridExportLocalizationConfig.DOWNLOAD));
81 |
82 | this.buttonBar.getAnchorDone().getElement().setAttribute("download", true);
83 | this.buttonBar.getBtnDone().setIcon(VaadinIcon.DOWNLOAD.create());
84 | this.getFooter().add(this.buttonBar);
85 |
86 | this.setResizable(true);
87 | this.setDraggable(true);
88 |
89 | this.setWidth("80%");
90 | this.setMaxWidth("70em");
91 |
92 | this.setHeight("90%");
93 | this.setMaxHeight("70em");
94 | }
95 |
96 | protected void addStepsToWizardPanel()
97 | {
98 | this.wizardPanel.addStep(new GeneralStep<>(this));
99 | this.wizardPanel.addStep(new FormatStep<>(this));
100 | this.wizardPanel.addStep(this.previewStep);
101 | }
102 |
103 | protected void registerListeners()
104 | {
105 | this.closeButton.addClickListener(ev -> this.close());
106 |
107 | this.buttonBar.addCancelClickListener(ev -> this.close());
108 |
109 | // Add the StreamResource to the download button when the preview is shown
110 | this.previewStep.addStreamResourceGeneratedListener(ev ->
111 | this.buttonBar.getAnchorDone().setHref(ev.getResource()));
112 | // Free up StreamResource when the user leaves the preview (navigates back)
113 | this.wizardPanel.addStepStateChangedListener(ev -> {
114 | if(!ev.isLastStep() && !this.buttonBar.getAnchorDone().getHref().isBlank())
115 | {
116 | this.buttonBar.getAnchorDone().setHref("");
117 | }
118 | });
119 | }
120 |
121 | @Override
122 | public void afterNavigation(final AfterNavigationEvent event)
123 | {
124 | // Workaround for https://github.com/vaadin/flow-components/issues/1541
125 | this.close();
126 | }
127 |
128 | @Override
129 | public String translate(final String key)
130 | {
131 | return this.localizationConfig.getTranslation(key, this);
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/wizard/GridExporterWizardState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.wizard;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 | import java.util.Objects;
21 |
22 | import software.xdev.vaadin.grid_exporter.column.ColumnConfiguration;
23 | import software.xdev.vaadin.grid_exporter.components.wizard.WizardState;
24 | import software.xdev.vaadin.grid_exporter.format.Format;
25 | import software.xdev.vaadin.grid_exporter.format.SpecificConfig;
26 | import software.xdev.vaadin.grid_exporter.grid.GridDataExtractor;
27 |
28 |
29 | public class GridExporterWizardState implements WizardState
30 | {
31 | protected final GridDataExtractor gridDataExtractor;
32 | protected final List availableFormats;
33 | protected final List> availableColumns;
34 |
35 | protected String fileName = "";
36 | protected List> selectedColumns;
37 | protected Format selectedFormat;
38 |
39 | protected final List specificConfigs = new ArrayList<>();
40 |
41 | public GridExporterWizardState(
42 | final GridDataExtractor gridDataExtractor,
43 | final List availableFormats,
44 | final List> availableColumns)
45 | {
46 | this.gridDataExtractor = Objects.requireNonNull(gridDataExtractor);
47 | this.availableFormats = new ArrayList<>(Objects.requireNonNull(availableFormats));
48 | this.availableColumns = new ArrayList<>(Objects.requireNonNull(availableColumns));
49 |
50 | // By default, all columns should be selected that have a name
51 | this.selectedColumns = new ArrayList<>(availableColumns.stream()
52 | .filter(col -> !col.getHeader().isBlank())
53 | .toList());
54 | }
55 |
56 | public GridDataExtractor getGridDataExtractor()
57 | {
58 | return this.gridDataExtractor;
59 | }
60 |
61 | public List getAvailableFormats()
62 | {
63 | return this.availableFormats;
64 | }
65 |
66 | public List> getAvailableColumns()
67 | {
68 | return this.availableColumns;
69 | }
70 |
71 | public List> getSelectedColumns()
72 | {
73 | return this.selectedColumns;
74 | }
75 |
76 | public String getFileName()
77 | {
78 | return this.fileName;
79 | }
80 |
81 | public void setFileName(final String fileName)
82 | {
83 | this.fileName = Objects.requireNonNull(fileName);
84 | }
85 |
86 | public void setSelectedColumns(final List> selectedColumns)
87 | {
88 | this.selectedColumns = Objects.requireNonNull(selectedColumns);
89 | }
90 |
91 | public Format getSelectedFormat()
92 | {
93 | return this.selectedFormat;
94 | }
95 |
96 | public void setSelectedFormat(final Format selectedFormat)
97 | {
98 | this.selectedFormat = selectedFormat;
99 | }
100 |
101 | public List getSpecificConfigs()
102 | {
103 | return this.specificConfigs;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/wizard/steps/AbstractGridExportWizardStepComposite.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.wizard.steps;
17 |
18 | import java.util.Objects;
19 |
20 | import com.vaadin.flow.component.Component;
21 |
22 | import software.xdev.vaadin.grid_exporter.Translator;
23 | import software.xdev.vaadin.grid_exporter.components.wizard.step.WizardStepComposite;
24 | import software.xdev.vaadin.grid_exporter.wizard.GridExporterWizardState;
25 |
26 | @SuppressWarnings("java:S1948")
27 | public abstract class AbstractGridExportWizardStepComposite
28 | extends WizardStepComposite>
29 | implements Translator
30 | {
31 | protected Translator translator;
32 |
33 | protected AbstractGridExportWizardStepComposite(final Translator translator)
34 | {
35 | this.translator = Objects.requireNonNull(translator);
36 | }
37 |
38 | @Override
39 | public String translate(final String key)
40 | {
41 | return this.translator.translate(key);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/wizard/steps/FormatStep.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.wizard.steps;
17 |
18 | import java.util.Collections;
19 | import java.util.List;
20 | import java.util.Objects;
21 |
22 | import com.vaadin.flow.component.combobox.ComboBox;
23 | import com.vaadin.flow.component.details.Details;
24 | import com.vaadin.flow.component.details.DetailsVariant;
25 | import com.vaadin.flow.component.orderedlayout.VerticalLayout;
26 | import com.vaadin.flow.data.binder.Binder;
27 | import com.vaadin.flow.data.provider.DataProvider;
28 |
29 | import software.xdev.vaadin.grid_exporter.GridExportLocalizationConfig;
30 | import software.xdev.vaadin.grid_exporter.Translator;
31 | import software.xdev.vaadin.grid_exporter.format.Format;
32 | import software.xdev.vaadin.grid_exporter.format.SpecificConfig;
33 | import software.xdev.vaadin.grid_exporter.format.SpecificConfigComponent;
34 | import software.xdev.vaadin.grid_exporter.wizard.GridExporterWizardState;
35 |
36 |
37 | @SuppressWarnings("java:S1948")
38 | public class FormatStep extends AbstractGridExportWizardStepComposite
39 | {
40 | protected final Binder> binder = new Binder<>();
41 |
42 | protected final ComboBox cbFormats = new ComboBox<>();
43 |
44 | protected final VerticalLayout vlConfigs = new VerticalLayout();
45 |
46 | protected List extends SpecificConfigComponent extends SpecificConfig>> configComponents =
47 | Collections.emptyList();
48 |
49 | public FormatStep(final Translator translator)
50 | {
51 | super(translator);
52 | this.setStepName(this.translate(GridExportLocalizationConfig.FORMAT));
53 |
54 | this.initUI();
55 |
56 | this.registerListeners();
57 |
58 | this.initBindings();
59 | }
60 |
61 | protected void initUI()
62 | {
63 | this.cbFormats.setLabel(this.translate(GridExportLocalizationConfig.FORMAT));
64 | this.cbFormats.setItemLabelGenerator(Format::getFormatNameToDisplay);
65 | this.cbFormats.setWidthFull();
66 | this.cbFormats.setMaxWidth("16em");
67 |
68 | this.vlConfigs.setSpacing(false);
69 | this.vlConfigs.setPadding(false);
70 | this.vlConfigs.setSizeFull();
71 |
72 | this.getContent().add(this.cbFormats, this.vlConfigs);
73 | this.getContent().setPadding(false);
74 | this.getContent().setSizeFull();
75 | }
76 |
77 | protected void registerListeners()
78 | {
79 | this.cbFormats.addValueChangeListener(ev ->
80 | {
81 | // Normally this should never happen due to the binder
82 | final Format newFormat = ev.getValue();
83 |
84 | this.showConfigComponentsFor(newFormat);
85 |
86 | if(newFormat == null)
87 | {
88 | return;
89 | }
90 |
91 | this.bindConfigComponents(this.getWizardState(), true);
92 | });
93 | }
94 |
95 | protected void showConfigComponentsFor(final Format format)
96 | {
97 | this.vlConfigs.removeAll();
98 |
99 | this.configComponents = format != null
100 | ? format.getConfigComponents()
101 | .stream()
102 | .map(creator -> creator.apply(this))
103 | .toList()
104 | : Collections.emptyList();
105 |
106 | this.configComponents.forEach(c ->
107 | {
108 | final Details details = new Details(c.getHeader(), c);
109 | details.setOpened(true);
110 | details.addThemeVariants(DetailsVariant.FILLED, DetailsVariant.SMALL);
111 | details.setWidthFull();
112 |
113 | this.vlConfigs.add(details);
114 | });
115 | }
116 |
117 | @SuppressWarnings({"unchecked", "rawtypes"})
118 | protected void bindConfigComponents(
119 | final GridExporterWizardState state,
120 | final boolean deleteNonMatchingFromState)
121 | {
122 | for(final SpecificConfigComponent> component : this.configComponents)
123 | {
124 | final SpecificConfig newConfig = component.getNewConfigSupplier().get();
125 |
126 | final SpecificConfig existing = state.getSpecificConfigs().stream()
127 | .filter(c -> Objects.equals(newConfig.getClass(), c.getClass()))
128 | .findFirst()
129 | .orElse(null);
130 |
131 | state.getSpecificConfigs().remove(existing);
132 |
133 | final SpecificConfig configToUse = existing == null ? newConfig : existing;
134 |
135 | ((SpecificConfigComponent)component).updateFrom(configToUse);
136 |
137 | state.getSpecificConfigs().add(configToUse);
138 | }
139 |
140 | if(deleteNonMatchingFromState)
141 | {
142 | // Remove all configs that are not required for the current state
143 | state.getSpecificConfigs().removeAll(
144 | state.getSpecificConfigs()
145 | .stream()
146 | .filter(ec -> this.configComponents.stream()
147 | .map(SpecificConfigComponent::getBean)
148 | .noneMatch(c -> Objects.equals(ec, c)))
149 | .toList()
150 | );
151 | }
152 | }
153 |
154 | protected void initBindings()
155 | {
156 | this.binder.forField(this.cbFormats)
157 | .asRequired()
158 | .bind(GridExporterWizardState::getSelectedFormat, GridExporterWizardState::setSelectedFormat);
159 | }
160 |
161 | @Override
162 | public void onEnterStep(final GridExporterWizardState state)
163 | {
164 | this.cbFormats.setItems(DataProvider.ofCollection(state.getAvailableFormats()));
165 |
166 | this.binder.setBean(state);
167 |
168 | this.bindConfigComponents(state, false);
169 | }
170 |
171 | @Override
172 | public boolean onProgress(final GridExporterWizardState state)
173 | {
174 | return this.binder.isValid() && this.configComponents.stream().allMatch(SpecificConfigComponent::isValid);
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/java/software/xdev/vaadin/grid_exporter/wizard/steps/PreviewStep.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.wizard.steps;
17 |
18 | import java.io.ByteArrayInputStream;
19 | import java.util.Objects;
20 |
21 | import com.vaadin.flow.component.ComponentEvent;
22 | import com.vaadin.flow.component.ComponentEventListener;
23 | import com.vaadin.flow.component.html.HtmlObject;
24 | import com.vaadin.flow.component.orderedlayout.VerticalLayout;
25 | import com.vaadin.flow.server.StreamResource;
26 | import com.vaadin.flow.shared.Registration;
27 |
28 | import software.xdev.vaadin.grid_exporter.GridExportLocalizationConfig;
29 | import software.xdev.vaadin.grid_exporter.Translator;
30 | import software.xdev.vaadin.grid_exporter.format.Format;
31 | import software.xdev.vaadin.grid_exporter.wizard.GridExporterWizardState;
32 |
33 |
34 | public class PreviewStep extends AbstractGridExportWizardStepComposite
35 | {
36 | protected HtmlObject resViewer = new HtmlObject();
37 |
38 | public PreviewStep(final Translator translator)
39 | {
40 | super(translator);
41 | this.setStepName(this.translate(GridExportLocalizationConfig.PREVIEW));
42 |
43 | this.initUI();
44 | }
45 |
46 | protected void initUI()
47 | {
48 | this.resViewer.getStyle().set("text-align", "center");
49 | this.resViewer.getElement().setText(this.translate(GridExportLocalizationConfig.UNABLE_TO_SHOW_PREVIEW));
50 | this.resViewer.setSizeFull();
51 |
52 | this.getContent().add(this.resViewer);
53 | this.getContent().setPadding(false);
54 | this.getContent().setSizeFull();
55 | }
56 |
57 | @Override
58 | public void onEnterStep(final GridExporterWizardState state)
59 | {
60 | // Generate data and preview
61 | final Format format = state.getSelectedFormat();
62 | final byte[] bytes = format.export(
63 | state.getGridDataExtractor(),
64 | state.getSelectedColumns(),
65 | state.getSpecificConfigs());
66 |
67 | final StreamResource resource = new StreamResource(
68 | state.getFileName() + "." + format.getFormatFilenameSuffix(),
69 | () -> new ByteArrayInputStream(bytes)
70 | );
71 | resource.setContentType(format.getMimeType());
72 |
73 | this.resViewer.setType(format.getMimeType());
74 | this.resViewer.setData(resource);
75 |
76 | this.fireEvent(new StreamResourceGeneratedEvent<>(resource, this, false));
77 | }
78 |
79 | @SuppressWarnings({ "rawtypes", "unchecked"})
80 | public Registration addStreamResourceGeneratedListener(
81 | final ComponentEventListener> listener)
82 | {
83 | return this.addListener(StreamResourceGeneratedEvent.class, (ComponentEventListener)listener);
84 | }
85 |
86 | public static class StreamResourceGeneratedEvent extends ComponentEvent>
87 | {
88 | protected final StreamResource resource;
89 |
90 | public StreamResourceGeneratedEvent(
91 | final StreamResource resource,
92 | final PreviewStep source, final boolean fromClient)
93 | {
94 | super(source, fromClient);
95 | this.resource = Objects.requireNonNull(resource);
96 | }
97 |
98 | public StreamResource getResource()
99 | {
100 | return this.resource;
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/main/resources/META-INF/resources/frontend/styles/wizard.css:
--------------------------------------------------------------------------------
1 | .wizard-panel-content {
2 | overflow-y: auto;
3 | }
4 |
5 | vaadin-tabs.wizard-panel-tabs vaadin-tab::before {
6 | display: none;
7 | }
8 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/test/java/software/xdev/vaadin/grid_exporter/column/headerresolving/VaadinColumnHeaderResolvingStrategyTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.column.headerresolving;
17 |
18 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
19 | import static org.junit.jupiter.api.Assertions.assertEquals;
20 | import static org.junit.jupiter.api.Assertions.assertFalse;
21 | import static org.junit.jupiter.api.Assertions.assertTrue;
22 |
23 | import java.util.Optional;
24 |
25 | import org.junit.jupiter.api.DisplayName;
26 | import org.junit.jupiter.api.Test;
27 |
28 | import com.vaadin.flow.component.grid.Grid;
29 | import com.vaadin.flow.component.grid.Grid.Column;
30 | import com.vaadin.flow.component.html.Span;
31 |
32 |
33 | class VaadinColumnHeaderResolvingStrategyTest
34 | {
35 | @Test
36 | @DisplayName("Grid-Header is read correctly from a grid with one set column header")
37 | void checkSetHeaderText()
38 | {
39 | final String expectedHeader = "username";
40 |
41 | final Grid grid = new Grid<>();
42 |
43 | final Column colUsername = grid
44 | .addColumn(TestUserDTO::username)
45 | .setHeader(expectedHeader);
46 |
47 | final Optional optResolvedName =
48 | new VaadinColumnHeaderResolvingStrategy().resolve(colUsername);
49 |
50 | assertTrue(optResolvedName.isPresent(), "No resolved column name found");
51 | assertEquals(expectedHeader, optResolvedName.get());
52 | }
53 |
54 | @Test
55 | @DisplayName("Grid-Header be found when read from a grid with a column renderer/component")
56 | void checkSetHeaderComponent()
57 | {
58 | final String expectedHeader = "text";
59 |
60 | final Grid grid = new Grid<>();
61 |
62 | final Column colUsername = grid
63 | .addColumn(TestUserDTO::username)
64 | .setHeader(new Span(expectedHeader));
65 |
66 | final Optional optResolvedName =
67 | new VaadinColumnHeaderResolvingStrategy().resolve(colUsername);
68 |
69 | assertTrue(optResolvedName.isPresent(), "No resolved column name found");
70 | assertEquals(expectedHeader, optResolvedName.get());
71 | }
72 |
73 | @Test
74 | @DisplayName("Grid-Header should not be found when read from a grid with no column header")
75 | void checkNoHeaderSet()
76 | {
77 | final Grid grid = new Grid<>();
78 |
79 | final Column colUsername = grid
80 | .addColumn(TestUserDTO::username);
81 |
82 | final Optional optResolvedName =
83 | new VaadinColumnHeaderResolvingStrategy().resolve(colUsername);
84 |
85 | assertFalse(optResolvedName.isPresent(), "column name found");
86 | }
87 |
88 | @Test
89 | @DisplayName("Test null safety")
90 | void nullSafety()
91 | {
92 | final Optional optResolvedName =
93 | assertDoesNotThrow(
94 | () -> new VaadinColumnHeaderResolvingStrategy().resolve(null));
95 |
96 | assertFalse(optResolvedName.isPresent(), "column name found");
97 | }
98 |
99 | record TestUserDTO(String username, String firstName, String lastName)
100 | {
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/vaadin-grid-exporter/src/test/java/software/xdev/vaadin/grid_exporter/grid/GridDataExtractorReflectionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2022 XDEV Software (https://xdev.software)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package software.xdev.vaadin.grid_exporter.grid;
17 |
18 | import java.util.function.Function;
19 | import java.util.stream.Stream;
20 |
21 | import org.junit.jupiter.api.Assertions;
22 | import org.junit.jupiter.api.DisplayName;
23 | import org.junit.jupiter.params.ParameterizedTest;
24 | import org.junit.jupiter.params.provider.Arguments;
25 | import org.junit.jupiter.params.provider.MethodSource;
26 |
27 | import com.vaadin.flow.component.grid.ColumnPathRenderer;
28 | import com.vaadin.flow.component.grid.Grid;
29 | import com.vaadin.flow.data.renderer.TextRenderer;
30 |
31 |
32 | class GridDataExtractorReflectionTest
33 | {
34 |
35 | static Stream checkFormattedValue()
36 | {
37 | return Stream.of(
38 | new CheckFormattedValueTestData(
39 | "ValueProvider",
40 | gr -> gr.addColumn(DummyData::text)),
41 | new CheckFormattedValueTestData(
42 | "TextRenderer",
43 | gr -> gr.addColumn(new TextRenderer<>(DummyData::text))),
44 | new CheckFormattedValueTestData(
45 | "ColumnPathRenderer",
46 | gr -> gr.addColumn(new ColumnPathRenderer<>("text", DummyData::text)))
47 | ).map(td -> Arguments.of(td.testDesc(), td.columnCreator(), td.item(), td.expectedResult()));
48 | }
49 |
50 | @DisplayName("Checking formattedValue")
51 | @ParameterizedTest(name = "{displayName} with {0}")
52 | @MethodSource
53 | void checkFormattedValue(
54 | final String checkingDesc,
55 | final Function, Grid.Column> columnCreator,
56 | final DummyData item,
57 | final String expectedResult)
58 | {
59 | final Grid grid = new Grid<>();
60 |
61 | final Grid.Column column = columnCreator.apply(grid);
62 |
63 | final String value =
64 | Assertions.assertDoesNotThrow(() -> new GridDataExtractor<>(grid).getFormattedValue(column, item));
65 |
66 | Assertions.assertEquals(expectedResult, value);
67 | }
68 |
69 | record CheckFormattedValueTestData(
70 | String testDesc,
71 | Function, Grid.Column> columnCreator,
72 | DummyData item,
73 | String expectedResult
74 | )
75 | {
76 | CheckFormattedValueTestData(
77 | final String testDesc,
78 | final Function, Grid.Column> columnCreator)
79 | {
80 | this(testDesc, columnCreator, new DummyData("Test"), "Test");
81 | }
82 | }
83 |
84 |
85 | record DummyData(String text)
86 | {
87 | }
88 | }
89 |
--------------------------------------------------------------------------------