Merge branch 'develop' into feature/cdm-4.7
[taxeditor.git] / eu.etaxonomy.taxeditor.molecular / src / main / java / eu / etaxonomy / taxeditor / molecular / handler / AbstractPherogramComponentHandler.java
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.molecular.handler;
10
11
12 import java.util.Iterator;
13
14 import org.eclipse.core.commands.AbstractHandler;
15 import org.eclipse.core.commands.ExecutionEvent;
16 import org.eclipse.core.commands.ExecutionException;
17
18 import eu.etaxonomy.taxeditor.model.AbstractUtility;
19 import eu.etaxonomy.taxeditor.molecular.editor.AlignmentEditor;
20 import eu.etaxonomy.taxeditor.molecular.editor.PherogramViewPart;
21 import info.bioinfweb.libralign.alignmentarea.AlignmentArea;
22 import info.bioinfweb.libralign.dataarea.implementations.pherogram.PherogramArea;
23 import info.bioinfweb.libralign.pherogram.PherogramComponent;
24
25
26
27 /**
28 * Abstract handler implementation allows to performs the concrete operation either on an instance of
29 * {@link PherogramViewPart} or all {@link AlignmentArea}s inside an instance of {@link AlignmentEditor}.
30 *
31 * @author Ben Stöver
32 * @date 23.06.2015
33 */
34 public abstract class AbstractPherogramComponentHandler extends AbstractHandler {
35 @Override
36 public Object execute(ExecutionEvent event) throws ExecutionException {
37 Object activePart = AbstractUtility.getActiveE4Part();
38
39 if (activePart instanceof AlignmentEditor) {
40 AlignmentEditor editor = (AlignmentEditor)activePart;
41 Iterator<String> idIterator = editor.getReadsArea().getAlignmentModel().sequenceIDIterator();
42 while (idIterator.hasNext()) {
43 PherogramArea area = editor.getPherogramArea(idIterator.next());
44 if (area != null) {
45 doExecute(event, area);
46 }
47 }
48 }
49 else if (activePart instanceof PherogramViewPart) {
50 doExecute(event, ((PherogramViewPart)activePart).getPherogramView().getTraceCurveView());
51 }
52 return null;
53 }
54
55
56 public abstract void doExecute(ExecutionEvent event, PherogramComponent component) throws ExecutionException;
57 }