Project

General

Profile

« Previous | Next » 

Revision c8daeda0

Added by Patrick Plitzner over 4 years ago

ref #6806 Add remove taxon node key listener for DEL

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/TaxonNodeDropAdapter.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.workingSet;
10 10

  
11
import java.util.ArrayList;
12
import java.util.Collection;
13

  
14 11
import org.eclipse.jface.util.LocalSelectionTransfer;
15 12
import org.eclipse.jface.viewers.ISelection;
16 13
import org.eclipse.jface.viewers.IStructuredSelection;
17 14
import org.eclipse.jface.viewers.ITreeSelection;
18
import org.eclipse.jface.viewers.Viewer;
19 15
import org.eclipse.jface.viewers.ViewerDropAdapter;
20 16
import org.eclipse.swt.dnd.TransferData;
21 17

  
......
41 37
    @Override
42 38
    public boolean performDrop(Object data) {
43 39
        TaxonNode taxonNode= (TaxonNode) ((ITreeSelection) data).getFirstElement();
44
        //load into WS editor session
45
        taxonNode = workingSetEditor.getCdmEntitySession().load(taxonNode, false);
46
        Viewer taxonTreeViewer = workingSetEditor.getTaxonTreeViewer();
47
        Object input = taxonTreeViewer.getInput();
48
        Collection<TaxonNode> treeNodes;
49
        if(input==null){
50
            treeNodes = new ArrayList<>();
51
        }
52
        else{
53
            treeNodes = (Collection<TaxonNode>) input;
54
        }
55
        treeNodes.add(taxonNode);
56
        taxonTreeViewer.setInput(treeNodes);
57
        workingSetEditor.setDirty();
40
        workingSetEditor.addTaxonNode(taxonNode);
58 41
        return true;
59 42
    }
60 43

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetEditor.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.workingSet;
10 10

  
11
import java.util.ArrayList;
11 12
import java.util.Collection;
12 13
import java.util.HashSet;
14
import java.util.Iterator;
13 15
import java.util.List;
14 16
import java.util.Map;
15 17
import java.util.Set;
......
28 30
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
29 31
import org.eclipse.e4.ui.services.IServiceConstants;
30 32
import org.eclipse.jface.util.LocalSelectionTransfer;
33
import org.eclipse.jface.viewers.IStructuredSelection;
31 34
import org.eclipse.jface.viewers.Viewer;
32 35
import org.eclipse.swt.SWT;
33 36
import org.eclipse.swt.dnd.DND;
34 37
import org.eclipse.swt.dnd.Transfer;
38
import org.eclipse.swt.events.KeyAdapter;
39
import org.eclipse.swt.events.KeyEvent;
35 40
import org.eclipse.swt.events.ModifyEvent;
36 41
import org.eclipse.swt.events.ModifyListener;
37 42
import org.eclipse.swt.widgets.Composite;
......
124 129
        Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer()};
125 130
        composite.getTaxonNodeTree().addDropSupport(dndOperations, transfers, new TaxonNodeDropAdapter(this));
126 131

  
132
        composite.getTaxonNodeTree().getTree().addKeyListener(new KeyAdapter() {
133
            @Override
134
            public void keyPressed(KeyEvent e) {
135
                if(e.character==SWT.DEL){
136
                    IStructuredSelection selection = (IStructuredSelection) composite.getTaxonNodeTree().getSelection();
137
                    Iterator<TaxonNode> iterator = selection.iterator();
138
                    while(iterator.hasNext()){
139
                        TaxonNode taxonNode = iterator.next();
140
                        removeTaxonNode(taxonNode);
141
                    }
142
                }
143
            }
144
        });
145

  
127 146
    }
128 147

  
129 148
    public void init(UUID workingSetUuid) {
......
154 173
        composite.getTxt_label().addModifyListener(labelModifyListener);
155 174
    }
156 175

  
176
    public void addTaxonNode(TaxonNode taxonNode){
177
        //load into WS editor session
178
        taxonNode = getCdmEntitySession().load(taxonNode, false);
179
        Viewer taxonTreeViewer = getTaxonTreeViewer();
180
        Object input = taxonTreeViewer.getInput();
181
        Collection<TaxonNode> treeNodes;
182
        if(input==null){
183
            treeNodes = new ArrayList<>();
184
        }
185
        else{
186
            treeNodes = (Collection<TaxonNode>) input;
187
        }
188
        treeNodes.add(taxonNode);
189
        taxonTreeViewer.setInput(treeNodes);
190
        dirty.setDirty(true);
191
    }
192

  
193
    private void removeTaxonNode(TaxonNode taxonNode){
194
        Viewer taxonTreeViewer = getTaxonTreeViewer();
195
        Collection<TaxonNode> input = (Collection<TaxonNode>) taxonTreeViewer.getInput();
196
        input.remove(taxonNode);
197
        taxonTreeViewer.setInput(input);
198
        dirty.setDirty(true);
199
    }
200

  
157 201
    /**
158 202
     * {@inheritDoc}
159 203
     */
......
237 281
        return composite.getTaxonNodeTree();
238 282
    }
239 283

  
240
    public void setDirty() {
241
        dirty.setDirty(true);
242
    }
243

  
244 284
    /**
245 285
     * {@inheritDoc}
246 286
     */

Also available in: Unified diff