Project

General

Profile

Download (6.61 KB) Statistics
| Branch: | Tag: | Revision:
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.databaseAdmin.preferencePage;
10

    
11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.events.SelectionAdapter;
13
import org.eclipse.swt.events.SelectionEvent;
14
import org.eclipse.swt.layout.GridLayout;
15
import org.eclipse.swt.widgets.Button;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Control;
18

    
19
import eu.etaxonomy.cdm.api.application.ICdmRepository;
20
import eu.etaxonomy.cdm.api.service.IPreferenceService;
21
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
22
import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
23
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
24
import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
25
import eu.etaxonomy.taxeditor.l10n.Messages;
26
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30
/**
31
 * @author k.luther
32
 * @since 29.05.2018
33
 *
34
 */
35
public class GeneralAdminPreferencePage extends CdmPreferencePage implements IE4AdminPreferencePage {
36

    
37

    
38
    boolean isShowIOMenu = true;
39
    boolean isShowMediaView = true;
40
    boolean isShowCheckListPerspective = false;
41
    boolean isShowTaxonNodeWizard = true;
42
    ICdmRepository controller = null;
43
    /**
44
     * {@inheritDoc}
45
     */
46
    @Override
47
    protected Control createContents(Composite parent) {
48
        final Composite composite = new Composite(parent, SWT.NULL);
49

    
50
        GridLayout gridLayout = new GridLayout();
51
        composite.setLayout(gridLayout);
52
        controller = CdmStore.getCurrentApplicationConfiguration();
53
        if (controller != null){
54
            IPreferenceService service = controller.getPreferenceService();
55
            PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowImportExportMenu);
56
            CdmPreference isShowSpecimenPref = service.find(key);
57
            if (isShowSpecimenPref != null){
58
                this.isShowIOMenu = Boolean.valueOf(isShowSpecimenPref.getValue());
59
            }
60

    
61
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowMediaView);
62
            CdmPreference isShowMediaViewPref = service.find(key);
63
            if (isShowMediaViewPref != null){
64
                this.isShowMediaView = Boolean.valueOf(isShowMediaViewPref.getValue());
65
            }
66

    
67
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowChecklistPerspective);
68
            CdmPreference isShowChecklistPref = service.find(key);
69
            if (isShowChecklistPref != null){
70
                this.isShowCheckListPerspective = Boolean.valueOf(isShowChecklistPref.getValue());
71
            }
72

    
73
            key = CdmPreference.NewKey(PreferenceSubject.NewTaxEditorInstance(), PreferencePredicate.ShowTaxonNodeWizard);
74
            CdmPreference isShowTaxonNodeWizardPref = service.find(key);
75
            if (isShowTaxonNodeWizardPref != null){
76
                this.isShowTaxonNodeWizard = Boolean.valueOf(isShowTaxonNodeWizardPref.getValue());
77
            }
78
        }
79
        final Button showIOMenuButton = new Button(composite, SWT.CHECK);
80

    
81
        showIOMenuButton.setText(Messages.DatabasePreferncesPage_Show_IOMenu);
82

    
83
        showIOMenuButton.setSelection(isShowIOMenu);
84
        showIOMenuButton.addSelectionListener(new SelectionAdapter(){
85
             @Override
86
             public void widgetSelected(SelectionEvent e) {
87
                 isShowIOMenu = showIOMenuButton.getSelection();
88

    
89
              }
90
         });
91

    
92
        final Button showMediaViewButton = new Button(composite, SWT.CHECK);
93

    
94
        showMediaViewButton.setText(Messages.DatabasePreferncesPage_Show_MediaView);
95

    
96
        showMediaViewButton.setSelection(isShowMediaView);
97
        showMediaViewButton.addSelectionListener(new SelectionAdapter(){
98
             @Override
99
             public void widgetSelected(SelectionEvent e) {
100
                 isShowMediaView = showIOMenuButton.getSelection();
101

    
102
              }
103
         });
104
        final Button showChecklistPerspectiveButton = new Button(composite, SWT.CHECK);
105

    
106
        showChecklistPerspectiveButton.setText(Messages.DatabasePreferncesPage_Show_ChecklistPerspective);
107

    
108
        showChecklistPerspectiveButton.setSelection(isShowCheckListPerspective);
109
        showChecklistPerspectiveButton.addSelectionListener(new SelectionAdapter(){
110
             @Override
111
             public void widgetSelected(SelectionEvent e) {
112
                 isShowCheckListPerspective = showChecklistPerspectiveButton.getSelection();
113

    
114
              }
115
         });
116

    
117
        final Button showTaxonNodeWizardButton = new Button(composite, SWT.CHECK);
118

    
119
        showTaxonNodeWizardButton.setText(Messages.DatabasePreferncesPage_Show_TaxonNodeWizard);
120

    
121
        showTaxonNodeWizardButton.setSelection(isShowTaxonNodeWizard);
122
        showTaxonNodeWizardButton.addSelectionListener(new SelectionAdapter(){
123
             @Override
124
             public void widgetSelected(SelectionEvent e) {
125
                 isShowTaxonNodeWizard = showTaxonNodeWizardButton.getSelection();
126

    
127
              }
128
         });
129

    
130
        return composite;
131
    }
132

    
133
    @Override
134
    public void createControl(Composite parent){
135
        super.createControl(parent);
136
        getControl().setVisible(false);
137
    }
138

    
139
    @Override
140
    public boolean performOk() {
141
       //ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
142
       if (controller != null){
143
           IPreferenceService service = controller.getPreferenceService();
144

    
145
           CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowImportExportMenu, Boolean.toString(this.isShowIOMenu));
146
           pref.setAllowOverride(false);
147
           service.set(pref);
148
           pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowMediaView, Boolean.toString(this.isShowMediaView));
149
           pref.setAllowOverride(false);
150
           service.set(pref);
151
           pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowChecklistPerspective, Boolean.toString(this.isShowCheckListPerspective));
152
           pref.setAllowOverride(false);
153
           service.set(pref);
154
           pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.ShowTaxonNodeWizard, Boolean.toString(this.isShowTaxonNodeWizard));
155
           pref.setAllowOverride(false);
156
           service.set(pref);
157
           PreferencesUtil.updateDBPreferences();
158

    
159

    
160
       }
161
       return true;
162
   }
163

    
164
}
(5-5/12)