Project

General

Profile

Download (5.43 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.featuretree.e4;
10

    
11
import org.eclipse.jface.viewers.ISelectionChangedListener;
12
import org.eclipse.jface.viewers.TreeViewer;
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.dnd.DND;
15
import org.eclipse.swt.dnd.DragSourceListener;
16
import org.eclipse.swt.dnd.DropTargetListener;
17
import org.eclipse.swt.dnd.Transfer;
18
import org.eclipse.swt.events.SelectionListener;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.layout.GridLayout;
21
import org.eclipse.swt.widgets.Button;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Label;
24
import org.eclipse.swt.widgets.Text;
25
import org.eclipse.swt.widgets.Tree;
26

    
27
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
28
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
29
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
30
import eu.etaxonomy.taxeditor.model.ImageResources;
31

    
32
/**
33
 * @author pplitzner
34
 * @since Jun 19, 2017
35
 *
36
 */
37
public class FeatureTreeEditorComposite extends Composite{
38

    
39
    private Label label_title;
40
    private Text text_title;
41
    private Button btnOpenFeatureTree;
42
    private TreeViewer viewer;
43
    private Button button_add;
44
    private Button button_remove;
45

    
46
    public FeatureTreeEditorComposite(Composite parent, int style) {
47
        super(parent, style);
48
        setLayout(new GridLayout(2, false));
49

    
50
        Composite composite_treeTitle = new Composite(this, SWT.NULL);
51
        composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
52
                false));
53
        GridLayout gl_composite_treeTitle = new GridLayout(2, false);
54
        gl_composite_treeTitle.marginWidth = 0;
55
        composite_treeTitle.setLayout(gl_composite_treeTitle);
56

    
57
        label_title = new Label(composite_treeTitle, SWT.NULL);
58
        label_title.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
59
        label_title.setText("Feature Tree");
60

    
61
        text_title = new Text(composite_treeTitle, SWT.BORDER);
62
        text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
63

    
64
        btnOpenFeatureTree = new Button(this, SWT.NONE);
65
        btnOpenFeatureTree.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
66
        btnOpenFeatureTree.setToolTipText("Open Tree");
67
        btnOpenFeatureTree.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
68

    
69
        viewer = new TreeViewer(this);
70
        Tree tree = viewer.getTree();
71
        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
72
        viewer.getControl().setLayoutData(
73
                new GridData(SWT.FILL, SWT.FILL, true, true));
74

    
75
        Composite composite_buttons = new Composite(this,
76
                SWT.NULL);
77
        composite_buttons.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false,
78
                false));
79
        composite_buttons.setLayout(new GridLayout());
80

    
81
        button_add = new Button(composite_buttons, SWT.PUSH);
82
        button_add.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
83
        button_add.setToolTipText("Add a feature to this feature tree.");
84
        button_add.setImage(ImageResources.getImage(ImageResources.ADD_EDIT));
85
        button_remove = new Button(composite_buttons, SWT.PUSH);
86
        button_remove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
87
        button_remove.setToolTipText("Remove a feature from this feature tree.");
88
        button_remove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
89
    }
90

    
91
    public void init(DragSourceListener dragSourceListener,
92
            DropTargetListener dropTargetListener, ISelectionChangedListener viewerSelectionChangedListener,
93
            SelectionListener selectionListener, SelectionListener addButtonSelectionListener, SelectionListener removeButtonSelectionListener) {
94
        viewer.setContentProvider(new FeatureTreeContentProvider());
95
        viewer.setLabelProvider(new FeatureTreeLabelProvider());
96

    
97
        int ops = DND.DROP_COPY | DND.DROP_MOVE;
98
        Transfer[] transfers = new Transfer[] { FeatureNodeTransfer
99
                .getInstance() };
100
        viewer.addDragSupport(ops, transfers, dragSourceListener);
101
        viewer.addDropSupport(ops, transfers, dropTargetListener);
102

    
103
        viewer.addSelectionChangedListener(viewerSelectionChangedListener);
104

    
105
        button_add.addSelectionListener(addButtonSelectionListener);
106
        button_remove.addSelectionListener(removeButtonSelectionListener);
107

    
108
        btnOpenFeatureTree.addSelectionListener(selectionListener);
109
    }
110

    
111
    /**
112
     * @return the label_title
113
     */
114
    public Label getLabel_title() {
115
        return label_title;
116
    }
117

    
118
    /**
119
     * @return the text_title
120
     */
121
    public Text getText_title() {
122
        return text_title;
123
    }
124

    
125
    /**
126
     * @return the btnOpenFeatureTree
127
     */
128
    public Button getBtnOpenFeatureTree() {
129
        return btnOpenFeatureTree;
130
    }
131

    
132
    /**
133
     * @return the viewer
134
     */
135
    public TreeViewer getViewer() {
136
        return viewer;
137
    }
138

    
139
    /**
140
     * @return the button_add
141
     */
142
    public Button getButton_add() {
143
        return button_add;
144
    }
145

    
146
    /**
147
     * @return the button_remove
148
     */
149
    public Button getButton_remove() {
150
        return button_remove;
151
    }
152

    
153
}
(4-4/4)