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
.SelectionListener
;
20 import org
.eclipse
.swt
.layout
.GridData
;
21 import org
.eclipse
.swt
.layout
.GridLayout
;
22 import org
.eclipse
.swt
.widgets
.Button
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Label
;
25 import org
.eclipse
.swt
.widgets
.Text
;
26 import org
.eclipse
.swt
.widgets
.Tree
;
28 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
29 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureNodeTransfer
;
30 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureTreeContentProvider
;
31 import eu
.etaxonomy
.taxeditor
.featuretree
.FeatureTreeLabelProvider
;
32 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
33 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
40 public class FeatureTreeEditorComposite
extends Composite
{
42 private FeatureTree featureTree
;
44 private Label label_title
;
45 private Text text_title
;
46 private Button btnOpenFeatureTree
;
47 private TreeViewer viewer
;
48 private Button button_add
;
49 private Button button_remove
;
50 private Button btnExportTree
;
52 public FeatureTreeEditorComposite(Composite parent
, int style
) {
54 setLayout(new GridLayout(2, false));
56 Composite composite_treeTitle
= new Composite(this, SWT
.NULL
);
57 composite_treeTitle
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true,
59 GridLayout gl_composite_treeTitle
= new GridLayout(2, false);
60 gl_composite_treeTitle
.marginWidth
= 0;
61 composite_treeTitle
.setLayout(gl_composite_treeTitle
);
63 label_title
= new Label(composite_treeTitle
, SWT
.NULL
);
64 label_title
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false, 1, 1));
65 label_title
.setText(Messages
.FeatureTreeEditorComposite_FEATURE_TREE
);
67 text_title
= new Text(composite_treeTitle
, SWT
.BORDER
);
68 text_title
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
70 btnOpenFeatureTree
= new Button(this, SWT
.NONE
);
71 btnOpenFeatureTree
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
72 btnOpenFeatureTree
.setToolTipText(Messages
.FeatureTreeEditorComposite_OPEN_TREE
);
73 btnOpenFeatureTree
.setImage(ImageResources
.getImage(ImageResources
.BROWSE_ICON
));
75 viewer
= new TreeViewer(this);
76 Tree tree
= viewer
.getTree();
77 tree
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1));
78 viewer
.getControl().setLayoutData(
79 new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
81 Composite composite_buttons
= new Composite(this,
83 composite_buttons
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.TOP
, false,
85 composite_buttons
.setLayout(new GridLayout());
87 button_add
= new Button(composite_buttons
, SWT
.PUSH
);
88 button_add
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
89 button_add
.setToolTipText(Messages
.FeatureTreeEditorComposite_ADD_FEATURE
);
90 button_add
.setImage(ImageResources
.getImage(ImageResources
.ADD_EDIT
));
91 button_remove
= new Button(composite_buttons
, SWT
.PUSH
);
92 button_remove
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
93 button_remove
.setToolTipText(Messages
.FeatureTreeEditorComposite_REMOVE_FEATURE
);
94 button_remove
.setImage(ImageResources
.getImage(ImageResources
.TRASH_ICON
));
96 btnExportTree
= new Button(composite_buttons
, SWT
.NONE
);
97 btnExportTree
.setToolTipText("Export feature tree");
98 btnExportTree
.setImage(ImageResources
.getImage(ImageResources
.MOVE_ICON
));
101 public void init(DragSourceListener dragSourceListener
,
102 DropTargetListener dropTargetListener
, ISelectionChangedListener viewerSelectionChangedListener
,
103 SelectionListener openFeatureTreeSelectionListener
, SelectionListener addButtonSelectionListener
, SelectionListener removeButtonSelectionListener
, SelectionListener exportButtonSelectionListener
) {
104 viewer
.setContentProvider(new FeatureTreeContentProvider());
105 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
107 int ops
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
108 Transfer
[] transfers
= new Transfer
[] { FeatureNodeTransfer
110 if(dragSourceListener
!=null){
111 viewer
.addDragSupport(ops
, transfers
, dragSourceListener
);
113 if(dropTargetListener
!=null){
114 viewer
.addDropSupport(ops
, transfers
, dropTargetListener
);
117 viewer
.addSelectionChangedListener(viewerSelectionChangedListener
);
119 button_add
.addSelectionListener(addButtonSelectionListener
);
120 button_remove
.addSelectionListener(removeButtonSelectionListener
);
121 btnExportTree
.addSelectionListener(exportButtonSelectionListener
);
123 btnOpenFeatureTree
.addSelectionListener(openFeatureTreeSelectionListener
);
126 public void setSelectedTree(FeatureTree featureTree
, ModifyListener modifyListener
) {
127 this.featureTree
= featureTree
;
129 getViewer().setInput(featureTree
);
131 getText_title().removeModifyListener(modifyListener
);
132 getText_title().setText(featureTree
.getTitleCache());
133 getText_title().addModifyListener(modifyListener
);
137 * @return the featureTree
139 public FeatureTree
getFeatureTree() {
144 * @return the label_title
146 public Label
getLabel_title() {
151 * @return the text_title
153 public Text
getText_title() {
158 * @return the btnOpenFeatureTree
160 public Button
getBtnOpenFeatureTree() {
161 return btnOpenFeatureTree
;
167 public TreeViewer
getViewer() {
172 * @return the button_add
174 public Button
getButton_add() {
179 * @return the button_remove
181 public Button
getButton_remove() {
182 return button_remove
;
186 * @return the btnExportTree
188 public Button
getBtnExportTree() {
189 return btnExportTree
;