MessagingUtils : added new method for a warning dialog when not connected to a datas...
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 9 Dec 2014 15:33:02 +0000 (15:33 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 9 Dec 2014 15:33:02 +0000 (15:33 +0000)
CdmStore : changed warning dialog to new method mentioned above
LanguagePreferencePage, PreferencesUtil, AbstractMenuPreferences : checks to fail nicely if not connected to a datasoruce

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/MessagingUtils.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/LanguagePreferencePage.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/AbstractMenuPreferences.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java

index e9033c3925ca875a46b6840bd22b1ebcd6482f8a..e44ad8f82ec17ebc7152a31cf7070174096f8df1 100644 (file)
@@ -490,6 +490,20 @@ public class MessagingUtils {
         MessagingUtils.warningDialog(title, source, status.getMessage());
     }
 
         MessagingUtils.warningDialog(title, source, status.getMessage());
     }
 
+    /**
+     * Standard warning dialog for the case when the application is not yet connected to the datasource
+     *
+     * @param source
+     */
+    public static void noDataSourceWarningDialog(Object source) {
+        MessagingUtils
+        .warningDialog(
+                "Application is not connected to a datastore",
+                source,
+                "The requested operation is only available when "
+                + "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
+    }
+
     /**
      * Displays a warning {@link org.eclipse.jface.dialogs.MessageDialog}.
      *
     /**
      * Displays a warning {@link org.eclipse.jface.dialogs.MessageDialog}.
      *
index e1a6b959c7b3b4c3ac3071c24029aa81900c0f59..b816fd4956165bfa33a117209acc581b45f8ba25 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -39,14 +39,14 @@ public class LanguagePreferencePage extends PreferencePage implements IWorkbench
 
        private boolean isMultilanguageTextEditingCapability;
        private Language globalLanguage;
 
        private boolean isMultilanguageTextEditingCapability;
        private Language globalLanguage;
-       
+
        private Composite createComposite(Composite parent){
                Composite composite = new Composite(parent, SWT.NULL);
                composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
                composite.setLayout(new RowLayout(SWT.HORIZONTAL));
                return composite;
        }
        private Composite createComposite(Composite parent){
                Composite composite = new Composite(parent, SWT.NULL);
                composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
                composite.setLayout(new RowLayout(SWT.HORIZONTAL));
                return composite;
        }
-       
+
        /* (non-Javadoc)
         * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
         */
        /* (non-Javadoc)
         * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
         */
@@ -55,14 +55,14 @@ public class LanguagePreferencePage extends PreferencePage implements IWorkbench
                Composite container = new Composite(parent, SWT.NULL);
                final GridLayout gridLayout = new GridLayout();
                container.setLayout(gridLayout);
                Composite container = new Composite(parent, SWT.NULL);
                final GridLayout gridLayout = new GridLayout();
                container.setLayout(gridLayout);
-               
+
                createSetDefaultLanguage(container);
                createSetDefaultLanguage(container);
-               
+
                createSetMultiLanguageTextEditingCapability(container);
                createSetMultiLanguageTextEditingCapability(container);
-                               
+
                return container;
                return container;
-               
-               
+
+
        }
 
        /**
        }
 
        /**
@@ -70,19 +70,23 @@ public class LanguagePreferencePage extends PreferencePage implements IWorkbench
         */
        private void createSetDefaultLanguage(Composite parent) {
                globalLanguage = PreferencesUtil.getGlobalLanguage();
         */
        private void createSetDefaultLanguage(Composite parent) {
                globalLanguage = PreferencesUtil.getGlobalLanguage();
-               
+
+               if(globalLanguage == null) {
+                   return;
+               }
+
                int curentSelectionIndex = 0;
                int curentSelectionIndex = 0;
-               
+
                final Composite composite = createComposite(parent);
                composite.setLayout(new RowLayout(1));
                final Composite composite = createComposite(parent);
                composite.setLayout(new RowLayout(1));
-               
+
                final Label label = new Label(composite, SWT.NONE);
                label.setText("Choose the global language that will be used throughout the editor to get representations in.");
                final Label label = new Label(composite, SWT.NONE);
                label.setText("Choose the global language that will be used throughout the editor to get representations in.");
-               
-               final Combo combo_globalLanguage = new Combo(composite, SWT.NONE); 
-               
+
+               final Combo combo_globalLanguage = new Combo(composite, SWT.NONE);
+
                List<Language> preferredLanguages = CdmStore.getTermManager().getPreferredTerms(Language.class);
                List<Language> preferredLanguages = CdmStore.getTermManager().getPreferredTerms(Language.class);
-               
+
                for(int i = 0; i < preferredLanguages.size(); i++){
                        Language language = preferredLanguages.get(i);
                        combo_globalLanguage.add(language.getLabel(), i);
                for(int i = 0; i < preferredLanguages.size(); i++){
                        Language language = preferredLanguages.get(i);
                        combo_globalLanguage.add(language.getLabel(), i);
@@ -90,9 +94,9 @@ public class LanguagePreferencePage extends PreferencePage implements IWorkbench
                                curentSelectionIndex = i;
                        }
                }
                                curentSelectionIndex = i;
                        }
                }
-               
+
                combo_globalLanguage.select(curentSelectionIndex);
                combo_globalLanguage.select(curentSelectionIndex);
-               
+
                combo_globalLanguage.addSelectionListener(new SelectionAdapter() {
                        /* (non-Javadoc)
                         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                combo_globalLanguage.addSelectionListener(new SelectionAdapter() {
                        /* (non-Javadoc)
                         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
@@ -102,25 +106,25 @@ public class LanguagePreferencePage extends PreferencePage implements IWorkbench
                                int selectionIndex = combo_globalLanguage.getSelectionIndex();
                                globalLanguage = Language.getLanguageByLabel(combo_globalLanguage.getItem(selectionIndex));
                        }
                                int selectionIndex = combo_globalLanguage.getSelectionIndex();
                                globalLanguage = Language.getLanguageByLabel(combo_globalLanguage.getItem(selectionIndex));
                        }
-               });             
+               });
        }
 
        /**
        }
 
        /**
-        * 
+        *
         */
        private void createSetMultiLanguageTextEditingCapability(Composite parent) {
                isMultilanguageTextEditingCapability = getPreferenceStore().getBoolean(IPreferenceKeys.MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
         */
        private void createSetMultiLanguageTextEditingCapability(Composite parent) {
                isMultilanguageTextEditingCapability = getPreferenceStore().getBoolean(IPreferenceKeys.MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
-               
+
                final Composite composite = createComposite(parent);
                final Composite composite = createComposite(parent);
-               
-               final Button button_toggle = new Button(composite, SWT.CHECK);          
-               
-               
+
+               final Button button_toggle = new Button(composite, SWT.CHECK);
+
+
                button_toggle.setText("Enable Multiple Language Editing Capability");
                button_toggle.setText("Enable Multiple Language Editing Capability");
-               
+
                button_toggle.setSelection(isMultilanguageTextEditingCapability);
                button_toggle.setSelection(isMultilanguageTextEditingCapability);
-               
-               
+
+
                button_toggle.addSelectionListener(new SelectionAdapter(){
                        /* (non-Javadoc)
                         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                button_toggle.addSelectionListener(new SelectionAdapter(){
                        /* (non-Javadoc)
                         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
@@ -147,7 +151,7 @@ public class LanguagePreferencePage extends PreferencePage implements IWorkbench
        public boolean performOk() {
                getPreferenceStore().setValue(IPreferenceKeys.MULTILANGUAGE_TEXT_EDITING_CAPABILITY, isMultilanguageTextEditingCapability);
                PreferencesUtil.setGlobalLanguage(globalLanguage);
        public boolean performOk() {
                getPreferenceStore().setValue(IPreferenceKeys.MULTILANGUAGE_TEXT_EDITING_CAPABILITY, isMultilanguageTextEditingCapability);
                PreferencesUtil.setGlobalLanguage(globalLanguage);
-               
+
                return super.performOk();
        }
 }
                return super.performOk();
        }
 }
index 484a133579ee30ddfa7fe9602f0cc232ceb9c900..17d5f913db3a662567d649f08fa66069198ee87e 100644 (file)
@@ -523,9 +523,16 @@ public class PreferencesUtil implements IPreferenceKeys {
        }
 
        public static Language getGlobalLanguage() {
        }
 
        public static Language getGlobalLanguage() {
+
+
                String languageUuidString = getPreferenceStore().getString(
                                GLOBAL_LANGUAGE_UUID);
 
                String languageUuidString = getPreferenceStore().getString(
                                GLOBAL_LANGUAGE_UUID);
 
+               if(!CdmStore.isActive()) {
+            MessagingUtils.noDataSourceWarningDialog(languageUuidString);
+            return null;
+        }
+
                if (CdmUtils.isBlank(languageUuidString)) {
                        return Language.getDefaultLanguage();
                }
                if (CdmUtils.isBlank(languageUuidString)) {
                        return Language.getDefaultLanguage();
                }
@@ -536,9 +543,11 @@ public class PreferencesUtil implements IPreferenceKeys {
        }
 
        public static void setGlobalLanguage(Language language) {
        }
 
        public static void setGlobalLanguage(Language language) {
-               getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID,
-                               language.getUuid().toString());
-               CdmStore.setDefaultLanguage(language);
+           if(language != null) {
+               getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID,language.getUuid().toString());
+               CdmStore.setDefaultLanguage(language);
+           }
+
        }
 
        /**
        }
 
        /**
index c8a7fc5b2fd1cfe72070784482bc38c0b2756e31..e98123ac9d339b34739187da3747f00aaf9c963a 100644 (file)
@@ -95,7 +95,11 @@ public abstract class AbstractMenuPreferences<T extends DefinedTermBase> extends
        }
 
        protected List<T> getTerms(){
        }
 
        protected List<T> getTerms(){
-               return TermStore.getTerms(getTermClass());
+           if(!CdmStore.isActive()) {
+               return new ArrayList<T>();
+           } else {
+               return TermStore.getTerms(getTermClass());
+           }
        }
 
        /**
        }
 
        /**
@@ -274,8 +278,13 @@ public abstract class AbstractMenuPreferences<T extends DefinedTermBase> extends
        /** {@inheritDoc} */
        @Override
     public void init(IWorkbench workbench) {
        /** {@inheritDoc} */
        @Override
     public void init(IWorkbench workbench) {
-               setPreferenceStore(PreferencesUtil.getPreferenceStore());
-               getConversationHolder().bind();
+           setPreferenceStore(PreferencesUtil.getPreferenceStore());
+           if(!CdmStore.isActive()) {
+               MessagingUtils.noDataSourceWarningDialog(null);
+
+           } else {
+               getConversationHolder().bind();
+           }
        }
 
        /*
        }
 
        /*
@@ -305,6 +314,10 @@ public abstract class AbstractMenuPreferences<T extends DefinedTermBase> extends
        /** {@inheritDoc} */
        @Override
        public boolean performOk() {
        /** {@inheritDoc} */
        @Override
        public boolean performOk() {
+           if(!CdmStore.isActive()) {
+               return true;
+           }
+
                if(checkNoneChecked()){
                        return false;
                }
                if(checkNoneChecked()){
                        return false;
                }
index 8b151109d24e2cf12f5d26087a06c041ea6319ae..f6b224dfcdd64a69149303684001fb1937b22f60 100644 (file)
@@ -99,12 +99,7 @@ public class CdmStore {
                        return instance;
                } else{// if (instance == null || !instance.isConnected) {
 
                        return instance;
                } else{// if (instance == null || !instance.isConnected) {
 
-                       MessagingUtils
-                                       .warningDialog(
-                                                       "Application is not connected to a datastore",
-                                                       instance,
-                                                       "The requested operation is only available when "
-                                                       + "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
+                       MessagingUtils.noDataSourceWarningDialog(instance);
 
                        AbstractUtility.showView(CdmDataSourceViewPart.ID);
                        return null;
 
                        AbstractUtility.showView(CdmDataSourceViewPart.ID);
                        return null;