Project

General

Profile

Revision cecbda95

IDcecbda951361de6069f327bdac4a237e4d4b94f5
Parent 8b4697e6
Child 871e0d37

Added by Patrick Plitzner over 3 years ago

Clean up and refactoring

  • Delete unused class
  • Rename class to avoid duplicate name

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyContentProvider.java
1
// $Id$
2
/**
3
 * Copyright (C) 2007 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

  
11
package eu.etaxonomy.taxeditor.editor.key.polytomous;
12

  
13
import java.util.ArrayList;
14
import java.util.List;
15

  
16
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.zest.core.viewers.IGraphContentProvider;
18

  
19
import eu.etaxonomy.cdm.model.description.PolytomousKey;
20
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
21
import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
22

  
23
/**
24
 * 
25
 * @author n.hoffmann
26
 * @created Mar 30, 2011
27
 * @version 1.0
28
 */
29
class PolytomousKeyContentProvider implements IGraphContentProvider {
30

  
31
	private List<PolytomousKeyRelationship> relations;
32

  
33
	@Override
34
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
35

  
36
	}
37

  
38
	@Override
39
	public void dispose() {
40

  
41
	}
42

  
43
	@Override
44
	public Object[] getElements(Object inputElement) {
45
		relations = new ArrayList<PolytomousKeyRelationship>();
46

  
47
		if (inputElement instanceof PolytomousKey) {
48
			getTreeRecursively(relations, inputElement);
49
		}
50
		return relations.toArray();
51
	}
52

  
53
	private void getTreeRecursively(List<PolytomousKeyRelationship> relations,
54
			Object parent) {
55
		List<PolytomousKeyNode> children;
56

  
57
		if (parent instanceof PolytomousKeyNode) {
58
			children = ((PolytomousKeyNode) parent).getChildren();
59
		} else if (parent instanceof PolytomousKey) {
60
			children = new ArrayList<PolytomousKeyNode>();
61
			children.add(((PolytomousKey) parent).getRoot());
62
		} else {
63
			throw new RuntimeException(
64
					"Parent element has to be PolytomousKeyNode or PolytomousKey, but was: "
65
							+ parent.getClass());
66
		}
67

  
68
		for (PolytomousKeyNode childNode : children) {
69
			relations.add(new PolytomousKeyRelationship(parent, childNode));
70
			getTreeRecursively(relations, childNode);
71
		}
72
	}
73

  
74
	@Override
75
	public Object getSource(Object relationship) {
76
		return ((PolytomousKeyRelationship) relationship).getSource();
77
	}
78

  
79
	@Override
80
	public Object getDestination(Object relationship) {
81
		return ((PolytomousKeyRelationship) relationship).getDestination();
82
	}
83

  
84
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyGraphContentProvider.java
1
// $Id$
2
/**
3
 * Copyright (C) 2007 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

  
11
package eu.etaxonomy.taxeditor.editor.key.polytomous;
12

  
13
import java.util.ArrayList;
14
import java.util.List;
15

  
16
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.zest.core.viewers.IGraphContentProvider;
18

  
19
import eu.etaxonomy.cdm.model.description.PolytomousKey;
20
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
21
import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
22

  
23
/**
24
 * 
25
 * @author n.hoffmann
26
 * @created Mar 30, 2011
27
 * @version 1.0
28
 */
29
class PolytomousKeyGraphContentProvider implements IGraphContentProvider {
30

  
31
	private List<PolytomousKeyRelationship> relations;
32

  
33
	@Override
34
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
35

  
36
	}
37

  
38
	@Override
39
	public void dispose() {
40

  
41
	}
42

  
43
	@Override
44
	public Object[] getElements(Object inputElement) {
45
		relations = new ArrayList<PolytomousKeyRelationship>();
46

  
47
		if (inputElement instanceof PolytomousKey) {
48
			getTreeRecursively(relations, inputElement);
49
		}
50
		return relations.toArray();
51
	}
52

  
53
	private void getTreeRecursively(List<PolytomousKeyRelationship> relations,
54
			Object parent) {
55
		List<PolytomousKeyNode> children;
56

  
57
		if (parent instanceof PolytomousKeyNode) {
58
			children = ((PolytomousKeyNode) parent).getChildren();
59
		} else if (parent instanceof PolytomousKey) {
60
			children = new ArrayList<PolytomousKeyNode>();
61
			children.add(((PolytomousKey) parent).getRoot());
62
		} else {
63
			throw new RuntimeException(
64
					"Parent element has to be PolytomousKeyNode or PolytomousKey, but was: "
65
							+ parent.getClass());
66
		}
67

  
68
		for (PolytomousKeyNode childNode : children) {
69
			relations.add(new PolytomousKeyRelationship(parent, childNode));
70
			getTreeRecursively(relations, childNode);
71
		}
72
	}
73

  
74
	@Override
75
	public Object getSource(Object relationship) {
76
		return ((PolytomousKeyRelationship) relationship).getSource();
77
	}
78

  
79
	@Override
80
	public Object getDestination(Object relationship) {
81
		return ((PolytomousKeyRelationship) relationship).getDestination();
82
	}
83

  
84
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/PolytomousKeyGraphEditor.java
47 47

  
48 48
	@Override
49 49
	protected IContentProvider getContentProvider() {
50
		return new PolytomousKeyContentProvider();
50
		return new PolytomousKeyGraphContentProvider();
51 51
	}
52 52
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyLabelProvider.java
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.navigation.key.polytomous;
5

  
6
import org.eclipse.jface.viewers.ColumnLabelProvider;
7
import org.eclipse.jface.viewers.ILabelProvider;
8

  
9
/**
10
 * @author n.hoffmann
11
 *
12
 */
13
public class PolytomousKeyLabelProvider extends ColumnLabelProvider implements
14
		ILabelProvider {
15

  
16
}
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java
11 11
import org.eclipse.core.runtime.IProgressMonitor;
12 12
import org.eclipse.jface.action.GroupMarker;
13 13
import org.eclipse.jface.action.MenuManager;
14
import org.eclipse.jface.viewers.ColumnLabelProvider;
14 15
import org.eclipse.jface.viewers.DoubleClickEvent;
15 16
import org.eclipse.jface.viewers.IDoubleClickListener;
16 17
import org.eclipse.jface.viewers.ISelection;
......
147 148
		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
148 149

  
149 150
		viewer.setContentProvider(new PolytomousKeyContentProvider());
150
		viewer.setLabelProvider(new PolytomousKeyLabelProvider());
151
		viewer.setLabelProvider(new ColumnLabelProvider());
151 152

  
152 153
		viewer.addDoubleClickListener(new IDoubleClickListener() {
153 154

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)