2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.featuretree
.e4
;
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
.ModifyListener
;
19 import org
.eclipse
.swt
.events
.SelectionAdapter
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.events
.SelectionListener
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.layout
.GridLayout
;
24 import org
.eclipse
.swt
.widgets
.Button
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.Label
;
27 import org
.eclipse
.swt
.widgets
.Listener
;
28 import org
.eclipse
.swt
.widgets
.Text
;
29 import org
.eclipse
.swt
.widgets
.Tree
;
31 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
32 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
33 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
34 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.TermTransfer
;
35 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureNodeTransfer
;
36 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureTreeContentProvider
;
37 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureTreeLabelProvider
;
38 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
39 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
40 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
41 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.FeatureTreeSelectionDialog
;
48 public class FeatureTreeEditorComposite
<T
extends DefinedTermBase
> extends Composite
{
50 private FeatureTree
<T
> featureTree
;
52 private Label label_title
;
53 private Text text_title
;
54 private Button btnOpenFeatureTree
;
55 private TreeViewer viewer
;
57 public FeatureTreeEditorComposite(Composite parent
, int style
) {
59 setLayout(new GridLayout(1, false));
61 Composite composite_treeTitle
= new Composite(this, SWT
.NULL
);
62 composite_treeTitle
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true,
64 GridLayout gl_composite_treeTitle
= new GridLayout(3, false);
65 gl_composite_treeTitle
.marginWidth
= 0;
66 composite_treeTitle
.setLayout(gl_composite_treeTitle
);
68 label_title
= new Label(composite_treeTitle
, SWT
.NULL
);
69 label_title
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
70 label_title
.setText(Messages
.FeatureTreeEditorComposite_FEATURE_TREE
);
72 text_title
= new Text(composite_treeTitle
, SWT
.BORDER
);
73 text_title
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
74 text_title
.setEditable(false);
76 btnOpenFeatureTree
= new Button(composite_treeTitle
, SWT
.NONE
);
77 btnOpenFeatureTree
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
78 btnOpenFeatureTree
.setToolTipText(Messages
.FeatureTreeEditorComposite_OPEN_TREE
);
79 btnOpenFeatureTree
.setImage(ImageResources
.getImage(ImageResources
.BROWSE_ICON
));
81 viewer
= new TreeViewer(new Tree(this, SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
));
82 Tree tree
= viewer
.getTree();
83 tree
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1));
84 viewer
.getControl().setLayoutData(
85 new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
88 public void init(String label
,
89 DragSourceListener dragSourceListener
,
90 DropTargetListener dropTargetListener
,
91 ISelectionChangedListener viewerSelectionChangedListener
,
92 IDirtyMarkable dirtyMarkable
,
93 ModifyListener textModifyListener
) {
99 viewerSelectionChangedListener
,
105 public void init(String label
, TermType termType
,
106 DragSourceListener dragSourceListener
,
107 DropTargetListener dropTargetListener
,
108 ISelectionChangedListener viewerSelectionChangedListener
,
109 IDirtyMarkable dirtyMarkable
,
110 ModifyListener textModifyListener
) {
116 viewerSelectionChangedListener
,
121 public void init(DragSourceListener dragSourceListener
,
122 DropTargetListener dropTargetListener
,
123 Transfer
[] transfers
,
124 ISelectionChangedListener viewerSelectionChangedListener
,
125 SelectionListener openFeatureTreeSelectionListener
,
126 ModifyListener textModifyListener
) {
132 viewerSelectionChangedListener
,
133 openFeatureTreeSelectionListener
,
137 private void init(String label
,
139 DragSourceListener dragSourceListener
,
140 DropTargetListener dropTargetListener
,
141 Transfer
[] transfers
,
142 ISelectionChangedListener viewerSelectionChangedListener
,
143 SelectionListener openFeatureTreeSelectionListener
,
144 IDirtyMarkable dirtyMarkable
,
145 ModifyListener textModifyListener
) {
147 label_title
.setText(label
);
150 viewer
.setContentProvider(new FeatureTreeContentProvider());
151 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
153 int ops
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
155 transfers
= new Transfer
[] {
156 FeatureNodeTransfer
.getInstance(),
157 TermTransfer
.getInstance(),
160 if(dragSourceListener
!=null){
161 viewer
.addDragSupport(ops
, transfers
, dragSourceListener
);
163 if(dropTargetListener
!=null){
164 viewer
.addDropSupport(ops
, transfers
, dropTargetListener
);
167 if(viewerSelectionChangedListener
!=null){
168 viewer
.addSelectionChangedListener(viewerSelectionChangedListener
);
171 if(textModifyListener
!=null){
172 text_title
.addModifyListener(textModifyListener
);
175 //add specific selection listener
176 if(openFeatureTreeSelectionListener
!=null){
177 btnOpenFeatureTree
.addSelectionListener(openFeatureTreeSelectionListener
);
180 //add default selection listener
181 btnOpenFeatureTree
.addSelectionListener(new SelectionAdapter(){
183 public void widgetSelected(SelectionEvent e
) {
184 FeatureTree
<T
> tree
= FeatureTreeSelectionDialog
.select(getDisplay().getActiveShell(),
187 setSelectedTree(tree
);
188 if(dirtyMarkable
!=null){
189 dirtyMarkable
.forceDirty();
197 public void setSelectedTree(FeatureTree
<T
> featureTree
) {
198 this.featureTree
= featureTree
;
200 viewer
.setInput(featureTree
);
202 Listener
[] listeners
= text_title
.getListeners(SWT
.Modify
);
203 for (Listener listener
: listeners
) {
204 text_title
.removeListener(SWT
.Modify
, listener
);
206 text_title
.setText(featureTree
!=null?featureTree
.getTitleCache():"");
207 for (Listener listener
: listeners
) {
208 text_title
.addListener(SWT
.Modify
, listener
);
212 public FeatureTree
<T
> getFeatureTree() {
216 public Label
getLabel_title() {
220 public Button
getBtnOpenFeatureTree() {
221 return btnOpenFeatureTree
;
224 public TreeViewer
getViewer() {