Project

General

Profile

Download (4.89 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.custom.CLabel;
13
import org.eclipse.swt.events.SelectionAdapter;
14
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Button;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.swt.widgets.Control;
19

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

    
29
/**
30
 * @author k.luther
31
 * @since 23.03.2018
32
 *
33
 */
34
public class PublishFlagPreference extends CdmPreferencePage implements IE4AdminPreferencePage{
35

    
36
   boolean setPublish;
37
   boolean setNotPublish;
38
   boolean inheritFromParent;
39

    
40
   String do_not_publish = "DO NOT PUBLISH";
41
   String inherit_from_parent = "PARENT";
42
   String publish = "PUBLISH";
43

    
44
   @Override
45
   public void init() {
46
       super.init();
47
       CdmPreference pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DefaultBehaviourForPublishFlag);
48
       if (pref != null){
49
           if (pref.getValue().equals(do_not_publish)){
50
               setNotPublish = true;
51
               setPublish = false;
52
               inheritFromParent = false;
53
           }
54

    
55
           if (pref.getValue().equals(inherit_from_parent)){
56
               setNotPublish = false;
57
               setPublish = false;
58
               inheritFromParent = true;
59
           }
60

    
61
           if (pref.getValue().equals(publish)){
62
               setNotPublish = false;
63
               setPublish = true;
64
               inheritFromParent = false;
65
           }
66
       }else{
67
           setNotPublish = false;
68
           setPublish = true;
69
           inheritFromParent = false;
70
       }
71

    
72
   }
73
    /**
74
     * {@inheritDoc}
75
     */
76
    @Override
77
    protected Control createContents(Composite parent) {
78
        final Composite composite = new Composite(parent, SWT.NULL);
79

    
80
        GridLayout gridLayout = new GridLayout();
81
        composite.setLayout(gridLayout);
82
        final CLabel description = new CLabel(composite, SWT.NULL);
83
        description.setText(Messages.PublishFlagPreference_description);
84
        gridLayout.numColumns = 1;
85
        gridLayout.horizontalSpacing= 10;
86
        gridLayout.makeColumnsEqualWidth = true;
87

    
88
        Button setPublishFlagAsDefault = new Button(composite, SWT.RADIO);
89
        setPublishFlagAsDefault.setText(Messages.PublishFlagPreference_set);
90
        setPublishFlagAsDefault.setSelection(setPublish);
91
        setPublishFlagAsDefault.addSelectionListener(new SelectionAdapter() {
92
            @Override
93
            public void widgetSelected(SelectionEvent e) {
94
               setPublish = !setPublish;
95
            }
96
        });
97
        Button setNotPublishFlagAsDefault = new Button(composite, SWT.RADIO);
98
        setNotPublishFlagAsDefault.setText(Messages.PublishFlagPreference_do_not_set);
99
        setNotPublishFlagAsDefault.setSelection(setNotPublish);
100
        setNotPublishFlagAsDefault.addSelectionListener(new SelectionAdapter() {
101
            @Override
102
            public void widgetSelected(SelectionEvent e) {
103
                setNotPublish = !setNotPublish;
104
            }
105
        });
106

    
107
        Button setInheritFromParent = new Button(composite, SWT.RADIO);
108
        setInheritFromParent.setText(Messages.PublishFlagPreference_inherit);
109
        setInheritFromParent.setSelection(inheritFromParent);
110
        setInheritFromParent.addSelectionListener(new SelectionAdapter() {
111
            @Override
112
            public void widgetSelected(SelectionEvent e) {
113
                inheritFromParent = !inheritFromParent;
114
            }
115
        });
116

    
117
        return composite;
118

    
119
    }
120

    
121

    
122
    @Override
123
    public boolean performOk() {
124
        String preferenceValue = null;
125
        if (setPublish){
126
            preferenceValue = publish;
127
        }else if (setNotPublish){
128
            preferenceValue = do_not_publish;
129
        } else{
130
            preferenceValue = inherit_from_parent;
131
        }
132
        CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.DefaultBehaviourForPublishFlag, preferenceValue);
133
        pref.setAllowOverride(true);
134

    
135
        ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
136
        if (controller == null){
137
            return false;
138
        }
139
        IPreferenceService service = controller.getPreferenceService();
140
        service.set(pref);
141

    
142
        return true;
143
    }
144

    
145

    
146

    
147

    
148
}
(9-9/10)