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
.term
.DefinedTermBase
;
32 import eu
.etaxonomy
.cdm
.model
.term
.TermTree
;
33 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
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
;
47 public class FeatureTreeEditorComposite
<T
extends DefinedTermBase
> extends Composite
{
49 private TermTree
<T
> featureTree
;
51 private Label label_title
;
52 private Text text_title
;
53 private Button btnOpenFeatureTree
;
54 private TreeViewer viewer
;
56 public FeatureTreeEditorComposite(Composite parent
, int style
) {
58 setLayout(new GridLayout(1, false));
60 Composite composite_treeTitle
= new Composite(this, SWT
.NULL
);
61 composite_treeTitle
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true,
63 GridLayout gl_composite_treeTitle
= new GridLayout(3, false);
64 gl_composite_treeTitle
.marginWidth
= 0;
65 composite_treeTitle
.setLayout(gl_composite_treeTitle
);
67 label_title
= new Label(composite_treeTitle
, SWT
.NULL
);
68 label_title
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
69 label_title
.setText(Messages
.FeatureTreeEditorComposite_FEATURE_TREE
);
71 text_title
= new Text(composite_treeTitle
, SWT
.BORDER
);
72 text_title
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
73 text_title
.setEditable(false);
75 btnOpenFeatureTree
= new Button(composite_treeTitle
, SWT
.NONE
);
76 btnOpenFeatureTree
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
77 btnOpenFeatureTree
.setToolTipText(Messages
.FeatureTreeEditorComposite_OPEN_TREE
);
78 btnOpenFeatureTree
.setImage(ImageResources
.getImage(ImageResources
.BROWSE_ICON
));
80 viewer
= new TreeViewer(new Tree(this, SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.MULTI
));
81 Tree tree
= viewer
.getTree();
82 tree
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1));
83 viewer
.getControl().setLayoutData(
84 new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
87 public void init(String label
,
88 DragSourceListener dragSourceListener
,
89 DropTargetListener dropTargetListener
,
90 ISelectionChangedListener viewerSelectionChangedListener
,
91 IDirtyMarkable dirtyMarkable
,
92 ModifyListener textModifyListener
) {
98 viewerSelectionChangedListener
,
104 public void init(String label
, TermType termType
,
105 DragSourceListener dragSourceListener
,
106 DropTargetListener dropTargetListener
,
107 ISelectionChangedListener viewerSelectionChangedListener
,
108 IDirtyMarkable dirtyMarkable
,
109 ModifyListener textModifyListener
) {
115 viewerSelectionChangedListener
,
120 public void init(DragSourceListener dragSourceListener
,
121 DropTargetListener dropTargetListener
,
122 Transfer
[] transfers
,
123 ISelectionChangedListener viewerSelectionChangedListener
,
124 SelectionListener openFeatureTreeSelectionListener
,
125 ModifyListener textModifyListener
) {
131 viewerSelectionChangedListener
,
132 openFeatureTreeSelectionListener
,
136 private void init(String label
,
138 DragSourceListener dragSourceListener
,
139 DropTargetListener dropTargetListener
,
140 Transfer
[] transfers
,
141 ISelectionChangedListener viewerSelectionChangedListener
,
142 SelectionListener openFeatureTreeSelectionListener
,
143 IDirtyMarkable dirtyMarkable
,
144 ModifyListener textModifyListener
) {
146 label_title
.setText(label
);
149 viewer
.setContentProvider(new FeatureTreeContentProvider());
150 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
152 int ops
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
154 transfers
= new Transfer
[] {
155 FeatureNodeTransfer
.getInstance(),
156 TermTransfer
.getInstance(),
159 if(dragSourceListener
!=null){
160 viewer
.addDragSupport(ops
, transfers
, dragSourceListener
);
162 if(dropTargetListener
!=null){
163 viewer
.addDropSupport(ops
, transfers
, dropTargetListener
);
166 if(viewerSelectionChangedListener
!=null){
167 viewer
.addSelectionChangedListener(viewerSelectionChangedListener
);
170 if(textModifyListener
!=null){
171 text_title
.addModifyListener(textModifyListener
);
174 //add specific selection listener
175 if(openFeatureTreeSelectionListener
!=null){
176 btnOpenFeatureTree
.addSelectionListener(openFeatureTreeSelectionListener
);
179 //add default selection listener
180 btnOpenFeatureTree
.addSelectionListener(new SelectionAdapter(){
182 public void widgetSelected(SelectionEvent e
) {
183 TermTree
<T
> tree
= FeatureTreeSelectionDialog
.select(getDisplay().getActiveShell(),
186 setSelectedTree(tree
);
187 if(dirtyMarkable
!=null){
188 dirtyMarkable
.forceDirty();
196 public void setSelectedTree(TermTree
<T
> featureTree
) {
197 this.featureTree
= featureTree
;
199 viewer
.setInput(featureTree
);
201 Listener
[] listeners
= text_title
.getListeners(SWT
.Modify
);
202 for (Listener listener
: listeners
) {
203 text_title
.removeListener(SWT
.Modify
, listener
);
205 text_title
.setText(featureTree
!=null?featureTree
.getTitleCache():"");
206 for (Listener listener
: listeners
) {
207 text_title
.addListener(SWT
.Modify
, listener
);
211 public TermTree
<T
> getFeatureTree() {
215 public Label
getLabel_title() {
219 public Button
getBtnOpenFeatureTree() {
220 return btnOpenFeatureTree
;
223 public TreeViewer
getViewer() {