import javax.annotation.PreDestroy;
import javax.inject.Inject;
+import org.eclipse.core.commands.operations.UndoContext;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.e4.core.commands.ECommandService;
+import org.eclipse.e4.core.di.annotations.Optional;
import org.eclipse.e4.ui.di.Focus;
+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.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.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IMemento;
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.editor.ITaxonEditor;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
import eu.etaxonomy.taxeditor.model.DataChangeBridge;
import eu.etaxonomy.taxeditor.model.IContextListener;
import eu.etaxonomy.taxeditor.model.IDataChangeBehavior;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.LoginManager;
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+import eu.etaxonomy.taxeditor.workbench.part.ICollapsableExpandable;
/**
*
*/
public class TaxonNavigatorE4 implements
IPostOperationEnabled, IConversationEnabled, Observer,
- ICdmEntitySessionEnabled, ICdmChangeListener, IContextListener {
+ ICdmEntitySessionEnabled, ICdmChangeListener, IContextListener,
+ ICollapsableExpandable {
private static final String RESTORING_TAXON_NAVIGATOR = Messages.TaxonNavigator_RESTORE;
private static final String TREE_PATHS = "treepaths"; //$NON-NLS-1$
+ private final int dndOperations = DND.DROP_MOVE;
+
private ConversationHolder conversation;
private ICdmEntitySession cdmEntitySession;
@Inject
private ESelectionService selService;
+ @Inject
+ private UISynchronize sync;
+
private ISelectionChangedListener selectionChangedListener;
- @Inject
+ private UndoContext undoContext;
+
+ @Inject
+ private MPart thisPart;
+
+ @Inject
+ private MApplication application;
+
+ @Inject
+ private EModelService modelService;
+
+ @Inject
+ private EPartService partService;
+
+ private boolean linkWithTaxon = false;
+
+ @Inject
public TaxonNavigatorE4() {
+ undoContext = new UndoContext();
CdmStore.getContextManager().addContextListener(this);
}
@PostConstruct
- private void create(Composite parent, EMenuService menuService){
+ private void create(Composite parent, EMenuService menuService, ECommandService commandService){
FillLayout layout = new FillLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
if(selection instanceof IStructuredSelection){
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
if(firstElement instanceof ICdmBase){
- NavigationUtil.openEditor((ICdmBase) firstElement, viewer.getControl().getShell());
+ NavigationUtil.openEditor((ICdmBase) firstElement, viewer.getControl().getShell(), modelService, partService, application);
}
}
});
//create context menu
menuService.registerContextMenu(viewer.getControl(), "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);
+
init();
}
}
TaxonNodeNavigatorComparator viewerComparator = new TaxonNodeNavigatorComparator(comparator);
viewer.setComparator(viewerComparator);
- //FIXME E4 migrate linking with editor
-// setLinkingEnabled(true);
if (CdmStore.isActive()) {
viewer.setInput(getInitialInput());
}
+ //Link with taxon selection
+ @Inject
+ @Optional
+ private void updateCurrentTaxon(@UIEventTopic(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR)ITaxonEditor editor){
+ if(linkWithTaxon){
+ viewer.refresh();
+ TaxonNode taxonNode = null;
+ if(editor.getTaxon()!=null && editor.getTaxon().getTaxonNodes()!=null){
+ taxonNode = editor.getTaxon().getTaxonNodes().iterator().next();
+ viewer.reveal(taxonNode);
+ viewer.setSelection(new StructuredSelection(taxonNode));
+ }
+ }
+ }
+
+ public void setLinkWithTaxon(boolean linkWithTaxon) {
+ this.linkWithTaxon = linkWithTaxon;
+ }
+
+ public boolean isLinkWithTaxon() {
+ return linkWithTaxon;
+ }
+
/**
* Refresh this navigators viewer
*/
return new TreePath(pathList.toArray());
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void collapse() {
+ viewer.collapseAll();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void expand() {
+ viewer.expandAll();
+ }
+
@Override
public ConversationHolder getConversationHolder() {
return conversation;
}
}
+ public UISynchronize getSync() {
+ return sync;
+ }
+
+ public TreeViewer getViewer() {
+ return viewer;
+ }
+
+ public UndoContext getUndoContext() {
+ return undoContext;
+ }
+
/** {@inheritDoc} */
@Override
public boolean postOperation(CdmBase objectAffectedByOperation) {
- // nothing to do here
+ viewer.refresh();
return true;
}