Project

General

Profile

Revision da04c055

IDda04c055368318fcc7dcabf214d53a0a415c6123
Parent 5e1dc099
Child 833d4759

Added by Katja Luther over 1 year ago

ref #7920: add handlers and wizards for area specific status preference selection

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/e4/OpenCommonNameAreaWizardHandler.java
1
/**
2
* Copyright (C) 2019 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.taxeditor.handler.e4;
10

  
11
import javax.inject.Named;
12

  
13
import org.eclipse.e4.core.di.annotations.Execute;
14
import org.eclipse.e4.ui.services.IServiceConstants;
15
import org.eclipse.jface.wizard.WizardDialog;
16
import org.eclipse.swt.widgets.Shell;
17

  
18
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
19
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
20
import eu.etaxonomy.taxeditor.l10n.Messages;
21
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
22
import eu.etaxonomy.taxeditor.preference.wizard.AvailableVocabularyWizard;
23

  
24
/**
25
 * @author k.luther
26
 * @since 22.01.2019
27
 *
28
 */
29
public class OpenCommonNameAreaWizardHandler {
30
    String commandID = "eu.etaxonomy.taxeditor.handler.e4.OpenCommonNameAreaWizardHandler"; //$NON-NLS-1$
31

  
32
    @Execute
33
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
34
        CdmPreference pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.CommonNameAreaVocabularies);
35
        if (pref == null){
36
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.CommonNameAreaVocabularies, null);
37
        }
38
        AvailableVocabularyWizard wizard = new AvailableVocabularyWizard(true, pref, Messages.OpenCommonNameAreaWizardAdminHandler_COMMON_NAMES);
39

  
40
        WizardDialog dialog = new WizardDialog(shell,
41
                wizard);
42

  
43
        dialog.open();
44
    }
45
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/e4/OpenDistributionAreaWizardHandler.java
1
/**
2
* Copyright (C) 2019 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.taxeditor.handler.e4;
10

  
11
import javax.inject.Named;
12

  
13
import org.eclipse.e4.core.di.annotations.Execute;
14
import org.eclipse.e4.ui.services.IServiceConstants;
15
import org.eclipse.jface.wizard.WizardDialog;
16
import org.eclipse.swt.widgets.Shell;
17

  
18
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
19
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
20
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard;
22

  
23
/**
24
 * @author k.luther
25
 * @since 24.04.2019
26
 *
27
 */
28
public class OpenDistributionAreaWizardHandler {
29
    String commandID = "eu.etaxonomy.taxeditor.handler.e4.OpenDistributionAreaWizardHandler"; //$NON-NLS-1$
30

  
31
    @Execute
32
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
33
        CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AvailableDistributionAreaTerms, null);
34
        pref.setAllowOverride(PreferencesUtil.getBooleanValue(PreferencesUtil.prefOverrideKey(PreferencePredicate.AvailableDistributionAreaTerms.getKey())));
35
        AvailableDistributionWizard wizard = new AvailableDistributionWizard();
36

  
37
        WizardDialog dialog = new WizardDialog(shell,
38
                wizard);
39

  
40
        dialog.open();
41
    }
42
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/e4/OpenDistributionPerAreaStatusWizardHandler.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.taxeditor.handler.e4;
10

  
11
import javax.inject.Named;
12

  
13
import org.eclipse.e4.core.di.annotations.Execute;
14
import org.eclipse.e4.ui.services.IServiceConstants;
15
import org.eclipse.jface.wizard.WizardDialog;
16
import org.eclipse.swt.widgets.Shell;
17

  
18
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionPerAreaStatusWizard;
19

  
20
/**
21
 * @author k.luther
22
 * @since 19.11.2018
23
 *
24
 */
25
public class OpenDistributionPerAreaStatusWizardHandler {
26
    String commandID = "eu.etaxonomy.taxeditor.handler.e4.OpenDistributionPerAreaStatusWizardHandler";
27

  
28
    @Execute
29
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
30

  
31
        AvailableDistributionPerAreaStatusWizard wizard = new AvailableDistributionPerAreaStatusWizard();
32

  
33
        WizardDialog dialog = new WizardDialog(shell,
34
                wizard);
35

  
36
        dialog.open();
37
    }
38
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPerAreaStatusPage.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.taxeditor.preference.wizard;
10

  
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.List;
14
import java.util.Map;
15
import java.util.UUID;
16

  
17
import org.apache.commons.lang.StringUtils;
18
import org.eclipse.jface.util.IPropertyChangeListener;
19
import org.eclipse.jface.util.PropertyChangeEvent;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.events.SelectionEvent;
22
import org.eclipse.swt.events.SelectionListener;
23
import org.eclipse.swt.layout.GridData;
24
import org.eclipse.swt.layout.GridLayout;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.swt.widgets.Text;
29

  
30
import eu.etaxonomy.cdm.api.service.ITermService;
31
import eu.etaxonomy.cdm.api.service.IVocabularyService;
32
import eu.etaxonomy.cdm.model.common.CdmBase;
33
import eu.etaxonomy.cdm.model.location.NamedArea;
34
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
35
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
36
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
37
import eu.etaxonomy.cdm.model.metadata.PreferenceResolver;
38
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
39
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
40
import eu.etaxonomy.cdm.persistence.dto.TermDto;
41
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
42
import eu.etaxonomy.taxeditor.l10n.Messages;
43
import eu.etaxonomy.taxeditor.model.ImageResources;
44
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
45
import eu.etaxonomy.taxeditor.preference.Resources;
46
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
47
import eu.etaxonomy.taxeditor.store.CdmStore;
48
import eu.etaxonomy.taxeditor.store.StoreUtil;
49
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
50

  
51
/**
52
 * @author k.luther
53
 * @since 05.10.2018
54
 *
55
 */
56
public class AvailableDistributionPerAreaStatusPage extends AvailableDistributionStatusPage implements IPropertyChangeListener{
57

  
58
    List<CdmPreference> perAreaPreferences = new ArrayList();
59
    List<TermVocabularyDto> vocs;
60
    NamedArea actualArea;
61
    CdmPreference actualPref;
62
    Text areaText;
63
    Button btnSelectArea;
64
    Button btnRemove;
65
    Label status;
66
    int countTerms;
67

  
68

  
69
    public AvailableDistributionPerAreaStatusPage(String pageName, List<CdmPreference> prefs, boolean localPref) {
70
        super(pageName, null, localPref);
71

  
72
        perAreaPreferences = prefs;
73
        if(PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies) == null && PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()) == null){
74
            vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
75

  
76
        }
77
        pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionStatus);
78
        if (pref == null){
79
            pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AvailableDistributionStatus, null);
80
        }
81
        initialiseVocabularies();
82
        countTerms = CdmStore.getTermManager().getPreferredTerms(type).size();
83
    }
84

  
85
    @Override
86
    public void createControl(Composite parent) {
87
        setTitle(Messages.AvailableDistributionStatusPage_PAGE_TITLE);
88
        setDescription(Messages.AvailableDistributionStatusPage_PAGE_DESCRIPTION);
89
        createAreaSelectionCombo(parent);
90

  
91
        super.createControl(parent);
92

  
93
    }
94

  
95

  
96
    protected void createAreaSelectionCombo(Composite parent) {
97

  
98
        Composite toolbar = new Composite(parent, SWT.NONE);
99
        toolbar.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
100
        GridLayout gl_toolbar = new GridLayout(4, false);
101
        gl_toolbar.horizontalSpacing = 4;
102
        gl_toolbar.marginHeight = 0;
103
        gl_toolbar.verticalSpacing = 0;
104
        toolbar.setLayout(gl_toolbar);
105

  
106
        Label areaLabel = new Label(toolbar, SWT.NONE);
107
        areaLabel.setText("Select area for area specific status");
108

  
109
        GridData textData = new GridData();
110
        textData.minimumWidth = 200;
111
        textData.widthHint = 200;
112
        areaText = new Text(toolbar,  SWT.NONE);
113
        areaText.setEditable(false);
114
        areaText.setBackground(StoreUtil
115
                .getColor(Resources.COLOR_TEXT_DISABLED_BACKGROUND));
116
        areaText.setLayoutData(textData);
117
        btnSelectArea = new Button(toolbar, SWT.PUSH | SWT.FLAT );
118
        btnSelectArea.setImage(ImageResources
119
                .getImage(ImageResources.BROWSE_ICON));
120
        btnSelectArea.setToolTipText("Browse Area");
121

  
122
        btnSelectArea.addSelectionListener(new SelectionListener(){
123

  
124
            @Override
125
            public void widgetSelected(SelectionEvent e) {
126
                refreshActualPrefernce();
127

  
128
                NamedArea selection = SelectionDialogFactory.getSelectionFromDialog(NamedArea.class, getShell(), //getConversationHolder(),
129
                        actualArea, null);
130
                actualArea = selection;
131
                PrefKey key;
132
                if (actualArea != null){
133
                    areaText.setText(actualArea.getLabel());
134
                    key = CdmPreference.NewKey(PreferenceSubject.NewInstance(PreferenceSubject.NewDistributionEditorInstance()+"area/"+actualArea.getUuid().toString()), PreferencePredicate.AvailableDistributionPerAreaStatus);
135
                    actualPref = PreferenceResolver.resolve(perAreaPreferences, key);
136
                    if (actualPref == null){
137
                        actualPref = CdmPreference.NewInstance(key, null);
138
                        perAreaPreferences.add(actualPref);
139
                    }
140
                }else{
141
                    actualPref = null;
142
                }
143

  
144
                status.setVisible(false);
145
                rememberCheckedValues(getCheckedValuesFromPreferences());
146

  
147
            }
148

  
149
            @Override
150
            public void widgetDefaultSelected(SelectionEvent e) {
151
                // TODO Auto-generated method stub
152

  
153
            }
154

  
155
        });
156
        btnRemove = new Button(toolbar, SWT.NONE);
157
        btnRemove.addSelectionListener(new SelectionListener(){
158

  
159
            @Override
160
            public void widgetSelected(SelectionEvent e) {
161

  
162

  
163
                PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewInstance(PreferenceSubject.NewDistributionEditorInstance()+"area/"+actualArea.getUuid().toString()), PreferencePredicate.AvailableDistributionPerAreaStatus);
164
                actualPref = PreferenceResolver.resolve(perAreaPreferences, key);
165
                actualPref = CdmPreference.NewInstance(key, null);
166

  
167
                perAreaPreferences.add(actualPref);
168
                status.setText("Preference for area " + actualArea.getLabel() + " removed.");
169
                status.setVisible(true);
170
                actualArea = null;
171
                areaText.setText("");
172
                rememberCheckedValues(getCheckedValuesFromPreferences());
173

  
174
            }
175

  
176
            @Override
177
            public void widgetDefaultSelected(SelectionEvent e) {
178
                // TODO Auto-generated method stub
179

  
180
            }
181

  
182
        });
183
        btnRemove.setImage(ImageResources.getImage(ImageResources.ACTIVE_DELETE_ICON));
184
        btnRemove.setToolTipText("");
185
        status = new Label(toolbar, SWT.NONE);
186
        status.setVisible(false);
187
    }
188

  
189

  
190
    @Override
191
    public void propertyChange(PropertyChangeEvent event) {
192
        if(event == null){
193
            return;
194
        }
195
        Object eventSource = event.getSource();
196
        if(eventSource != this && btnSelectArea.equals(eventSource)){
197
            if (actualArea != null){
198
                PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewInstance(PreferenceSubject.DISTR_EDITOR+"/area/"+actualArea.getUuid().toString()), PreferencePredicate.AvailableDistributionPerAreaStatus);
199
                actualPref = PreferenceResolver.resolve(perAreaPreferences, key);
200
                areaText.setText(actualArea.getLabel());
201
            }else{
202
                actualPref = null;
203
            }
204

  
205
        }
206
    }
207

  
208
    @Override
209
    protected String getCheckedValuesFromPreferences() {
210
       String checkedValues = null;
211
       if (actualArea == null){
212
           checkedValues = pref.getValue();
213
       }else{
214
           if (actualPref == null){
215
               PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewInstance(PreferenceSubject.DISTR_EDITOR+"/area/"+actualArea.getUuid().toString()), PreferencePredicate.AvailableDistributionPerAreaStatus);
216
               actualPref = PreferenceResolver.resolve(perAreaPreferences, key);
217

  
218
               if (actualPref == null){
219
                   actualPref = CdmPreference.NewInstance(key, null);
220
                   checkedValues = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionStatus.getKey(), true);
221

  
222
               }
223
           }
224
           checkedValues = actualPref.getValue();
225
       }
226

  
227
       return checkedValues;
228
    }
229

  
230
    protected void refreshActualPrefernce(){
231
        String saveCheckedElements;
232
        getViewer().expandAll();
233

  
234

  
235
        if (countTerms == getViewer().getCheckedElements().length){
236
            saveCheckedElements = null;
237
        }else{
238
            Object[] checkedElements = getViewer().getCheckedElements();
239
            List<UUID> listUIIDChecked = new ArrayList<>();
240
            List<DefinedTermBase> preferredTerms = new ArrayList<>();
241
            for (Object o : checkedElements) {
242
                 if(o instanceof TermDto){
243
                     TermDto termDto = (TermDto) o;
244
                     listUIIDChecked.add(termDto.getUuid());
245
                     preferredTerms.add(CdmStore.getService(ITermService.class).load(termDto.getUuid()));
246
                 }
247
             }
248
             saveCheckedElements = StringUtils.join(listUIIDChecked, ";"); //$NON-NLS-1$
249
             if (StringUtils.isBlank(saveCheckedElements)){
250
                 saveCheckedElements = null;
251
         }
252
        }
253
        if (actualArea == null){
254
            CdmPreference savePref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.AvailableDistributionStatus, saveCheckedElements);
255
            savePref.setAllowOverride(pref.isAllowOverride());
256
            pref = savePref;
257
        }else{
258
            PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewInstance(PreferenceSubject.NewDistributionEditorInstance()+"area/"+actualArea.getUuid().toString()), PreferencePredicate.AvailableDistributionPerAreaStatus);
259
            actualPref = PreferenceResolver.resolve(perAreaPreferences, key);
260
            CdmPreference savePref = CdmPreference.NewInstance(PreferenceSubject.fromKey(key), PreferencePredicate.AvailableDistributionPerAreaStatus, saveCheckedElements);
261
            if (actualPref != null){
262
               perAreaPreferences.remove(actualPref);
263
            }
264
            perAreaPreferences.add(savePref);
265
            actualPref = savePref;
266

  
267
        }
268
    }
269

  
270
    @Override
271
    public ICdmEntitySession getCdmEntitySession() {
272
        return null;
273
    }
274

  
275
    @Override
276
    public <T extends CdmBase> Collection<T> getRootEntities() {
277
        return null;
278
    }
279

  
280
    @Override
281
    public Map<Object, List<String>> getPropertyPathsMap() {
282
        return null;
283
    }
284

  
285
    @Override
286
    protected  List<TermVocabularyDto> getVocabulariesFromPreference(){
287
     return null;
288
    }
289

  
290
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPerAreaStatusWizard.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.taxeditor.preference.wizard;
10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
14
import org.eclipse.jface.wizard.IWizardPage;
15
import org.eclipse.jface.wizard.Wizard;
16

  
17
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
18
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
19
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
20
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
21
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
22
import eu.etaxonomy.taxeditor.l10n.Messages;
23
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24
import eu.etaxonomy.taxeditor.store.CdmStore;
25

  
26
/**
27
 * @author k.luther
28
 * @since 05.10.2018
29
 *
30
 */
31
public class AvailableDistributionPerAreaStatusWizard extends Wizard implements IConversationEnabled{
32
    private ConversationHolder conversation;
33
    private final AvailableDistributionPerAreaStatusPage aPage;
34
    List<CdmPreference> prefs;
35

  
36
    public AvailableDistributionPerAreaStatusWizard() {
37
        setWindowTitle(Messages.AvailableDistributionStatusWizard_WIZARD_TITLE);
38
        // TODO if preferenceStore has elements checked load elements in wizard
39
        prefs = PreferencesUtil.getPreferencesFromDB(PreferencePredicate.AvailableDistributionPerAreaStatus);
40
        if (prefs == null) {
41
            prefs = new ArrayList();
42
        }
43
        aPage = new AvailableDistributionPerAreaStatusPage(Messages.AvailableDistributionStatusWizard_PAGE_TITLE, prefs, false);
44

  
45
    }
46

  
47
    @Override
48
    public void addPages() {
49
        addPage(aPage);
50
    }
51

  
52
    @Override
53
    public IWizardPage getPage(String pageName) {
54

  
55
        return aPage;
56
    }
57

  
58
    @Override
59
    public int getPageCount() {
60
       return 1;
61
    }
62

  
63
    @Override
64
    public IWizardPage[] getPages() {
65
        IWizardPage[] pages = new IWizardPage[1];
66
        pages [0] = aPage;
67
        return pages;
68
    }
69

  
70
    @Override
71
    public String getWindowTitle() {
72

  
73
        return Messages.AvailableDistributionStatusWizard_WINDOW_TITLE;
74
    }
75

  
76
    @Override
77
    public boolean performCancel() {
78
        // TODO Auto-generated method stub
79
        return true;
80
    }
81

  
82
    @Override
83
    public boolean performFinish() {
84
        aPage.refreshActualPrefernce();
85
        PreferencesUtil.setPreferencesToDB(aPage.perAreaPreferences);
86
        PreferencesUtil.setPreferenceToDB(aPage.pref);
87
       // PreferencesUtil.setBooleanValue(PreferencesUtil.createOverridePreferenceString(PreferencePredicate.AvailableDistributionStatus.getKey()), aPage.override);
88
        PreferencesUtil.firePreferencesChanged(this.getClass());
89
        return true;
90
    }
91

  
92
    @Override
93
    public void update(CdmDataChangeMap changeEvents) {
94

  
95
    }
96

  
97
    @Override
98
    public ConversationHolder getConversationHolder() {
99
        if (conversation == null) {
100
            conversation = CdmStore.createConversation();
101
        }
102
        return conversation;
103
    }
104

  
105
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)