package eu.etaxonomy.taxeditor.bulkeditor.handler;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import eu.etaxonomy.taxeditor.annotatedlineeditor.LineAnnotationModel;
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
+import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.store.CdmStore;
LineAnnotation annotation = (LineAnnotation) model.getAnnotation(object);
DeleteResult result = new DeleteResult();
+ String errorMessage= "The object ";
//result.setError();
try {
ICdmApplicationConfiguration controller;
IOccurrenceService service = controller.getOccurrenceService();
if (object != null){
result = service.delete(((SpecimenOrObservationBase) object).getUuid());
+ errorMessage = "The specimen or observation ";
}
} else if (object instanceof Reference){
IReferenceService service = controller.getReferenceService();
if (object != null){
result = service.delete(((Reference) object).getUuid());
+ errorMessage = "The reference ";
}
} else if (object instanceof Group){
IGroupService service = controller.getGroupService();
if (object != null){
result = service.delete(((Group) object).getUuid());
+ errorMessage = "The group ";
}
}else if (object instanceof User){
IUserService service = controller.getUserService();
if (object != null){
result = service.delete(((User) object).getUuid());
+ errorMessage = "The user ";
}
} else if (object instanceof TaxonNameBase){
INameService service = controller.getNameService();
if (object != null){
NameDeletionConfigurator config = new NameDeletionConfigurator();
result = service.delete(((TaxonNameBase) object).getUuid(), config);
+ errorMessage = "The name ";
}
} else if (object instanceof TaxonBase){
ITaxonService service = controller.getTaxonService();
if (object != null){
if (object instanceof Taxon){
result = service.deleteTaxon(((TaxonBase) object).getUuid(), null, null);
+ errorMessage = "The taxon ";
}else{
result = service.deleteSynonym(((Synonym)object).getUuid(), null);
+ errorMessage = "The synonym ";
}
}
} else if (object instanceof TeamOrPersonBase){
IAgentService service = controller.getAgentService();
//TeamOrPersonBase teamOrPerson = (TeamOrPersonBase)service.load(((TeamOrPersonBase) object).getUuid());
result = service.delete(((TeamOrPersonBase)object).getUuid());
+ errorMessage = "The team or person ";
}
} catch (Exception e){
MessagingUtils.errorDialog("Exception occured. Delete not possible", getClass(), e.getMessage(), TaxeditorBulkeditorPlugin.PLUGIN_ID, null, true);
}
if (result.isError() || result.isAbort()){
if (!result.getExceptions().isEmpty()) {
- String message = null;
+ List<String> messages = new ArrayList<String>();
int i = result.getExceptions().size();
for (Exception e:result.getExceptions()){
- i--;
- message+= e.getMessage();
- if (i>0){
- message+= ", ";
- }
+ messages.add(e.getMessage());
}
+ errorMessage += "could not be deleted.";
-
- MessagingUtils.messageDialog("Delete not possible", getClass(), result.getExceptions().toString(), null);
+ DeleteResultMessagingUtils.messageDialogWithDetails(result,errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
}else{
MessagingUtils.messageDialog("Delete not possible", getClass(), "The object could not be deleted. An exception occured.", null);
}
if (result.isOk() ){
((BulkEditor) editor).removeAnnotatedLine(annotation);
if(result.getUpdatedObjects().size() != 0 || !result.getExceptions().isEmpty()){
- MessagingUtils.informationDialog("Delete successfull", "The object is deleted but there are updated objects: " + result.toString());
+ List<String> messages = new ArrayList<String>();
+ int i = result.getExceptions().size();
+ for (Exception e:result.getExceptions()){
+ messages.add(e.getMessage());
+ }
+ errorMessage += "was deleted but there where updated objects";
+ DeleteResultMessagingUtils.messageDialogWithDetails(result, errorMessage, TaxeditorBulkeditorPlugin.PLUGIN_ID);
}
}
@Override
public TeamOrPersonBase save(TeamOrPersonBase entity) {
if(CdmStore.getCurrentSessionManager().isRemoting()) {
- return (TeamOrPersonBase) CdmStore.getService(IAgentService.class).merge(entity);
+ return (TeamOrPersonBase) CdmStore.getService(IAgentService.class).merge(entity, true);
} else {
CdmStore.getService(IAgentService.class).saveOrUpdate(entity) ;
return entity;
@Override
public Group save(Group entity) {
if(CdmStore.getCurrentSessionManager().isRemoting()) {
- return CdmStore.getService(IGroupService.class).merge(entity) ;
+ return CdmStore.getService(IGroupService.class).merge(entity, true) ;
} else {
CdmStore.getService(IGroupService.class).saveOrUpdate(entity);
return entity;
@Override
public TaxonNameBase save(TaxonNameBase entity) {
if(CdmStore.getCurrentSessionManager().isRemoting()) {
- return CdmStore.getService(INameService.class).merge(entity) ;
+ return CdmStore.getService(INameService.class).merge(entity, true) ;
} else {
CdmStore.getService(INameService.class).saveOrUpdate(entity);
return entity;
@Override
public SpecimenOrObservationBase<IIdentifiableEntityCacheStrategy> save(SpecimenOrObservationBase entity) {
if(CdmStore.getCurrentSessionManager().isRemoting()) {
- return CdmStore.getService(IOccurrenceService.class).merge(entity) ;
+ return CdmStore.getService(IOccurrenceService.class).merge(entity, true) ;
} else {
CdmStore.getService(IOccurrenceService.class).save(entity);
return entity;
@Override
public Reference save(Reference entity) {
if(CdmStore.getCurrentSessionManager().isRemoting()) {
- return CdmStore.getService(IReferenceService.class).merge(entity);
+ return CdmStore.getService(IReferenceService.class).merge(entity, true);
} else {
CdmStore.getService(IReferenceService.class).saveOrUpdate(entity);
return entity;
@Override\r
public TaxonBase save(TaxonBase entity) {\r
if(CdmStore.getCurrentSessionManager().isRemoting()) {\r
- return CdmStore.getService(ITaxonService.class).merge(entity);\r
+ return CdmStore.getService(ITaxonService.class).merge(entity, true);\r
} else {\r
CdmStore.getService(ITaxonService.class).saveOrUpdate(entity);\r
return entity;\r
@Override
public User save(User entity) {
if(CdmStore.getCurrentSessionManager().isRemoting()) {
- return CdmStore.getService(IUserService.class).merge(entity);
+ return CdmStore.getService(IUserService.class).merge(entity, true);
} else {
CdmStore.getService(IUserService.class).saveOrUpdate(entity);
return entity;
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
import eu.etaxonomy.taxeditor.model.DescriptionHelper;
import eu.etaxonomy.taxeditor.model.LineSelection;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart;
private String referencedObjectTitleCache;
private ConversationHolder conversation;
+ private ICdmEntitySession cdmEntitySession;
+
+ public ReferencingObjectsView() {
+ cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
+ }
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createViewer(org.eclipse.swt.widgets.Composite)
viewer.setColumnProperties(titles);
}
+ @Override
+ public void setFocus() {
+ cdmEntitySession.bind();
+ }
/**
* <p>updateReferencingObjects</p>
*
@Override
public void run() {
if (entityUUID != null){
-
+ ICdmEntitySession previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
+ cdmEntitySession.bind();
List<CdmBase> referencingObjects = getReferencingObjects(entityUUID, objectClass);
-
+ if(previousCdmEntitySession != null) {
+ previousCdmEntitySession.bind();
+ }
updateView(referencingObjects);
}
conversation.close();
selectionService.removePostSelectionListener(this);
selectionService.removeSelectionListener(this);
+ cdmEntitySession.dispose();
super.dispose();
}
import eu.etaxonomy.cdm.api.service.IService;
import eu.etaxonomy.cdm.api.service.ITestService;
import eu.etaxonomy.cdm.io.service.IIOService;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.taxeditor.service.ICachedCommonService;
+import eu.etaxonomy.taxeditor.session.DefaultNewEntityListener;
/**
* @author cmathew
public static CdmApplicationState getInstance() {
if(cdmApplicationState == null) {
cdmApplicationState = new CdmApplicationState();
+ CdmBase.setNewEntityListener(new DefaultNewEntityListener());
}
return cdmApplicationState;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
private final CacheLoader cacheLoader;
-
+ private final Map<UUID, CdmBase> newEntitiesMap = new HashMap<UUID, CdmBase>();
public CdmTransientEntityCacher(String cacheId, ICdmEntitySessionManager cdmEntitySessionManager) {
this.cacheId = cacheId;
this.cdmEntitySessionManager = cdmEntitySessionManager;
cacheLoader = new CacheLoader(this);
+
}
public CdmTransientEntityCacher(Object sessionOwner, ICdmEntitySessionManager cdmEntitySessionManager) {
*/
private CacheConfiguration getEntityCacheConfiguration(String cacheId) {
SizeOfPolicyConfiguration sizeOfConfig = new SizeOfPolicyConfiguration();
- sizeOfConfig.setMaxDepth(10000);
+ sizeOfConfig.setMaxDepth(100);
sizeOfConfig.setMaxDepthExceededBehavior("abort");
return new CacheConfiguration(cacheId, 0)
}
-
+ public void addNewEntity(CdmBase newEntity) {
+ if(newEntity != null && newEntity.getId() == 0 && newEntity.getUuid() != null) {
+ newEntitiesMap.put(newEntity.getUuid(), newEntity);
+ }
+ }
@Override
public void put(CdmBase cdmEntity) {
cachedCdmEntity = getFromCache(id);
if(cachedCdmEntity == null) {
- getCache().put(new Element(id, cdmEntity));
- cdmEntity.initListener();
- logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " put in cache");
+ CdmBase cdmEntityToCache = cdmEntity;
+ CdmBase newEntity = newEntitiesMap.get(cdmEntity.getUuid());
+ if(newEntity != null) {
+ newEntity.setId(cdmEntity.getId());
+ cdmEntityToCache = newEntity;
+ }
+ getCache().put(new Element(id, cdmEntityToCache));
+ cdmEntityToCache.initListener();
+ newEntitiesMap.remove(cdmEntity.getUuid());
+ logger.info(" - object of type " + cdmEntityToCache.getClass().getName() + " with id " + cdmEntityToCache.getId() + " put in cache");
return;
}
logger.info(" - object of type " + cdmEntity.getClass().getName() + " with id " + cdmEntity.getId() + " already exists");
public void dispose() {
CacheManager.create().removeCache(cache.getName());
cache.dispose();
+ newEntitiesMap.clear();
}
+
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#load(java.lang.Object, boolean)
*/
*/
@Override
public <T extends CdmBase> T remoteUpdate(IService<T> service, T cdmBase) {
- T mergedCdmBase = service.merge(cdmBase);
+ T mergedCdmBase = service.merge(cdmBase, true);
return mergedCdmBase;
}
return propertyPathsMap.get(obj);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#addNewCdmEntity(eu.etaxonomy.cdm.model.common.CdmBase)
+ */
+ @Override
+ public void addNewCdmEntity(CdmBase newEntity) {
+ cdmTransientEntityCacher.addNewEntity(newEntity);
+ }
+
}
}
@Override
- public ICdmEntitySession bindNullSession(ICdmEntitySessionEnabled sessionOwner) {
+ public ICdmEntitySession bindNullSession() {
if(nullSession == null) {
- nullSession = new NullSession(sessionOwner, this);
- } else {
- nullSession.setOwner(sessionOwner);
+ nullSession = new NullSession(null, this);
}
setActiveSession(nullSession);
setActiveSession(null);
}
ownerSessionMap.remove(owner);
+ notifyObservers();
}
if(session != null) {
session.dispose();
}
- notifyObservers();
+ if(nullSession != null && nullSession.getOwner() == owner) {
+ nullSession = null;
+ }
+
}
+
@Override
public void disposeAll() {
Set<ICdmEntitySessionEnabled> owners =
session.dispose();
}
}
- notifyObservers();
+
}
void addToOwnerSessionMap(ICdmEntitySessionEnabled owner, ICdmEntitySession session) {
ownerSessionMap.put(owner, session);
+ notifyObservers();
}
/* (non-Javadoc)
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 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.session;
+
+import org.apache.log4j.Logger;
+
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.model.NewEntityListener;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+
+/**
+ * @author cmathew
+ * @date 30 Sep 2015
+ *
+ */
+public class DefaultNewEntityListener implements NewEntityListener {
+
+ private static final Logger logger = Logger.getLogger(DefaultNewEntityListener.class);
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.NewEntityListener#onCreate(eu.etaxonomy.cdm.model.common.CdmBase)
+ */
+ @Override
+ public void onCreate(CdmBase cdmBase) {
+ logger.warn("New Entity created : " + cdmBase);
+ if(CdmApplicationState.getCurrentAppConfig() instanceof CdmApplicationRemoteController){
+ ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager().getActiveSession().addNewCdmEntity(cdmBase);
+ }
+ }
+
+}
*/
public List<String> getPropertyPaths(Object obj);
+ public void addNewCdmEntity(CdmBase newEntity);
+
}
\ No newline at end of file
* @param sessionOwner
* @return
*/
- public ICdmEntitySession bindNullSession(ICdmEntitySessionEnabled sessionOwner);
+ public ICdmEntitySession bindNullSession();
public abstract void bind(ICdmEntitySessionEnabled sessionOwner);
*/
public ICdmEntitySession getNullSession();
+
}
\ No newline at end of file
*/
@Override
public void bind() {
- cdmEntitySessionManager.bindNullSession(sessionOwner);
+ cdmEntitySessionManager.bindNullSession();
}
/* (non-Javadoc)
*/
@Override
public <T extends CdmBase> T remoteUpdate(IService<T> service, T cdmBase) {
- T mergedCdmBase = service.merge(cdmBase);
+ T mergedCdmBase = service.merge(cdmBase, true);
return mergedCdmBase;
}
return propertyPathsMap.get(obj);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#addNewCdmEntity(eu.etaxonomy.cdm.model.common.CdmBase)
+ */
+ @Override
+ public void addNewCdmEntity(CdmBase newEntity) {
+ // TODO Auto-generated method stub
+
+ }
+
}
return null;
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySession#addNewCdmEntity(eu.etaxonomy.cdm.model.common.CdmBase)
+ */
+ @Override
+ public void addNewCdmEntity(CdmBase newEntity) {
+ // TODO Auto-generated method stub
+
+ }
+
}
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager#bindNullSession(eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled)
*/
@Override
- public ICdmEntitySession bindNullSession(ICdmEntitySessionEnabled sessionOwner) {
+ public ICdmEntitySession bindNullSession() {
return new MockCdmEntitySession();
}
return new MockCdmEntitySession();
}
-
-
}
CreateDerivateContextMenu_ADD=Add...
CreateDerivateContextMenu_DNA_SAMPLE=DNA Sample
CreateDerivateContextMenu_MEDIA=Media...
-CreateDerivateContextMenu_MEDIA_EXISTING=Media Specimen with existing media
-CreateDerivateContextMenu_MEDIA_SPECIMEN=Media Specimen
+CreateDerivateContextMenu_MEDIA_EXISTING=Use existing media item
+CreateDerivateContextMenu_MEDIA_SPECIMEN=Media item
CreateDerivateContextMenu_NO_CHILD_DERIVATE=No child derivatives
CreateDerivateContextMenu_SEQUENCE=Consensus Sequence
CreateDerivateContextMenu_SINGLE_READ=Single Read
CreateDerivateContextMenu_ADD=Hinzufügen...
CreateDerivateContextMenu_DNA_SAMPLE=DNA Probe
CreateDerivateContextMenu_MEDIA=Media...
-CreateDerivateContextMenu_MEDIA_EXISTING=Medienbeleg aus vorhandender Mediendatei
-CreateDerivateContextMenu_MEDIA_SPECIMEN=Medienbeleg
+CreateDerivateContextMenu_MEDIA_EXISTING=Vorhandendes Medienobjekt verwenden
+CreateDerivateContextMenu_MEDIA_SPECIMEN=Medienobjekt
CreateDerivateContextMenu_NO_CHILD_DERIVATE=Keine Kind-Derivate
CreateDerivateContextMenu_SEQUENCE=Konsensussequenz
CreateDerivateContextMenu_SINGLE_READ=Single Read
@Override
public void merge() {
if(CdmStore.getCurrentSessionManager().isRemoting()) {
- group = CdmStore.getService(IGroupService.class).merge(group);
+ group = CdmStore.getService(IGroupService.class).merge(group, true);
}
}
}
return defaultService.merge(arg0, arg1);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.IService#merge(java.util.List, boolean)
+ */
+ @Override
+ public List<AgentBase> merge(List<AgentBase> arg0, boolean arg1) {
+ return defaultService.merge(arg0, arg1);
+ }
+
}
return defaultService.merge(arg0, arg1);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.IService#merge(java.util.List, boolean)
+ */
+ @Override
+ public List<Classification> merge(List<Classification> arg0, boolean arg1) {
+ return defaultService.merge(arg0, arg1);
+ }
+
}
return defaultService.merge(arg0, arg1);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.IService#merge(java.util.List, boolean)
+ */
+ @Override
+ public List<Collection> merge(List<Collection> arg0, boolean arg1) {
+ return defaultService.merge(arg0, arg1);
+ }
+
}
}
/* (non-Javadoc)
+
* @see eu.etaxonomy.cdm.api.service.IDescriptionService#moveTaxonDescription(java.util.UUID, java.util.UUID)
*/
@Override
public UpdateResult moveTaxonDescription(UUID descriptionUuid, UUID targetTaxonUuid) {
-
return defaultService.moveTaxonDescription(descriptionUuid, targetTaxonUuid);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.IService#merge(java.util.List, boolean)
+ */
+ @Override
+ public List<DescriptionBase> merge(List<DescriptionBase> arg0, boolean arg1) {
+
+ return defaultService.merge(arg0, arg1);
+ }
+
+
+
}
public TaxonNameBase merge(TaxonNameBase arg0, boolean arg1) {
return defaultService.merge(arg0, arg1);
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.IService#merge(java.util.List, boolean)
+ */
+ @Override
+ public List<TaxonNameBase> merge(List<TaxonNameBase> arg0, boolean arg1) {
+ return defaultService.merge(arg0, arg1);
+ }
}
return defaultService.merge(arg0, arg1);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.IService#merge(java.util.List, boolean)
+ */
+ @Override
+ public List<SpecimenOrObservationBase> merge(List<SpecimenOrObservationBase> arg0, boolean arg1) {
+ return defaultService.merge(arg0, arg1);
+ }
+
+ @Override
+ public Pager<Media> getMediainHierarchy(SpecimenOrObservationBase arg0, Integer arg1, Integer arg2,
+ List<String> arg3) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
public Reference merge(Reference arg0, boolean arg1) {
return defaultService.merge(arg0, arg1);
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.IService#merge(java.util.List, boolean)
+ */
+ @Override
+ public List<Reference> merge(List<Reference> arg0, boolean arg1) {
+ return defaultService.merge(arg0, arg1);
+ }
}
return defaultService.merge(arg0, arg1);
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.IService#merge(java.util.List, boolean)
+ */
+ @Override
+ public List<TaxonBase> merge(List<TaxonBase> arg0, boolean arg1) {
+ return defaultService.merge(arg0, arg1);
+ }
+
}
public DefinedTermBase merge(DefinedTermBase arg0, boolean arg1) {
return defaultService.merge(arg0, arg1);
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.service.IService#merge(java.util.List, boolean)
+ */
+ @Override
+ public List<DefinedTermBase> merge(List<DefinedTermBase> arg0, boolean arg1) {
+ return defaultService.merge(arg0, arg1);
+ }
}
@Override
public void merge() {
if(CdmStore.getCurrentSessionManager().isRemoting()) {
- List<SpecimenOrObservationBase> mergedEntities = CdmApplicationState.getCurrentAppConfig().getOccurrenceService().merge(new ArrayList(getRootEntities()));
+ List<SpecimenOrObservationBase> mergedEntities = CdmApplicationState.getCurrentAppConfig().getOccurrenceService().merge(new ArrayList(getRootEntities()), true);
}
}
public void widgetSelected(SelectionEvent e) {
//select media
Media media = MediaSelectionDialog.select(AbstractUtility.getShell(), null, null);
- //create MediaSpecimen
- MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(specimenType);
- mediaSpecimen.setMediaSpecimen(media);
-
- //attach to parent
- if(selectedNode.getValue() instanceof SpecimenOrObservationBase){
- SpecimenOrObservationBase<?> specimenOrObservationBase = (SpecimenOrObservationBase<?>)selectedNode.getValue();
-
- specimenOrObservationBase.addDerivationEvent(DerivationEvent.NewSimpleInstance(specimenOrObservationBase, mediaSpecimen, derivationEventType));
- mediaSpecimen.setCacheStrategy(new DerivedUnitFacadeCacheStrategy());
- mediaSpecimen.getTitleCache(); //update title cache
- CdmStore.getService(IOccurrenceService.class).merge(specimenOrObservationBase);
- }
+ if(media!=null){
+ //create MediaSpecimen
+ MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(specimenType);
+ mediaSpecimen.setMediaSpecimen(media);
- //refresh view
- DerivateView derivateView = null;
- if(AbstractUtility.getActivePart() instanceof DerivateView){
- derivateView = (DerivateView) AbstractUtility.getActivePart();
- }
- if(derivateView!=null){
+ //attach to parent
+ if(selectedNode.getValue() instanceof SpecimenOrObservationBase){
+ SpecimenOrObservationBase<?> specimenOrObservationBase = (SpecimenOrObservationBase<?>)selectedNode.getValue();
+
+ specimenOrObservationBase.addDerivationEvent(DerivationEvent.NewSimpleInstance(specimenOrObservationBase, mediaSpecimen, derivationEventType));
+ mediaSpecimen.setCacheStrategy(new DerivedUnitFacadeCacheStrategy());
+ mediaSpecimen.getTitleCache(); //update title cache
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IOccurrenceService.class).merge(specimenOrObservationBase, true);
+ }
+ }
- derivateView.getConversationHolder().commit();
- derivateView.refreshTree(mediaSpecimen);
+ //refresh view
+ DerivateView derivateView = null;
+ if(AbstractUtility.getActivePart() instanceof DerivateView){
+ derivateView = (DerivateView) AbstractUtility.getActivePart();
+ }
+ if(derivateView!=null){
+
+ derivateView.getConversationHolder().commit();
+ derivateView.refreshTree(mediaSpecimen);
+ }
}
}
});
Sequence newInstance = Sequence.NewInstance(dnaSample, "", 0); //$NON-NLS-1$
createdElement = newInstance;
}
- CdmStore.getService(IOccurrenceService.class).merge((SpecimenOrObservationBase) selectedDerivate);
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IOccurrenceService.class).merge((SpecimenOrObservationBase) selectedDerivate, true);
+ }
}
else if(selectedDerivate instanceof Sequence){
SingleRead newInstance = SingleRead.NewInstance();
((Sequence) selectedDerivate).addSingleRead(newInstance);
createdElement = newInstance;
- CdmApplicationState.getCurrentAppConfig().getSequenceService().merge((Sequence)selectedDerivate);
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmApplicationState.getCurrentAppConfig().getSequenceService().merge((Sequence)selectedDerivate, true);
+ }
}
- else if(selectedDerivate instanceof SpecimenOrObservationBase && DerivedUnit.class.isAssignableFrom(childClass)){
+ if(selectedDerivate instanceof SpecimenOrObservationBase && DerivedUnit.class.isAssignableFrom(childClass)){
SpecimenOrObservationBase<?> specimenOrObservationBase = (SpecimenOrObservationBase<?>)selectedDerivate;
DerivedUnit derivedUnit;
if(childClass.equals(DnaSample.class)){
derivedUnit.setCacheStrategy(new DerivedUnitFacadeCacheStrategy());
derivedUnit.getTitleCache(); //update title cache
createdElement = derivedUnit;
- CdmStore.getService(IOccurrenceService.class).merge((SpecimenOrObservationBase) selectedDerivate);
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IOccurrenceService.class).merge((SpecimenOrObservationBase) selectedDerivate, true);
+ }
}
//refresh view
if(derivateView!=null){
- //CdmStore.getService(IOccurrenceService.class).merge((SpecimenOrObservationBase) selectedDerivate);
derivateView.getConversationHolder().commit();
derivateView.refreshTree(createdElement);
}
package eu.etaxonomy.taxeditor.editor.view.descriptive.operation;
+import org.apache.commons.lang.StringUtils;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
import eu.etaxonomy.cdm.api.service.IDescriptionService;
+import eu.etaxonomy.cdm.model.common.Annotation;
+import eu.etaxonomy.cdm.model.common.AnnotationType;
+import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
monitor.worked(20);
bind();
- /*String moveMessage = String.format("Description moved from %s", EditorUtil.getActiveMultiPageTaxonEditor().getTaxon());
+ String moveMessage = String.format("Description moved from %s", EditorUtil.getActiveMultiPageTaxonEditor().getTaxon());
if(description.isProtectedTitleCache()){
String separator = "";
if(!StringUtils.isBlank(description.getTitleCache())){
annotation.setAnnotationType(AnnotationType.TECHNICAL());
description.addAnnotation(annotation);
newAcceptedTaxonNode.getTaxon().addDescription(description);
- CdmStore.getService(IDescriptionService.class).saveOrUpdate(description);*/
+ if (CdmApplicationState.getCurrentAppConfig() instanceof CdmApplicationRemoteController) {
+ CdmStore.getService(IDescriptionService.class).merge(description);
+ } else {
+ CdmStore.getService(IDescriptionService.class).saveOrUpdate(description);
+ }
- CdmStore.getService(IDescriptionService.class).moveTaxonDescription(description.getUuid(), newAcceptedTaxonNode.getTaxon().getUuid());
+ // CdmStore.getService(IDescriptionService.class).moveTaxonDescription(description.getUuid(), newAcceptedTaxonNode.getTaxon().getUuid());
monitor.worked(40);
return postExecute(description);
//re-loading sequence to avoid session conflicts
Sequence sequenceNode = CdmStore.getService(ISequenceService.class).load(((AlignmentEditorInput)getEditorInput()).getSequenceNodeUuid());
+ ((AlignmentEditorInput)getEditorInput()).setSequenceNode(sequenceNode);
StringAdapter stringProvider = new StringAdapter(getEditableConsensusArea().getAlignmentModel(), false); // Throws an exception if a token has more than one character.
// Write consensus sequence:
}
monitor.worked(1);
+ ((AlignmentEditorInput)getEditorInput()).merge();
// Commit the conversation and start a new transaction immediately:
conversationHolder.commit(true);
monitor.worked(1);
if(conversationHolder!=null){
conversationHolder.bind();
}
+ ((AlignmentEditorInput)getEditorInput()).bind();
}
+ @Override
+ public void dispose() {
+ ((AlignmentEditorInput)getEditorInput()).dispose();
+ }
public boolean isInsertMode() {
return getAlignmentsContainer().getEditSettings().isInsert();
package eu.etaxonomy.taxeditor.molecular.editor;
+import java.util.Arrays;
+import java.util.List;
import java.util.UUID;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPersistableElement;
+import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
+import eu.etaxonomy.cdm.model.molecular.Sequence;
+import eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
/**
* @author Ben Stöver
* @date 04.08.2014
*/
-public class AlignmentEditorInput implements IEditorInput {
+public class AlignmentEditorInput extends CdmEntitySessionInput implements IEditorInput {
private static final String name = "AlignmentEditor";
private final UUID sequenceNodeUuid;
-
+ private Sequence sequenceNode;
public AlignmentEditorInput(UUID sequenceNodeUuid) {
- super();
+ super(false);
this.sequenceNodeUuid = sequenceNodeUuid;
+ initSession();
}
}
return true;
}
+
+
+ public void setSequenceNode(Sequence sequenceNode) {
+ this.sequenceNode = sequenceNode;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+ */
+ @Override
+ public List<Sequence> getRootEntities() {
+ return Arrays.asList(sequenceNode);
+ }
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.editor.CdmEntitySessionInput#merge()
+ */
+ @Override
+ public void merge() {
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(ISequenceService.class).merge(sequenceNode, true);
+ }
+ }
}
@Override\r
public void doSave(IProgressMonitor monitor) {\r
getConversationHolder().commit();\r
- CdmStore.getService(IVocabularyService.class).merge(new ArrayList<TermVocabulary>(getRootEntities()));\r
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {\r
+ CdmStore.getService(IVocabularyService.class).merge(new ArrayList<TermVocabulary>(getRootEntities()), true);\r
+ }\r
setDirty(false);\r
getDefinedTermEditorInput().initialiseVocabularies();\r
viewer.refresh();\r
// $Id$
/**
* Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
+ * 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.
*/
* <p>
* EditFeatureTreeWizardPage class.
* </p>
- *
+ *
* @author n.hoffmann
* @created Aug 5, 2010
* @version 1.0
* <p>
* Constructor for EditFeatureTreeWizardPage.
* </p>
- *
+ *
* @param pageName
* a {@link java.lang.String} object.
*/
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets
* .Composite)
* <p>
* setSelectedTree
* </p>
- *
+ *
* @param featureTree
* a {@link eu.etaxonomy.cdm.model.description.FeatureTree}
* object.
.getAdditionalFeatures();
for (Feature feature : additionalFeatures) {
FeatureNode child = FeatureNode.NewInstance(feature);
- CdmStore.getService(IFeatureNodeService.class)
- .saveOrUpdate(child);
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IFeatureNodeService.class).merge(child, true);
+ } else {
+ CdmStore.getService(IFeatureNodeService.class).saveOrUpdate(child);
+ }
parent.addChild(child);
}
viewer.refresh();
*/
@Override
public void dragFinished(DragSourceEvent event) {
- if (!event.doit)
- return;
+ if (!event.doit) {
+ return;
+ }
// if the featureNode was moved, remove it from the source viewer
if (event.detail == DND.DROP_MOVE) {
IStructuredSelection selection = (IStructuredSelection) viewer
// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.featuretree;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
import org.eclipse.jface.wizard.Wizard;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
* @created Aug 5, 2010
* @version 1.0
*/
-public class FeatureTreeEditorWizard extends Wizard {
-
+public class FeatureTreeEditorWizard extends Wizard implements ICdmEntitySessionEnabled {
+
private SelectFeatureTreeWizardPage selectFeatureTreePage;
private EditFeatureTreeWizardPage editFeatureTreePage;
-
+
private FeatureTree selectedFeatureTree;
private ConversationHolder conversation;
-
+ private ICdmEntitySession cdmEntitySession;
+ private ICdmEntitySession previousCdmEntitySession;
+
/**
* <p>Constructor for FeatureTreeEditorWizard.</p>
*/
public FeatureTreeEditorWizard(){
conversation = CdmStore.createConversation();
+ previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
+ cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
setWindowTitle("Feature Tree Editor");
}
-
+
/**
* <p>addPages</p>
*/
- public void addPages() {
+ @Override
+ public void addPages() {
selectFeatureTreePage = new SelectFeatureTreeWizardPage("SELECT");
addPage(selectFeatureTreePage);
-
+
editFeatureTreePage = new EditFeatureTreeWizardPage("EDIT");
addPage(editFeatureTreePage);
}
public boolean performFinish() {
try{
if (selectedFeatureTree != null){
- CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(selectedFeatureTree);
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IFeatureTreeService.class).merge(selectedFeatureTree, true);
+ } else {
+ CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(selectedFeatureTree);
+ }
}
conversation.commit();
}finally{
conversation.close();
+ cdmEntitySession.dispose();
+ if(previousCdmEntitySession != null) {
+ previousCdmEntitySession.bind();
+ }
}
-
+
return true;
}
+ /** {@inheritDoc} */
+ @Override
+ public boolean performCancel() {
+ cdmEntitySession.dispose();
+ if(previousCdmEntitySession != null) {
+ previousCdmEntitySession.bind();
+ }
+ return true;
+ }
+
/**
* <p>Setter for the field <code>selectedFeatureTree</code>.</p>
*
public FeatureTree getSelectedFeatureTree() {
return selectedFeatureTree;
}
-
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
+ */
+ @Override
+ public ICdmEntitySession getCdmEntitySession() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+ */
+ @Override
+ public List<FeatureTree> getRootEntities() {
+ return Arrays.asList(selectedFeatureTree);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
+ */
+ @Override
+ public Map<Object, List<String>> getPropertyPathsMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2015 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.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+
+import eu.etaxonomy.cdm.api.service.DeleteResult;
+
+/**
+ * @author k.luther
+ * @date Oct 5, 2015
+ *
+ */
+public class DeleteResultMessagingUtils extends MessagingUtils {
+ /**
+ * Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
+ *
+ * @param title
+ * @param source
+ * @param message
+ */
+ public static void messageDialogWithDetails(DeleteResult result, String message, String pluginId) {
+ if (result.isOk() && result.getExceptions().isEmpty()){
+ return;
+ }
+ List<String> details = new ArrayList<String>();
+ String title= "";
+
+ if (result.isOk() && result.getExceptions().size() > 0){
+ for (Exception e:result.getExceptions()){
+ details.add(e.getMessage());
+ }
+ title = "The delete was successfull.";
+ }
+ String stackTraceWithContext = getContextInfo(details);
+ CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, new Status(IStatus.ERROR, pluginId, null), stackTraceWithContext);
+ ced.open();
+
+
+
+ }
+}
return stackTraceAndContextInfo.toString();
}
+ public static String getContextInfo(List<String> contextInfo) {
+ StringBuffer scontextInfoStringBuffer = new StringBuffer();
+
+
+ for(String infoItem : contextInfo) {
+ scontextInfoStringBuffer.append(infoItem + System.getProperty("line.separator"));
+ }
+
+
+
+ return scontextInfoStringBuffer.toString();
+ }
+
private static Throwable getDefaultThrowable() {
return new Throwable("Error thrown but no associated exception");
}
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(IAmplificationService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IAmplificationService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(IAmplificationService.class).save(getEntity());
+ }
}
/** {@inheritDoc} */
protected void saveEntity() {
//CdmStore.getService(IClassificationService.class).saveOrUpdate(getEntity());
Classification classification = getEntity();
- CdmStore.getService(IClassificationService.class).merge(getEntity());
-
- CdmApplicationState.getCurrentDataChangeService()
- .fireChangeEvent(new CdmChangeEvent(Action.Create, classification, NewTaxonNodeWizard.class), true);
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IClassificationService.class).merge(getEntity(), true);
+ CdmApplicationState.getCurrentDataChangeService()
+ .fireChangeEvent(new CdmChangeEvent(Action.Create, classification, NewTaxonNodeWizard.class), true);
+ } else {
+ CdmStore.getService(IClassificationService.class).save(getEntity());
+ }
}
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(ICollectionService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(ICollectionService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(ICollectionService.class).save(getEntity());
+ }
}
/* (non-Javadoc)
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(IOccurrenceService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IOccurrenceService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(IOccurrenceService.class).save(getEntity());
+ }
}
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(IOccurrenceService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IOccurrenceService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(IOccurrenceService.class).save(getEntity());
+ }
}
@Override
*/
@Override
protected void saveEntity() {
- CdmStore.getService(IGrantedAuthorityService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IGrantedAuthorityService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(IGrantedAuthorityService.class).save(getEntity());
+ }
}
/* (non-Javadoc)
*/
@Override
protected void saveEntity() {
- CdmStore.getService(IGroupService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IGroupService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(IGroupService.class).save(getEntity());
+ }
}
/* (non-Javadoc)
*/
@Override
protected void saveEntity() {
- CdmStore.getService(IAgentService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IAgentService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(IAgentService.class).save(getEntity());
+ }
}
/* (non-Javadoc)
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(INameService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(INameService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(INameService.class).save(getEntity());
+ }
}
@Override
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(IAgentService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IAgentService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(IAgentService.class).save(getEntity());
+ }
}
@Override
@Override
protected void saveEntity() {
if(!polytomousKeyPage.getPolytomousKeyName().equals("")) {
- CdmStore.getService(IPolytomousKeyService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IPolytomousKeyService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(IPolytomousKeyService.class).save(getEntity());
+ }
}
}
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(IPrimerService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IPrimerService.class).merge(getEntity(),true);
+ } else {
+ CdmStore.getService(IPrimerService.class).save(getEntity());
+ }
}
/** {@inheritDoc} */
TaxonNode taxonNode = parent.addChildTaxon(taxon, parent.getReference(), parent.getMicroReference());
if(CdmStore.getCurrentSessionManager().isRemoting()) {
- taxonNode = CdmStore.getService(ITaxonNodeService.class).merge(taxonNode);
+ taxonNode = CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
} else {
taxonNode = CdmStore.getService(ITaxonNodeService.class).save(taxonNode);
}
/** {@inheritDoc} */
@Override
protected void saveEntity() {
- CdmStore.getService(IAgentService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IAgentService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(IAgentService.class).save(getEntity());
+ }
}
@Override
@Override
protected void saveEntity() {
- CdmStore.getService(IUserService.class).merge(getEntity());
+ if(CdmStore.getCurrentSessionManager().isRemoting()) {
+ CdmStore.getService(IUserService.class).merge(getEntity(), true);
+ } else {
+ CdmStore.getService(IUserService.class).save(getEntity());
+ }
}
@Override
package eu.etaxonomy.taxeditor.preference;
-import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
+import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.element.CommandHandlerButton;
* @created Aug 5, 2010
* @version 1.0
*/
-public class FeatureTreePreferences extends PreferencePage implements
+public class FeatureTreePreferences extends CdmPreferencePage implements
IWorkbenchPreferencePage {
/**
import java.util.Map;
import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.resource.ImageDescriptor;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
*/
public abstract class CdmPreferencePage extends PreferencePage implements ICdmEntitySessionEnabled {
+ private ICdmEntitySession previousCdmEntitySession;
+ private boolean isApply;
+
public CdmPreferencePage() {
- bindNullSession();
+ initSession();
}
public CdmPreferencePage(String title) {
super(title);
- bindNullSession();
+ initSession();
}
- private void bindNullSession() {
- if(CdmStore.isActive()) {
- CdmStore.getCurrentSessionManager().bindNullSession(this);
- }
+ public CdmPreferencePage(String title, ImageDescriptor image) {
+ super(title, image);
+ initSession();
+ }
+
+ private void initSession() {
+ previousCdmEntitySession = CdmStore.getCurrentSessionManager().getActiveSession();
+ bindNullSession();
}
- protected void disposeNullSession() {
+ private void bindNullSession() {
if(CdmStore.isActive()) {
- CdmStore.getCurrentSessionManager().dispose(this);
+ CdmStore.getCurrentSessionManager().bindNullSession();
}
}
@Override
public boolean performOk() {
- disposeNullSession();
+ if(previousCdmEntitySession != null && !isApply) {
+ previousCdmEntitySession.bind();
+ }
return super.performOk();
}
@Override
public boolean performCancel() {
- disposeNullSession();
+ if(previousCdmEntitySession != null) {
+ previousCdmEntitySession.bind();
+ }
return super.performCancel();
}
- /* (non-Javadoc)
+ @Override
+ public void performApply() {
+ isApply = true;
+ super.performApply();
+ isApply = false;
+ }
+
+ /* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
*/
@Override
protected AvailableDistributionPage(String pageName) {
super(pageName);
// TODO check if configuration exists
- CdmStore.getCurrentSessionManager().bindNullSession(this);
+ CdmStore.getCurrentSessionManager().bindNullSession();
}
/*
/**
- *
+ *
*/
package eu.etaxonomy.taxeditor.ui.section.description;
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
/** {@inheritDoc} */
@Override
public DescriptionElementSource createNewElement() {
+ if(getEntity().getId() == 0) {
+ MessagingUtils.warningDialog("Description not saved", this, "Please save the newly created description before adding source");
+ return null;
+ }
return DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
}
node.setParent(currentnode);
children.add(node);
}
- return children.toArray();
}
else if(value instanceof Sequence){
Set<SingleRead> singleReads = ((Sequence) value).getSingleReads();
}
return children.toArray();
}
- else if(value instanceof SpecimenOrObservationBase){
+
+ if(value instanceof SpecimenOrObservationBase){
List<DerivedUnit> derivates = getDerivates((SpecimenOrObservationBase<?>) value);
for (DerivedUnit derivedUnit:derivates) {
TreeNode node = new TreeNode(derivedUnit);
else if(element instanceof Sequence){
return !((Sequence)element).getSingleReads().isEmpty();
}
- else if(element instanceof SpecimenOrObservationBase){
+
+ if(element instanceof SpecimenOrObservationBase){
SpecimenOrObservationBase<?> specimenOrObservation = (SpecimenOrObservationBase<?>)element;
for(DerivationEvent event:specimenOrObservation.getDerivationEvents()){
if(!event.getDerivatives().isEmpty()){
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManagerObserver;
+import eu.etaxonomy.taxeditor.session.NullSession;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
Collection<ICdmEntitySession> sessions = cdmEntitySessionManager.getSessions();
txtNoOfSessions.setText(String.valueOf(sessions.size()));
for(ICdmEntitySession session : sessions) {
- if(session.getOwner() != null) {
- TableItem item = new TableItem(tableSessions, SWT.NULL);
- item.setText(session.getOwner().toString());
- String activePrefix = "";
- if(session.isActive()) {
- activePrefix = "*";
- }
- item.setText(0, activePrefix + session.getOwner().toString());
- LiveCacheStatistics cacheStatistics = session.getCacheStatistics();
- item.setText(1, getInMemoryStats(cacheStatistics));
- item.setText(2, getOnDiskStats(cacheStatistics));
- }
+ addSession(session);
+ }
+ ICdmEntitySession nullSession = cdmEntitySessionManager.getNullSession();
+ if(nullSession != null) {
+ addSession(nullSession);
}
for (int i=0; i<titles.length; i++) {
tableSessions.getColumn (i).pack ();
}
+ private void addSession(ICdmEntitySession session) {
+
+ TableItem item = new TableItem(tableSessions, SWT.NULL);
+
+ String activePrefix = "";
+ if(session.isActive()) {
+ activePrefix = "*";
+ }
+ String sessionOwnerString = "";
+ if(session instanceof NullSession) {
+ sessionOwnerString = "Null Session";
+ } else {
+ if(session.getOwner() != null) {
+ sessionOwnerString = session.getOwner().toString();
+ }
+ }
+ item.setText(0, activePrefix + sessionOwnerString);
+ LiveCacheStatistics cacheStatistics = session.getCacheStatistics();
+ item.setText(1, getInMemoryStats(cacheStatistics));
+ item.setText(2, getOnDiskStats(cacheStatistics));
+ }
+
private String getInMemoryStats(LiveCacheStatistics statistics) {
if(statistics != null) {
long localHeapSize = statistics.getLocalHeapSize();
import org.apache.log4j.Logger;
import org.eclipse.core.commands.ExecutionException;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import org.unitils.dbunit.annotation.DataSet;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.ITaxonService;
import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.OriginalSourceType;
+import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.description.TextData;
import eu.etaxonomy.cdm.model.name.BotanicalName;
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
import eu.etaxonomy.cdm.model.name.NonViralName;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
+import eu.etaxonomy.taxeditor.store.CdmStore;
/**
* @author cmathew
taxonService.merge(taxon);
}
+ @Ignore
+ @Test
+ public void addDescription() {
+ UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
+
+ TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
+ Taxon taxon = taxonNode.getTaxon();
+ TaxonDescription description = TaxonDescription.NewInstance(taxon);
+
+
+ TextData textData = TextData.NewInstance();
+
+ textData.setFeature(Feature.ECOLOGY());
+ description.addElement(textData);
+
+ DescriptionElementSource descriptionElementSource = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
+ textData.addSource(descriptionElementSource);
+
+
+ CdmStore.getService(ITaxonNodeService.class).merge(taxonNode);
+
+ description.getId();
+ }
+
+
+ @Test
+ public void addTaxonNodeCascadeProblem() {
+ UUID taxonNodeUuid = UUID.fromString("ce54c396-3694-47f2-abb0-1d7b7e057985");
+
+ TaxonNode taxonNode = taxonNodeService.load(taxonNodeUuid);
+ Taxon childTaxon = Taxon.NewInstance(null, null);
+ TaxonNode childTaxonNode = taxonNode.addChildTaxon(childTaxon, null, null);
+ Taxon grandChildTaxon = Taxon.NewInstance(null, null);
+ TaxonNode grandChildTaxonNode = childTaxonNode.addChildTaxon(grandChildTaxon, null, null);
+
+ CdmStore.getService(ITaxonNodeService.class).merge(taxonNode, true);
+
+ Assert.assertEquals(taxonNode.getChildNodes().get(0).getId(), childTaxonNode.getId());
+ Assert.assertEquals(taxonNode.getChildNodes().get(0).getTaxon().getId(), childTaxon.getId());
+ Assert.assertEquals(taxonNode.getChildNodes().get(0).getChildNodes().get(0).getId(), grandChildTaxonNode.getId());
+ Assert.assertEquals(taxonNode.getChildNodes().get(0).getChildNodes().get(0).getTaxon().getId(), grandChildTaxon.getId());
+ }
+
}
pKey = polytomousKeyService.merge(pKey, true);
grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
Assert.assertTrue(0 != grandChildNode.getId());
-
- grandChildNode.setStatement(KeyStatement.NewInstance("test"));
+ KeyStatement ks = KeyStatement.NewInstance("test");
+ grandChildNode.setStatement(ks);
pKey = polytomousKeyService.merge(pKey, true);
- grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
- KeyStatement ks = grandChildNode.getStatement();
+ //grandChildNode = pKey.getRoot().getChildAt(0).getChildAt(0);
+ //KeyStatement ks = grandChildNode.getStatement();
Assert.assertTrue(0 != ks.getId());
}
rootChildNode.addChild(grandChildNode);
- grandChildNode = polytomousKeyNodeService.merge(grandChildNode);
+ polytomousKeyNodeService.merge(grandChildNode);
- PolytomousKeyNode greatGrandChildNode = PolytomousKeyNode.NewInstance();
- grandChildNode.addChild(greatGrandChildNode);
Assert.assertFalse(pKey.getRoot().getChildAt(0).getChildAt(0).getId() == 0);
}
<SynonymRelationship id="50" created="2010-12-21 15:09:45.0" uuid="60d1466f-5823-4a69-a071-1887d0c1e72b" doubtful="false" partial="false" proparte="false" relatedfrom_id="388" relatedto_id="387" />
<LanguageString id="10"/>
+ <DescriptionBase/>
+ <DescriptionElementBase/>
</dataset>