Project

General

Profile

« Previous | Next » 

Revision f6a8dc56

Added by Patrick Plitzner over 10 years ago

merged model adaptions to cdmlib 3.2.4 from campanula branch

View differences:

eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/DeleteHandler.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
29 29
import org.eclipse.ui.PartInitException;
30 30
import org.eclipse.ui.handlers.HandlerUtil;
31 31

  
32
import eu.etaxonomy.cdm.model.taxon.ITreeNode;
32
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
33 33
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
34 34
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
35 35
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
......
50 50
	private TaxonNavigator taxonNavigator;
51 51

  
52 52
	/** {@inheritDoc} */
53
	public Object execute(ExecutionEvent event) throws ExecutionException {
54
		
53
	@Override
54
    public Object execute(ExecutionEvent event) throws ExecutionException {
55

  
55 56
		activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
56
		
57

  
57 58
		taxonNavigator = NavigationUtil.showNavigator();
58
				
59

  
59 60
		TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
60
		
61

  
61 62
		String plural = selection.size() > 1 ? "s" : "";
62 63
		// Prompt user for confirmation
63 64
		if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Are you sure you want to delete the selected node" + plural +"?")){
64 65
			return null;
65 66
		}
66
		
67

  
67 68
		Iterator selectionIterator = selection.iterator();
68
		Set<ITreeNode> treeNodes = new HashSet<ITreeNode>();
69
		
69
		Set<ITaxonTreeNode> treeNodes = new HashSet<ITaxonTreeNode>();
70

  
70 71
		while (selectionIterator.hasNext()){
71 72
			Object object = selectionIterator.next();
72
			if(object instanceof ITreeNode)
73
				treeNodes.add((ITreeNode) object);
73
			if(object instanceof ITaxonTreeNode) {
74
                treeNodes.add((ITaxonTreeNode) object);
75
            }
74 76
		}
75
			
77

  
76 78
		AbstractPostOperation operation = null;
77 79
		try {
78 80
			operation = new DeleteOperation(
79
					event.getCommand().getName(), NavigationUtil.getUndoContext(), 
81
					event.getCommand().getName(), NavigationUtil.getUndoContext(),
80 82
					treeNodes, taxonNavigator, taxonNavigator);
81
			
83

  
82 84
			IStatus status = NavigationUtil.executeOperation(operation);
83
			
84
			
85

  
86

  
85 87
			// FIXME is there a better place for this code?
86 88
			if (status == Status.OK_STATUS){
87
				for (ITreeNode treeNode : treeNodes){
89
				for (ITaxonTreeNode treeNode : treeNodes){
88 90
					if(treeNode instanceof TaxonNode) {
89 91
						closeObsoleteEditor((TaxonNode) treeNode);
90 92
					}
91 93
				}
92 94
			}
93
		
95

  
94 96
		} catch (NotDefinedException e) {
95 97
			NavigationUtil.warn(getClass(), "Command name not set");
96 98
		}
97 99
		return null;
98 100
	}
99
	
101

  
100 102
	private void closeObsoleteEditor(TaxonNode taxonNode){
101 103
		for (IEditorReference ref : activePage.getEditorReferences()) {
102 104
			try {
103
				IEditorInput input = ref.getEditorInput(); 
105
				IEditorInput input = ref.getEditorInput();
104 106
				if (input instanceof TaxonEditorInput) {
105 107
					TaxonNode node = ((TaxonEditorInput) input).getTaxonNode();
106 108
					if (taxonNode.equals(node)) {

Also available in: Unified diff