import org.apache.commons.lang.StringUtils;
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeConfigurator;
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
+import eu.etaxonomy.cdm.api.service.IPreferenceService;
import eu.etaxonomy.cdm.api.service.ITermService;
import eu.etaxonomy.cdm.api.service.config.FindTaxaAndNamesConfiguratorImpl;
import eu.etaxonomy.cdm.api.service.config.IFindTaxaAndNamesConfigurator;
import eu.etaxonomy.cdm.model.common.MarkerType;
import eu.etaxonomy.cdm.model.common.TermBase;
import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.cdm.model.metadata.CdmPreference;
+import eu.etaxonomy.cdm.model.metadata.CdmPreference.PrefKey;
+import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
+import eu.etaxonomy.cdm.model.metadata.PreferenceSubject;
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
import eu.etaxonomy.cdm.strategy.match.MatchException;
import eu.etaxonomy.cdm.strategy.match.MatchMode;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
import eu.etaxonomy.taxeditor.store.CdmStore;
-import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
public static final String P2_REPOSITORIES_DELIM = ",";
public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
+
+
/**
* <p>
* getPreferenceStore
*/
public static void setPreferredNomenclaturalCode(
NomenclaturalCode preferredCode) {
+ ICdmApplicationConfiguration controller;
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
+ CdmPreference preference = null;
+ if (controller == null){
+ return;
+ }
+ if (preferredCode == null){
+ preference = controller.getPreferenceService().find(key);
+ if (preference == null){
+ return;
+ } else{
+ int index = StringUtils.lastIndexOf(preference.getValue(), ".");
+ UUID uuid = UUID.fromString(preference.getValue().substring(index +1, preference.getValue().length()));
+ preferredCode = NomenclaturalCode.getByUuid(uuid);
+ }
+ } else{
+ preference = CdmPreference.NewInstance(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode, preferredCode.getKey());
+ controller.getPreferenceService().set(preference);
+ }
+
+
getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY,
- getPreferenceKey(preferredCode));
+ getPreferenceKey(preferredCode));
}
+ public static NomenclaturalCode getPreferredNomenclaturalCode(){
+ return getPreferredNomenclaturalCode(false);
+ }
+
/**
* <p>
* getPreferredNomenclaturalCode
*
* @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object.
*/
- public static NomenclaturalCode getPreferredNomenclaturalCode() {
-
- for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
- String preferredCode = getPreferenceStore().getString(
+ public static NomenclaturalCode getPreferredNomenclaturalCode(boolean preConnected) {
+ ICdmApplicationConfiguration controller;
+ CdmPreference pref = null;
+ if (!preConnected){
+ try{
+ controller = CdmStore.getCurrentApplicationConfiguration();
+ PrefKey key = CdmPreference.NewKey(PreferenceSubject.NewDatabaseInstance(), PreferencePredicate.NomenclaturalCode);
+ pref = controller.getPreferenceService().find(key);
+ }catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ String preferredCode;
+ if(pref == null){
+ preferredCode = getPreferenceStore().getString(
PREFERRED_NOMENCLATURAL_CODE_KEY);
+ }else{
+ preferredCode = pref.getValue();
+ }
+
+ for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) {
+// String preferredCode = getPreferenceStore().getString(
+// PREFERRED_NOMENCLATURAL_CODE_KEY);
if (getPreferenceKey(code).equals(preferredCode)) {
return code;
}
* @return
*/
private static String getPreferenceKey(ICdmBase cdmBase) {
- cdmBase = (ICdmBase) HibernateProxyHelper.deproxy(cdmBase);
+ cdmBase = HibernateProxyHelper.deproxy(cdmBase);
String key = cdmBase.getClass().getName().concat(".")
.concat(cdmBase.getUuid().toString());
* @return
*/
public static String getPreferenceKey(ISimpleTerm simpleTerm) {
- simpleTerm = (ISimpleTerm) HibernateProxyHelper.deproxy(simpleTerm);
+ simpleTerm = HibernateProxyHelper.deproxy(simpleTerm);
String key = simpleTerm.getClass().getName().concat(".")
.concat(simpleTerm.getUuid().toString());
if (key.contains("javassist")) {
* @return
*/
public static String getPreferenceKey(IDefinedTerm definedTerm) {
- definedTerm = (IDefinedTerm) HibernateProxyHelper.deproxy(definedTerm);
+ definedTerm = HibernateProxyHelper.deproxy(definedTerm);
String key = definedTerm.getClass().getName().concat(".")
.concat(definedTerm.getUuid().toString());
if (key.contains("javassist")) {
TAXON_SERVICE_CONFIGURATOR_NAMES));
configurator.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(
TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES));
+ //configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.valueOf(getPreferenceStore().getString(TAXON_SERVICE_CONFIGURATOR_MATCH_MODE)));
return configurator;
}
"http://www.biodiversitylibrary.org/openurl");
getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_WIDTH, "1000");
getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_HEIGHT, "1000");
- getPreferenceStore().setDefault(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE, true);
+ getPreferenceStore().setDefault(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE, false);
+ getPreferenceStore().setDefault(CHECKLIST_ID_IN_VOCABULARY, true);
}
/**
// First time Editor is opened, no nomenclatural code has been set
- if (PreferencesUtil.getPreferredNomenclaturalCode() == null) {
+ if (PreferencesUtil.getPreferredNomenclaturalCode(true) == null) {
PreferencesUtil.setPreferredNomenclaturalCode(NomenclaturalCode.ICNAFP);
/*
"The following has been set as your preferred nomenclatural code:\n\n\t"
+ NomenclaturalCodeHelper
.getDescription(code)
- + "\n\nYou iour is not consistent throughout the application. For DescriptionElemts and also PolytomousKeyNode.Question and PolytomousKeyNode.Statement it shows only the languages where text is available whereas for PolytomousKeyNode.modyfingText it shows a strange list of about 10-20 (different for different nodes) most of them starting with can change the nomenclatural code at any time in the \"Preferences\" menu.");*/
+ + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu.");*/
}
}
public static void checkDefaultLanguage(){
if(PreferencesUtil.getPreferredDefaultLangugae() == null){
- Shell shell = StoreUtil.getShell();
+ Shell shell = AbstractUtility.getShell();
int open = new DefaultLanguageDialog(shell).open();
- if(open == 0){//FIXME:window performed ok. Find variable for it
+ if(open == Window.OK){
PlatformUI.getWorkbench().restart();
}
}else{
private static String getMarkerTypeEditingPreferenceKey(
MarkerType markerType) {
- markerType = (MarkerType) HibernateProxyHelper.deproxy(markerType);
+ markerType = HibernateProxyHelper.deproxy(markerType);
return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX;
}
*/
public void writePropertyToConfigFile(int setLanguage) throws IOException {
File file = org.eclipse.core.runtime.preferences.ConfigurationScope.INSTANCE.getLocation().toFile();
+ //give warning to user if the directory has no write access
+ if(file == null){
+ throw new IOException();
+ }
Properties properties = load(file.getAbsolutePath()+"/config.ini");
switch(setLanguage){
case 0:
return p2Repos;
}
+
+ /**
+ * enables/disables nested composite. <br>
+ *
+ * @param ctrl - Composite to be en-/disabeld
+ * @param enabled - boolean
+ */
+ public static void recursiveSetEnabled(Control ctrl, boolean enabled) {
+ if (ctrl instanceof Composite) {
+ Composite comp = (Composite) ctrl;
+ for (Control c : comp.getChildren()) {
+ recursiveSetEnabled(c, enabled);
+ }
+ } else {
+ ctrl.setEnabled(enabled);
+ }
+ }
+
+ /**
+ * <p>
+ * getSortRanksNaturally
+ * </p>
+ *
+ * @return a boolean.
+ */
+ public static boolean getSortNodesNaturally() {
+ return getPreferenceStore().getBoolean(SORT_NODES_NATURALLY);
+ }
+
+ /**
+ * <p>
+ * setSortRanksNaturally
+ * </p>
+ *
+ * @param selection
+ * a boolean.
+ */
+ public static void setSortNodesNaturally(boolean selection) {
+ getPreferenceStore().setValue(SORT_NODES_NATURALLY, selection);
+ }
+
+
+ /**
+ * <p>
+ * getSortRanksNaturally
+ * </p>
+ *
+ * @return a boolean.
+ */
+ public static boolean getSortNodesStrictlyAlphabetically() {
+ return getPreferenceStore().getBoolean(SORT_NODES_ALPHABETICALLY);
+ }
+
+ /**
+ * <p>
+ * setSortRanksNaturally
+ * </p>
+ *
+ * @param selection
+ * a boolean.
+ */
+ public static void setSortNodesStrictlyAlphabetically(boolean selection) {
+ getPreferenceStore().setValue(SORT_NODES_ALPHABETICALLY, selection);
+ }
+
+ /**
+ * <p>
+ * setStoreNavigatorState
+ * </p>
+ *
+ * @param selection
+ * a boolean.
+ */
+ public static boolean isStoreNavigatorState() {
+ return getPreferenceStore().getBoolean(RESTORE_NAVIGATOR_STATE);
+
+ }
+
+ /**
+ * <p>
+ * setStoreNavigatorState
+ * </p>
+ *
+ * @param selection
+ * a boolean.
+ */
+ public static void setStoreNavigatorState(boolean selection) {
+ getPreferenceStore().setValue(RESTORE_NAVIGATOR_STATE, selection);
+
+ }
+
+ /**
+ * @return
+ */
+ public static boolean isShowUpWidgetIsDisposedMessages() {
+ return getPreferenceStore().getBoolean(IS_SHOW_UP_WIDGET_IS_DISPOSED);
+ }
+ public static void setShowUpWidgetIsDisposedMessages(boolean selection) {
+ getPreferenceStore().setValue(IS_SHOW_UP_WIDGET_IS_DISPOSED, selection);
+ }
+
+ /**
+ * @return
+ */
+ public static boolean isShowIdInVocabularyInChecklistEditor() {
+ return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_ID_IN_VOCABULARY);
+ }
+ public static void setShowIdInVocabularyInChecklistEditor(boolean selection) {
+ getPreferenceStore().setValue(CHECKLIST_ID_IN_VOCABULARY, selection);
+ }
+
+ /**
+ * @return
+ */
+ public static boolean isShowRankInChecklistEditor() {
+ return getPreferenceStore().getBoolean(IPreferenceKeys.CHECKLIST_SHOW_RANK);
+ }
+ public static void setShowRankInChecklistEditor(boolean selection) {
+ getPreferenceStore().setValue(CHECKLIST_SHOW_RANK, selection);
+ }
+
}