Project

General

Profile

« Previous | Next » 

Revision 7bd84a66

Added by Patrick Plitzner about 7 years ago

ref #6527 Refactor configurator composite

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/DeleteHandler.java
17 17
import org.eclipse.core.commands.ExecutionException;
18 18
import org.eclipse.core.commands.common.NotDefinedException;
19 19
import org.eclipse.core.commands.operations.IUndoContext;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.jface.dialogs.MessageDialog;
22 20
import org.eclipse.jface.viewers.IStructuredSelection;
23 21
import org.eclipse.jface.viewers.TreePath;
24 22
import org.eclipse.jface.viewers.TreeSelection;
......
105 103
					// TODO use undo context specific to editor
106 104
                    MediaDeletionConfigurator config = new MediaDeletionConfigurator();
107 105

  
108
                    DeleteConfiguratorDialog dialog;
109
                    dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), Messages.DeleteHandler_CONFIRM_DELETION,  null,  Messages.DeleteHandler_CONFIRM_DELETION_MESSAGE, MessageDialog.WARNING, new String[] { Messages.DeleteHandler_DELETE, Messages.DeleteHandler_SKIP }, 0);
110
                    int result_dialog= dialog.open();
111
                    if (result_dialog != Status.OK){
106
                    if (!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, HandlerUtil.getActiveShell(event), Messages.DeleteHandler_CONFIRM_DELETION,  Messages.DeleteHandler_CONFIRM_DELETION_MESSAGE)){
112 107
                        return null;
113 108
                    }
114 109

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteConfiguratorDialog.java
46 46

  
47 47
    public DeleteConfiguratorDialog(DeleteConfiguratorBase configurator, Shell parentShell, String dialogTitle,
48 48
            Image dialogTitleImage, String dialogMessage, int dialogImageType, String[] dialogButtonLabels, int defaultIndex) {
49
        super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex);
50
        this.configurator = configurator;
51
        this.fromBulkEditor = false;
49
        this(configurator, parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex, false);
52 50
    }
53 51

  
54 52
    @Override
......
65 63
        }  else if(configurator instanceof NameDeletionConfigurator){
66 64
            composite.addConfiguratorComposite(new DeleteNameConfiguratorComposite((NameDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
67 65
        }  else if(configurator instanceof MediaDeletionConfigurator){
68
            if (!fromBulkEditor){
69
                composite.addConfiguratorComposite(new DeleteMediaConfiguratorComposite((MediaDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE, fromBulkEditor));
70
            }else{
71
                composite.addConfiguratorComposite(new DeleteMediaConfiguratorComposite((MediaDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
72
            }
66
            composite.addConfiguratorComposite(new DeleteMediaConfiguratorComposite((MediaDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE, fromBulkEditor));
73 67
        }
74 68

  
75 69

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/deleteConfigurator/DeleteMediaConfiguratorComposite.java
15 15
import org.eclipse.swt.SWT;
16 16
import org.eclipse.swt.events.DisposeEvent;
17 17
import org.eclipse.swt.events.DisposeListener;
18
import org.eclipse.swt.layout.GridData;
19
import org.eclipse.swt.layout.GridLayout;
20 18
import org.eclipse.swt.layout.RowLayout;
21 19
import org.eclipse.swt.widgets.Button;
22 20
import org.eclipse.swt.widgets.Composite;
23 21
import org.eclipse.swt.widgets.Display;
24 22
import org.eclipse.swt.widgets.Event;
25
import org.eclipse.swt.widgets.Listener;
26 23
import org.eclipse.ui.forms.widgets.FormToolkit;
27 24

  
28 25
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
......
40 37
    private final MediaDeletionConfigurator configurator;
41 38
    private final Button btnDeleteIfUsedInTaxonDescription;
42 39
    private final Button btnDeleteIfUsedInSpecimenDescription;
43
    private final Button btnRemoveFromImageGallery;
44
    private final boolean isInBulkEditor;
40
    private Button btnRemoveFromImageGallery;
45 41

  
46 42

  
47
    /**
48
     * Create the composite.
49
     * @param parent
50
     * @param style
51
     */
52
    public DeleteMediaConfiguratorComposite(MediaDeletionConfigurator configurator, Composite parent, int style) {
53
        super(parent, style);
54
        this.configurator = configurator;
55
        this.isInBulkEditor = false;
56
        addDisposeListener(new DisposeListener() {
57
            @Override
58
            public void widgetDisposed(DisposeEvent e) {
59
                toolkit.dispose();
60
            }
61
        });
62
        toolkit.paintBordersFor(this);
63
        setLayout(new RowLayout(SWT.VERTICAL));
64
        setBackground(getBackground());
65

  
66
        btnRemoveFromImageGallery = null;
67

  
68
        btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.CHECK);
69
        btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInTaxonDescription);
70
        btnDeleteIfUsedInTaxonDescription.setSelection(false);
71

  
72
        btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
73
        btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
74
        btnDeleteIfUsedInSpecimenDescription.setSelection(false);
75

  
76

  
77
        m_bindingContext = initDataBindings();
78

  
79
    }
80

  
81 43
    public DeleteMediaConfiguratorComposite(MediaDeletionConfigurator configurator, Composite parent, int style, boolean inBulkEditor) {
82 44
        super(parent, style);
83 45
        this.configurator = configurator;
84
        this.isInBulkEditor = inBulkEditor;
85 46
        addDisposeListener(new DisposeListener() {
86 47
            @Override
87 48
            public void widgetDisposed(DisposeEvent e) {
......
89 50
            }
90 51
        });
91 52
        toolkit.paintBordersFor(this);
92
        setLayout(new GridLayout());
53
        setLayout(new RowLayout(SWT.VERTICAL));
93 54
        setBackground(getBackground());
94 55

  
95

  
96

  
97

  
98
        if (!inBulkEditor){
99
            btnRemoveFromImageGallery = new Button(this, SWT.RADIO);
100
            btnRemoveFromImageGallery.setText(Messages.DeleteConfiguration_media_removeFromGallery);
101

  
102
            btnRemoveFromImageGallery.setSelection(true);
103
            btnRemoveFromImageGallery.setVisible(true);
104
            btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.RADIO);
105
            btnDeleteIfUsedInTaxonDescription.setSelection(false);
106
            btnDeleteIfUsedInTaxonDescription.setVisible(true);
107
            btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_delete);
108
            btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
109
            btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
110
            btnDeleteIfUsedInSpecimenDescription.setVisible(false);
111
            btnDeleteIfUsedInTaxonDescription.addListener(SWT.Selection, new Listener() {
112
                @Override
113
             public void handleEvent(Event e) {
114
                    Button b = (Button) e.widget;
115
                    GridData data = (GridData)  btnDeleteIfUsedInTaxonDescription.getLayoutData();
116
                    data.exclude = b.getSelection();
117
                    btnDeleteIfUsedInSpecimenDescription.setVisible(data.exclude);
118

  
119
                }
120
         });
121

  
122

  
123

  
124

  
125
        } else{
126
            btnRemoveFromImageGallery =null;
56
        if (inBulkEditor){
127 57
            btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.CHECK);
128
            btnDeleteIfUsedInTaxonDescription.setSelection(false);
129 58
            btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInTaxonDescription);
130
            btnDeleteIfUsedInTaxonDescription.setVisible(true);
131

  
132
            btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
133
            btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
134
            btnDeleteIfUsedInSpecimenDescription.setVisible(true);
135 59
        }
60
        else {
61
            btnDeleteIfUsedInTaxonDescription = new Button(this, SWT.RADIO);
62
            btnDeleteIfUsedInTaxonDescription.setText(Messages.DeleteConfiguration_media_delete);
136 63

  
64
            btnRemoveFromImageGallery = new Button(this, SWT.RADIO);
65
            btnRemoveFromImageGallery.setText(Messages.DeleteConfiguration_media_removeFromGallery);
66
        }
137 67

  
68
        btnDeleteIfUsedInSpecimenDescription = new Button(this, SWT.CHECK);
69
        btnDeleteIfUsedInSpecimenDescription.setText(Messages.DeleteConfiguration_media_deleteIfUsedInSpecimenDescription);
138 70

  
71
        if(inBulkEditor){
72
            btnDeleteIfUsedInSpecimenDescription.setEnabled(true);
73
        }
74
        else{
75
            btnDeleteIfUsedInSpecimenDescription.setEnabled(false);
139 76

  
77
            btnDeleteIfUsedInTaxonDescription.addListener(SWT.Selection, (Event e) -> {
78
                Button b = (Button) e.widget;
79
                btnDeleteIfUsedInSpecimenDescription.setEnabled(b.getSelection());
140 80

  
141

  
81
            });
82
        }
83
        btnDeleteIfUsedInTaxonDescription.setSelection(true);
142 84

  
143 85
        m_bindingContext = initDataBindings();
144 86

  
......
150 92
        IObservableValue observeSelectionBtnDeleteIfUsedInTaxonDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInTaxonDescription);
151 93
        IObservableValue deleteIfUsedInTaxonDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInTaxonDescription").observe(configurator);
152 94
        bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInTaxonDescription, deleteIfUsedInTaxonDescriptionConfiguratorObserveValue, null, null);
153
        if (isInBulkEditor){
154
            IObservableValue observeSelectionBtnDeleteIfUsedInSpecimenDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInSpecimenDescription);
155
            IObservableValue deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInSpecimenDescription").observe(configurator);
156
            bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInSpecimenDescription, deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue, null, null);
157
        }else{
95

  
96
        if(btnRemoveFromImageGallery!=null){
158 97
            IObservableValue observeSelectionBtnRemoveFromImageGallery = WidgetProperties.selection().observe(btnRemoveFromImageGallery);
159 98
            IObservableValue removeFromImageGalleryConfiguratorObserveValue = PojoProperties.value("onlyRemoveFromGallery").observe(configurator);
160 99
            bindingContext.bindValue(observeSelectionBtnRemoveFromImageGallery, removeFromImageGalleryConfiguratorObserveValue, null, null);
161

  
162
            IObservableValue observeSelectionBtnDeleteIfUsedInSpecimenDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInSpecimenDescription);
163
            IObservableValue deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInSpecimenDescription").observe(configurator);
164
            bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInSpecimenDescription, deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue, null, null);
165 100
        }
166 101

  
102
        IObservableValue observeSelectionBtnDeleteIfUsedInSpecimenDescription = WidgetProperties.selection().observe(btnDeleteIfUsedInSpecimenDescription);
103
        IObservableValue deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue = PojoProperties.value("deleteIfUsedInSpecimenDescription").observe(configurator);
104
        bindingContext.bindValue(observeSelectionBtnDeleteIfUsedInSpecimenDescription, deleteIfUsedInSpecimenDescriptionConfiguratorObserveValue, null, null);
105

  
167 106
        return bindingContext;
168 107
    }
169 108

  

Also available in: Unified diff