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
.IDirtyMarkable
;
38 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
39 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.FeatureTreeSelectionDialog
;
46 public class FeatureTreeEditorComposite
extends Composite
{
48 private FeatureTree featureTree
;
50 private Label label_title
;
51 private Text text_title
;
52 private Button btnOpenFeatureTree
;
53 private TreeViewer viewer
;
55 public FeatureTreeEditorComposite(Composite parent
, int style
) {
57 setLayout(new GridLayout(1, false));
59 Composite composite_treeTitle
= new Composite(this, SWT
.NULL
);
60 composite_treeTitle
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true,
62 GridLayout gl_composite_treeTitle
= new GridLayout(3, false);
63 gl_composite_treeTitle
.marginWidth
= 0;
64 composite_treeTitle
.setLayout(gl_composite_treeTitle
);
66 label_title
= new Label(composite_treeTitle
, SWT
.NULL
);
67 label_title
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
68 label_title
.setText(Messages
.FeatureTreeEditorComposite_FEATURE_TREE
);
70 text_title
= new Text(composite_treeTitle
, SWT
.BORDER
);
71 text_title
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
72 text_title
.setEnabled(false);
74 btnOpenFeatureTree
= new Button(composite_treeTitle
, SWT
.NONE
);
75 btnOpenFeatureTree
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
76 btnOpenFeatureTree
.setToolTipText(Messages
.FeatureTreeEditorComposite_OPEN_TREE
);
77 btnOpenFeatureTree
.setImage(ImageResources
.getImage(ImageResources
.BROWSE_ICON
));
79 viewer
= new TreeViewer(new Tree(this, SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
80 Tree tree
= viewer
.getTree();
81 tree
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 3, 1));
82 viewer
.getControl().setLayoutData(
83 new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
86 public void init(String label
, DragSourceListener dragSourceListener
, DropTargetListener dropTargetListener
,
87 ISelectionChangedListener viewerSelectionChangedListener
, IDirtyMarkable dirtyMarkable
,
88 ModifyListener textModifyListener
) {
89 this.init(label
, dragSourceListener
, dropTargetListener
, viewerSelectionChangedListener
, null, dirtyMarkable
,
92 public void init(DragSourceListener dragSourceListener
, DropTargetListener dropTargetListener
,
93 ISelectionChangedListener viewerSelectionChangedListener
,
94 SelectionListener openFeatureTreeSelectionListener
,
95 ModifyListener textModifyListener
) {
96 init(null, dragSourceListener
, dropTargetListener
, viewerSelectionChangedListener
, openFeatureTreeSelectionListener
,
97 null, textModifyListener
);
99 private void init(String label
, DragSourceListener dragSourceListener
,
100 DropTargetListener dropTargetListener
,
101 ISelectionChangedListener viewerSelectionChangedListener
,
102 SelectionListener openFeatureTreeSelectionListener
, IDirtyMarkable dirtyMarkable
,
103 ModifyListener textModifyListener
) {
104 if(label_title
!=null){
105 label_title
.setText(label
);
108 viewer
.setContentProvider(new FeatureTreeContentProvider());
109 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
111 int ops
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
112 Transfer
[] transfers
= new Transfer
[] { FeatureNodeTransfer
113 .getInstance(), TermTransfer
.getInstance() };
114 if(dragSourceListener
!=null){
115 viewer
.addDragSupport(ops
, transfers
, dragSourceListener
);
117 if(dropTargetListener
!=null){
118 viewer
.addDropSupport(ops
, transfers
, dropTargetListener
);
121 if(viewerSelectionChangedListener
!=null){
122 viewer
.addSelectionChangedListener(viewerSelectionChangedListener
);
125 if(textModifyListener
!=null){
126 text_title
.addModifyListener(textModifyListener
);
129 //add specific selection listener
130 if(openFeatureTreeSelectionListener
!=null){
131 btnOpenFeatureTree
.addSelectionListener(openFeatureTreeSelectionListener
);
134 //add default selection listener
135 btnOpenFeatureTree
.addSelectionListener(new SelectionAdapter(){
137 public void widgetSelected(SelectionEvent e
) {
138 FeatureTree tree
= FeatureTreeSelectionDialog
.select(getDisplay().getActiveShell(),
141 setSelectedTree(tree
);
142 text_title
.setEnabled(false);
143 if(dirtyMarkable
!=null){
144 dirtyMarkable
.forceDirty();
152 public void setSelectedTree(FeatureTree featureTree
) {
153 this.featureTree
= featureTree
;
155 viewer
.setInput(featureTree
);
157 Listener
[] listeners
= text_title
.getListeners(SWT
.Modify
);
158 for (Listener listener
: listeners
) {
159 text_title
.removeListener(SWT
.Modify
, listener
);
161 text_title
.setText(featureTree
!=null?featureTree
.getTitleCache():"");
162 for (Listener listener
: listeners
) {
163 text_title
.addListener(SWT
.Modify
, listener
);
165 text_title
.setEnabled(true);
166 text_title
.setEnabled(true);
169 public FeatureTree
getFeatureTree() {
173 public Text
getText_title() {
177 public Label
getLabel_title() {
181 public Button
getBtnOpenFeatureTree() {
182 return btnOpenFeatureTree
;
185 public TreeViewer
getViewer() {