Revision 2be2ac05
Added by Andreas Kohlbecker over 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/dialog/ContinueAlternativeCancelDialog.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2018 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.cdm.vaadin.component.dialog; |
|
10 |
|
|
11 |
import com.vaadin.server.FontAwesome; |
|
12 |
import com.vaadin.ui.Alignment; |
|
13 |
import com.vaadin.ui.Button; |
|
14 |
import com.vaadin.ui.Button.ClickListener; |
|
15 |
import com.vaadin.ui.HorizontalLayout; |
|
16 |
import com.vaadin.ui.Label; |
|
17 |
import com.vaadin.ui.VerticalLayout; |
|
18 |
import com.vaadin.ui.Window; |
|
19 |
import com.vaadin.ui.themes.ValoTheme; |
|
20 |
|
|
21 |
/** |
|
22 |
* @author a.kohlbecker |
|
23 |
* @since Nov 14, 2018 |
|
24 |
* |
|
25 |
*/ |
|
26 |
public class ContinueAlternativeCancelDialog extends Window { |
|
27 |
|
|
28 |
private static final long serialVersionUID = -1948284511236663594L; |
|
29 |
|
|
30 |
private Button alternativeButton; |
|
31 |
private Button continueButton; |
|
32 |
private Button cancelButton; |
|
33 |
|
|
34 |
/** |
|
35 |
* @param caption |
|
36 |
*/ |
|
37 |
public ContinueAlternativeCancelDialog(String caption, String message, String continueText, String alternativeText) { |
|
38 |
super(caption); |
|
39 |
setModal(true); |
|
40 |
VerticalLayout subContent = new VerticalLayout(); |
|
41 |
subContent.setMargin(true); |
|
42 |
setContent(subContent); |
|
43 |
alternativeButton = new Button(alternativeText, FontAwesome.SAVE); |
|
44 |
alternativeButton.setStyleName(ValoTheme.BUTTON_PRIMARY); |
|
45 |
continueButton = new Button(continueText, FontAwesome.REMOVE); |
|
46 |
continueButton.setStyleName(ValoTheme.BUTTON_DANGER); |
|
47 |
cancelButton = new Button("Cancel", FontAwesome.ARROW_CIRCLE_LEFT); |
|
48 |
Label messageLabel = new Label(message, com.vaadin.shared.ui.label.ContentMode.HTML); |
|
49 |
subContent.addComponent(messageLabel); |
|
50 |
HorizontalLayout buttonBar = new HorizontalLayout(alternativeButton, continueButton, cancelButton); |
|
51 |
buttonBar.setStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); |
|
52 |
buttonBar.setWidth(100, Unit.PERCENTAGE); |
|
53 |
buttonBar.setSpacing(true); |
|
54 |
buttonBar.setExpandRatio(alternativeButton, 1); |
|
55 |
buttonBar.setComponentAlignment(continueButton, Alignment.TOP_RIGHT); |
|
56 |
buttonBar.setComponentAlignment(alternativeButton, Alignment.TOP_RIGHT); |
|
57 |
buttonBar.setComponentAlignment(cancelButton, Alignment.TOP_RIGHT); |
|
58 |
subContent.addComponent(buttonBar); |
|
59 |
} |
|
60 |
|
|
61 |
public void addContinueClickListener(ClickListener listener){ |
|
62 |
continueButton.addClickListener(listener); |
|
63 |
} |
|
64 |
public void addAlternativeClickListener(ClickListener listener){ |
|
65 |
alternativeButton.addClickListener(listener); |
|
66 |
} |
|
67 |
|
|
68 |
public void addCancelClickListener(ClickListener listener){ |
|
69 |
cancelButton.addClickListener(listener); |
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
|
75 |
} |
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPopupEditor.java | ||
---|---|---|
38 | 38 |
import com.vaadin.ui.AbstractOrderedLayout; |
39 | 39 |
import com.vaadin.ui.Alignment; |
40 | 40 |
import com.vaadin.ui.Button; |
41 |
import com.vaadin.ui.Button.ClickListener; |
|
41 | 42 |
import com.vaadin.ui.CheckBox; |
42 | 43 |
import com.vaadin.ui.Component; |
43 | 44 |
import com.vaadin.ui.CssLayout; |
... | ... | |
56 | 57 |
import com.vaadin.ui.TextField; |
57 | 58 |
import com.vaadin.ui.UI; |
58 | 59 |
import com.vaadin.ui.VerticalLayout; |
59 |
import com.vaadin.ui.Window; |
|
60 | 60 |
import com.vaadin.ui.themes.ValoTheme; |
61 | 61 |
|
62 | 62 |
import eu.etaxonomy.cdm.database.PermissionDeniedException; |
63 | 63 |
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix; |
64 |
import eu.etaxonomy.cdm.vaadin.component.dialog.ContinueAlternativeCancelDialog; |
|
64 | 65 |
import eu.etaxonomy.cdm.vaadin.event.EditorActionContext; |
65 | 66 |
import eu.etaxonomy.cdm.vaadin.event.EditorActionContextFormat; |
66 | 67 |
import eu.etaxonomy.cdm.vaadin.event.EditorActionContextFormatter; |
... | ... | |
382 | 383 |
protected void cancelEditorDialog(){ |
383 | 384 |
|
384 | 385 |
if(fieldGroup.isModified()){ |
385 |
String message = "<p>The editor has been modified.<br>Do you want to save your changes or discard them?<p>"; |
|
386 |
Window editorModifiedDialog = new Window("Cancel editor"); |
|
387 |
editorModifiedDialog.setModal(true); |
|
388 |
VerticalLayout subContent = new VerticalLayout(); |
|
389 |
subContent.setMargin(true); |
|
390 |
editorModifiedDialog.setContent(subContent); |
|
391 |
Button save = new Button("Save", FontAwesome.SAVE); |
|
392 |
save.setStyleName(ValoTheme.BUTTON_PRIMARY); |
|
393 |
Button discard = new Button("Discard", FontAwesome.REMOVE); |
|
394 |
discard.setStyleName(ValoTheme.BUTTON_DANGER); |
|
395 |
Button cancel = new Button("Cancel", FontAwesome.ARROW_CIRCLE_LEFT); |
|
396 |
Label messageLabel = new Label(message, com.vaadin.shared.ui.label.ContentMode.HTML); |
|
397 |
subContent.addComponent(messageLabel); |
|
398 |
HorizontalLayout buttonBar = new HorizontalLayout(save, discard, cancel); |
|
399 |
buttonBar.setStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); |
|
400 |
buttonBar.setWidth(100, Unit.PERCENTAGE); |
|
401 |
buttonBar.setSpacing(true); |
|
402 |
buttonBar.setExpandRatio(save, 1); |
|
403 |
buttonBar.setComponentAlignment(discard, Alignment.TOP_RIGHT); |
|
404 |
buttonBar.setComponentAlignment(save, Alignment.TOP_RIGHT); |
|
405 |
buttonBar.setComponentAlignment(cancel, Alignment.TOP_RIGHT); |
|
406 |
subContent.addComponent(buttonBar); |
|
407 |
save.addClickListener(e -> {editorModifiedDialog.close(); save();}); |
|
408 |
discard.addClickListener(e -> {editorModifiedDialog.close(); cancel();}); |
|
409 |
cancel.addClickListener(e -> editorModifiedDialog.close()); |
|
386 |
|
|
387 |
ContinueAlternativeCancelDialog editorModifiedDialog = new ContinueAlternativeCancelDialog( |
|
388 |
"Cancel editor", |
|
389 |
"<p>The editor has been modified.<br>Do you want to save your changes or discard them?<p>", |
|
390 |
"Discard", |
|
391 |
"Save"); |
|
392 |
ClickListener saveListener = e -> {editorModifiedDialog.close(); save();}; |
|
393 |
ClickListener discardListener = e -> {editorModifiedDialog.close(); cancel();}; |
|
394 |
ClickListener cancelListener = e -> editorModifiedDialog.close(); |
|
395 |
editorModifiedDialog.addAlternativeClickListener(saveListener); |
|
396 |
editorModifiedDialog.addContinueClickListener(discardListener); |
|
397 |
editorModifiedDialog.addCancelClickListener(cancelListener); |
|
398 |
|
|
410 | 399 |
UI.getCurrent().addWindow(editorModifiedDialog); |
411 | 400 |
} else { |
412 | 401 |
cancel(); |
Also available in: Unified diff
ref #7906 ContinueAlternativeCancelDialog implemented