private static CdmStore instance;
- //private final ICdmRepository applicationConfiguration;
-
private static ContextManager contextManager = new ContextManager();
private static LoginManager loginManager = new LoginManager();
private boolean isConnected;
-
-
- /**
- * @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object.
- */
protected static CdmStore getDefault(boolean connecting){
if (instance != null && instance.isConnected) {
return instance;
}
}
- /**
- * <p>
- * getDefault
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object.
- */
protected static CdmStore getDefault(){
return getDefault(false);
}
/**
* Initialize the with the last edited datasource
+ * @deprecated this method is not needed anymore after fully changing to remoting.
+ * Therefore it will be removed
*/
+ @Deprecated
public static void connect() {
-
- ICdmSource cdmSource;
try {
-
- cdmSource = CdmDataSourceRepository.getCurrentCdmSource();
+ ICdmSource cdmSource = CdmDataSourceRepository.getCurrentCdmSource();
connect(cdmSource);
} catch (Exception e) {
MessagingUtils.messageDialog("Connection to CDM Source Failed", CdmStore.class, "Could not connect to target CDM Source", e);
}
-
-
}
/**
job.setUser(true);
job.setPriority(Job.BUILD);
job.schedule();
-
}
private static void connect(final ICdmSource cdmSource,
instance.close();
}
}
-
}
+
private void close() {
- isConnected = false;
- cdmSource = null;
+ this.isConnected = false;
+ this.cdmSource = null;
CdmApplicationState.dispose();
}
ICdmSource cdmSource) {
instance = new CdmStore(applicationController, cdmSource);
CdmApplicationState.setCdmServiceCacher(new CdmServiceCacher());
-
}
private CdmStore(ICdmRepository repository,
return null;
}
- /**
- * <p>
- * getCurrentApplicationController
- * </p>
- *
- * @return a
- * {@link eu.etaxonomy.cdm.remote.api.application.CdmApplicationController}
- * object.
- */
public static ICdmRepository getCurrentApplicationConfiguration() {
if (getDefault() != null) {
return getDefault().getApplicationConfiguration();
return getCurrentSessionManager(false);
}
-
public static ICdmEntitySessionManager getCurrentSessionManager(boolean connecting) {
if (getDefault(connecting) != null) {
return getDefault(connecting).getSessionManager();
}
return null;
-
}
/**
return getCurrentApplicationConfiguration().getPermissionEvaluator();
}
-
/*
* SECURITY RELATED CONVENIENCE METHODS
*/
return getDefault().getLanguage();
}
- /**
- * <p>
- * setDefaultLanguage
- * </p>
- *
- * @param language
- * a {@link eu.etaxonomy.cdm.model.common.Language} object.
- */
public static void setDefaultLanguage(Language language) {
getDefault().setLanguage(language);
}
- /**
- * @return the language
- */
private Language getLanguage() {
return language;
}
- /**
- * @param language
- * the language to set
- */
private void setLanguage(Language language) {
this.language = language;
}
* LOGIN
*/
- /**
- * <p>
- * Getter for the field <code>loginManager</code>.
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.store.LoginManager} object.
- */
public static LoginManager getLoginManager() {
return loginManager;
}
- /**
- * <p>
- * Getter for the field <code>contextManager</code>.
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.store.ContextManager} object.
- */
public static ContextManager getContextManager() {
return contextManager;
}
* IMPORT/EXPORT FACTORIES
*/
- /**
- * <p>
- * Getter for the field <code>importHandler</code>.
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.io.ImportManager} object.
- */
public static ImportManager getImportManager() {
return ImportManager.NewInstance(getCurrentApplicationConfiguration());
}
- /**
- * <p>
- * Getter for the field <code>exportHandler</code>.
- * </p>
- *
- * @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object.
- */
public static ExportManager getExportManager() {
return ExportManager.NewInstance(getCurrentApplicationConfiguration());
}
return null;
}
- /**
- * <p>
- * getDataSource
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
- * @deprecated currently retained for backward compatibility - use {@link getActiveCdmSource()} instead
- */
- // public static ICdmDataSource getDataSource() {
- // if (isActive()) {
- // return (ICdmDataSource)instance.getCdmSource();
- // }
- // return null;
- // }
-
- /**
- * @return
- */
private ICdmSource getCdmSource() {
return cdmSource;
}
-
@SuppressWarnings("unchecked")
public static <T extends CdmBase> IService<T> getService(T cdmBase){
IService<T> service = null;
*/
package eu.etaxonomy.taxeditor.ui.dialog.selection;
- import java.util.UUID;
+import java.util.UUID;
import org.eclipse.swt.widgets.Shell;
-import eu.etaxonomy.cdm.api.application.ICdmRepository;
import eu.etaxonomy.cdm.api.service.IReferenceService;
+import eu.etaxonomy.cdm.config.ICdmSource;
import eu.etaxonomy.cdm.model.agent.Person;
import eu.etaxonomy.cdm.model.agent.Team;
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
-import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
import eu.etaxonomy.taxeditor.newWizard.NewReferenceWizard;
import eu.etaxonomy.taxeditor.remoting.source.CdmServerInfo;
-import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
import eu.etaxonomy.taxeditor.store.CdmStore;
-
/**
* @author k.luther
* @date 02.05.2017
*/
public class ExtReferenceSelectionDialog extends
- AbstractFilteredCdmResourceSelectionDialog<Reference> {
-
- protected static boolean isInReference = false;
- private Reference currentReference;
- ICdmRepository controller;
- ICdmRemoteSource remoteSource ;
- Reference remoteSourceRef;
- IReferenceService service = null;
-
-
- /**
- * <p>select</p>
- *
- * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
- * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
- * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
- * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
- */
- public static Reference select(Shell shell, //ConversationHolder conversation,
- Reference reference, boolean isInReference) {
- ExtReferenceSelectionDialog dialog = new ExtReferenceSelectionDialog(shell, //conversation,
- "Choose a reference", false, reference, isInReference);
- return getSelectionFromDialog(dialog);
- }
-
- /**
- * <p>select</p>
- *
- * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
- * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
- * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
- * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
- */
- public static Reference select(Shell shell, //ConversationHolder conversation,
- Reference reference) {
- ExtReferenceSelectionDialog dialog = new ExtReferenceSelectionDialog(shell, //conversation,
- "Choose a reference", false, reference);
- return getSelectionFromDialog(dialog);
- }
-
-
-
-
+ AbstractFilteredCdmResourceSelectionDialog<Reference> {
+
+ protected static boolean isInReference = false;
+ private Reference currentReference;
+ private ICdmSource remoteSource ;
+ private Reference remoteSourceRef;
+ private IReferenceService service = null;
+
+ /**
+ * <p>select</p>
+ *
+ * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
+ * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
+ * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
+ * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
+ */
+ public static Reference select(Shell shell, //ConversationHolder conversation,
+ Reference reference, boolean isInReference) {
+ ExtReferenceSelectionDialog dialog = new ExtReferenceSelectionDialog(shell, //conversation,
+ "Choose a reference", false, reference, isInReference);
+ return getSelectionFromDialog(dialog);
+ }
+ /**
+ * <p>select</p>
+ *
+ * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
+ * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
+ * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
+ * @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
+ */
+ public static Reference select(Shell shell, //ConversationHolder conversation,
+ Reference reference) {
+ ExtReferenceSelectionDialog dialog = new ExtReferenceSelectionDialog(shell, //conversation,
+ "Choose a reference", false, reference);
+ return getSelectionFromDialog(dialog);
+ }
- /**
- * <p>Constructor for FilteredReferenceSelectionDialog.</p>
- *
- * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
- * @param title a {@link java.lang.String} object.
- * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
- * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
- * @param multi a boolean.
- */
- protected ExtReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
- String title, boolean multi, Reference reference) {
- super(shell, //conversation,
- title, multi, ExtReferenceSelectionDialog.class.getCanonicalName());
- this.currentReference = reference;
+ /**
+ * <p>Constructor for FilteredReferenceSelectionDialog.</p>
+ *
+ * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
+ * @param title a {@link java.lang.String} object.
+ * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
+ * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
+ * @param multi a boolean.
+ */
+ protected ExtReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
+ String title, boolean multi, Reference reference) {
+ super(shell, //conversation,
+ title, multi, ExtReferenceSelectionDialog.class.getCanonicalName());
+ this.currentReference = reference;
// controller = CdmStore.getCurrentApplicationConfiguration();
- remoteSource = CdmServerInfo.getDevServerRemoteSource();
- remoteSourceRef = ReferenceFactory.newDatabase();
- remoteSourceRef.setTitle(remoteSource.getName());
- }
-
-
-
+ remoteSource = CdmServerInfo.getDevServerRemoteSource();
+ remoteSourceRef = ReferenceFactory.newDatabase();
+ remoteSourceRef.setTitle(remoteSource.getName());
+ }
- /**
- * <p>Constructor for FilteredReferenceSelectionDialog.</p>
- *
- * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
- * @param title a {@link java.lang.String} object.
- * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
- * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
- * @param multi a boolean.
- */
- protected ExtReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
- String title, boolean multi, Reference reference, boolean isInReference) {
- super(shell, //conversation,
- title, multi, ExtReferenceSelectionDialog.class.getCanonicalName());
- this.isInReference = isInReference;
- this.currentReference = reference;
+ /**
+ * <p>Constructor for FilteredReferenceSelectionDialog.</p>
+ *
+ * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
+ * @param title a {@link java.lang.String} object.
+ * @param reference a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
+ * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
+ * @param multi a boolean.
+ */
+ protected ExtReferenceSelectionDialog(Shell shell, //ConversationHolder conversation,
+ String title, boolean multi, Reference reference, boolean isInReference) {
+ super(shell, //conversation,
+ title, multi, ExtReferenceSelectionDialog.class.getCanonicalName());
+ ExtReferenceSelectionDialog.isInReference = isInReference;
+ this.currentReference = reference;
// controller = CdmStore.getCurrentApplicationConfiguration();
// CdmServerInfoConfig parameterObject = new CdmServerInfoConfig("localhost", "localhost", 8080, "cdmserver/", true);
// CdmInstanceInfo selectedCdmInstance = selectedCsii.getInstanceFromName("local-cuba") ;
// Integer port;
// remoteSource = selectedCsii.getCdmRemoteSource(selectedCdmInstance, 80);
+ }
+ @Override
+ protected Reference getPersistentObject(UUID cdmUuid) {
+ Reference extRef = service.load(cdmUuid);
+ Reference newRef = ReferenceFactory.newReference( extRef.getType());
+ if (extRef.getTitle() != null){
+ newRef.setTitle(extRef.getTitle());
+ }else{
+ newRef.setTitleCache(extRef.getTitleCache(), true);
+ }
+ if (extRef.getAbbrevTitle() != null){
+ newRef.setAbbrevTitle(extRef.getAbbrevTitle());
+ }else{
+ newRef.setAbbrevTitleCache(extRef.getAbbrevTitleCache(), true);
}
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
- */
- /** {@inheritDoc} */
- @Override
- protected Reference getPersistentObject(UUID cdmUuid) {
- Reference extRef = service.load(cdmUuid);
-
- Reference newRef = ReferenceFactory.newReference( extRef.getType());
- if (extRef.getTitle() != null){
- newRef.setTitle(extRef.getTitle());
+ if (extRef.getInReference() != null){
+ Reference inRef = extRef.getInReference();
+ Reference newRefInRef = ReferenceFactory.newReference( extRef.getInBook().getType());
+ if (inRef.getTitle() != null){
+ newRefInRef.setTitle(inRef.getTitle());
}else{
- newRef.setTitleCache(extRef.getTitleCache(), true);
+ newRefInRef.setTitleCache(inRef.getTitleCache(), true);
}
- if (extRef.getAbbrevTitle() != null){
- newRef.setAbbrevTitle(extRef.getAbbrevTitle());
+ if (inRef.getAbbrevTitle() != null){
+ newRefInRef.setAbbrevTitle(inRef.getAbbrevTitle());
}else{
- newRef.setAbbrevTitleCache(extRef.getAbbrevTitleCache(), true);
+ newRefInRef.setAbbrevTitleCache(inRef.getAbbrevTitleCache(), true);
}
+ newRefInRef.addSource(OriginalSourceType.Other, String.valueOf(newRefInRef.getId()), "Reference", remoteSourceRef, null);
+ newRef.setInReference(newRefInRef);
+ newRef.setProtectedTitleCache(false);
+ newRef.setProtectedAbbrevTitleCache(false);
+ newRef.addSource(OriginalSourceType.Other, String.valueOf(newRef.getId()), "Reference", remoteSourceRef, null);
+ }
+ TeamOrPersonBase<?> author;
+ if (extRef.getAuthorship() != null){
+ if (extRef.getAuthorship() instanceof Person){
+ author = Person.NewTitledInstance(extRef.getAuthorship().getTitleCache());
+ author.setProtectedTitleCache(true);
+ }else{
+ author = Team.NewInstance();
+ Person newMember;
- if (extRef.getInReference() != null){
- Reference inRef = extRef.getInReference();
- Reference newRefInRef = ReferenceFactory.newReference( extRef.getInBook().getType());
- if (inRef.getTitle() != null){
- newRefInRef.setTitle(inRef.getTitle());
- }else{
- newRefInRef.setTitleCache(inRef.getTitleCache(), true);
- }
- if (inRef.getAbbrevTitle() != null){
- newRefInRef.setAbbrevTitle(inRef.getAbbrevTitle());
- }else{
- newRefInRef.setAbbrevTitleCache(inRef.getAbbrevTitleCache(), true);
- }
- newRefInRef.addSource(OriginalSourceType.Other, String.valueOf(newRefInRef.getId()), "Reference", remoteSourceRef, null);
- newRef.setInReference(newRefInRef);
- newRef.setProtectedTitleCache(false);
- newRef.setProtectedAbbrevTitleCache(false);
- newRef.addSource(OriginalSourceType.Other, String.valueOf(newRef.getId()), "Reference", remoteSourceRef, null);
- }
- TeamOrPersonBase author;
- if (extRef.getAuthorship() != null){
- if (extRef.getAuthorship() instanceof Person){
- author = Person.NewTitledInstance(extRef.getAuthorship().getTitleCache());
- author.setProtectedTitleCache(true);
- }else{
- author = Team.NewInstance();
- Person newMember;
-
- for (Person member:((Team)extRef.getAuthorship()).getTeamMembers()){
- newMember = Person.NewTitledInstance(member.getTitleCache());
- ((Team)author).addTeamMember(newMember);
- }
-
- }
- newRef.setAuthorship(author);
+ for (Person member:((Team)extRef.getAuthorship()).getTeamMembers()){
+ newMember = Person.NewTitledInstance(member.getTitleCache());
+ ((Team)author).addTeamMember(newMember);
+ }
}
-
- newRef = CdmStore.getService(IReferenceService.class).save(newRef);
-
- return newRef;
+ newRef.setAuthorship(author);
}
+ newRef = CdmStore.getService(IReferenceService.class).save(newRef);
+ return newRef;
+ }
- /** {@inheritDoc} */
- @Override
- protected void callService(String pattern) {
-
+ @Override
+ protected void callService(String pattern) {
- if (remoteSource != null){
+ if (remoteSource != null){
// if (service == null){
// service = CdmApplicationRemoteConfiguration.getExtReferenceService(remoteSource);
// }
- if (pattern.equals("?")){ //$NON-NLS-1$
- if (isInReference && currentReference != null){
- model = service.getUuidAndTitleCache(null, null, currentReference.getType());
- }else{
- model = service.getUuidAndTitleCache(null, null);
- }
+ if (pattern.equals("?")){ //$NON-NLS-1$
+ if (isInReference && currentReference != null){
+ model = service.getUuidAndTitleCache(null, null, currentReference.getType());
}else{
- if (isInReference && currentReference != null){
- model = service.getUuidAndTitleCache(limitOfInitialElements, pattern, currentReference.getType());
- }else{
- model = service.getUuidAndTitleCache(limitOfInitialElements,pattern);
-
- }
+ model = service.getUuidAndTitleCache(null, null);
}
- }
- }
-
-
- /** {@inheritDoc} */
- @Override
- protected String getTitle(Reference cdmObject) {
- if(cdmObject == null){
- return "";
}else{
- return super.getTitle(cdmObject);
+ if (isInReference && currentReference != null){
+ model = service.getUuidAndTitleCache(limitOfInitialElements, pattern, currentReference.getType());
+ }else{
+ model = service.getUuidAndTitleCache(limitOfInitialElements,pattern);
+ }
}
+ }
+ }
+
+ @Override
+ protected String getTitle(Reference cdmObject) {
+ if(cdmObject == null){
+ return "";
+ }else{
+ return super.getTitle(cdmObject);
+ }
// }else{
// return DefaultReferenceCacheStrategy.putAuthorToEndOfString(cdmObject.getTitleCache(), cdmObject.getAuthorship().getTitleCache());
// }
- }
-
- /** {@inheritDoc} */
- @Override
- protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
- return new NewReferenceWizard();
- }
-
- /** {@inheritDoc} */
- @Override
- protected String[] getNewWizardText() {
- return new String[]{"Reference "};
- }
-
}
+ @Override
+ protected NewReferenceWizard getNewEntityWizard(String parameter) {
+ return new NewReferenceWizard();
+ }
+ @Override
+ protected String[] getNewWizardText() {
+ return new String[]{"Reference "};
+ }
+}