From eed65ec6200081498672114034d8e6dd99a75860 Mon Sep 17 00:00:00 2001 From: "n.hoffmann" Date: Thu, 21 Apr 2011 13:53:25 +0000 Subject: [PATCH] Drastically reducing code by using field editors for preferences --- .../taxeditor/io/AbstractIOManager.java | 60 ++- .../etaxonomy/taxeditor/io/ExportManager.java | 156 ++++--- .../preference/FeatureTreePreferences.java | 73 +-- .../preference/MobotOpenUrlPreferences.java | 92 ++-- .../NomenclaturalCodePreferences.java | 132 ++---- .../taxeditor/preference/PreferencesUtil.java | 438 +++++++++++------- .../TaxonomicEditorGeneralPreferences.java | 237 ++-------- .../etaxonomy/taxeditor/store/CdmStore.java | 387 +++++++++------- 8 files changed, 791 insertions(+), 784 deletions(-) diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractIOManager.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractIOManager.java index 09b5afca0..2c552df0c 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractIOManager.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractIOManager.java @@ -1,12 +1,12 @@ // $Id$ /** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* 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. -*/ + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * 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. + */ package eu.etaxonomy.taxeditor.io; @@ -17,8 +17,10 @@ import eu.etaxonomy.cdm.api.application.CdmApplicationController; import eu.etaxonomy.cdm.io.common.IIoConfigurator; /** - *

Abstract AbstractIOHandler class.

- * + *

+ * Abstract AbstractIOHandler class. + *

+ * * @author n.hoffmann * @created Sep 11, 2009 * @version 1.0 @@ -26,27 +28,34 @@ import eu.etaxonomy.cdm.io.common.IIoConfigurator; public abstract class AbstractIOManager { protected CdmApplicationController applicationController; - + public static enum TYPE { BerlinModel, Jaxb, Tcs, Excel_Taxa, Endnote, Sdd, Abcd } /** - *

Constructor for AbstractIOHandler.

- * - * @param applicationController a {@link eu.etaxonomy.cdm.api.application.CdmApplicationController} object. - * @param a CONFIGURATOR object. + *

+ * Constructor for AbstractIOHandler. + *

+ * + * @param applicationController + * a + * {@link eu.etaxonomy.cdm.api.application.CdmApplicationController} + * object. + * @param + * a CONFIGURATOR object. */ - protected AbstractIOManager(CdmApplicationController applicationController){ + protected AbstractIOManager(CdmApplicationController applicationController) { this.applicationController = applicationController; } - + /** * Starts the IO process - * - * @param configurator a CONFIGURATOR object. + * + * @param configurator + * a CONFIGURATOR object. */ - public void run(final CONFIGURATOR configurator){ + public void run(final CONFIGURATOR configurator) { // create job Job job = createIOJob(configurator); // configure the job @@ -54,13 +63,16 @@ public abstract class AbstractIOManager { job.setUser(true); // schedule job job.schedule(); - + } - + /** - *

createIOJob

- * - * @param configurator a CONFIGURATOR object. + *

+ * createIOJob + *

+ * + * @param configurator + * a CONFIGURATOR object. * @return a {@link org.eclipse.core.runtime.jobs.Job} object. */ protected abstract Job createIOJob(CONFIGURATOR configurator); diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java index d8697df40..88093316e 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java @@ -1,12 +1,12 @@ // $Id$ /** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* 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. -*/ + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * 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. + */ package eu.etaxonomy.taxeditor.io; @@ -28,127 +28,157 @@ import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter; import eu.etaxonomy.taxeditor.store.StoreUtil; /** - *

ExportHandler class.

- * + *

+ * ExportHandler class. + *

+ * * @author n.hoffmann * @created Sep 11, 2009 * @version 1.0 */ -public class ExportManager extends AbstractIOManager{ - +public class ExportManager extends AbstractIOManager { + /** * * @param applicationController */ - private ExportManager(CdmApplicationController applicationController){ + private ExportManager(CdmApplicationController applicationController) { super(applicationController); } - + /** - *

NewInstance

- * - * @param applicationController a {@link eu.etaxonomy.cdm.api.application.CdmApplicationController} object. + *

+ * NewInstance + *

+ * + * @param applicationController + * a + * {@link eu.etaxonomy.cdm.api.application.CdmApplicationController} + * object. * @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object. */ - public static ExportManager NewInstance(CdmApplicationController applicationController){ + public static ExportManager NewInstance( + CdmApplicationController applicationController) { return new ExportManager(applicationController); } - + /** - *

createIOJob

- * - * @param configurator a {@link eu.etaxonomy.cdm.io.common.IExportConfigurator} object. + *

+ * createIOJob + *

+ * + * @param configurator + * a {@link eu.etaxonomy.cdm.io.common.IExportConfigurator} + * object. * @return a {@link org.eclipse.core.runtime.jobs.Job} object. */ - protected Job createIOJob(final IExportConfigurator configurator){ - + @Override + protected Job createIOJob(final IExportConfigurator configurator) { + Assert.isNotNull(configurator, "Configuration may not be null"); - + final Display display = Display.getCurrent(); - - Job job = new Job("Export: " + configurator.getClass().getSimpleName()){ + + Job job = new Job("Export: " + configurator.getClass().getSimpleName()) { @Override protected IStatus run(IProgressMonitor monitor) { - monitor.beginTask("Exporting database. This will take some time.", 100); + monitor.beginTask( + "Exporting database. This will take some time.", 100); monitor.worked(10); - + display.asyncExec(new Runnable() { - + @Override public void run() { // terminate any open transactions - IConversationEnabled activePart = (IConversationEnabled) StoreUtil.getActivePage().getActivePart(); + IConversationEnabled activePart = (IConversationEnabled) StoreUtil + .getActivePage().getActivePart(); activePart.getConversationHolder().commit(false); } }); - + monitor.worked(10); - + CdmDefaultExport exporter = new CdmDefaultExport(); - configurator.setProgressMonitor(CdmProgressMonitorAdapter.CreateSubMonitor(monitor, 80)); + configurator.setProgressMonitor(CdmProgressMonitorAdapter + .CreateSubMonitor(monitor, 80)); exporter.setCdmAppController(applicationController); monitor.worked(10); - - try{ + + try { exporter.invoke(configurator); monitor.worked(60); - }catch(RuntimeException e){ - StoreUtil.errorDialog("Error exporting data", this, "An error occured while" + - "exporting to destination '" + configurator.getDestinationNameString() + "'.\n" + - "Please check error log for details.", e); + } catch (RuntimeException e) { + StoreUtil.errorDialog("Error exporting data", this, + "An error occured while" + + "exporting to destination '" + + configurator.getDestinationNameString() + + "'.\n" + + "Please check error log for details.", e); } - + display.asyncExec(new Runnable() { - + @Override public void run() { // terminate any open transactions - IConversationEnabled activePart = (IConversationEnabled) StoreUtil.getActivePage().getActivePart(); - // restarting transaction and committing it to trigger change listener + IConversationEnabled activePart = (IConversationEnabled) StoreUtil + .getActivePage().getActivePart(); + // restarting transaction and committing it to trigger + // change listener // TODO verify correct behaviour activePart.getConversationHolder().startTransaction(); activePart.getConversationHolder().commit(); } }); monitor.worked(10); - + return Status.OK_STATUS; } }; - + return job; } - + /** * @param jaxb * @return */ private IIoConfigurator getConfigurator(TYPE type) { Assert.isNotNull(type, "Type should not be null"); - - switch (type){ - case Jaxb: - return JaxbExportConfigurator.NewInstance(null, null); - case Sdd: - return SDDExportConfigurator.NewInstance(null, null, null); - default: - StoreUtil.notImplementedMessage(this); - throw new IllegalArgumentException("Export not supported yet"); + + switch (type) { + case Jaxb: + return JaxbExportConfigurator.NewInstance(null, null); + case Sdd: + return SDDExportConfigurator.NewInstance(null, null, null); + default: + StoreUtil.notImplementedMessage(this); + throw new IllegalArgumentException("Export not supported yet"); } } - + /** - *

JaxbConfigurator

- * + *

+ * JaxbConfigurator + *

+ * * @return a {@link eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator} object. */ - public final JaxbExportConfigurator JaxbConfigurator() { return (JaxbExportConfigurator) getConfigurator(TYPE.Jaxb); } + public final JaxbExportConfigurator JaxbConfigurator() { + return (JaxbExportConfigurator) getConfigurator(TYPE.Jaxb); + } /** - *

SddConfigurator

- * - * @return a {@link eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator} object. + *

+ * SddConfigurator + *

+ * + * @return a {@link eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator} + * object. */ - public final SDDExportConfigurator SddConfigurator() { return (SDDExportConfigurator) getConfigurator(TYPE.Sdd); } + public final SDDExportConfigurator SddConfigurator() { + return (SDDExportConfigurator) getConfigurator(TYPE.Sdd); + } } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureTreePreferences.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureTreePreferences.java index 969807d13..df0300989 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureTreePreferences.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/FeatureTreePreferences.java @@ -1,12 +1,12 @@ // $Id$ /** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* 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. -*/ + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * 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. + */ package eu.etaxonomy.taxeditor.preference; @@ -26,8 +26,10 @@ import org.eclipse.ui.IWorkbenchPreferencePage; import eu.etaxonomy.taxeditor.featuretree.FeatureTreeEditorWizard; /** - *

FeatureTreePreferences class.

- * + *

+ * FeatureTreePreferences class. + *

+ * * @author n.hoffmann * @created Aug 5, 2010 * @version 1.0 @@ -36,61 +38,78 @@ public class FeatureTreePreferences extends PreferencePage implements IWorkbenchPreferencePage { /** - *

Constructor for FeatureTreePreferences.

+ *

+ * Constructor for FeatureTreePreferences. + *

*/ public FeatureTreePreferences() { } /** - *

Constructor for FeatureTreePreferences.

- * - * @param title a {@link java.lang.String} object. + *

+ * Constructor for FeatureTreePreferences. + *

+ * + * @param title + * a {@link java.lang.String} object. */ public FeatureTreePreferences(String title) { super(title); } /** - *

Constructor for FeatureTreePreferences.

- * - * @param title a {@link java.lang.String} object. - * @param image a {@link org.eclipse.jface.resource.ImageDescriptor} object. + *

+ * Constructor for FeatureTreePreferences. + *

+ * + * @param title + * a {@link java.lang.String} object. + * @param image + * a {@link org.eclipse.jface.resource.ImageDescriptor} object. */ public FeatureTreePreferences(String title, ImageDescriptor image) { super(title, image); } - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) */ /** {@inheritDoc} */ @Override public void init(IWorkbench workbench) { } - /* (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) */ /** {@inheritDoc} */ @Override protected Control createContents(Composite parent) { - + Composite composite = new Composite(parent, SWT.NULL); composite.setLayout(new GridLayout()); - + final Button button_openFeatureTree = new Button(composite, SWT.PUSH); button_openFeatureTree.setText("Open FeatureTree Editor"); - + button_openFeatureTree.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { FeatureTreeEditorWizard featureTreeEditorDialog = new FeatureTreeEditorWizard(); - WizardDialog dialog = new WizardDialog(getShell(), featureTreeEditorDialog); - + WizardDialog dialog = new WizardDialog(getShell(), + featureTreeEditorDialog); + dialog.open(); } }); - + return composite; } } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/MobotOpenUrlPreferences.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/MobotOpenUrlPreferences.java index 77b935002..8679d677e 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/MobotOpenUrlPreferences.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/MobotOpenUrlPreferences.java @@ -1,12 +1,12 @@ // $Id$ /** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* 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. -*/ + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * 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. + */ package eu.etaxonomy.taxeditor.preference; @@ -31,69 +31,77 @@ import org.eclipse.ui.IWorkbenchPreferencePage; public class MobotOpenUrlPreferences extends PreferencePage implements IWorkbenchPreferencePage { - private String openUrlServiceAccessPoint; private String openUrlImageMaxWidth; private String openUrlImageMaxHeight; - - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) */ @Override public void init(IWorkbench workbench) { setPreferenceStore(PreferencesUtil.getPreferenceStore()); } - /* (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) */ @Override protected Control createContents(Composite parent) { Composite container = new Composite(parent, SWT.NULL); final GridLayout gridLayout = new GridLayout(); container.setLayout(gridLayout); - + creatOpenUrlServiceAccessPoint(container); - + createOpenUrlImageSize(container); - + return container; } - + /** * @param container */ private void createOpenUrlImageSize(Composite container) { - openUrlImageMaxWidth = getPreferenceStore().getString(IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH); - openUrlImageMaxHeight = getPreferenceStore().getString(IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT); - + openUrlImageMaxWidth = getPreferenceStore().getString( + IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH); + openUrlImageMaxHeight = getPreferenceStore().getString( + IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT); + Composite composite = new Composite(container, SWT.NULL); final GridLayout gridLayout = new GridLayout(2, false); composite.setLayout(gridLayout); - + final CLabel labelWidth = new CLabel(composite, SWT.NULL); labelWidth.setText("Image Maximum Width: "); - + final Text textWidth = new Text(composite, SWT.BORDER); textWidth.setText(openUrlImageMaxWidth); textWidth.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); - + textWidth.addModifyListener(new ModifyListener() { - + public void modifyText(ModifyEvent e) { openUrlImageMaxWidth = textWidth.getText(); } }); - + final CLabel labelHeight = new CLabel(composite, SWT.NULL); labelHeight.setText("Image Maximum Height: "); - + final Text textHeight = new Text(composite, SWT.BORDER); textHeight.setText(openUrlImageMaxHeight); textHeight.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); - + textHeight.addModifyListener(new ModifyListener() { - + public void modifyText(ModifyEvent e) { openUrlImageMaxHeight = textHeight.getText(); } @@ -101,32 +109,38 @@ public class MobotOpenUrlPreferences extends PreferencePage implements } private void creatOpenUrlServiceAccessPoint(Composite composite) { - openUrlServiceAccessPoint = getPreferenceStore().getString(IPreferenceKeys.OPENURL_ACCESS_POINT); - + openUrlServiceAccessPoint = getPreferenceStore().getString( + IPreferenceKeys.OPENURL_ACCESS_POINT); + final CLabel label = new CLabel(composite, SWT.NULL); label.setText("Mobot Open Url Service Access Point:"); - + final Text text = new Text(composite, SWT.BORDER); text.setText(openUrlServiceAccessPoint); text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); - + text.addModifyListener(new ModifyListener() { - + public void modifyText(ModifyEvent e) { openUrlServiceAccessPoint = text.getText(); } }); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.eclipse.jface.preference.PreferencePage#performOk() */ @Override public boolean performOk() { - getPreferenceStore().setValue(IPreferenceKeys.OPENURL_ACCESS_POINT, openUrlServiceAccessPoint); - getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH, openUrlImageMaxWidth); - getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT, openUrlImageMaxHeight); - + getPreferenceStore().setValue(IPreferenceKeys.OPENURL_ACCESS_POINT, + openUrlServiceAccessPoint); + getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH, + openUrlImageMaxWidth); + getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT, + openUrlImageMaxHeight); + return super.performOk(); } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalCodePreferences.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalCodePreferences.java index bde2e26f4..fd3b21782 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalCodePreferences.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/NomenclaturalCodePreferences.java @@ -1,24 +1,17 @@ /** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* 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. -*/ + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * 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. + */ package eu.etaxonomy.taxeditor.preference; -import java.util.HashMap; -import java.util.Map; +import java.util.List; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.RadioGroupFieldEditor; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -27,92 +20,59 @@ import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper; import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; /** - *

NomenclaturalCodePreferences class.

- * + *

+ * NomenclaturalCodePreferences class. + *

+ * * @author p.ciardelli * @created 16.09.2008 * @version 1.0 */ -public class NomenclaturalCodePreferences extends PreferencePage implements - IWorkbenchPreferencePage { - - /** Constant PLUGIN_ID="eu.etaxonomy.taxeditor.preferences.nome"{trunked} */ - public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.nomenclatural"; - - private NomenclaturalCode preferredCode; +public class NomenclaturalCodePreferences extends FieldEditorPreferencePage + implements IWorkbenchPreferencePage { - private Map buttons = new HashMap(); - - /** - *

Constructor for NomenclaturalCodePreferences.

+ /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors + * () */ - public NomenclaturalCodePreferences() { - super(); - setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified."); + @Override + protected void createFieldEditors() { + + addField(new RadioGroupFieldEditor( + IPreferenceKeys.PREFERRED_NOMENCLATURAL_CODE_KEY, + "Available Codes", 1, getLabelAndValues(), + getFieldEditorParent(), true)); + } /** - * {@inheritDoc} - * - * Create contents of the preference page + * @return */ - @Override - public Control createContents(Composite parent) { - - Composite container = new Composite(parent, SWT.NULL); - container.setLayout(new GridLayout()); - - for (final NomenclaturalCode code : NomenclaturalCodeHelper.getSupportedCodes()) { - Button button = new Button(container, SWT.RADIO); - button.setText(NomenclaturalCodeHelper.getDescription(code)); - button.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - preferredCode = code; - } - }); - buttons.put(code, button); - } - - preferredCode = PreferencesUtil.getPreferredNomenclaturalCode(); - if (preferredCode == null) { - preferredCode = NomenclaturalCodeHelper.getDefaultCode(); - PreferencesUtil.setPreferredNomenclaturalCode(preferredCode); + private String[][] getLabelAndValues() { + List supportedCodes = NomenclaturalCodeHelper + .getSupportedCodes(); + String[][] labelAndValues = new String[supportedCodes.size()][2]; + for (int i = 0; i < supportedCodes.size(); i++) { + labelAndValues[i][0] = NomenclaturalCodeHelper + .getDescription(supportedCodes.get(i)); + labelAndValues[i][1] = PreferencesUtil + .getPreferenceKey(supportedCodes.get(i)); } - setButton(preferredCode); - - return container; + return labelAndValues; } /** * {@inheritDoc} - * + * * Initialize the preference page */ public void init(IWorkbench workbench) { - setPreferenceStore(TaxeditorStorePlugin.getDefault().getPreferenceStore()); - } - - /** - *

performDefaults

- */ - protected void performDefaults() { - setButton(NomenclaturalCodeHelper.getDefaultCode()); - } - - /** - *

performOk

- * - * @return a boolean. - */ - public boolean performOk() { - PreferencesUtil.setPreferredNomenclaturalCode(preferredCode); - return true; - } - - private void setButton(NomenclaturalCode preferredCode) { - this.preferredCode = preferredCode; - for (NomenclaturalCode code : buttons.keySet()) { - buttons.get(code).setSelection(code.equals(preferredCode)); - } + setPreferenceStore(TaxeditorStorePlugin.getDefault() + .getPreferenceStore()); + setDescription("Choose which nomenclatural code you would like to use for scientific names unless otherwise specified."); } + } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java index 310ee58a3..aaa47ef9d 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java @@ -1,11 +1,11 @@ /** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* 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. -*/ + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * 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. + */ package eu.etaxonomy.taxeditor.preference; @@ -45,70 +45,83 @@ import eu.etaxonomy.taxeditor.store.StoreUtil; import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; /** - *

PreferencesUtil class.

- * + *

+ * PreferencesUtil class. + *

+ * * @author p.ciardelli * @author n.hoffmann * @created 05.12.2008 * @version 1.0 */ -public class PreferencesUtil implements IPreferenceKeys{ +public class PreferencesUtil implements IPreferenceKeys { /** * */ public static final String PREFERRED_TERMS_CHANGE = "preferred_terms"; - - /** - *

getPreferenceStore

- * + *

+ * getPreferenceStore + *

+ * * @return a {@link org.eclipse.jface.preference.IPreferenceStore} object. */ public static IPreferenceStore getPreferenceStore() { return TaxeditorStorePlugin.getDefault().getPreferenceStore(); } - + /** - *

setPreferredNomenclaturalCode

- * - * @param preferredCode a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object. + *

+ * setPreferredNomenclaturalCode + *

+ * + * @param preferredCode + * a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} + * object. */ - public static void setPreferredNomenclaturalCode(NomenclaturalCode preferredCode) { - getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY, getPreferenceKey(preferredCode)); + public static void setPreferredNomenclaturalCode( + NomenclaturalCode preferredCode) { + getPreferenceStore().setValue(PREFERRED_NOMENCLATURAL_CODE_KEY, + getPreferenceKey(preferredCode)); } - + /** - *

getPreferredNomenclaturalCode

- * + *

+ * getPreferredNomenclaturalCode + *

+ * * @return a {@link eu.etaxonomy.cdm.model.name.NomenclaturalCode} object. */ public static NomenclaturalCode getPreferredNomenclaturalCode() { - + for (NomenclaturalCode code : NomenclaturalCodeHelper.getAllCodes()) { - String preferredCode = getPreferenceStore().getString(PREFERRED_NOMENCLATURAL_CODE_KEY); + String preferredCode = getPreferenceStore().getString( + PREFERRED_NOMENCLATURAL_CODE_KEY); if (getPreferenceKey(code).equals(preferredCode)) { return code; } } return null; } - + /** * Get the match strategy for the given class that was stored in preferences * or the default strategy if it was not stored in preferences - * - * @param clazz a {@link java.lang.Class} object. + * + * @param clazz + * a {@link java.lang.Class} object. * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object. */ - public static IMatchStrategy getMatchStrategy(Class clazz){ + public static IMatchStrategy getMatchStrategy(Class clazz) { String className = clazz.getName(); - if(getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX + className)){ + if (getPreferenceStore().getBoolean(MATCH_STRATEGY_PREFIX + className)) { IMatchStrategy matchStrategy = getDefaultMatchStrategy(clazz); - - for(String fieldName : matchStrategy.getMatchFieldPropertyNames()){ - String matchModeName = getPreferenceStore().getString(getMatchStrategyFieldName(className, fieldName)); + + for (String fieldName : matchStrategy.getMatchFieldPropertyNames()) { + String matchModeName = getPreferenceStore().getString( + getMatchStrategyFieldName(className, fieldName)); MatchMode matchMode = MatchMode.valueOf(matchModeName); try { matchStrategy.setMatchMode(fieldName, matchMode); @@ -117,29 +130,32 @@ public class PreferencesUtil implements IPreferenceKeys{ throw new RuntimeException(e); } } - + return matchStrategy; } return getDefaultMatchStrategy(clazz); } - + /** * Stores a matchStrategy into the preference store. - * - * @param matchStrategy a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object. + * + * @param matchStrategy + * a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} + * object. */ - public static void setMatchStrategy(IMatchStrategy matchStrategy){ + public static void setMatchStrategy(IMatchStrategy matchStrategy) { String className = matchStrategy.getMatchClass().getName(); getPreferenceStore().setValue(MATCH_STRATEGY_PREFIX + className, true); - + Set matchFields = matchStrategy.getMatchFieldPropertyNames(); - - for(String fieldName : matchFields){ - getPreferenceStore().setValue(getMatchStrategyFieldName(className, fieldName), + + for (String fieldName : matchFields) { + getPreferenceStore().setValue( + getMatchStrategyFieldName(className, fieldName), matchStrategy.getMatchMode(fieldName).name()); } } - + /** * Helper method to create the preference property for a match field. * @@ -147,47 +163,56 @@ public class PreferencesUtil implements IPreferenceKeys{ * @param fieldName * @return */ - private static String getMatchStrategyFieldName(String className, String fieldName){ - return MATCH_STRATEGY_PREFIX + className + "." + fieldName; + private static String getMatchStrategyFieldName(String className, + String fieldName) { + return MATCH_STRATEGY_PREFIX + className + "." + fieldName; } - + /** * Returns the default match strategy for a given class. - * - * @param clazz a {@link java.lang.Class} object. + * + * @param clazz + * a {@link java.lang.Class} object. * @return a {@link eu.etaxonomy.cdm.strategy.match.IMatchStrategy} object. */ - public static IMatchStrategy getDefaultMatchStrategy(Class clazz){ + public static IMatchStrategy getDefaultMatchStrategy(Class clazz) { return DefaultMatchStrategy.NewInstance(clazz); } - - + /** - *

getDateFormatPattern

- * + *

+ * getDateFormatPattern + *

+ * * @return a {@link java.lang.String} object. */ - public static String getDateFormatPattern(){ + public static String getDateFormatPattern() { // TODO make this configurable in properties String pattern = "Y-M-d H:m"; return pattern; } - + /** - *

addTermToPreferredTerms

- * - * @param term a T object. - * @param a T object. + *

+ * addTermToPreferredTerms + *

+ * + * @param term + * a T object. + * @param + * a T object. */ - public static void addTermToPreferredTerms(T term){ + public static void addTermToPreferredTerms(T term) { -// VocabularyEnum vocabulary = VocabularyEnum.getVocabularyEnum(term.getClass()); -// -// getPreferenceStore().setValue(getPreferenceKey(term), VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term)); -// -// firePreferencesChanged(term.getClass()); + // VocabularyEnum vocabulary = + // VocabularyEnum.getVocabularyEnum(term.getClass()); + // + // getPreferenceStore().setValue(getPreferenceKey(term), + // VocabularyStore.getTermVocabulary(vocabulary).getTerms().contains(term)); + // + // firePreferencesChanged(term.getClass()); } - + /** * Construct a unique key using the CdmBase object's uuid * @@ -196,10 +221,9 @@ public class PreferencesUtil implements IPreferenceKeys{ */ private static String getPreferenceKey(ICdmBase cdmBase) { cdmBase = (ICdmBase) HibernateProxyHelper.deproxy(cdmBase); - - String key = cdmBase.getClass().getName() - . concat(".") - . concat(cdmBase.getUuid().toString()); + + String key = cdmBase.getClass().getName().concat(".") + .concat(cdmBase.getUuid().toString()); if (key.contains("javassist")) { StoreUtil.info("proxy"); } @@ -212,82 +236,103 @@ public class PreferencesUtil implements IPreferenceKeys{ * @param cdmBase * @return */ - private static String getPreferenceKey(IDefinedTerm definedTerm) { + public static String getPreferenceKey(IDefinedTerm definedTerm) { definedTerm = (IDefinedTerm) HibernateProxyHelper.deproxy(definedTerm); - String key = definedTerm.getClass().getName() - . concat(".") - . concat(definedTerm.getUuid().toString()); + String key = definedTerm.getClass().getName().concat(".") + .concat(definedTerm.getUuid().toString()); if (key.contains("javassist")) { - StoreUtil.warn(PreferencesUtil.class, "Trying to persist a preference based on a proxy class."); + StoreUtil.warn(PreferencesUtil.class, + "Trying to persist a preference based on a proxy class."); } return key; } - + /** * Retrieves search preferences from the preference store - * + * * @return an {@link ITaxonServiceConfigurator} to pass to search methods */ public static ITaxonServiceConfigurator getSearchConfigurator() { ITaxonServiceConfigurator configurator = initializeSearchConfigurator(); - - configurator.setDoTaxa(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_TAXA)); - configurator.setDoSynonyms(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_SYNONYMS)); - configurator.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_NAMES)); - configurator.setDoTaxaByCommonNames(getPreferenceStore().getBoolean(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES)); + + configurator.setDoTaxa(getPreferenceStore().getBoolean( + TAXON_SERVICE_CONFIGURATOR_TAXA)); + configurator.setDoSynonyms(getPreferenceStore().getBoolean( + TAXON_SERVICE_CONFIGURATOR_SYNONYMS)); + configurator.setDoNamesWithoutTaxa(getPreferenceStore().getBoolean( + TAXON_SERVICE_CONFIGURATOR_NAMES)); + configurator.setDoTaxaByCommonNames(getPreferenceStore().getBoolean( + TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES)); return configurator; } - + /** * create new preferences, setting all search options to true - * - * @return a {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} object. + * + * @return a + * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} + * object. */ - public static ITaxonServiceConfigurator initializeSearchConfigurator(){ - ITaxonServiceConfigurator configurator = TaxonServiceConfiguratorImpl.NewInstance(); - + public static ITaxonServiceConfigurator initializeSearchConfigurator() { + ITaxonServiceConfigurator configurator = TaxonServiceConfiguratorImpl + .NewInstance(); + configurator.setDoTaxa(true); configurator.setDoSynonyms(true); configurator.setDoNamesWithoutTaxa(true); configurator.setDoTaxaByCommonNames(true); - - configurator.setTaxonPropertyPath(Arrays.asList("$", - "titleCache", "name", "name.$", "relationsFromThisTaxon.$")); - - configurator.setSynonymPropertyPath(Arrays.asList("$", - "titleCache", "name", "name.$", "synonymRelations.relatedTo.*")); - - // DEFAULT VALUES - // match mode is a simple like, actually all other match modes are kind of bogus - configurator.setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.LIKE); + + configurator.setTaxonPropertyPath(Arrays.asList("$", "titleCache", + "name", "name.$", "relationsFromThisTaxon.$")); + + configurator.setSynonymPropertyPath(Arrays.asList("$", "titleCache", + "name", "name.$", "synonymRelations.relatedTo.*")); + + // DEFAULT VALUES + // match mode is a simple like, actually all other match modes are kind + // of bogus + configurator + .setMatchMode(eu.etaxonomy.cdm.persistence.query.MatchMode.LIKE); // we set page number and size here as this should always be unlimited configurator.setPageNumber(0); // TODO currently limit results to 10000 configurator.setPageSize(10000); - + return configurator; } - + /** * Store search preferences - * - * @param configurator a {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} object. + * + * @param configurator + * a + * {@link eu.etaxonomy.cdm.api.service.config.ITaxonServiceConfigurator} + * object. */ - public static void setSearchConfigurator(ITaxonServiceConfigurator configurator){ - getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA, configurator.isDoTaxa()); - getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, configurator.isDoSynonyms()); - getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES, configurator.isDoNamesWithoutTaxa()); - getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES, configurator.isDoTaxaByCommonNames()); + public static void setSearchConfigurator( + ITaxonServiceConfigurator configurator) { + getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_TAXA, + configurator.isDoTaxa()); + getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, + configurator.isDoSynonyms()); + getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_NAMES, + configurator.isDoNamesWithoutTaxa()); + getPreferenceStore().setValue(TAXON_SERVICE_CONFIGURATOR_COMMON_NAMES, + configurator.isDoTaxaByCommonNames()); } /** - *

firePreferencesChanged

- * - * @param clazz a {@link java.lang.Class} object. + *

+ * firePreferencesChanged + *

+ * + * @param clazz + * a {@link java.lang.Class} object. */ public static void firePreferencesChanged(Class clazz) { - getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE, null, clazz); + getPreferenceStore().firePropertyChangeEvent(PREFERRED_TERMS_CHANGE, + null, clazz); } /** @@ -295,40 +340,53 @@ public class PreferencesUtil implements IPreferenceKeys{ */ public static void setDefaults() { getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_TAXA, true); - getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, true); - getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT, "http://edit.br.fgov.be/edit_wp5/v1/areas.php"); - getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP, true); - getPreferenceStore().setDefault(OPENURL_ACCESS_POINT, "http://www.biodiversitylibrary.org/openurl"); + getPreferenceStore().setDefault(TAXON_SERVICE_CONFIGURATOR_SYNONYMS, + true); + getPreferenceStore().setDefault(EDIT_MAP_SERVICE_ACCES_POINT, + "http://edit.br.fgov.be/edit_wp5/v1/areas.php"); + getPreferenceStore().setDefault(SHOULD_CONNECT_AT_STARTUP, true); + getPreferenceStore().setDefault(OPENURL_ACCESS_POINT, + "http://www.biodiversitylibrary.org/openurl"); getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_WIDTH, "1000"); getPreferenceStore().setDefault(OPENURL_IMAGE_MAX_HEIGHT, "1000"); } /** - *

checkNomenclaturalCode

+ *

+ * checkNomenclaturalCode + *

*/ - public static void checkNomenclaturalCode() { + public static void checkNomenclaturalCode() { // First time Editor is opened, no nomenclatural code has been set if (PreferencesUtil.getPreferredNomenclaturalCode() == null) { StoreUtil.info("No nomencatural code set."); - + Shell shell = StoreUtil.getShell(); - + // Query user re: preferred nom. code Dialog dialog = new InitNomenclaturalCodePrefDialog(shell); dialog.open(); - + // Short message confirming user's choice - NomenclaturalCode code = PreferencesUtil.getPreferredNomenclaturalCode(); - MessageDialog.openInformation(shell, "Nomenclatural code set", - "The following has been set as your preferred nomenclatural code:\n\n\t" + - NomenclaturalCodeHelper.getDescription(code) + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu."); + NomenclaturalCode code = PreferencesUtil + .getPreferredNomenclaturalCode(); + MessageDialog + .openInformation( + shell, + "Nomenclatural code set", + "The following has been set as your preferred nomenclatural code:\n\n\t" + + NomenclaturalCodeHelper + .getDescription(code) + + "\n\nYou can change the nomenclatural code at any time in the \"Preferences\" menu."); } } /** - *

getMapServiceAccessPoint

- * + *

+ * getMapServiceAccessPoint + *

+ * * @return a {@link java.lang.String} object. */ public static String getMapServiceAccessPoint() { @@ -336,8 +394,10 @@ public class PreferencesUtil implements IPreferenceKeys{ } /** - *

shouldConnectAtStartUp

- * + *

+ * shouldConnectAtStartUp + *

+ * * @return a boolean. */ public static boolean shouldConnectAtStartUp() { @@ -345,60 +405,77 @@ public class PreferencesUtil implements IPreferenceKeys{ } /** - *

getDefaultFeatureTreeForTextualDescription

- * + *

+ * getDefaultFeatureTreeForTextualDescription + *

+ * * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object. */ public static FeatureTree getDefaultFeatureTreeForTextualDescription() { - String uuidString = getPreferenceStore().getString(FEATURE_TREE_DEFAULT_TEXT); - return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(IFeatureTreeService.class).load(UUID.fromString(uuidString)); + String uuidString = getPreferenceStore().getString( + FEATURE_TREE_DEFAULT_TEXT); + return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService( + IFeatureTreeService.class).load(UUID.fromString(uuidString)); } /** - *

getDefaultFeatureTreeForStructuredDescription

- * + *

+ * getDefaultFeatureTreeForStructuredDescription + *

+ * * @return a {@link eu.etaxonomy.cdm.model.description.FeatureTree} object. */ public static FeatureTree getDefaultFeatureTreeForStructuredDescription() { - String uuidString = getPreferenceStore().getString(FEATURE_TREE_DEFAULT_STRUCTURE); - return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService(IFeatureTreeService.class).load(UUID.fromString(uuidString)); + String uuidString = getPreferenceStore().getString( + FEATURE_TREE_DEFAULT_STRUCTURE); + return CdmUtils.isEmpty(uuidString) ? null : CdmStore.getService( + IFeatureTreeService.class).load(UUID.fromString(uuidString)); } /** - *

setSortRanksHierarchichally

- * - * @param selection a boolean. + *

+ * setSortRanksHierarchichally + *

+ * + * @param selection + * a boolean. */ public static void setSortRanksHierarchichally(boolean selection) { getPreferenceStore().setValue(SORT_RANKS_HIERARCHICHALLY, selection); - } - + } + /** - *

getSortRanksHierarchichally

- * + *

+ * getSortRanksHierarchichally + *

+ * * @return a boolean. */ - public static boolean getSortRanksHierarchichally(){ + public static boolean getSortRanksHierarchichally() { return getPreferenceStore().getBoolean(SORT_RANKS_HIERARCHICHALLY); } public static boolean isMultilanguageTextEditingCapability() { - return getPreferenceStore().getBoolean(MULTILANGUAGE_TEXT_EDITING_CAPABILITY); + return getPreferenceStore().getBoolean( + MULTILANGUAGE_TEXT_EDITING_CAPABILITY); } - - public static Language getGlobalLanguage(){ - String languageUuidString = getPreferenceStore().getString(GLOBAL_LANGUAGE_UUID); - - if(CdmUtils.isEmpty(languageUuidString)){ + + public static Language getGlobalLanguage() { + String languageUuidString = getPreferenceStore().getString( + GLOBAL_LANGUAGE_UUID); + + if (CdmUtils.isEmpty(languageUuidString)) { return Language.DEFAULT(); } - + UUID languageUuid = UUID.fromString(languageUuidString); - return (Language) CdmStore.getService(ITermService.class).load(languageUuid); + return (Language) CdmStore.getService(ITermService.class).load( + languageUuid); } - - public static void setGlobalLanguage(Language language){ - getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID, language.getUuid().toString()); + + public static void setGlobalLanguage(Language language) { + getPreferenceStore().setValue(GLOBAL_LANGUAGE_UUID, + language.getUuid().toString()); CdmStore.setDefaultLanguage(language); } @@ -406,17 +483,18 @@ public class PreferencesUtil implements IPreferenceKeys{ * @return */ public static Map getEditMarkerTypePreferences() { - List markerTypes = CdmStore.getTermManager().getPreferredMarkerTypes(); - + List markerTypes = CdmStore.getTermManager() + .getPreferredMarkerTypes(); + Map result = new HashMap(); - - for(MarkerType markerType : markerTypes){ + + for (MarkerType markerType : markerTypes) { String name = getMarkerTypeEditingPreferenceKey(markerType); Boolean value = getPreferenceStore().getBoolean(name); - + result.put(markerType, value); } - + return result; } @@ -425,34 +503,44 @@ public class PreferencesUtil implements IPreferenceKeys{ */ public static void setEditMarkerTypePreferences( Map markerTypeEditingMap) { - for(MarkerType markerType : markerTypeEditingMap.keySet()){ + for (MarkerType markerType : markerTypeEditingMap.keySet()) { String name = getMarkerTypeEditingPreferenceKey(markerType); - getPreferenceStore().setValue(name, markerTypeEditingMap.get(markerType)); + getPreferenceStore().setValue(name, + markerTypeEditingMap.get(markerType)); } - + } - - private static String getMarkerTypeEditingPreferenceKey(MarkerType markerType){ + + private static String getMarkerTypeEditingPreferenceKey( + MarkerType markerType) { markerType = (MarkerType) HibernateProxyHelper.deproxy(markerType); return markerType.getClass().getName() + EDIT_MARKER_TYPE_PREFIX; } - + /** - *

setEditMarkerTypePreference

- * - * @param input a {@link org.eclipse.ui.IEditorInput} object. - * @param markerType a {@link eu.etaxonomy.cdm.model.common.MarkerType} object. - * @param edit a boolean. + *

+ * setEditMarkerTypePreference + *

+ * + * @param input + * a {@link org.eclipse.ui.IEditorInput} object. + * @param markerType + * a {@link eu.etaxonomy.cdm.model.common.MarkerType} object. + * @param edit + * a boolean. */ - public static void setEditMarkerTypePreference(MarkerType markerType, boolean edit) { - getPreferenceStore().setValue(getMarkerTypeEditingPreferenceKey(markerType), edit); + public static void setEditMarkerTypePreference(MarkerType markerType, + boolean edit) { + getPreferenceStore().setValue( + getMarkerTypeEditingPreferenceKey(markerType), edit); } /** * @return */ public static DerivedUnitFacadeConfigurator getDerivedUnitConfigurator() { - DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator.NewInstance(); + DerivedUnitFacadeConfigurator configurator = DerivedUnitFacadeConfigurator + .NewInstance(); configurator.setMoveDerivedUnitMediaToGallery(true); configurator.setMoveFieldObjectMediaToGallery(true); return configurator; diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/TaxonomicEditorGeneralPreferences.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/TaxonomicEditorGeneralPreferences.java index c7d11ba64..92a530963 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/TaxonomicEditorGeneralPreferences.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/TaxonomicEditorGeneralPreferences.java @@ -1,216 +1,71 @@ // $Id$ /** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* 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. -*/ + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * 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. + */ package eu.etaxonomy.taxeditor.preference; -import org.eclipse.jface.preference.PreferencePage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CLabel; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.layout.RowLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Text; +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.StringFieldEditor; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; /** - *

TaxonomicEditorGeneralPreferences class.

- * + *

+ * TaxonomicEditorGeneralPreferences class. + *

+ * * @author n.hoffmann * @created Sep 1, 2009 * @version 1.0 */ -public class TaxonomicEditorGeneralPreferences extends PreferencePage implements - IWorkbenchPreferencePage { - - boolean showUuidInSupplementalView; - - private String editMapServiceAccessPoint; - - private boolean shouldConnectAtStartup; - - private boolean shouldExpandSectionWhenDataAvailable; +public class TaxonomicEditorGeneralPreferences extends + FieldEditorPreferencePage implements IWorkbenchPreferencePage { - private boolean shouldShowExperimentalFeatures; - - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors + * () */ - /** {@inheritDoc} */ @Override - protected Control createContents(Composite parent) { - Composite container = new Composite(parent, SWT.NULL); - final GridLayout gridLayout = new GridLayout(); - container.setLayout(gridLayout); - - createShowUuidInSupplementalView(container); - createMapServiceAccessPoint(container); - createShouldConnectAtStartUp(container); - createShouldExpandSectionWhenDataAvailable(container); - - createShowExperimentalFeatures(container); - - return container; - } - - - private void createShouldExpandSectionWhenDataAvailable(Composite container) { - shouldExpandSectionWhenDataAvailable = getPreferenceStore().getBoolean(IPreferenceKeys.SHOULD_EXPAND_SECTION_WHEN_DATA_AVAILABLE); - - final Composite composite = createComposite(container); - - final Button button = new Button(composite, SWT.CHECK); - button.setText("Should expand sections when data is available (Details View)"); - - button.setSelection(shouldExpandSectionWhenDataAvailable); - - button.addSelectionListener(new SelectionAdapter(){ - @Override - public void widgetSelected(SelectionEvent e) { - shouldExpandSectionWhenDataAvailable = button.getSelection(); - } - }); - - } + protected void createFieldEditors() { + addField(new BooleanFieldEditor(PreferencesUtil.SHOW_DEBUG_INFORMATION, + "Show UUID and object ID in supplemental data view.", + getFieldEditorParent())); + addField(new BooleanFieldEditor( + IPreferenceKeys.SHOULD_EXPAND_SECTION_WHEN_DATA_AVAILABLE, + "Should expand sections when data is available (Details View)", + getFieldEditorParent())); + addField(new StringFieldEditor( + IPreferenceKeys.EDIT_MAP_SERVICE_ACCES_POINT, + "EDIT Map Service Access Point:", getFieldEditorParent())); + addField(new BooleanFieldEditor( + IPreferenceKeys.SHOULD_CONNECT_AT_STARTUP, + "Connect to last used datasource when launching", + getFieldEditorParent())); + addField(new BooleanFieldEditor( + IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES, + "Show experimental features", getFieldEditorParent())); - private void createMapServiceAccessPoint(Composite composite) { - editMapServiceAccessPoint = PreferencesUtil.getMapServiceAccessPoint(); - -// Composite composite = createComposite(parent); - - final CLabel label = new CLabel(composite, SWT.NULL); - label.setText("EDIT Map Service Access Point:"); - - final Text text = new Text(composite, SWT.BORDER); - text.setText(editMapServiceAccessPoint); - text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); - - text.addModifyListener(new ModifyListener() { - - public void modifyText(ModifyEvent e) { - editMapServiceAccessPoint = text.getText(); - } - }); } - - - private void createShowUuidInSupplementalView(Composite parent){ - showUuidInSupplementalView = getPreferenceStore().getBoolean(PreferencesUtil.SHOW_DEBUG_INFORMATION); - - final Composite composite = createComposite(parent); - - final Button button_toggle = new Button(composite, SWT.CHECK); - - - button_toggle.setText("Show UUID and object ID in supplemental data view."); - - button_toggle.setSelection(showUuidInSupplementalView); - - - button_toggle.addSelectionListener(new SelectionAdapter(){ - /* (non-Javadoc) - * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) - */ - @Override - public void widgetSelected(SelectionEvent e) { - showUuidInSupplementalView = button_toggle.getSelection(); - } - }); - - } - - private void createShouldConnectAtStartUp(Composite parent){ - shouldConnectAtStartup = getPreferenceStore().getBoolean(IPreferenceKeys.SHOULD_CONNECT_AT_STARTUP); - - final Composite composite = createComposite(parent); - - final Button button_toggle = new Button(composite, SWT.CHECK); - - - button_toggle.setText("Connect to last used datasource when launching."); - - button_toggle.setSelection(shouldConnectAtStartup); - - - button_toggle.addSelectionListener(new SelectionAdapter(){ - /* (non-Javadoc) - * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) - */ - @Override - public void widgetSelected(SelectionEvent e) { - shouldConnectAtStartup = button_toggle.getSelection(); - } - }); - } - - /** - * @param container + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) */ - private void createShowExperimentalFeatures(Composite parent) { - shouldShowExperimentalFeatures = getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES); - final Composite composite = createComposite(parent); - - final Button button_toggle = new Button(composite, SWT.CHECK); - - - button_toggle.setText("Show experimental features-"); - - button_toggle.setSelection(shouldShowExperimentalFeatures); - - - button_toggle.addSelectionListener(new SelectionAdapter(){ - /* (non-Javadoc) - * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) - */ - @Override - public void widgetSelected(SelectionEvent e) { - shouldShowExperimentalFeatures = button_toggle.getSelection(); - } - }); - } - - 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.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) - */ - /** {@inheritDoc} */ + @Override public void init(IWorkbench workbench) { setPreferenceStore(PreferencesUtil.getPreferenceStore()); } - /** {@inheritDoc} */ - @Override - public boolean performOk() { - - getPreferenceStore().setValue(IPreferenceKeys.SHOW_DEBUG_INFORMATION, showUuidInSupplementalView); - getPreferenceStore().setValue(IPreferenceKeys.EDIT_MAP_SERVICE_ACCES_POINT, editMapServiceAccessPoint); - getPreferenceStore().setValue(IPreferenceKeys.SHOULD_CONNECT_AT_STARTUP, shouldConnectAtStartup); - getPreferenceStore().setValue(IPreferenceKeys.SHOULD_EXPAND_SECTION_WHEN_DATA_AVAILABLE, shouldExpandSectionWhenDataAvailable); - getPreferenceStore().setValue(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES, shouldShowExperimentalFeatures); - - return super.performOk(); - } - } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java index 3417e3704..b0492bf84 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java @@ -1,11 +1,11 @@ /** -* Copyright (C) 2007 EDIT -* European Distributed Institute of Taxonomy -* 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. -*/ + * Copyright (C) 2007 EDIT + * European Distributed Institute of Taxonomy + * 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. + */ package eu.etaxonomy.taxeditor.store; @@ -36,86 +36,94 @@ import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart; /** - * This implementation of ICdmDataRepository depends on hibernate sessions to store the data correctly - * for the current session. No state is held in this class. - * - * Only methods that either get or manipulate data are exposed here. So this class acts as a facade - * for the methods in cdmlib-service. - * + * This implementation of ICdmDataRepository depends on hibernate sessions to + * store the data correctly for the current session. No state is held in this + * class. + * + * Only methods that either get or manipulate data are exposed here. So this + * class acts as a facade for the methods in cdmlib-service. + * * @author n.hoffmann * @created 17.03.2009 * @version 1.0 */ -public class CdmStore{ - - private static final Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource("/eu/etaxonomy/cdm/editorApplicationContext.xml", TaxeditorStorePlugin.class); +public class CdmStore { + + private static final Resource DEFAULT_APPLICATION_CONTEXT = new ClassPathResource( + "/eu/etaxonomy/cdm/editorApplicationContext.xml", + TaxeditorStorePlugin.class); private static final DbSchemaValidation DEFAULT_DB_SCHEMA_VALIDATION = DbSchemaValidation.VALIDATE; - + private static CdmStore instance; - - private CdmApplicationController applicationController; - - private static LoginManager loginManager; - - private static ImportManager importManager; - - private static ExportManager exportManager; - - private static ContextManager contextManager; - + + private final CdmApplicationController applicationController; + + private static LoginManager loginManager = new LoginManager(); + + private static ContextManager contextManager = new ContextManager();; + private static TermManager termManager = new TermManager(); - - private static SearchManager searchManager; - - private static EditorManager editorManager; - + + private static SearchManager searchManager = new SearchManager(); + + private static EditorManager editorManager = new EditorManager(); + private static CdmStoreConnector job; - + private Language language; - + private ICdmDataSource cdmDatasource; - + private boolean isConnected; - + /** - *

getDefault

- * + *

+ * getDefault + *

+ * * @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object. */ - protected static CdmStore getDefault(){ - if(instance != null && instance.isConnected){ + protected static CdmStore getDefault() { + if (instance != null && instance.isConnected) { return instance; - }else if(instance == null || !instance.isConnected){ - - StoreUtil.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."); - + } else if (instance == null || !instance.isConnected) { + + StoreUtil + .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."); + StoreUtil.showView(CdmDataSourceViewPart.ID); - - } - + + } + throw new RuntimeException(); } - + /** * Initialize the with the last edited datasource */ public static void connect() { - - ICdmDataSource datasource = CdmDataSourceRepository.getCurrentDataSource(); - + + ICdmDataSource datasource = CdmDataSourceRepository + .getCurrentDataSource(); + connect(datasource); } - + /** * Initialize with a specific datasource - * - * @param datasource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object. + * + * @param datasource + * a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object. */ public static void connect(ICdmDataSource datasource) { - connect(datasource, DEFAULT_DB_SCHEMA_VALIDATION, DEFAULT_APPLICATION_CONTEXT); + connect(datasource, DEFAULT_DB_SCHEMA_VALIDATION, + DEFAULT_APPLICATION_CONTEXT); } - + /** * Initialize and provide * @@ -123,36 +131,42 @@ public class CdmStore{ * @param dbSchemaValidation * @param applicationContextBean */ - private static void connect(final ICdmDataSource datasource, final DbSchemaValidation dbSchemaValidation, final Resource applicationContextBean){ + private static void connect(final ICdmDataSource datasource, + final DbSchemaValidation dbSchemaValidation, + final Resource applicationContextBean) { StoreUtil.info("Connecting to datasource: " + datasource); - - job = new CdmStoreConnector(Display.getDefault(), datasource, dbSchemaValidation, applicationContextBean); + + job = new CdmStoreConnector(Display.getDefault(), datasource, + dbSchemaValidation, applicationContextBean); job.setUser(true); job.setPriority(Job.BUILD); job.schedule(); - + } - public static boolean isConnecting(){ + public static boolean isConnecting() { return job != null && job.getState() == Job.RUNNING; } /** * Closes the current application context - * - * @param monitor a {@link org.eclipse.core.runtime.IProgressMonitor} object. + * + * @param monitor + * a {@link org.eclipse.core.runtime.IProgressMonitor} object. */ - public static void close(final IProgressMonitor monitor){ - Display.getDefault().asyncExec(new Runnable(){ - /* (non-Javadoc) + public static void close(final IProgressMonitor monitor) { + Display.getDefault().asyncExec(new Runnable() { + /* + * (non-Javadoc) + * * @see java.lang.Runnable#run() */ @Override public void run() { getContextManager().notifyContextAboutToStop(monitor); - if((monitor == null || (!monitor.isCanceled()) && isActive())){ + if ((monitor == null || (!monitor.isCanceled()) && isActive())) { getContextManager().notifyContextStop(monitor); - if(instance.getApplicationController() != null){ + if (instance.getApplicationController() != null) { instance.getApplicationController().close(); } instance.close(); @@ -165,38 +179,44 @@ public class CdmStore{ isConnected = false; cdmDatasource = null; } - - static void setInstance(CdmApplicationController applicationController, ICdmDataSource dataSource){ + + static void setInstance(CdmApplicationController applicationController, + ICdmDataSource dataSource) { instance = new CdmStore(applicationController, dataSource); } - - private CdmStore(CdmApplicationController applicationController, ICdmDataSource dataSource){ + + private CdmStore(CdmApplicationController applicationController, + ICdmDataSource dataSource) { this.applicationController = applicationController; this.cdmDatasource = dataSource; isConnected = true; } - + /** - * All calls to the datastore require + * All calls to the datastore require * * @return */ - private CdmApplicationController getApplicationController(){ - try{ + private CdmApplicationController getApplicationController() { + try { return applicationController; - }catch(Exception e){ + } catch (Exception e) { StoreUtil.error(CdmStore.class, e); } return null; } - + /** - *

getCurrentApplicationController

- * - * @return a {@link eu.etaxonomy.cdm.api.application.CdmApplicationController} object. + *

+ * getCurrentApplicationController + *

+ * + * @return a + * {@link eu.etaxonomy.cdm.api.application.CdmApplicationController} + * object. */ - public static CdmApplicationController getCurrentApplicationController(){ - if(getDefault() != null){ + public static CdmApplicationController getCurrentApplicationController() { + if (getDefault() != null) { return getDefault().getApplicationController(); } return null; @@ -207,39 +227,42 @@ public class CdmStore{ */ /** - * Creates a new conversation, binds resources to the conversation and - * start a transaction for this conversation. - * - * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. + * Creates a new conversation, binds resources to the conversation and start + * a transaction for this conversation. + * + * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} + * object. */ public static ConversationHolder createConversation() { - ConversationHolder conversation = getCurrentApplicationController().NewConversation(); - + ConversationHolder conversation = getCurrentApplicationController() + .NewConversation(); + conversation.startTransaction(); return conversation; } - + /** - * Generic method that will return an implementation of the given service interface - * or null if the + * Generic method that will return an implementation of the given service + * interface or null if the * * @param * @param serviceClass * @return */ - public static T getService(Class serviceClass){ - ICdmApplicationConfiguration controller = getCurrentApplicationController(); - - Method[] methods = ICdmApplicationConfiguration.class.getDeclaredMethods(); - + public static T getService(Class serviceClass) { + ICdmApplicationConfiguration configuration = getCurrentApplicationController(); + + Method[] methods = ICdmApplicationConfiguration.class + .getDeclaredMethods(); + T service = null; - - for(Method method : methods){ + + for (Method method : methods) { Type type = method.getGenericReturnType(); - - if(type.equals(serviceClass)){ + + if (type.equals(serviceClass)) { try { - service = (T) method.invoke(controller, null); + service = (T) method.invoke(configuration, null); break; } catch (IllegalArgumentException e) { StoreUtil.error(CdmStore.class, e); @@ -250,51 +273,65 @@ public class CdmStore{ } } } - + return service; } - + /** - *

getAuthenticationManager

- * - * @return a {@link org.springframework.security.authentication.ProviderManager} object. + *

+ * getAuthenticationManager + *

+ * + * @return a + * {@link org.springframework.security.authentication.ProviderManager} + * object. */ - public static ProviderManager getAuthenticationManager() { return getCurrentApplicationController().getAuthenticationManager();} - + public static ProviderManager getAuthenticationManager() { + return getCurrentApplicationController().getAuthenticationManager(); + } + /** - *

getGeoService

- * + *

+ * getGeoService + *

+ * * @return a {@link eu.etaxonomy.cdm.ext.geo.IEditGeoService} object. */ - public static IEditGeoService getGeoService(){ - return (IEditGeoService) getCurrentApplicationController().getBean("editGeoService"); + public static IEditGeoService getGeoService() { + return (IEditGeoService) getCurrentApplicationController().getBean( + "editGeoService"); } - + /* * LANGUAGE */ - + /** - *

getDefaultLanguage

- * + *

+ * getDefaultLanguage + *

+ * * @return a {@link eu.etaxonomy.cdm.model.common.Language} object. */ - public static Language getDefaultLanguage(){ - if(getDefault().getLanguage() == null){ + public static Language getDefaultLanguage() { + if (getDefault().getLanguage() == null) { getDefault().setLanguage(PreferencesUtil.getGlobalLanguage()); } return getDefault().getLanguage(); } /** - *

setDefaultLanguage

- * - * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object. + *

+ * setDefaultLanguage + *

+ * + * @param language + * a {@link eu.etaxonomy.cdm.model.common.Language} object. */ - public static void setDefaultLanguage(Language language){ + public static void setDefaultLanguage(Language language) { getDefault().setLanguage(language); } - + /** * @return the language */ @@ -303,108 +340,100 @@ public class CdmStore{ } /** - * @param language the language to set + * @param language + * the language to set */ private void setLanguage(Language language) { this.language = language; } - + /* * LOGIN */ - + /** - *

Getter for the field loginManager.

- * + *

+ * Getter for the field loginManager. + *

+ * * @return a {@link eu.etaxonomy.taxeditor.store.LoginManager} object. */ - public static LoginManager getLoginManager(){ - if(loginManager == null){ - loginManager = new LoginManager(); - } + public static LoginManager getLoginManager() { return loginManager; } - + /** - *

Getter for the field contextManager.

- * + *

+ * Getter for the field contextManager. + *

+ * * @return a {@link eu.etaxonomy.taxeditor.store.ContextManager} object. */ - public static ContextManager getContextManager(){ - if(contextManager == null){ - contextManager = new ContextManager(); - } + public static ContextManager getContextManager() { return contextManager; } - - public static TermManager getTermManager(){ + + public static TermManager getTermManager() { return termManager; } - - public static SearchManager getSearchManager(){ - if(searchManager == null){ - searchManager = new SearchManager(); - } + + public static SearchManager getSearchManager() { return searchManager; } - + public static EditorManager getEditorManager() { - if(editorManager == null){ - editorManager = new EditorManager(); - } - return editorManager; } - + /* * IMPORT/EXPORT FACTORIES */ - + /** - *

Getter for the field importHandler.

- * + *

+ * Getter for the field importHandler. + *

+ * * @return a {@link eu.etaxonomy.taxeditor.io.ImportManager} object. */ - public static ImportManager getImportManager(){ - if(importManager == null){ - importManager = ImportManager.NewInstance(getCurrentApplicationController()); - } - return importManager; + public static ImportManager getImportManager() { + return ImportManager.NewInstance(getCurrentApplicationController()); } - + /** - *

Getter for the field exportHandler.

- * + *

+ * Getter for the field exportHandler. + *

+ * * @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object. */ - public static ExportManager getExportManager(){ - if(exportManager == null){ - exportManager = ExportManager.NewInstance(getCurrentApplicationController()); - } - return exportManager; + public static ExportManager getExportManager() { + return ExportManager.NewInstance(getCurrentApplicationController()); } - + /** * Whether this CdmStore is currently connected to a datasource - * + * * @return a boolean. */ - public static boolean isActive(){ + public static boolean isActive() { return instance != null && instance.isConnected; } /** - *

getDataSource

- * + *

+ * getDataSource + *

+ * * @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object. */ - public static ICdmDataSource getDataSource(){ - if(isActive()){ + public static ICdmDataSource getDataSource() { + if (isActive()) { return instance.getDatasource(); } return null; } - + /** * @return */ -- 2.34.1