ref #6694 l10n of FeatureTreeEditor
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / featuretree / e4 / FeatureTreeEditorComposite.java
1 /**
2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.featuretree.e4;
10
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.SelectionListener;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Button;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.Label;
24 import org.eclipse.swt.widgets.Text;
25 import org.eclipse.swt.widgets.Tree;
26
27 import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
28 import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
29 import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
30 import eu.etaxonomy.taxeditor.l10n.Messages;
31 import eu.etaxonomy.taxeditor.model.ImageResources;
32
33 /**
34 * @author pplitzner
35 * @since Jun 19, 2017
36 *
37 */
38 public class FeatureTreeEditorComposite extends Composite{
39
40 private Label label_title;
41 private Text text_title;
42 private Button btnOpenFeatureTree;
43 private TreeViewer viewer;
44 private Button button_add;
45 private Button button_remove;
46
47 public FeatureTreeEditorComposite(Composite parent, int style) {
48 super(parent, style);
49 setLayout(new GridLayout(2, false));
50
51 Composite composite_treeTitle = new Composite(this, SWT.NULL);
52 composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
53 false));
54 GridLayout gl_composite_treeTitle = new GridLayout(2, false);
55 gl_composite_treeTitle.marginWidth = 0;
56 composite_treeTitle.setLayout(gl_composite_treeTitle);
57
58 label_title = new Label(composite_treeTitle, SWT.NULL);
59 label_title.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
60 label_title.setText(Messages.FeatureTreeEditorComposite_FEATURE_TREE);
61
62 text_title = new Text(composite_treeTitle, SWT.BORDER);
63 text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
64
65 btnOpenFeatureTree = new Button(this, SWT.NONE);
66 btnOpenFeatureTree.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
67 btnOpenFeatureTree.setToolTipText(Messages.FeatureTreeEditorComposite_OPEN_TREE);
68 btnOpenFeatureTree.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
69
70 viewer = new TreeViewer(this);
71 Tree tree = viewer.getTree();
72 tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
73 viewer.getControl().setLayoutData(
74 new GridData(SWT.FILL, SWT.FILL, true, true));
75
76 Composite composite_buttons = new Composite(this,
77 SWT.NULL);
78 composite_buttons.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false,
79 false));
80 composite_buttons.setLayout(new GridLayout());
81
82 button_add = new Button(composite_buttons, SWT.PUSH);
83 button_add.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
84 button_add.setToolTipText(Messages.FeatureTreeEditorComposite_ADD_FEATURE);
85 button_add.setImage(ImageResources.getImage(ImageResources.ADD_EDIT));
86 button_remove = new Button(composite_buttons, SWT.PUSH);
87 button_remove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
88 button_remove.setToolTipText(Messages.FeatureTreeEditorComposite_REMOVE_FEATURE);
89 button_remove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
90 }
91
92 public void init(DragSourceListener dragSourceListener,
93 DropTargetListener dropTargetListener, ISelectionChangedListener viewerSelectionChangedListener,
94 SelectionListener selectionListener, SelectionListener addButtonSelectionListener, SelectionListener removeButtonSelectionListener) {
95 viewer.setContentProvider(new FeatureTreeContentProvider());
96 viewer.setLabelProvider(new FeatureTreeLabelProvider());
97
98 int ops = DND.DROP_COPY | DND.DROP_MOVE;
99 Transfer[] transfers = new Transfer[] { FeatureNodeTransfer
100 .getInstance() };
101 viewer.addDragSupport(ops, transfers, dragSourceListener);
102 viewer.addDropSupport(ops, transfers, dropTargetListener);
103
104 viewer.addSelectionChangedListener(viewerSelectionChangedListener);
105
106 button_add.addSelectionListener(addButtonSelectionListener);
107 button_remove.addSelectionListener(removeButtonSelectionListener);
108
109 btnOpenFeatureTree.addSelectionListener(selectionListener);
110 }
111
112 /**
113 * @return the label_title
114 */
115 public Label getLabel_title() {
116 return label_title;
117 }
118
119 /**
120 * @return the text_title
121 */
122 public Text getText_title() {
123 return text_title;
124 }
125
126 /**
127 * @return the btnOpenFeatureTree
128 */
129 public Button getBtnOpenFeatureTree() {
130 return btnOpenFeatureTree;
131 }
132
133 /**
134 * @return the viewer
135 */
136 public TreeViewer getViewer() {
137 return viewer;
138 }
139
140 /**
141 * @return the button_add
142 */
143 public Button getButton_add() {
144 return button_add;
145 }
146
147 /**
148 * @return the button_remove
149 */
150 public Button getButton_remove() {
151 return button_remove;
152 }
153
154 }