package eu.etaxonomy.taxeditor.navigation.navigator;
import java.util.ArrayList;
+import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Observable;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.navigator.CommonNavigator;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
+import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
import eu.etaxonomy.cdm.api.service.IClassificationService;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.taxon.Classification;
-import eu.etaxonomy.cdm.model.taxon.TaxonComparatorSearch;
+import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNodeComparator;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.LoginManager;
* @version 1.0
*/
public class TaxonNavigator extends CommonNavigator implements
- IPostOperationEnabled, IConversationEnabled, Observer {
+ IPostOperationEnabled, IConversationEnabled, Observer, ICdmEntitySessionEnabled {
/**
* Constant
private ConversationHolder conversation;
+ private ICdmEntitySession cdmEntitySession;
+
private String partNameCache;
private IDataChangeBehavior dataChangeBehavior;
+ private Root root;
+
/*
* (non-Javadoc)
*
/** {@inheritDoc} */
@Override
protected IAdaptable getInitialInput() {
-
- TaxonComparatorSearch comparator = new TaxonComparatorSearch();
- TaxonNodeComparator viewerComparator = new TaxonNodeComparator(comparator);
+ Comparator comparator;
+ if (PreferencesUtil.getSortNodesNaturally()){
+ comparator = new TaxonNaturalComparator();
+ } else{
+ comparator = new TaxonNodeComparator();
+ }
+ TaxonNodeNavigatorComparator viewerComparator = new TaxonNodeNavigatorComparator(comparator);
this.getCommonViewer().setComparator(viewerComparator);
+ setLinkingEnabled(true);
// this.getCommonViewer().addSelectionChangedListener(new ISelectionChangedListener() {
-//
+//
// @Override
// public void selectionChanged(SelectionChangedEvent arg0) {
// IStructuredSelection selection = (IStructuredSelection) getCommonViewer().getSelection();
-//
+//
// Object firstElement = selection.getFirstElement();
// //
// if (!(firstElement instanceof Classification)){
// //NavigationUtil.selectInNavigator(firstElement, null);
// NavigationUtil.openEditor(firstElement);
// }
-//
+//
// }
// } );
-
+
if (CdmStore.isActive()) {
-
+
// TODO when closing and reopening the taxon navigator
// we do not preserve state. Closing the view, in contrary to
// closing the whole application
// should be handled by the state manager too
-
- return new Root(conversation);
+ root = new Root(conversation);
+ return root;
}
return new EmptyRoot();
}
* </p>
*/
public void init() {
+
if (CdmStore.isActive() && conversation == null) {
conversation = CdmStore.createConversation();
conversation.registerForDataStoreChanges(TaxonNavigator.this);
}
+ if (CdmStore.isActive() && cdmEntitySession == null) {
+ cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
+ CdmApplicationState.getCurrentDataChangeService().register(this);
+ }
CdmStore.getLoginManager().addObserver(this);
}
getCommonViewer().refresh();
}
+ /**
+ * Refresh this navigators viewer
+ */
+ public void refresh(Set objects) {
+ for(Object obj : objects) {
+ getCommonViewer().refresh(obj);
+ }
+ }
+
/**
* Removes all content
*/
* a {@link org.eclipse.core.runtime.IProgressMonitor} object.
*/
public void restore(IMemento memento, IProgressMonitor monitor) {
+ root = new Root(conversation);
if (memento == null) {
- getCommonViewer().setInput(new Root(conversation));
+ getCommonViewer().setInput(root);
return;
}
int mementoWork = 0;
subProgressMonitor.worked(1);
conversation.registerForDataStoreChanges(TaxonNavigator.this);
subProgressMonitor.worked(1);
- getCommonViewer().setInput(new Root(conversation));
+ getCommonViewer().setInput(root);
subProgressMonitor.worked(1);
getCommonViewer().refresh();
subProgressMonitor.worked(1);
path += ((CdmBase) segment).getUuid().toString() + " ";
monitor.worked(1);
} else {
- NavigationUtil.warn(getClass(),
+ MessagingUtils.warn(getClass(),
"Non-taxon tree path segment " + segment);
}
}
if (conversation != null) {
conversation.unregisterForDataStoreChanges(this);
}
+ if(cdmEntitySession != null) {
+ cdmEntitySession.dispose();
+ }
}
/*
if (getConversationHolder() != null) {
getConversationHolder().bind();
}
+ if(cdmEntitySession != null) {
+ cdmEntitySession.bind();
+ }
}
/*
}
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
+ */
+ @Override
+ public ICdmEntitySession getCdmEntitySession() {
+ return cdmEntitySession;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+ */
+ @Override
+ public List<Classification> getRootEntities() {
+ if(root != null) {
+ return root.getParentBeans();
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.api.application.ICdmChangeListener#onChange(eu.etaxonomy.cdm.api.application.CdmChangeEvent)
+ */
+ @Override
+ public void onChange(CdmChangeEvent event) {
+ for(CdmBase cb : event.getChangedObjects()) {
+ if(cb instanceof TaxonNode) {
+ getCommonViewer().refresh(cb);
+ } else if (cb instanceof Classification) {
+ getCommonViewer().refresh();
+ }
+ }
+
+ }
}