-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
package eu.etaxonomy.taxeditor.navigation.navigator;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;
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.application.ICdmChangeListener;
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.common.ITreeNode;
+import eu.etaxonomy.cdm.model.taxon.Classification;
import eu.etaxonomy.cdm.model.taxon.TaxonNaturalComparator;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.model.taxon.TaxonNodeByNameComparator;
import eu.etaxonomy.cdm.model.taxon.TaxonNodeByRankAndNameComparator;
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.navigation.l10n.Messages;
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;
* @author p.ciardelli
* @author n.hoffmann
* @created 02.06.2009
- * @version 1.0
+ * @version 1.0+-
*/
public class TaxonNavigator extends CommonNavigator implements
- IPostOperationEnabled, IConversationEnabled, Observer {
+ IPostOperationEnabled, IConversationEnabled, Observer,
+ ICdmEntitySessionEnabled, ICdmChangeListener {
- /**
+ private static final String RESTORING_TAXON_NAVIGATOR = Messages.TaxonNavigator_RESTORE;
+
+ /**
* Constant
* <code>ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked}</code>
*/
public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator"; //$NON-NLS-1$
- private static final String TREE_PATH = "treepath";
+ private static final String TREE_PATH = "treepath"; //$NON-NLS-1$
- private static final String TREE_PATHS = "treepaths";
+ private static final String TREE_PATHS = "treepaths"; //$NON-NLS-1$
private ConversationHolder conversation;
+ private ICdmEntitySession cdmEntitySession;
+
private String partNameCache;
private IDataChangeBehavior dataChangeBehavior;
+ private Root root;
+
/*
* (non-Javadoc)
*
Comparator<TaxonNode> comparator;
if (PreferencesUtil.getSortNodesNaturally()){
comparator = new TaxonNaturalComparator();
- } else{
+ } else if (PreferencesUtil.getSortNodesStrictlyAlphabetically()){
+ comparator = new TaxonNodeByNameComparator();
+ }else {
comparator = new TaxonNodeByRankAndNameComparator();
}
TaxonNodeNavigatorComparator viewerComparator = new TaxonNodeNavigatorComparator(comparator);
this.getCommonViewer().setComparator(viewerComparator);
+ //this.getCommonViewer().setAutoExpandLevel(2);
setLinkingEnabled(true);
// this.getCommonViewer().addSelectionChangedListener(new ISelectionChangedListener() {
//
// we do not preserve state. Closing the view, in contrary to
// closing the whole application
// should be handled by the state manager too
+ root = new Root(conversation);
- return 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 = CdmStore.getCurrentSessionManager().newSession(this, true);
+ CdmApplicationState.getCurrentDataChangeService().register(this);
+ }
CdmStore.getLoginManager().addObserver(this);
+
+
}
/**
getConversationHolder().commit();
}
}
- getCommonViewer().refresh();
+ if(!getCommonViewer().getTree().isDisposed()){
+ 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;
IProgressMonitor subProgressMonitor = NavigationUtil
.getSubProgressMonitor(monitor, 1);
- subProgressMonitor.beginTask("Restoring Taxon Navigator",
+ subProgressMonitor.beginTask(RESTORING_TAXON_NAVIGATOR,
1 + mementoWork + 5);
- subProgressMonitor.subTask("Restoring Taxon Navigator");
+ subProgressMonitor.subTask(RESTORING_TAXON_NAVIGATOR);
subProgressMonitor.worked(1);
conversation = CdmStore.createConversation();
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);
return null;
}
- for (String uuid : string.split(" ")) {
+ for (String uuid : string.split(" ")) { //$NON-NLS-1$
CdmBase cdmBaseObject = CdmStore.getService(
IClassificationService.class).getTaxonNodeByUuid(
UUID.fromString(uuid));
memento = memento.createChild(TREE_PATHS);
TreePath[] treePaths = this.getCommonViewer().getExpandedTreePaths();
- monitor.beginTask("Saving Taxon Navigator State", treePaths.length);
+ monitor.beginTask(Messages.TaxonNavigator_SAVE_TASK, treePaths.length);
for (TreePath treePath : treePaths) {
int pathLength = treePath.getSegmentCount();
- String path = "";
+ String path = ""; //$NON-NLS-1$
for (int i = 0; i < pathLength; i++) {
Object segment = treePath.getSegment(i);
if (segment instanceof CdmBase) {
- path += ((CdmBase) segment).getUuid().toString() + " ";
+ path += ((CdmBase) segment).getUuid().toString() + " "; //$NON-NLS-1$
monitor.worked(1);
} else {
MessagingUtils.warn(getClass(),
- "Non-taxon tree path segment " + segment);
+ "Non-taxon tree path segment " + segment); //$NON-NLS-1$
}
}
memento.createChild(TREE_PATH, path.trim());
@Override
public String getFrameToolTipText(Object element) {
if (element instanceof Root) {
- return "Taxonomic Tree";
+ return Messages.TaxonNavigator_TAXON_TREE;
}
return super.getFrameToolTipText(element);
}
if (conversation != null) {
conversation.unregisterForDataStoreChanges(this);
}
+ if(cdmEntitySession != null) {
+ cdmEntitySession.dispose();
+ }
+ if(CdmApplicationState.getCurrentDataChangeService() != null) {
+ CdmApplicationState.getCurrentDataChangeService().unregister(this);
+ }
}
/*
if (getConversationHolder() != null) {
getConversationHolder().bind();
}
+ if(cdmEntitySession != null) {
+ cdmEntitySession.bind();
+ }
}
/*
/** {@inheritDoc} */
@Override
- protected void handleDoubleClick(DoubleClickEvent anEvent) {
- NavigationUtil.executeEditHandler();
+ protected void handleDoubleClick(DoubleClickEvent event) {
+// ISelection selection = event.getSelection();
+// if(selection instanceof IStructuredSelection){
+// Object firstElement = ((IStructuredSelection) selection).getFirstElement();
+// if(firstElement instanceof ICdmBase){
+// NavigationUtil.openEditor((ICdmBase) firstElement, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+// }
+// }
// If the double click is passed up to the super-class it will
// expand/collapse trees.
// We do not want that
getCommonViewer().getControl().setEnabled(!busy);
if (busy) {
partNameCache = getPartName();
- setPartName("Loading datasources");
+ setPartName(Messages.TaxonNavigator_LOAD_DATASOURCE);
} else {
if (partNameCache != null) {
setPartName(partNameCache);
}
}
+
+ /* (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<ITreeNode> 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) {
+// if(event.getAction() == Action.Delete && Classification.class.equals(event.getEntityType())) {
+// refresh();
+// return;
+// }
+ refresh();
+ for(CdmBase cb : event.getChangedObjects()) {
+ if(cb instanceof TaxonNode) {
+ TaxonNode tn = (TaxonNode)cb;
+ if(tn.getTaxon() == null) {
+ getCommonViewer().refresh(tn.getClassification());
+ } else {
+ getCommonViewer().refresh(cb);
+ }
+ } else if (cb instanceof Classification) {
+ getCommonViewer().refresh();
+ }
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
+ */
+ @Override
+ public Map<Object, List<String>> getPropertyPathsMap() {
+ Map<Object, List<String>> propertyPathsMap = new HashMap<Object, List<String>>();
+ List<String> taxonNodePropertyPaths = Arrays.asList(new String[] {
+ "taxon.name" //$NON-NLS-1$
+ });
+ propertyPathsMap.put("childNodes", taxonNodePropertyPaths); //$NON-NLS-1$
+ return propertyPathsMap;
+ }
}