Project

General

Profile

Download (1.81 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.navigation.navigator.handler;
10

    
11
import org.eclipse.core.commands.ExecutionEvent;
12
import org.eclipse.ui.IEditorInput;
13
import org.eclipse.ui.IEditorReference;
14
import org.eclipse.ui.IWorkbenchPage;
15
import org.eclipse.ui.PartInitException;
16
import org.eclipse.ui.handlers.HandlerUtil;
17

    
18
import eu.etaxonomy.cdm.model.common.ITreeNode;
19
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
20
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
21

    
22
/**
23
 * @author cmathew
24
 * @date 16 Jun 2015
25
 *
26
 */
27
public class NavigatorHandlerUtils {
28

    
29
    protected static boolean closeObsoleteEditor(ExecutionEvent event, TaxonNode taxonNode){
30
        IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
31
        boolean result = true;
32
        for (IEditorReference ref : activePage.getEditorReferences()) {
33
            try {
34
                String treeIndex = ((ITreeNode)taxonNode).treeIndex();
35

    
36

    
37
                IEditorInput input = ref.getEditorInput();
38
                if (input instanceof TaxonEditorInput) {
39
                    TaxonNode node = ((TaxonEditorInput) input).getTaxonNode();
40
                    //if node is a child of taxonNode then close the editor
41
                    if( ((ITreeNode) node).treeIndex().startsWith(treeIndex)){
42
                    //if (taxonNode.equals(node)) {
43
                        result &= activePage.closeEditor(ref.getEditor(false), true);
44

    
45
                    }
46
                }
47
            } catch (PartInitException e) {
48
                continue;
49
            }
50
        }
51
        return result;
52
    }
53

    
54
}
(8-8/16)