import org.eclipse.e4.ui.di.UIEventTopic;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
+import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement;
+import org.eclipse.e4.ui.model.application.ui.menu.impl.HandledToolItemImpl;
import org.eclipse.e4.ui.services.EMenuService;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
import org.eclipse.jface.util.LocalSelectionTransfer;
+import org.eclipse.jface.viewers.IElementComparer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
+import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
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.api.service.TaxonNodeDtoByNameComparator;
+import eu.etaxonomy.cdm.api.service.TaxonNodeDtoByRankAndNameComparator;
+import eu.etaxonomy.cdm.api.service.TaxonNodeDtoNaturalComparator;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.ICdmBase;
-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.dto.TaxonNodeDto;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
+import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
import eu.etaxonomy.taxeditor.model.IContextListener;
import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;
+import eu.etaxonomy.taxeditor.navigation.AppModelId;
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
import eu.etaxonomy.taxeditor.navigation.navigator.EmptyRoot;
layout.type = SWT.VERTICAL;
parent.setLayout(layout);
- viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
+ viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
viewer.getControl().setLayoutData(LayoutConstants.FILL());
viewer.setContentProvider(new TaxonNavigatorContentProviderE4());
if(firstElement instanceof ICdmBase){
NavigationUtil.openEditor((ICdmBase) firstElement, viewer.getControl().getShell(), modelService, partService, application);
}
+ if(firstElement instanceof TaxonNodeDto){
+ NavigationUtil.openEditor((TaxonNodeDto) firstElement, viewer.getControl().getShell(), modelService, partService, application);
+ }
}
});
viewer.addSelectionChangedListener(selectionChangedListener);
//create context menu
- menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.navigator.popupmenu.taxonnavigator");
+ menuService.registerContextMenu(viewer.getControl(), AppModelId.POPUPMENU_EU_ETAXONOMY_TAXEDITOR_NAVIGATOR_POPUPMENU_TAXONNAVIGATOR );
//add drag'n'drop support
Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer()};
viewer.addDragSupport(dndOperations, transfers, new TreeNodeDragListenerE4(viewer));
viewer.addDropSupport(dndOperations, transfers, new TreeNodeDropAdapterE4(this));
- //add toolbar
-// MToolBar toolBar = MMenuFactory.INSTANCE.createToolBar();
-// MHandledToolItem linkWithEditor = MMenuFactory.INSTANCE.createHandledToolItem();
-// linkWithEditor.setIconURI("platform:/plugin/eu.etaxonomy.taxeditor.store/icons/synced.gif");
-// Command command = commandService.getCommand("eu.etaxonomy.taxeditor.navigation.command.linkWithTaxon");
-// MCommand mCommand = MCommandsFactory.INSTANCE.createCommand();
-// mCommand.setElementId(command.getId());
-// try {
-// mCommand.setCommandName(command.getName());
-// } catch (NotDefinedException e) {
-// e.printStackTrace();
-// }
-// linkWithEditor.setCommand(mCommand);
-// linkWithEditor.setType(ItemType.CHECK);
-// toolBar.getChildren().add(linkWithEditor);
-// thisPart.setToolbar(toolBar);
+ updateSyncButton();
+
+
init();
}
+ protected void updateSyncButton() {
+ MPart viewPart = partService.findPart(AppModelId.PARTDESCRIPTOR_EU_ETAXONOMY_TAXEDITOR_NAVIGATION_NAVIGATOR);
+ if(viewPart!=null){
+ MToolBar toolBar = viewPart.getToolbar();
+
+ List<MToolBarElement> toolBarElements = toolBar.getChildren();
+
+ MToolBarElement upperHandledMenuItem = toolBarElements.get(1);
+ if (upperHandledMenuItem instanceof HandledToolItemImpl){
+ ((HandledToolItemImpl)upperHandledMenuItem).setSelected(linkWithTaxon);
+ }
+ }
+ }
+
/** {@inheritDoc} */
protected IAdaptable getInitialInput() {
- Comparator<TaxonNode> comparator;
+ Comparator<TaxonNodeDto> comparator;
if (PreferencesUtil.getSortNodesNaturally()){
- comparator = new TaxonNaturalComparator();
+ comparator = new TaxonNodeDtoNaturalComparator();
} else if (PreferencesUtil.getSortNodesStrictlyAlphabetically()){
- comparator = new TaxonNodeByNameComparator();
+ comparator = new TaxonNodeDtoByNameComparator();
}else {
- comparator = new TaxonNodeByRankAndNameComparator();
+ comparator = new TaxonNodeDtoByRankAndNameComparator();
}
+
TaxonNodeNavigatorComparator viewerComparator = new TaxonNodeNavigatorComparator(comparator);
viewer.setComparator(viewerComparator);
+ viewer.setComparer(new IElementComparer() {
+
+ @Override
+ public int hashCode(Object element) {
+ if (element instanceof TaxonNodeDto){
+ TaxonNodeDto nodeDto = (TaxonNodeDto)element;
+
+ String s = nodeDto.getUuid().toString();
+ if (s != null) {
+ return s.hashCode();
+ }
+ return element.hashCode();
+ }else{
+ return element.toString().hashCode();
+ }
+ }
+
+ @Override
+ public boolean equals(Object element1, Object element2) {
+ if (element1 instanceof TaxonNodeDto && element2 instanceof TaxonNodeDto){
+ TaxonNodeDto node1 = (TaxonNodeDto)element1;
+ TaxonNodeDto node2 = (TaxonNodeDto)element2;
+ return (node1.getUuid().equals(node2.getUuid()));
+ }else {
+ return element1.equals(element2);
+ }
+ }
+ }
+ );
if (CdmStore.isActive()) {
//Link with taxon selection
@Inject
@Optional
- private void updateCurrentTaxon(@UIEventTopic(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR)ITaxonEditor editor){
- if(linkWithTaxon){
+ public void updateCurrentTaxon(@UIEventTopic(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR)ITaxonEditor editor){
+ if(linkWithTaxon && editor!=null){
viewer.refresh();
- TaxonNode taxonNode = null;
+ TaxonNodeDto taxonNode = null;
if(editor.getTaxon()!=null && editor.getTaxon().getTaxonNodes()!=null){
- taxonNode = editor.getTaxon().getTaxonNodes().iterator().next();
+ if (editor instanceof TaxonNameEditorE4){
+ taxonNode = new TaxonNodeDto( ((TaxonNameEditorE4)editor).getEditorInput().getTaxonNode());
+ }else{
+ taxonNode = new TaxonNodeDto(editor.getTaxon().getTaxonNodes().iterator().next());
+ }
viewer.reveal(taxonNode);
viewer.setSelection(new StructuredSelection(taxonNode));
}
if(!viewer.getTree().isDisposed()){
viewer.refresh();
}
+
+ updateSyncButton();
}
/**
for(Object obj : objects) {
viewer.refresh(obj);
}
+ updateSyncButton();
+ }
+
+ /**
+ * Refresh this navigators viewer
+ */
+ public void refresh(Object object) {
+ viewer.refresh(object);
+ updateSyncButton();
}
/**
viewer.setInput(new EmptyRoot());
}
- public void restore(IMemento memento, IProgressMonitor monitor) {
+ private void restore(IMemento memento, IProgressMonitor monitor) {
root = new Root(conversation);
if (memento == null) {
viewer.setInput(root);
dataChangeBehavior = null;
if (conversation != null) {
conversation.unregisterForDataStoreChanges(this);
+ conversation.close();
}
if(cdmEntitySession != null) {
cdmEntitySession.dispose();
+ cdmEntitySession = null;
}
if(CdmApplicationState.getCurrentDataChangeService() != null) {
CdmApplicationState.getCurrentDataChangeService().unregister(this);
if(o instanceof LoginManager){
refresh();
}
+
}
/** {@inheritDoc} */
@Override
}
DataChangeBridge.handleDataChange(changeEvents, dataChangeBehavior);
+ updateSyncButton();
+
}
@Override
}
@Override
- public List<ITreeNode> getRootEntities() {
+ public List<TaxonNodeDto> getRootEntities() {
if(root != null) {
return root.getParentBeans();
}
viewer.refresh(cb);
}
} else if (cb instanceof Classification) {
+ if ( event.getAction().equals(Action.Create)){
+ root.addRootNode((Classification)cb);
+ } else if ( event.getAction().equals(Action.Delete)){
+ root.removeRootNode((Classification)cb);
+ }
viewer.refresh();
}
}
*/
@Override
public void contextStart(IMemento memento, IProgressMonitor monitor) {
- if(viewer!=null){
+ if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()){
init();
}
}
@Override
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
}
+
+ @Inject
+ @Optional
+ private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_NAVIGATOR)boolean refresh){
+ if(refresh){
+ refresh();
+ }
+ }
}