Project

General

Profile

Revision dea4cffc

IDdea4cffcc01f08168bcc2da108e6fe64149778ee
Parent 22be3a02
Child c9bb625e

Added by Katja Luther over 1 year ago

ref #8385: add allowOverride to AbcdProvider PreferencePage

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/databaseAdmin/preferencePage/AbcdImportProviderAdminPreferencePage.java
10 10

  
11 11
import org.apache.commons.lang.StringUtils;
12 12
import org.eclipse.swt.SWT;
13
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.GridData;
14 16
import org.eclipse.swt.layout.GridLayout;
15 17
import org.eclipse.swt.widgets.Composite;
16 18
import org.eclipse.swt.widgets.Control;
......
19 21
import eu.etaxonomy.cdm.api.service.IPreferenceService;
20 22
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
21 23
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
22
import eu.etaxonomy.taxeditor.l10n.Messages;
23 24
import eu.etaxonomy.taxeditor.preference.AbcdImportProvider;
24 25
import eu.etaxonomy.taxeditor.preference.ListComponent;
25 26
import eu.etaxonomy.taxeditor.store.CdmStore;
......
35 36

  
36 37
    @Override
37 38
    protected Control createContents(Composite parent) {
39
        isAdminPreference = true;
38 40
        final Composite composite = new Composite(parent, SWT.NULL);
39
        final CLabel description = new CLabel(composite, SWT.NULL);
40
        description.setText(Messages.AbcdImportProvider_description);
41

  
41 42
        GridLayout gridLayout = new GridLayout();
42 43
        composite.setLayout(gridLayout);
43 44

  
44
        gridLayout.numColumns = 3;
45
        gridLayout.numColumns = 2;
45 46
        //gridLayout.horizontalSpacing= 5;
46 47
        //gridLayout.makeColumnsEqualWidth = true;
47 48

  
48 49
        composite.setLayout(gridLayout);
49 50
        biocaseProviderList = new ListComponent(composite, SWT.SCROLL_LINE,true, this);
51
        allowOverride = createAllowOverrideButton(composite);
52
        GridData layoutData = (GridData) allowOverride.getLayoutData();
53
        layoutData.horizontalAlignment = SWT.LEFT;
54
        //layoutData.horizontalSpan = 2;
55

  
56
        allowOverride.setSelection(biocaseProviderList.getProviderListPreference() != null? biocaseProviderList.getProviderListPreference().isAllowOverride(): true);
57
        allowOverride.addSelectionListener(new SelectionAdapter() {
58
            @Override
59
            public void widgetSelected(SelectionEvent e) {
60
                setApply(true);
61
            }
62
        });
63

  
50 64
        setApply(true);
51 65
        return composite;
52 66
    }
......
58 72
            providerList = biocaseProviderList.createAllProviderString();
59 73

  
60 74
            CdmPreference pref = CdmPreference.NewTaxEditorInstance(PreferencePredicate.BioCaseProvider, providerList);
61
            pref.setAllowOverride(true);
75
            pref.setAllowOverride(allowOverride.getSelection());
62 76

  
63 77
            ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
64 78
            if (controller == null){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/Messages.java
671 671
    public static String Preference_Use_Default;
672 672

  
673 673

  
674
    public static String AbcdImportProvider_description_not_available;
675

  
676

  
674 677

  
675 678

  
676 679

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages.properties
374 374
AbcdImportPreference_allow_override_tooltip=Use local preference for ABCD import configurator.
375 375

  
376 376
AbcdImportProvider_description=Configure the default list of biocase provider for the specimen search
377
AbcdImportProvider_description_not_available=Local preferences are not allowed for biocase provider.\nIf you want to change the preference please contact an administrator.
377 378
AvailableAreaVocabulariesPage_PAGE_DESCRIPTION=Select vocabularies to select the available areas from.
378 379
AvailableAreaVocabulariesPage_PAGE_TITLE=Select Vocabularies for %s
379 380
AvailableDistributionPage_CHECK_MESSAGE=Please check at least one item
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/l10n/messages_de.properties
374 374
AbcdImportPreference_override_tooltip=Die lokale Pr?ferenzen f?r den ABCD Import Konfigurator sollen verwendet werden.
375 375

  
376 376
AbcdImportProvider_description=Konfiguration einer Liste von Biocase Providern f?r die Specimen Suche
377
AbcdImportProvider_description_not_available=Es d?rfen keine lokalen ?nderungen an den Biocase Providern vorgenommen werden.\nWenn Sie die Pr?ferenz dennoch ?ndern wollen, wenden Sie sich bitte an einen Administrator
377 378
AvailableAreaVocabulariesPage_PAGE_DESCRIPTION=Auswahl der Vokabulare, aus denen die Gebiete f?r %s ausgew?hlt werden sollen.
378 379
AvailableAreaVocabulariesPage_PAGE_TITLE=Vokabular f?r %s ausw?hlen
379 380
AvailableDistributionPage_CHECK_MESSAGE=Bitte w?hlen Sie mindestens einen Eintrag aus
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AbcdImportProvider.java
9 9
package eu.etaxonomy.taxeditor.preference;
10 10

  
11 11
import org.eclipse.swt.SWT;
12
import org.eclipse.swt.custom.CLabel;
13 12
import org.eclipse.swt.layout.GridLayout;
13
import org.eclipse.swt.widgets.Button;
14 14
import org.eclipse.swt.widgets.Composite;
15 15
import org.eclipse.swt.widgets.Control;
16 16

  
17 17
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
18
import eu.etaxonomy.taxeditor.l10n.Messages;
19 18
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
20 19

  
21 20
/**
......
26 25
public class AbcdImportProvider extends CdmPreferencePage implements IE4PreferencePage{
27 26

  
28 27
    protected ListComponent biocaseProviderList;
28
    protected Button allowOverride;
29 29

  
30 30
    @Override
31 31
    protected Control createContents(Composite parent) {
32 32
        final Composite composite = new Composite(parent, SWT.NULL);
33
        final CLabel description = new CLabel(composite, SWT.NULL);
34
        description.setText(Messages.AbcdImportProvider_description);
33

  
35 34
        GridLayout gridLayout = new GridLayout();
36 35
        composite.setLayout(gridLayout);
37 36

  
......
41 40

  
42 41
        composite.setLayout(gridLayout);
43 42
        biocaseProviderList = new ListComponent(composite, SWT.SCROLL_LINE,false, this);
43

  
44 44
        setApply(true);
45 45
        return composite;
46 46
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/DistributionStatusAndNamedAreaVocabularies.java
253 253

  
254 254
        commandHandlerString = "eu.etaxonomy.taxeditor.store.open.OpenDistributionEditorWizardHandler";
255 255
        commandHandlerStringStatus = "eu.etaxonomy.taxeditor.store.open.OpenDistributionStatusWizardHandler";
256
        setApply(true);
256
       // setApply(true);
257 257
    }
258 258

  
259 259
    /**
......
295 295
            }
296 296

  
297 297
        }
298

  
298 299
        prefStatus = null;
299 300
        prefAreaVoc = null;
300
        setApply(true);
301 301
        refresh();
302
        setApply(true);
303

  
302 304
    }
303 305

  
304 306
    @Override
......
306 308
        if (!isApply()){
307 309
            return true;
308 310
        }
309

  
311
        CdmPreferenceCache cache = CdmPreferenceCache.instance();
310 312
        if (prefStatus == null){
311
            List<CdmPreference> prefsToDelete =PreferencesUtil.getPreference(PreferencePredicate.AvailableDistributionStatus);
313
            List<CdmPreference> prefsToDelete =cache.getAllForPredicate(PreferencePredicate.AvailableDistributionStatus.getKey());
312 314
            PreferencesUtil.removeFromDB(prefsToDelete);
313 315
        }
314 316
        if (prefAreaVoc == null){
315
            List<CdmPreference> prefsToDelete =PreferencesUtil.getPreference(PreferencePredicate.AvailableDistributionAreaVocabularies);
317
            List<CdmPreference> prefsToDelete =cache.getAllForPredicate(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
316 318
            PreferencesUtil.removeFromDB(prefsToDelete);
317 319
        }
318 320
        List<CdmPreference> toDelete = new ArrayList<>();
......
332 334
    @Optional
333 335
    public void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_DATASOURCE)boolean refresh){
334 336
        if(refresh){
337
            getValues();
335 338
            refresh();
336 339
        }
337 340
    }
......
342 345
        if (event != null
343 346
                && PreferencesUtil.PREFERRED_TERMS_CHANGE.equals(event
344 347
                        .getProperty())) {
348
            getValues();
345 349
            refresh();
346 350
        }
347 351
    }
......
350 354
     *
351 355
     */
352 356
    private void refresh() {
353
        getValues();
357
        //getValues();
354 358
        table.removeAll();
355
        Iterator<CdmPreference> prefIterator = prefStatus.iterator();
356
        CdmPreference pref;
357
        while (prefIterator.hasNext()){
358
            pref = prefIterator.next();
359
            createTableRow(pref);
359
        if (prefStatus != null){
360
            Iterator<CdmPreference> prefIterator = prefStatus.iterator();
361
            CdmPreference pref;
362
            while (prefIterator.hasNext()){
363
                pref = prefIterator.next();
364
                createTableRow(pref);
360 365

  
366
            }
361 367
        }
362 368
        table.redraw();
363 369
        table.pack();
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ListComponent.java
17 17
import org.apache.commons.lang.StringUtils;
18 18
import org.eclipse.jface.resource.JFaceResources;
19 19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.custom.CLabel;
20 21
import org.eclipse.swt.events.ModifyEvent;
21 22
import org.eclipse.swt.events.ModifyListener;
22 23
import org.eclipse.swt.events.MouseEvent;
......
48 49
    private static final String addString = Messages.ListComponent_ADD_PROVIDER;
49 50
    private static final String removeString = Messages.ListComponent_REMOVE_PROVIDER;
50 51
    private static final String noProvider = Messages.ListComponent_NO_PROVIDER_AVAILABLE;
52
    private static final String serverSidePreference = "Server Side Preference:";
51 53
    private Button removeButton;
52 54
    private Text providerURI;
53 55
    protected Label labelException;
54 56
    boolean isAdmin = false;
55 57
    CdmPreferencePage preferencePage;
58
    CdmPreference providerListPreference;
59

  
60

  
61
    public CdmPreference getProviderListPreference() {
62
        return providerListPreference;
63
    }
64

  
65

  
66
    public void setProviderListPreference(CdmPreference providerListPreference) {
67
        this.providerListPreference = providerListPreference;
68
    }
56 69

  
57 70

  
58 71
    public ListComponent(Composite parent, int style, boolean isAdmin, CdmPreferencePage parentPage) {
59 72
        this.isAdmin= isAdmin;
60 73
        this.preferencePage = parentPage;
74
        providerListPreference = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.BioCaseProvider);
75
        if (!isAdmin && !providerListPreference.isAllowOverride()){
76
            Label editingNotAllowed = new Label(parent, style);
77
            editingNotAllowed.setText(Messages.AbcdImportProvider_description_not_available);
78
            return ;
79
        }
80
        final CLabel description = new CLabel(parent, SWT.NULL);
81
        description.setText(Messages.AbcdImportProvider_description);
61 82
        list = new List(parent, SWT.BORDER |  SWT.V_SCROLL);
62 83
        GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 3);
63 84
        gridData.grabExcessHorizontalSpace = true;
......
66 87
        Rectangle clientArea = parent.getShell().getClientArea ();
67 88
        list.setBounds (clientArea.x, clientArea.y, 50, 500);
68 89

  
69
        CdmPreference providerListPreference = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.BioCaseProvider);
90

  
70 91
        String allProviderString = ""; //$NON-NLS-1$
92
        String allProviderStringDB = "";
93

  
71 94
        if (!isAdmin && (providerListPreference != null && providerListPreference.isAllowOverride())){
72 95
            allProviderString = PreferencesUtil.getStringValue(PreferencePredicate.BioCaseProvider.getKey(), true);
96

  
73 97
        }else{
74 98
            if (providerListPreference != null){
75 99
                allProviderString  = providerListPreference.getValue();
76 100
            }
77 101
        }
78
//         = PreferencesUtil.getPreferenceStore().getString(IPreferenceKeys.BIOCASE_PROVIDER_LIST);
102

  
79 103
        //the string is structured like this: http://ww3.bgbm.org/biocase/pywrapper.cgi?dsa=DNA_Bank;http:...;
80 104
        String[] providerArray = allProviderString.split(";"); //$NON-NLS-1$
81 105
        for (String providerString : providerArray){
82 106
            if (!StringUtils.isBlank(providerString)){
83 107
                list.add(providerString);
108

  
84 109
            }
85 110
        }
111

  
86 112
        if (list.getItemCount() == 0){
87 113
            list.add(noProvider);
88 114
        }
......
137 163
            //there's a valid selection
138 164
            //so go ahead and remove whatever's selected.
139 165
            int index = list.getSelectionIndex();
166
            String item = list.getItem(index);
167
            if (item.equals(serverSidePreference)) {
168
                return;
169
            }
140 170
            list.remove(index);
141 171

  
172

  
142 173
            int size = list.getItemCount();
143 174

  
144 175
            if (size == 0) { //Nothing's left, disable removing.
......
269 300
        String allProviderString = null;
270 301
        boolean first = true;
271 302
        for (String item: list.getItems()){
272
            if (item.equals(noProvider)){
303
            if (item.equals(noProvider) || item.equals(serverSidePreference)){
273 304
                //do nothing
274 305
            }else if (first || allProviderString == null || allProviderString == ""){ //$NON-NLS-1$
275 306
                allProviderString = item.trim();

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)