Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / NavigatorHandlerUtils.java
1 // $Id$
2 /**
3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.taxeditor.navigation.navigator.handler;
11
12 import org.eclipse.core.commands.ExecutionEvent;
13 import org.eclipse.ui.IEditorInput;
14 import org.eclipse.ui.IEditorReference;
15 import org.eclipse.ui.IWorkbenchPage;
16 import org.eclipse.ui.PartInitException;
17 import org.eclipse.ui.handlers.HandlerUtil;
18
19 import eu.etaxonomy.cdm.model.common.ITreeNode;
20 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21 import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
22
23 /**
24 * @author cmathew
25 * @date 16 Jun 2015
26 *
27 */
28 public class NavigatorHandlerUtils {
29
30 protected static boolean closeObsoleteEditor(ExecutionEvent event, TaxonNode taxonNode){
31 IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
32 boolean result = true;
33 for (IEditorReference ref : activePage.getEditorReferences()) {
34 try {
35 String treeIndex = ((ITreeNode)taxonNode).treeIndex();
36
37
38 IEditorInput input = ref.getEditorInput();
39 if (input instanceof TaxonEditorInput) {
40 TaxonNode node = ((TaxonEditorInput) input).getTaxonNode();
41 //if node is a child of taxonNode then close the editor
42 if( ((ITreeNode) node).treeIndex().startsWith(treeIndex)){
43 //if (taxonNode.equals(node)) {
44 result &= activePage.closeEditor(ref.getEditor(false), true);
45
46 }
47 }
48 } catch (PartInitException e) {
49 continue;
50 }
51 }
52 return result;
53 }
54
55 }