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
.description
.FeatureTree
;
32 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.TermTransfer
;
33 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureNodeTransfer
;
34 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureTreeContentProvider
;
35 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureTreeLabelProvider
;
36 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
37 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
38 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.FeatureTreeSelectionDialog
;
45 public class FeatureTreeEditorComposite
extends Composite
{
47 private FeatureTree featureTree
;
49 private Label label_title
;
50 private Text text_title
;
51 private Button btnOpenFeatureTree
;
52 private TreeViewer viewer
;
54 public FeatureTreeEditorComposite(Composite parent
, int style
) {
56 setLayout(new GridLayout(1, false));
58 Composite composite_treeTitle
= new Composite(this, SWT
.NULL
);
59 composite_treeTitle
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true,
61 GridLayout gl_composite_treeTitle
= new GridLayout(3, false);
62 gl_composite_treeTitle
.marginWidth
= 0;
63 composite_treeTitle
.setLayout(gl_composite_treeTitle
);
65 label_title
= new Label(composite_treeTitle
, SWT
.NULL
);
66 label_title
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
67 label_title
.setText(Messages
.FeatureTreeEditorComposite_FEATURE_TREE
);
69 text_title
= new Text(composite_treeTitle
, SWT
.BORDER
);
70 text_title
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
71 text_title
.setEnabled(false);
73 btnOpenFeatureTree
= new Button(composite_treeTitle
, SWT
.NONE
);
74 btnOpenFeatureTree
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
75 btnOpenFeatureTree
.setToolTipText(Messages
.FeatureTreeEditorComposite_OPEN_TREE
);
76 btnOpenFeatureTree
.setImage(ImageResources
.getImage(ImageResources
.BROWSE_ICON
));
78 viewer
= new TreeViewer(new Tree(this, SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
79 Tree tree
= viewer
.getTree();
80 tree
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1));
81 viewer
.getControl().setLayoutData(
82 new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
85 public void init(DragSourceListener dragSourceListener
, DropTargetListener dropTargetListener
,
86 ISelectionChangedListener viewerSelectionChangedListener
,
87 SelectionListener openFeatureTreeSelectionListener
) {
88 viewer
.setContentProvider(new FeatureTreeContentProvider());
89 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
91 int ops
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
92 Transfer
[] transfers
= new Transfer
[] { FeatureNodeTransfer
93 .getInstance(), TermTransfer
.getInstance() };
94 if(dragSourceListener
!=null){
95 viewer
.addDragSupport(ops
, transfers
, dragSourceListener
);
97 if(dropTargetListener
!=null){
98 viewer
.addDropSupport(ops
, transfers
, dropTargetListener
);
101 if(viewerSelectionChangedListener
!=null){
102 viewer
.addSelectionChangedListener(viewerSelectionChangedListener
);
105 //add specific selection listener
106 if(openFeatureTreeSelectionListener
!=null){
107 btnOpenFeatureTree
.addSelectionListener(openFeatureTreeSelectionListener
);
110 //add default selection listener
111 btnOpenFeatureTree
.addSelectionListener(new SelectionAdapter(){
113 public void widgetSelected(SelectionEvent e
) {
114 FeatureTree tree
= FeatureTreeSelectionDialog
.select(getDisplay().getActiveShell(),
117 setSelectedTree(tree
, null);
118 getText_title().setEnabled(false);
125 public void setSelectedTree(FeatureTree featureTree
, ModifyListener modifyListener
) {
126 this.featureTree
= featureTree
;
128 getViewer().setInput(featureTree
);
130 Listener
[] listeners
= getText_title().getListeners(SWT
.Modify
);
131 for (Listener listener
: listeners
) {
132 getText_title().removeListener(SWT
.Modify
, listener
);
134 getText_title().setText(featureTree
.getTitleCache());
135 for (Listener listener
: listeners
) {
136 getText_title().addListener(SWT
.Modify
, listener
);
138 getText_title().setEnabled(true);
139 text_title
.setEnabled(true);
143 * @return the featureTree
145 public FeatureTree
getFeatureTree() {
150 * @return the label_title
152 public Label
getLabel_title() {
157 * @return the text_title
159 public Text
getText_title() {
164 * @return the btnOpenFeatureTree
166 public Button
getBtnOpenFeatureTree() {
167 return btnOpenFeatureTree
;
173 public TreeViewer
getViewer() {