Project

General

Profile

Revision a60ccec4

IDa60ccec498f4cd80c13842a4546a00950edb5645
Parent f9840e06
Child 0ae3531b

Added by Katja Luther about 1 year ago

ref #8385: enable apply button when provider added or removed from preference

View differences:

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

  
11 11
import org.apache.commons.lang.StringUtils;
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.custom.CLabel;
14
import org.eclipse.swt.layout.GridLayout;
12 15
import org.eclipse.swt.widgets.Composite;
13 16
import org.eclipse.swt.widgets.Control;
14 17

  
......
16 19
import eu.etaxonomy.cdm.api.service.IPreferenceService;
17 20
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
18 21
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
22
import eu.etaxonomy.taxeditor.l10n.Messages;
19 23
import eu.etaxonomy.taxeditor.preference.AbcdImportProvider;
20 24
import eu.etaxonomy.taxeditor.preference.ListComponent;
21 25
import eu.etaxonomy.taxeditor.store.CdmStore;
......
27 31
 */
28 32
public class AbcdImportProviderAdminPreferencePage extends AbcdImportProvider implements IE4AdminPreferencePage{
29 33

  
30
    private ListComponent biocaseProviderList;
34

  
31 35

  
32 36
    @Override
33 37
    protected Control createContents(Composite parent) {
34
        Control composite = super.createContents(parent);
35
        biocaseProviderList.setAdmin(true);
38
        final Composite composite = new Composite(parent, SWT.NULL);
39
        final CLabel description = new CLabel(composite, SWT.NULL);
40
        description.setText(Messages.AbcdImportProvider_description);
41
        GridLayout gridLayout = new GridLayout();
42
        composite.setLayout(gridLayout);
43

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

  
48
        composite.setLayout(gridLayout);
49
        biocaseProviderList = new ListComponent(composite, SWT.SCROLL_LINE,true, this);
36 50
        setApply(true);
37 51
        return composite;
38 52
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/AbcdImportProvider.java
25 25
 */
26 26
public class AbcdImportProvider extends CdmPreferencePage implements IE4PreferencePage{
27 27

  
28
    private ListComponent biocaseProviderList;
28
    protected ListComponent biocaseProviderList;
29 29

  
30 30
    @Override
31 31
    protected Control createContents(Composite parent) {
......
40 40
        //gridLayout.makeColumnsEqualWidth = true;
41 41

  
42 42
        composite.setLayout(gridLayout);
43
        biocaseProviderList = new ListComponent(composite, SWT.SCROLL_LINE,false);
43
        biocaseProviderList = new ListComponent(composite, SWT.SCROLL_LINE,false, this);
44 44
        setApply(true);
45 45
        return composite;
46 46
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/ListComponent.java
10 10

  
11 11

  
12 12
import java.awt.Toolkit;
13
import java.net.URL;
13 14

  
14 15
import javax.swing.event.DocumentEvent;
15 16

  
16 17
import org.apache.commons.lang.StringUtils;
18
import org.eclipse.jface.resource.JFaceResources;
17 19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.events.ModifyEvent;
21
import org.eclipse.swt.events.ModifyListener;
18 22
import org.eclipse.swt.events.MouseEvent;
19 23
import org.eclipse.swt.events.MouseListener;
20 24
import org.eclipse.swt.graphics.Rectangle;
21 25
import org.eclipse.swt.layout.GridData;
22 26
import org.eclipse.swt.widgets.Button;
23 27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Display;
29
import org.eclipse.swt.widgets.Label;
24 30
import org.eclipse.swt.widgets.List;
25 31
import org.eclipse.swt.widgets.Text;
26 32

  
27 33
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
28 34
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
29 35
import eu.etaxonomy.taxeditor.l10n.Messages;
36
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
30 37

  
31 38

  
32 39
/**
......
34 41
 * @date 20.04.2017
35 42
 *
36 43
 */
37
public class ListComponent
44
public class ListComponent implements ModifyListener
38 45
                      {
39 46
    private List list;
40 47

  
......
43 50
    private static final String noProvider = Messages.ListComponent_NO_PROVIDER_AVAILABLE;
44 51
    private Button removeButton;
45 52
    private Text providerURI;
53
    protected Label labelException;
46 54
    boolean isAdmin = false;
55
    CdmPreferencePage preferencePage;
47 56

  
48 57

  
49
    public ListComponent(Composite parent, int style, boolean isAdmin) {
58
    public ListComponent(Composite parent, int style, boolean isAdmin, CdmPreferencePage parentPage) {
50 59
        this.isAdmin= isAdmin;
60
        this.preferencePage = parentPage;
51 61
        list = new List(parent, SWT.BORDER |  SWT.V_SCROLL);
52 62
        GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, true, 2, 3);
53 63
        gridData.grabExcessHorizontalSpace = true;
......
58 68

  
59 69
        CdmPreference providerListPreference = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.BioCaseProvider);
60 70
        String allProviderString = ""; //$NON-NLS-1$
61
        if (!isAdmin && providerListPreference.isAllowOverride()){
71
        if (!isAdmin && (providerListPreference != null && providerListPreference.isAllowOverride())){
62 72
            allProviderString = PreferencesUtil.getStringValue(PreferencePredicate.BioCaseProvider.getKey(), true);
63 73
        }else{
64 74
            if (providerListPreference != null){
......
94 104
        dataProviderUri.horizontalAlignment = GridData.FILL;
95 105
        dataProviderUri.horizontalSpan = 3;
96 106
        providerURI.setLayoutData(dataProviderUri);
107
        providerURI.addModifyListener(this);
108
        labelException = new Label(parent, SWT.NULL);
109
        labelException.setText("");
110

  
111

  
112
        labelException.setLayoutData(dataProviderUri);
97 113

  
98 114
        Button addButton = new Button(parent, SWT.NULL);
99 115
        AddListener addListener = new AddListener(addButton);
......
135 151
                }
136 152

  
137 153
                list.setSelection(index-1);
138

  
154
                preferencePage.setApply(true);
139 155

  
140 156
            }
141 157
        }
......
217 233
            String name = providerURI.getText();
218 234

  
219 235
            //User didn't type in a unique name...
220
            if (name.equals("") || alreadyInList(name)) { //$NON-NLS-1$
236
            if (name.equals("") || alreadyInList(name) || !StringUtils.isBlank(labelException.getText())) { //$NON-NLS-1$
221 237
                Toolkit.getDefaultToolkit().beep();
222 238
                providerURI.selectAll();
223 239
                return;
......
245 261
            //Select the new item
246 262

  
247 263
            providerURI.setText(""); //$NON-NLS-1$
248

  
264
            preferencePage.setApply(true);
249 265
        }
250 266
    }
251 267

  
......
268 284
    }
269 285

  
270 286

  
287
    @Override
288
    public void modifyText(ModifyEvent e) {
289
        if(e.widget==providerURI){
290
            Text text = (Text) e.widget;
291
            boolean hasControlCharacters = false;
292
            String textString = text.getText();
293
            int stringLength = textString.length();
294
            for (int i = 0; i < stringLength; i++) {
295
                if (Character.isISOControl(textString.charAt(i))) {
296
                    hasControlCharacters = true;
297
                    break;
298
                }
299
            }
300

  
301
                //remove control character such as line breaks etc.
302
                try {
303
                    getParsedText();
304
                    labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
305
                    labelException.setForeground(Display.getCurrent().getSystemColor(SWT.NULL));
306
                    labelException.setText("");
307
                } catch (Exception exception) {
308
                    labelException.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
309
                    labelException.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
310
                    labelException.setText(Messages.UriWithLabelElement_URL_NOT_SAVED+exception.getLocalizedMessage());
311
                }
312
            }
313

  
314

  
315
    }
316

  
317

  
318
    protected URL getParsedText() throws Exception {
319
        String uriText = providerURI.getText();
320
        if(!StringUtils.isBlank(uriText)){
321
            return new URL(providerURI.getText());
322
        }
323
        return null;
324
    }
325

  
326

  
271 327

  
272 328
}
273 329

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)