Project

General

Profile

« Previous | Next » 

Revision 34fd7a1c

Added by Patrick Plitzner almost 7 years ago

ref #6694 Extract composite and Listeners from FeatureTreeEditor

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureNodeDragListener.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.IStructuredSelection;
12
import org.eclipse.jface.viewers.TreeViewer;
13
import org.eclipse.swt.dnd.DND;
14
import org.eclipse.swt.dnd.DragSourceAdapter;
15
import org.eclipse.swt.dnd.DragSourceEvent;
16

  
17
import eu.etaxonomy.cdm.model.description.FeatureNode;
18
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
19

  
20
class FeatureNodeDragListener extends DragSourceAdapter {
21

  
22
	private final TreeViewer viewer;
23

  
24
	public FeatureNodeDragListener(TreeViewer viewer) {
25
		this.viewer = viewer;
26
	}
27

  
28
	/**
29
	 * Method declared on DragSourceListener
30
	 */
31
	@Override
32
	public void dragFinished(DragSourceEvent event) {
33
		if (!event.doit) {
34
            return;
35
        }
36
		// if the featureNode was moved, remove it from the source viewer
37
		if (event.detail == DND.DROP_MOVE) {
38
			IStructuredSelection selection = (IStructuredSelection) viewer
39
					.getSelection();
40
			viewer.remove(selection);
41
			viewer.refresh();
42
		}
43
	}
44

  
45
	/**
46
	 * Method declared on DragSourceListener
47
	 */
48
	@Override
49
	public void dragSetData(DragSourceEvent event) {
50
		IStructuredSelection selection = (IStructuredSelection) viewer
51
				.getSelection();
52
		FeatureNode[] featureNodes = (FeatureNode[]) selection.toList()
53
				.toArray(new FeatureNode[selection.size()]);
54
		if (FeatureNodeTransfer.getInstance().isSupportedType(
55
				event.dataType)) {
56
			event.data = featureNodes;
57
		}
58
	}
59

  
60
	/**
61
	 * Method declared on DragSourceListener
62
	 */
63
	@Override
64
	public void dragStart(DragSourceEvent event) {
65
		event.doit = !viewer.getSelection().isEmpty();
66
	}
67

  
68
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureNodeDropAdapter.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.TreeViewer;
12
import org.eclipse.jface.viewers.Viewer;
13
import org.eclipse.jface.viewers.ViewerDropAdapter;
14
import org.eclipse.swt.dnd.TransferData;
15

  
16
import eu.etaxonomy.cdm.model.description.FeatureNode;
17
import eu.etaxonomy.cdm.model.description.FeatureTree;
18
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
19
import eu.etaxonomy.taxeditor.model.MessagingUtils;
20

  
21
class FeatureNodeDropAdapter extends ViewerDropAdapter {
22

  
23
	/**
24
     *
25
     */
26
    private final FeatureTreeEditor featureTreeEditor;
27

  
28
    protected FeatureNodeDropAdapter(FeatureTreeEditor featureTreeEditor, Viewer viewer) {
29
		super(viewer);
30
        this.featureTreeEditor = featureTreeEditor;
31
	}
32

  
33
	@Override
34
	public boolean performDrop(Object data) {
35
		FeatureNode target = (FeatureNode) getCurrentTarget();
36
		int position = 0;
37

  
38
		if (target != null) {
39
			int location = getCurrentLocation();
40
			FeatureNode parent = target.getParent();
41
			if (location == LOCATION_BEFORE) {
42
				position = Math.max(0, parent.getIndex(target) - 1);
43
				target = parent;
44
			}
45

  
46
			if (location == LOCATION_AFTER) {
47
				position = parent.getIndex(target);
48
				target = parent;
49
			}
50
		}
51

  
52
		// set target to root node if there is no target specified
53
		if (target == null) {
54
			FeatureTree featureTree = (FeatureTree) getViewer().getInput();
55
			target = featureTree.getRoot();
56
		}
57

  
58
		Object[] droppedObjects = (Object[]) data;
59
		TreeViewer viewer = (TreeViewer) getViewer();
60

  
61
		// cannot drop a feature node onto itself
62
		for (Object droppedObject : droppedObjects) {
63
			if (droppedObject == null) {
64
				MessagingUtils.warningDialog(
65
								"Operation not supported yet",
66
								this,
67
								"We are currently unable to change the order of freshly created "
68
										+ "feature trees nodes. Please close and reopen the dialog to change the order of features.");
69
				return false;
70
			}
71
			if (droppedObject.equals(target)) {
72
				return false;
73
			}
74
		}
75
		for (Object droppedObject : droppedObjects) {
76
			FeatureNode droppedNode = (FeatureNode) droppedObject;
77
			target.addChild(droppedNode, position);
78
			viewer.add(target, droppedNode);
79
			viewer.reveal(droppedNode);
80
		}
81
        this.featureTreeEditor.setDirty(true);
82
		return true;
83
	}
84

  
85
	@Override
86
	public boolean validateDrop(Object target, int operation,
87
			TransferData transferData) {
88
		return FeatureNodeTransfer.getInstance().isSupportedType(
89
				transferData);
90
	}
91

  
92
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java
24 24
import org.eclipse.jface.viewers.ISelectionChangedListener;
25 25
import org.eclipse.jface.viewers.IStructuredSelection;
26 26
import org.eclipse.jface.viewers.SelectionChangedEvent;
27
import org.eclipse.jface.viewers.TreeViewer;
28
import org.eclipse.jface.viewers.Viewer;
29
import org.eclipse.jface.viewers.ViewerDropAdapter;
30 27
import org.eclipse.jface.wizard.WizardDialog;
31 28
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.dnd.DND;
33
import org.eclipse.swt.dnd.DragSourceAdapter;
34
import org.eclipse.swt.dnd.DragSourceEvent;
35
import org.eclipse.swt.dnd.Transfer;
36
import org.eclipse.swt.dnd.TransferData;
37 29
import org.eclipse.swt.events.ModifyEvent;
38 30
import org.eclipse.swt.events.ModifyListener;
39 31
import org.eclipse.swt.events.SelectionAdapter;
40 32
import org.eclipse.swt.events.SelectionEvent;
41
import org.eclipse.swt.events.SelectionListener;
42
import org.eclipse.swt.layout.GridData;
43
import org.eclipse.swt.layout.GridLayout;
44
import org.eclipse.swt.widgets.Button;
45 33
import org.eclipse.swt.widgets.Composite;
46
import org.eclipse.swt.widgets.Label;
47 34
import org.eclipse.swt.widgets.Shell;
48
import org.eclipse.swt.widgets.Text;
49
import org.eclipse.swt.widgets.Tree;
50 35

  
51 36
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
52 37
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
......
57 42
import eu.etaxonomy.cdm.model.description.FeatureNode;
58 43
import eu.etaxonomy.cdm.model.description.FeatureTree;
59 44
import eu.etaxonomy.taxeditor.featuretree.AvailableFeaturesWizard;
60
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
61
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
62
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
63
import eu.etaxonomy.taxeditor.model.ImageResources;
64
import eu.etaxonomy.taxeditor.model.MessagingUtils;
65 45
import eu.etaxonomy.taxeditor.store.CdmStore;
66 46
import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog;
67 47

  
......
74 54
public class FeatureTreeEditor implements
75 55
		ModifyListener, ISelectionChangedListener {
76 56

  
77
	private TreeViewer viewer;
78
	private Label label_title;
79
	private Button button_add;
80
	private Button button_remove;
81
	private FeatureTree featureTree;
82
	private Text text_title;
83
    private Button btnOpenFeatureTree;
84

  
85 57
    private ConversationHolder conversation;
86 58

  
87 59
    @Inject
......
92 64

  
93 65
    private Shell shell;
94 66

  
67
    private FeatureTree featureTree;
68

  
69
    private FeatureTreeEditorComposite composite;
70

  
95 71
    @Inject
96 72
    public FeatureTreeEditor(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
97 73
        this.shell = shell;
......
103 79
	/** {@inheritDoc} */
104 80
	@PostConstruct
105 81
	public void createControl(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
106
	    parent.setLayout(new GridLayout(2, false));
107

  
108
		Composite composite_treeTitle = new Composite(parent, SWT.NULL);
109
		composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
110
				false));
111
		GridLayout gl_composite_treeTitle = new GridLayout(2, false);
112
		gl_composite_treeTitle.marginWidth = 0;
113
		composite_treeTitle.setLayout(gl_composite_treeTitle);
114

  
115
		label_title = new Label(composite_treeTitle, SWT.NULL);
116
		label_title.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
117
		label_title.setText("Feature Tree");
118

  
119
		text_title = new Text(composite_treeTitle, SWT.BORDER);
120
		text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
121

  
122
		btnOpenFeatureTree = new Button(parent, SWT.NONE);
123
		btnOpenFeatureTree.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
124
		btnOpenFeatureTree.setToolTipText("Open Tree");
125
		btnOpenFeatureTree.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
126

  
127
		viewer = new TreeViewer(parent);
128
		Tree tree = viewer.getTree();
129
		tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
130
		viewer.getControl().setLayoutData(
131
				new GridData(SWT.FILL, SWT.FILL, true, true));
132

  
133
		Composite composite_buttons = new Composite(parent,
134
				SWT.NULL);
135
		composite_buttons.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false,
136
				false));
137
		composite_buttons.setLayout(new GridLayout());
138

  
139
		button_add = new Button(composite_buttons, SWT.PUSH);
140
		button_add.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
141
		button_add.setToolTipText("Add a feature to this feature tree.");
142
		button_add.setImage(ImageResources.getImage(ImageResources.ADD_EDIT));
143
		button_remove = new Button(composite_buttons, SWT.PUSH);
144
		button_remove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
145
		button_remove.setToolTipText("Remove a feature from this feature tree.");
146
		button_remove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
147

  
148
		init(shell);
149
	}
150

  
151
	private void setDirty(boolean isDirty){
152
	    this.dirty.setDirty(isDirty);
153
	}
154

  
155
    private void init(Shell shell) {
156
        viewer.setContentProvider(new FeatureTreeContentProvider());
157
        viewer.setLabelProvider(new FeatureTreeLabelProvider());
158

  
159
        int ops = DND.DROP_COPY | DND.DROP_MOVE;
160
        Transfer[] transfers = new Transfer[] { FeatureNodeTransfer
161
                .getInstance() };
162
        viewer.addDragSupport(ops, transfers, new FeatureNodeDragListener(
163
                viewer));
164
        viewer.addDropSupport(ops, transfers,
165
                new FeatureNodeDropAdapter(viewer));
166

  
167
        viewer.addSelectionChangedListener(this);
168

  
169
        button_add.addSelectionListener(new AddButtonListener());
170
        button_remove.addSelectionListener(new RemoveSelectionListener());
171

  
172
        btnOpenFeatureTree.addSelectionListener(new SelectionListener() {
173

  
82
	    composite = new FeatureTreeEditorComposite(parent, SWT.NULL);
83
		composite.init(new FeatureNodeDragListener(composite.getViewer()), new FeatureNodeDropAdapter(this, composite.getViewer()), this, new SelectionAdapter() {
174 84
            @Override
175 85
            public void widgetSelected(SelectionEvent e) {
176 86
                FeatureTree tree = FeatureTreeSelectionDialog.select(shell, conversation, null);
......
178 88
                    setSelectedTree(tree);
179 89
                }
180 90
            }
91
        }, new AddButtonListener(), new RemoveSelectionListener());
92
	}
181 93

  
182
            @Override
183
            public void widgetDefaultSelected(SelectionEvent e) {
184
            }
185
        });
186
    }
94
	public void setDirty(boolean isDirty){
95
	    this.dirty.setDirty(isDirty);
96
	}
187 97

  
188 98
    public void setSelectedTree(FeatureTree featureTree) {
189 99
		this.featureTree = HibernateProxyHelper.deproxy(featureTree, FeatureTree.class);
190 100
		this.featureTree.setRoot(HibernateProxyHelper.deproxy(featureTree.getRoot(), FeatureNode.class));
191
		viewer.setInput(featureTree);
101
		composite.getViewer().setInput(featureTree);
192 102

  
193
		text_title.removeModifyListener(this);
194
		text_title.setText(featureTree.getTitleCache());
195
		text_title.addModifyListener(this);
103
		composite.getText_title().removeModifyListener(this);
104
		composite.getText_title().setText(featureTree.getTitleCache());
105
		composite.getText_title().addModifyListener(this);
196 106
	}
197 107

  
198 108
	/** {@inheritDoc} */
199 109
	@Override
200 110
	public void modifyText(ModifyEvent e) {
201
		featureTree.setTitleCache(text_title.getText(), true);
111
		featureTree.setTitleCache(composite.getText_title().getText(), true);
202 112
		setDirty(true);
203 113
	}
204 114

  
......
208 118
		IStructuredSelection selection = (IStructuredSelection) event
209 119
				.getSelection();
210 120

  
211
		button_add.setEnabled(selection.size() <= 1);
212
		button_remove.setEnabled(selection.size() > 0);
121
		composite.getButton_add().setEnabled(selection.size() <= 1);
122
		composite.getButton_remove().setEnabled(selection.size() > 0);
213 123
		//propagate selection
214 124
		IStructuredSelection isel = (IStructuredSelection) event.getSelection();
215 125
		selService.setSelection((isel.size() == 1 ? isel.getFirstElement() : isel.toArray()));
......
217 127

  
218 128
	@Focus
219 129
	public void focus(){
220
	    viewer.getControl().setFocus();
130
	    composite.getViewer().getControl().setFocus();
221 131
        if(conversation!=null && !conversation.isBound()){
222 132
            conversation.bind();
223 133
        }
......
237 147
			WizardDialog dialog = new WizardDialog(shell, wizard);
238 148

  
239 149
			if (dialog.open() == IStatus.OK) {
240
				IStructuredSelection selection = (IStructuredSelection) viewer
150
				IStructuredSelection selection = (IStructuredSelection) composite.getViewer()
241 151
						.getSelection();
242 152
				FeatureNode parent = (FeatureNode) (selection.getFirstElement() != null ? selection
243
						.getFirstElement() : ((FeatureTree) viewer.getInput())
153
						.getFirstElement() : ((FeatureTree) composite.getViewer().getInput())
244 154
						.getRoot());
245 155
				Collection<Feature> additionalFeatures = wizard
246 156
						.getAdditionalFeatures();
......
251 161
					parent.addChild(child);
252 162
				}
253 163
				setDirty(true);
254
				viewer.refresh();
164
				composite.getViewer().refresh();
255 165
			}
256 166
		}
257 167

  
......
260 170
	private class RemoveSelectionListener extends SelectionAdapter {
261 171
		@Override
262 172
		public void widgetSelected(SelectionEvent e) {
263
			IStructuredSelection selection = (IStructuredSelection) viewer
173
			IStructuredSelection selection = (IStructuredSelection) composite.getViewer()
264 174
					.getSelection();
265 175

  
266 176
			for (Object selectedObject : selection.toArray()) {
......
272 182

  
273 183
			}
274 184
			setDirty(true);
275
			viewer.refresh();
185
			composite.getViewer().refresh();
276 186
		}
277 187
	}
278

  
279
	private class FeatureNodeDragListener extends DragSourceAdapter {
280

  
281
		private final TreeViewer viewer;
282

  
283
		public FeatureNodeDragListener(TreeViewer viewer) {
284
			this.viewer = viewer;
285
		}
286

  
287
		/**
288
		 * Method declared on DragSourceListener
289
		 */
290
		@Override
291
		public void dragFinished(DragSourceEvent event) {
292
			if (!event.doit) {
293
                return;
294
            }
295
			// if the featureNode was moved, remove it from the source viewer
296
			if (event.detail == DND.DROP_MOVE) {
297
				IStructuredSelection selection = (IStructuredSelection) viewer
298
						.getSelection();
299
				viewer.remove(selection);
300
				viewer.refresh();
301
			}
302
		}
303

  
304
		/**
305
		 * Method declared on DragSourceListener
306
		 */
307
		@Override
308
		public void dragSetData(DragSourceEvent event) {
309
			IStructuredSelection selection = (IStructuredSelection) viewer
310
					.getSelection();
311
			FeatureNode[] featureNodes = (FeatureNode[]) selection.toList()
312
					.toArray(new FeatureNode[selection.size()]);
313
			if (FeatureNodeTransfer.getInstance().isSupportedType(
314
					event.dataType)) {
315
				event.data = featureNodes;
316
			}
317
		}
318

  
319
		/**
320
		 * Method declared on DragSourceListener
321
		 */
322
		@Override
323
		public void dragStart(DragSourceEvent event) {
324
			event.doit = !viewer.getSelection().isEmpty();
325
		}
326

  
327
	}
328

  
329
	private class FeatureNodeDropAdapter extends ViewerDropAdapter {
330

  
331
		protected FeatureNodeDropAdapter(Viewer viewer) {
332
			super(viewer);
333
		}
334

  
335
		@Override
336
		public boolean performDrop(Object data) {
337
			FeatureNode target = (FeatureNode) getCurrentTarget();
338
			int position = 0;
339

  
340
			if (target != null) {
341
				int location = getCurrentLocation();
342
				FeatureNode parent = target.getParent();
343
				if (location == LOCATION_BEFORE) {
344
					position = Math.max(0, parent.getIndex(target) - 1);
345
					target = parent;
346
				}
347

  
348
				if (location == LOCATION_AFTER) {
349
					position = parent.getIndex(target);
350
					target = parent;
351
				}
352
			}
353

  
354
			// set target to root node if there is no target specified
355
			if (target == null) {
356
				FeatureTree featureTree = (FeatureTree) getViewer().getInput();
357
				target = featureTree.getRoot();
358
			}
359

  
360
			Object[] droppedObjects = (Object[]) data;
361
			TreeViewer viewer = (TreeViewer) getViewer();
362

  
363
			// cannot drop a feature node onto itself
364
			for (Object droppedObject : droppedObjects) {
365
				if (droppedObject == null) {
366
					MessagingUtils.warningDialog(
367
									"Operation not supported yet",
368
									this,
369
									"We are currently unable to change the order of freshly created "
370
											+ "feature trees nodes. Please close and reopen the dialog to change the order of features.");
371
					return false;
372
				}
373
				if (droppedObject.equals(target)) {
374
					return false;
375
				}
376
			}
377
			for (Object droppedObject : droppedObjects) {
378
				FeatureNode droppedNode = (FeatureNode) droppedObject;
379
				target.addChild(droppedNode, position);
380
				viewer.add(target, droppedNode);
381
				viewer.reveal(droppedNode);
382
			}
383
            setDirty(true);
384
			return true;
385
		}
386

  
387
		@Override
388
		public boolean validateDrop(Object target, int operation,
389
				TransferData transferData) {
390
			return FeatureNodeTransfer.getInstance().isSupportedType(
391
					transferData);
392
		}
393

  
394
	}
395 188
}
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.model.ImageResources;
31

  
32
/**
33
 * @author pplitzner
34
 * @since Jun 19, 2017
35
 *
36
 */
37
public class FeatureTreeEditorComposite extends Composite{
38

  
39
    private Label label_title;
40
    private Text text_title;
41
    private Button btnOpenFeatureTree;
42
    private TreeViewer viewer;
43
    private Button button_add;
44
    private Button button_remove;
45

  
46
    public FeatureTreeEditorComposite(Composite parent, int style) {
47
        super(parent, style);
48
        setLayout(new GridLayout(2, false));
49

  
50
        Composite composite_treeTitle = new Composite(this, SWT.NULL);
51
        composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
52
                false));
53
        GridLayout gl_composite_treeTitle = new GridLayout(2, false);
54
        gl_composite_treeTitle.marginWidth = 0;
55
        composite_treeTitle.setLayout(gl_composite_treeTitle);
56

  
57
        label_title = new Label(composite_treeTitle, SWT.NULL);
58
        label_title.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
59
        label_title.setText("Feature Tree");
60

  
61
        text_title = new Text(composite_treeTitle, SWT.BORDER);
62
        text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
63

  
64
        btnOpenFeatureTree = new Button(this, SWT.NONE);
65
        btnOpenFeatureTree.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
66
        btnOpenFeatureTree.setToolTipText("Open Tree");
67
        btnOpenFeatureTree.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
68

  
69
        viewer = new TreeViewer(this);
70
        Tree tree = viewer.getTree();
71
        tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
72
        viewer.getControl().setLayoutData(
73
                new GridData(SWT.FILL, SWT.FILL, true, true));
74

  
75
        Composite composite_buttons = new Composite(this,
76
                SWT.NULL);
77
        composite_buttons.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false,
78
                false));
79
        composite_buttons.setLayout(new GridLayout());
80

  
81
        button_add = new Button(composite_buttons, SWT.PUSH);
82
        button_add.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
83
        button_add.setToolTipText("Add a feature to this feature tree.");
84
        button_add.setImage(ImageResources.getImage(ImageResources.ADD_EDIT));
85
        button_remove = new Button(composite_buttons, SWT.PUSH);
86
        button_remove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
87
        button_remove.setToolTipText("Remove a feature from this feature tree.");
88
        button_remove.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
89
    }
90

  
91
    public void init(DragSourceListener dragSourceListener,
92
            DropTargetListener dropTargetListener, ISelectionChangedListener viewerSelectionChangedListener,
93
            SelectionListener selectionListener, SelectionListener addButtonSelectionListener, SelectionListener removeButtonSelectionListener) {
94
        viewer.setContentProvider(new FeatureTreeContentProvider());
95
        viewer.setLabelProvider(new FeatureTreeLabelProvider());
96

  
97
        int ops = DND.DROP_COPY | DND.DROP_MOVE;
98
        Transfer[] transfers = new Transfer[] { FeatureNodeTransfer
99
                .getInstance() };
100
        viewer.addDragSupport(ops, transfers, dragSourceListener);
101
        viewer.addDropSupport(ops, transfers, dropTargetListener);
102

  
103
        viewer.addSelectionChangedListener(viewerSelectionChangedListener);
104

  
105
        button_add.addSelectionListener(addButtonSelectionListener);
106
        button_remove.addSelectionListener(removeButtonSelectionListener);
107

  
108
        btnOpenFeatureTree.addSelectionListener(selectionListener);
109
    }
110

  
111
    /**
112
     * @return the label_title
113
     */
114
    public Label getLabel_title() {
115
        return label_title;
116
    }
117

  
118
    /**
119
     * @return the text_title
120
     */
121
    public Text getText_title() {
122
        return text_title;
123
    }
124

  
125
    /**
126
     * @return the btnOpenFeatureTree
127
     */
128
    public Button getBtnOpenFeatureTree() {
129
        return btnOpenFeatureTree;
130
    }
131

  
132
    /**
133
     * @return the viewer
134
     */
135
    public TreeViewer getViewer() {
136
        return viewer;
137
    }
138

  
139
    /**
140
     * @return the button_add
141
     */
142
    public Button getButton_add() {
143
        return button_add;
144
    }
145

  
146
    /**
147
     * @return the button_remove
148
     */
149
    public Button getButton_remove() {
150
        return button_remove;
151
    }
152

  
153
}

Also available in: Unified diff