Project

General

Profile

« Previous | Next » 

Revision bcad19b9

Added by Cherian Mathew over 9 years ago

MessagingUtils : added new method for a warning dialog when not connected to a datasource
CdmStore : changed warning dialog to new method mentioned above
LanguagePreferencePage, PreferencesUtil, AbstractMenuPreferences : checks to fail nicely if not connected to a datasoruce

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java
490 490
        MessagingUtils.warningDialog(title, source, status.getMessage());
491 491
    }
492 492

  
493
    /**
494
     * Standard warning dialog for the case when the application is not yet connected to the datasource
495
     *
496
     * @param source
497
     */
498
    public static void noDataSourceWarningDialog(Object source) {
499
        MessagingUtils
500
        .warningDialog(
501
                "Application is not connected to a datastore",
502
                source,
503
                "The requested operation is only available when "
504
                + "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
505
    }
506

  
493 507
    /**
494 508
     * Displays a warning {@link org.eclipse.jface.dialogs.MessageDialog}.
495 509
     *
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/LanguagePreferencePage.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
39 39

  
40 40
	private boolean isMultilanguageTextEditingCapability;
41 41
	private Language globalLanguage;
42
	
42

  
43 43
	private Composite createComposite(Composite parent){
44 44
		Composite composite = new Composite(parent, SWT.NULL);
45 45
		composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
46 46
		composite.setLayout(new RowLayout(SWT.HORIZONTAL));
47 47
		return composite;
48 48
	}
49
	
49

  
50 50
	/* (non-Javadoc)
51 51
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
52 52
	 */
......
55 55
		Composite container = new Composite(parent, SWT.NULL);
56 56
		final GridLayout gridLayout = new GridLayout();
57 57
		container.setLayout(gridLayout);
58
		
58

  
59 59
		createSetDefaultLanguage(container);
60
		
60

  
61 61
		createSetMultiLanguageTextEditingCapability(container);
62
				
62

  
63 63
		return container;
64
		
65
		
64

  
65

  
66 66
	}
67 67

  
68 68
	/**
......
70 70
	 */
71 71
	private void createSetDefaultLanguage(Composite parent) {
72 72
		globalLanguage = PreferencesUtil.getGlobalLanguage();
73
		
73

  
74
		if(globalLanguage == null) {
75
		    return;
76
		}
77

  
74 78
		int curentSelectionIndex = 0;
75
		
79

  
76 80
		final Composite composite = createComposite(parent);
77 81
		composite.setLayout(new RowLayout(1));
78
		
82

  
79 83
		final Label label = new Label(composite, SWT.NONE);
80 84
		label.setText("Choose the global language that will be used throughout the editor to get representations in.");
81
		
82
		final Combo combo_globalLanguage = new Combo(composite, SWT.NONE); 
83
		
85

  
86
		final Combo combo_globalLanguage = new Combo(composite, SWT.NONE);
87

  
84 88
		List<Language> preferredLanguages = CdmStore.getTermManager().getPreferredTerms(Language.class);
85
		
89

  
86 90
		for(int i = 0; i < preferredLanguages.size(); i++){
87 91
			Language language = preferredLanguages.get(i);
88 92
			combo_globalLanguage.add(language.getLabel(), i);
......
90 94
				curentSelectionIndex = i;
91 95
			}
92 96
		}
93
		
97

  
94 98
		combo_globalLanguage.select(curentSelectionIndex);
95
		
99

  
96 100
		combo_globalLanguage.addSelectionListener(new SelectionAdapter() {
97 101
			/* (non-Javadoc)
98 102
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
......
102 106
				int selectionIndex = combo_globalLanguage.getSelectionIndex();
103 107
				globalLanguage = Language.getLanguageByLabel(combo_globalLanguage.getItem(selectionIndex));
104 108
			}
105
		});		
109
		});
106 110
	}
107 111

  
108 112
	/**
109
	 * 
113
	 *
110 114
	 */
111 115
	private void createSetMultiLanguageTextEditingCapability(Composite parent) {
112 116
		isMultilanguageTextEditingCapability = getPreferenceStore().getBoolean(IPreferenceKeys.MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
113
		
117

  
114 118
		final Composite composite = createComposite(parent);
115
		
116
		final Button button_toggle = new Button(composite, SWT.CHECK);		
117
		
118
		
119

  
120
		final Button button_toggle = new Button(composite, SWT.CHECK);
121

  
122

  
119 123
		button_toggle.setText("Enable Multiple Language Editing Capability");
120
		
124

  
121 125
		button_toggle.setSelection(isMultilanguageTextEditingCapability);
122
		
123
		
126

  
127

  
124 128
		button_toggle.addSelectionListener(new SelectionAdapter(){
125 129
			/* (non-Javadoc)
126 130
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
......
147 151
	public boolean performOk() {
148 152
		getPreferenceStore().setValue(IPreferenceKeys.MULTILANGUAGE_TEXT_EDITING_CAPABILITY, isMultilanguageTextEditingCapability);
149 153
		PreferencesUtil.setGlobalLanguage(globalLanguage);
150
		
154

  
151 155
		return super.performOk();
152 156
	}
153 157
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
523 523
	}
524 524

  
525 525
	public static Language getGlobalLanguage() {
526

  
527

  
526 528
		String languageUuidString = getPreferenceStore().getString(
527 529
				GLOBAL_LANGUAGE_UUID);
528 530

  
531
		if(!CdmStore.isActive()) {
532
            MessagingUtils.noDataSourceWarningDialog(languageUuidString);
533
            return null;
534
        }
535

  
529 536
		if (CdmUtils.isBlank(languageUuidString)) {
530 537
			return Language.getDefaultLanguage();
531 538
		}
......
536 543
	}
537 544

  
538 545
	public static void setGlobalLanguage(Language language) {
539
		getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID,
540
				language.getUuid().toString());
541
		CdmStore.setDefaultLanguage(language);
546
	    if(language != null) {
547
	        getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
548
	        CdmStore.setDefaultLanguage(language);
549
	    }
550

  
542 551
	}
543 552

  
544 553
	/**
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/AbstractMenuPreferences.java
95 95
	}
96 96

  
97 97
	protected List<T> getTerms(){
98
		return TermStore.getTerms(getTermClass());
98
	    if(!CdmStore.isActive()) {
99
	        return new ArrayList<T>();
100
	    } else {
101
	        return TermStore.getTerms(getTermClass());
102
	    }
99 103
	}
100 104

  
101 105
	/**
......
274 278
	/** {@inheritDoc} */
275 279
	@Override
276 280
    public void init(IWorkbench workbench) {
277
		setPreferenceStore(PreferencesUtil.getPreferenceStore());
278
		getConversationHolder().bind();
281
	    setPreferenceStore(PreferencesUtil.getPreferenceStore());
282
	    if(!CdmStore.isActive()) {
283
	        MessagingUtils.noDataSourceWarningDialog(null);
284

  
285
	    } else {
286
	        getConversationHolder().bind();
287
	    }
279 288
	}
280 289

  
281 290
	/*
......
305 314
	/** {@inheritDoc} */
306 315
	@Override
307 316
	public boolean performOk() {
317
	    if(!CdmStore.isActive()) {
318
	        return true;
319
	    }
320

  
308 321
		if(checkNoneChecked()){
309 322
			return false;
310 323
		}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java
99 99
			return instance;
100 100
		} else{// if (instance == null || !instance.isConnected) {
101 101

  
102
			MessagingUtils
103
					.warningDialog(
104
							"Application is not connected to a datastore",
105
							instance,
106
							"The requested operation is only available when "
107
							+ "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
102
			MessagingUtils.noDataSourceWarningDialog(instance);
108 103

  
109 104
			AbstractUtility.showView(CdmDataSourceViewPart.ID);
110 105
			return null;

Also available in: Unified diff