package eu.etaxonomy.taxeditor.featuretree.e4;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
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.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
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.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IMemento;
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
+import eu.etaxonomy.taxeditor.featuretree.e4.operation.AddFeatureOperation;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.IContextListener;
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
import eu.etaxonomy.taxeditor.store.AppModelId;
import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart;
/**
viewer.addDragSupport(ops, transfers, new FeatureNodeDragListener(viewer));
viewer.addDropSupport(ops, transfers, new FeatureTreeDropAdapter(this, viewer, sync));
viewer.addSelectionChangedListener(this);
+ viewer.getTree().addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if(e.stateMask == SWT.MOD1 && e.keyCode == 'c'){
+ copy(viewer.getStructuredSelection());
+ }
+ else if(e.stateMask == SWT.MOD1 && e.keyCode == 'v'){
+ paste(viewer.getStructuredSelection());
+ }
+ }
+ });
List<FeatureTree> trees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
+ Collections.sort(trees, (tree1, tree2) -> tree1.getTitleCache().compareTo(tree2.getTitleCache()));
viewer.setInput(trees);
//create context menu
menuService.registerContextMenu(viewer.getControl(), AppModelId.POPUPMENU_EU_ETAXONOMY_TAXEDITOR_STORE_POPUPMENU_FEATURETREEEDITOR);
}
+ public void paste(IStructuredSelection selection) {
+ if (StoreUtil.promptCheckIsDirty(this)) {
+ return;
+ }
+
+ ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
+ Object firstElement = selection.getFirstElement();
+ FeatureNode parentNode = null;
+ if(firstElement instanceof FeatureNode){
+ parentNode = (FeatureNode) firstElement;
+ }
+ else if(firstElement instanceof FeatureTree){
+ parentNode = ((FeatureTree)firstElement).getRoot();
+ }
+ if(parentNode!=null){
+ FeatureNode copiedNode = (FeatureNode) ((IStructuredSelection)clipBoardSelection).getFirstElement();
+
+ AddFeatureOperation operation = new AddFeatureOperation(copiedNode.getFeature(), parentNode, this, this);
+ AbstractUtility.executeOperation(operation, sync);
+ }
+
+ }
+
+ public void copy(IStructuredSelection selection) {
+ LocalSelectionTransfer.getTransfer().setSelection(selection);
+ }
+
private void initSession(){
if(conversation == null){
conversation = CdmStore.createConversation();
if(objectAffectedByOperation instanceof FeatureNode){
FeatureNode node = (FeatureNode)objectAffectedByOperation;
viewer.expandToLevel(node.getFeatureTree(), 1);
+ }
+ if(objectAffectedByOperation!=null){
StructuredSelection selection = new StructuredSelection(objectAffectedByOperation);
viewer.setSelection(selection);
}