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
;
34 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
35 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
42 public class FeatureTreeEditorComposite
extends Composite
{
44 private FeatureTree featureTree
;
46 private Label label_title
;
47 private Text text_title
;
48 private Button btnOpenFeatureTree
;
49 private TreeViewer viewer
;
50 private Button btnAdd
;
51 private Button btnRemove
;
52 private Button btnExportTree
;
54 private Composite composite_buttons
;
56 public FeatureTreeEditorComposite(Composite parent
, int style
) {
58 setLayout(new GridLayout(2, 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(2, 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));
74 btnOpenFeatureTree
= new Button(this, 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(this);
80 Tree tree
= viewer
.getTree();
81 tree
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1));
82 viewer
.getControl().setLayoutData(
83 new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
85 composite_buttons
= new Composite(this,
87 composite_buttons
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.TOP
, false,
89 composite_buttons
.setLayout(new GridLayout());
91 btnAdd
= new Button(composite_buttons
, SWT
.PUSH
);
92 btnAdd
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
93 btnAdd
.setToolTipText(Messages
.FeatureTreeEditorComposite_ADD_FEATURE
);
94 btnAdd
.setImage(ImageResources
.getImage(ImageResources
.ADD_EDIT
));
95 btnRemove
= new Button(composite_buttons
, SWT
.PUSH
);
96 btnRemove
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
97 btnRemove
.setToolTipText(Messages
.FeatureTreeEditorComposite_REMOVE_FEATURE
);
98 btnRemove
.setImage(ImageResources
.getImage(ImageResources
.TRASH_ICON
));
100 btnExportTree
= new Button(composite_buttons
, SWT
.NONE
);
101 btnExportTree
.setToolTipText("Export feature tree");
102 btnExportTree
.setImage(ImageResources
.getImage(ImageResources
.MOVE_ICON
));
103 btnExportTree
.setVisible(TaxeditorStorePlugin
.getDefault().getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_EXPERIMENTAL_FEATURES
));
106 public void init(DragSourceListener dragSourceListener
,
107 DropTargetListener dropTargetListener
, ISelectionChangedListener viewerSelectionChangedListener
,
108 SelectionListener openFeatureTreeSelectionListener
, SelectionListener addButtonSelectionListener
, SelectionListener removeButtonSelectionListener
, SelectionListener exportButtonSelectionListener
) {
109 viewer
.setContentProvider(new FeatureTreeContentProvider());
110 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
112 int ops
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
113 Transfer
[] transfers
= new Transfer
[] { FeatureNodeTransfer
115 if(dragSourceListener
!=null){
116 viewer
.addDragSupport(ops
, transfers
, dragSourceListener
);
118 if(dropTargetListener
!=null){
119 viewer
.addDropSupport(ops
, transfers
, dropTargetListener
);
122 viewer
.addSelectionChangedListener(viewerSelectionChangedListener
);
124 btnAdd
.addSelectionListener(addButtonSelectionListener
);
125 btnRemove
.addSelectionListener(removeButtonSelectionListener
);
126 btnExportTree
.addSelectionListener(exportButtonSelectionListener
);
128 btnOpenFeatureTree
.addSelectionListener(openFeatureTreeSelectionListener
);
131 public void setSelectedTree(FeatureTree featureTree
, ModifyListener modifyListener
) {
132 this.featureTree
= featureTree
;
134 getViewer().setInput(featureTree
);
136 getText_title().removeModifyListener(modifyListener
);
137 getText_title().setText(featureTree
.getTitleCache());
138 getText_title().addModifyListener(modifyListener
);
142 * @return the featureTree
144 public FeatureTree
getFeatureTree() {
149 * @return the label_title
151 public Label
getLabel_title() {
156 * @return the text_title
158 public Text
getText_title() {
163 * @return the btnOpenFeatureTree
165 public Button
getBtnOpenFeatureTree() {
166 return btnOpenFeatureTree
;
172 public TreeViewer
getViewer() {
177 * @return the button_add
179 public Button
getBtnAdd() {
184 * @return the button_remove
186 public Button
getBtnRemove() {
191 * @return the composite_buttons
193 public Composite
getComposite_buttons() {
194 return composite_buttons
;
198 * @return the btnExportTree
200 public Button
getBtnExportTree() {
201 return btnExportTree
;