Project

General

Profile

Revision 1c54a64e

ID1c54a64ef6f64860b17921009ce210728ce88053
Parent eb916729
Child b599010f

Added by Patrick Plitzner about 1 year ago

ref #7873 Implement copy&paste keyboard shortcuts

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java
28 28
import org.eclipse.e4.ui.workbench.modeling.EPartService;
29 29
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
30 30
import org.eclipse.jface.util.LocalSelectionTransfer;
31
import org.eclipse.jface.viewers.ISelection;
31 32
import org.eclipse.jface.viewers.ISelectionChangedListener;
32 33
import org.eclipse.jface.viewers.IStructuredSelection;
33 34
import org.eclipse.jface.viewers.SelectionChangedEvent;
34 35
import org.eclipse.jface.viewers.StructuredSelection;
35 36
import org.eclipse.jface.viewers.TreeViewer;
37
import org.eclipse.swt.SWT;
36 38
import org.eclipse.swt.dnd.DND;
37 39
import org.eclipse.swt.dnd.Transfer;
40
import org.eclipse.swt.events.KeyAdapter;
41
import org.eclipse.swt.events.KeyEvent;
38 42
import org.eclipse.swt.layout.FillLayout;
39 43
import org.eclipse.swt.widgets.Composite;
40 44
import org.eclipse.ui.IMemento;
......
49 53
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
50 54
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
51 55
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
56
import eu.etaxonomy.taxeditor.featuretree.e4.operation.AddFeatureOperation;
57
import eu.etaxonomy.taxeditor.model.AbstractUtility;
52 58
import eu.etaxonomy.taxeditor.model.IContextListener;
53 59
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
54 60
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
......
56 62
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
57 63
import eu.etaxonomy.taxeditor.store.AppModelId;
58 64
import eu.etaxonomy.taxeditor.store.CdmStore;
65
import eu.etaxonomy.taxeditor.store.StoreUtil;
59 66
import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart;
60 67

  
61 68
/**
......
112 119
        viewer.addDragSupport(ops, transfers, new FeatureNodeDragListener(viewer));
113 120
        viewer.addDropSupport(ops, transfers, new FeatureTreeDropAdapter(this, viewer, sync));
114 121
        viewer.addSelectionChangedListener(this);
122
        viewer.getTree().addKeyListener(new KeyAdapter() {
123
            @Override
124
            public void keyPressed(KeyEvent e) {
125
                if(e.stateMask == SWT.MOD1 && e.keyCode == 'c'){
126
                    copy(viewer.getStructuredSelection());
127
                }
128
                else if(e.stateMask == SWT.MOD1 && e.keyCode == 'v'){
129
                    paste(viewer.getStructuredSelection());
130
                }
131
            }
132
        });
115 133

  
116 134
        List<FeatureTree> trees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
117 135
        viewer.setInput(trees);
......
120 138
        menuService.registerContextMenu(viewer.getControl(), AppModelId.POPUPMENU_EU_ETAXONOMY_TAXEDITOR_STORE_POPUPMENU_FEATURETREEEDITOR);
121 139
    }
122 140

  
141
    public void paste(IStructuredSelection selection) {
142
        if (StoreUtil.promptCheckIsDirty(this)) {
143
            return;
144
        }
145

  
146
        ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
147
        Object firstElement = selection.getFirstElement();
148
        FeatureNode parentNode = null;
149
        if(firstElement instanceof FeatureNode){
150
            parentNode = (FeatureNode) firstElement;
151
        }
152
        else if(firstElement instanceof FeatureTree){
153
            parentNode = ((FeatureTree)firstElement).getRoot();
154
        }
155
        if(parentNode!=null){
156
            FeatureNode copiedNode = (FeatureNode) ((IStructuredSelection)clipBoardSelection).getFirstElement();
157

  
158
            AddFeatureOperation operation = new AddFeatureOperation(copiedNode.getFeature(), parentNode, this, this);
159
            AbstractUtility.executeOperation(operation, sync);
160
        }
161

  
162
    }
163

  
164
    public void copy(IStructuredSelection selection) {
165
        LocalSelectionTransfer.getTransfer().setSelection(selection);
166
    }
167

  
123 168
    private void initSession(){
124 169
        if(conversation == null){
125 170
            conversation = CdmStore.createConversation();
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/CopyFeatureHandler.java
9 9
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
10 10
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
11 11
import org.eclipse.e4.ui.services.IServiceConstants;
12
import org.eclipse.jface.util.LocalSelectionTransfer;
13 12
import org.eclipse.jface.viewers.IStructuredSelection;
14 13

  
15 14
import eu.etaxonomy.cdm.model.description.FeatureNode;
16
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
15
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
17 16

  
18 17
public class CopyFeatureHandler {
19 18

  
20 19
    @Execute
21
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
22
        LocalSelectionTransfer.getTransfer().setSelection(selection);
20
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
21
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
22
        ((FeatureTreeEditor) part.getObject()).copy(selection);
23 23
    }
24 24

  
25 25
    @CanExecute
......
27 27
            @Named(IServiceConstants.ACTIVE_PART) MPart part,
28 28
            MHandledMenuItem menuItem){
29 29
        boolean canExecute = false;
30
        canExecute =part.getObject() instanceof IFeatureTreeEditor
30
        canExecute =part.getObject() instanceof FeatureTreeEditor
31 31
                && selection!=null
32 32
                && selection.size()==1
33 33
                && selection.getFirstElement() instanceof FeatureNode;
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/PasteFeatureHandler.java
6 6
import org.eclipse.e4.core.di.annotations.CanExecute;
7 7
import org.eclipse.e4.core.di.annotations.Execute;
8 8
import org.eclipse.e4.core.di.annotations.Optional;
9
import org.eclipse.e4.ui.di.UISynchronize;
10 9
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
11 10
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
12 11
import org.eclipse.e4.ui.services.IServiceConstants;
......
15 14
import org.eclipse.jface.viewers.IStructuredSelection;
16 15

  
17 16
import eu.etaxonomy.cdm.model.description.FeatureNode;
18
import eu.etaxonomy.cdm.model.description.FeatureTree;
19
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
20
import eu.etaxonomy.taxeditor.featuretree.e4.operation.AddFeatureOperation;
21
import eu.etaxonomy.taxeditor.model.AbstractUtility;
22
import eu.etaxonomy.taxeditor.store.StoreUtil;
17
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
23 18

  
24 19
public class PasteFeatureHandler {
25 20

  
26 21
    @Execute
27 22
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
28
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, UISynchronize sync){
29
        IFeatureTreeEditor editor = (IFeatureTreeEditor)part.getObject();
30

  
31
        if (StoreUtil.promptCheckIsDirty(editor)) {
32
            return;
33
        }
34

  
35
        ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
36
        Object firstElement = selection.getFirstElement();
37
        FeatureNode parentNode = null;
38
        if(firstElement instanceof FeatureNode){
39
            parentNode = (FeatureNode) firstElement;
40
        }
41
        else if(firstElement instanceof FeatureTree){
42
            parentNode = ((FeatureTree)firstElement).getRoot();
43
        }
44
        if(parentNode!=null){
45
            FeatureNode copiedNode = (FeatureNode) ((IStructuredSelection)clipBoardSelection).getFirstElement();
46

  
47
            AddFeatureOperation operation = new AddFeatureOperation(copiedNode.getFeature(), parentNode, editor, editor);
48
            AbstractUtility.executeOperation(operation, sync);
49
        }
23
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
24
        FeatureTreeEditor editor = (FeatureTreeEditor)part.getObject();
25
        editor.paste(selection);
50 26
    }
51 27

  
52 28
    @CanExecute
53 29
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
30
            @Named(IServiceConstants.ACTIVE_PART) MPart part,
54 31
            MHandledMenuItem menuItem){
55 32
        boolean canExecute = false;
56 33
        ISelection transferSelection = LocalSelectionTransfer.getTransfer().getSelection();
57
        canExecute = selection!=null
34
        canExecute = part.getObject() instanceof FeatureTreeEditor
35
                && selection!=null
58 36
                && selection.size()==1
59 37
                && transferSelection instanceof IStructuredSelection
60 38
                && ((IStructuredSelection)transferSelection).size()==1

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)