1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.featuretree;
|
12
|
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
16
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
17
|
import org.eclipse.jface.viewers.ListViewer;
|
18
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
19
|
import org.eclipse.jface.viewers.StructuredSelection;
|
20
|
import org.eclipse.jface.wizard.WizardPage;
|
21
|
import org.eclipse.swt.SWT;
|
22
|
import org.eclipse.swt.events.ModifyEvent;
|
23
|
import org.eclipse.swt.events.ModifyListener;
|
24
|
import org.eclipse.swt.events.SelectionAdapter;
|
25
|
import org.eclipse.swt.events.SelectionEvent;
|
26
|
import org.eclipse.swt.layout.GridData;
|
27
|
import org.eclipse.swt.layout.GridLayout;
|
28
|
import org.eclipse.swt.widgets.Button;
|
29
|
import org.eclipse.swt.widgets.Composite;
|
30
|
import org.eclipse.swt.widgets.Label;
|
31
|
import org.eclipse.swt.widgets.Text;
|
32
|
|
33
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
34
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
35
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
36
|
|
37
|
/**
|
38
|
* <p>SelectFeatureTreeWizardPage class.</p>
|
39
|
*
|
40
|
* @author n.hoffmann
|
41
|
* @created Aug 5, 2010
|
42
|
* @version 1.0
|
43
|
*/
|
44
|
public class SelectFeatureTreeWizardPage extends WizardPage implements ISelectionChangedListener, ModifyListener{
|
45
|
|
46
|
private ListViewer viewer;
|
47
|
private Text text_title;
|
48
|
private Button button_add;
|
49
|
private Button button_remove;
|
50
|
|
51
|
/**
|
52
|
* <p>Constructor for SelectFeatureTreeWizardPage.</p>
|
53
|
*
|
54
|
* @param pageName a {@link java.lang.String} object.
|
55
|
*/
|
56
|
protected SelectFeatureTreeWizardPage(String pageName) {
|
57
|
super(pageName);
|
58
|
setMessage("Select a Feature Tree or create a new one.");
|
59
|
}
|
60
|
|
61
|
/* (non-Javadoc)
|
62
|
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
|
63
|
*/
|
64
|
/** {@inheritDoc} */
|
65
|
@Override
|
66
|
public void createControl(Composite parent) {
|
67
|
Composite composite = new Composite(parent, SWT.NULL);
|
68
|
|
69
|
composite.setLayout(new GridLayout());
|
70
|
|
71
|
Composite composite_treeContent = new Composite(composite, SWT.NULL);
|
72
|
composite_treeContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
|
73
|
true, true));
|
74
|
composite_treeContent.setLayout(new GridLayout(2, false));
|
75
|
|
76
|
viewer = new ListViewer(composite_treeContent);
|
77
|
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
78
|
|
79
|
button_remove = new Button(composite_treeContent, SWT.PUSH);
|
80
|
button_remove.setText("Remove");
|
81
|
button_remove.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false));
|
82
|
|
83
|
Composite composite_treeTitle = new Composite(composite, SWT.NULL);
|
84
|
composite_treeTitle.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true,
|
85
|
false));
|
86
|
composite_treeTitle.setLayout(new GridLayout(3, false));
|
87
|
|
88
|
|
89
|
|
90
|
Label label_title = new Label(composite_treeTitle, SWT.NULL);
|
91
|
label_title.setText("New Feature Tree");
|
92
|
|
93
|
text_title = new Text(composite_treeTitle, SWT.NULL);
|
94
|
text_title.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
95
|
|
96
|
button_add = new Button(composite_treeTitle, SWT.PUSH);
|
97
|
button_add.setText("Add");
|
98
|
|
99
|
viewer.setContentProvider(new FeatureTreeContentProvider());
|
100
|
viewer.setLabelProvider(new FeatureTreeLabelProvider());
|
101
|
|
102
|
viewer.addSelectionChangedListener(this);
|
103
|
|
104
|
text_title.addModifyListener(this);
|
105
|
button_add.addSelectionListener(new AddButtonSelectionListener());
|
106
|
button_remove.addSelectionListener(new RemoveButtonSelectionListener());
|
107
|
|
108
|
List<FeatureTree> input = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
|
109
|
|
110
|
viewer.setInput(input);
|
111
|
modifyText(null);
|
112
|
setControl(composite);
|
113
|
}
|
114
|
|
115
|
/** {@inheritDoc} */
|
116
|
@Override
|
117
|
public void selectionChanged(SelectionChangedEvent event) {
|
118
|
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
|
119
|
|
120
|
if(selection.size() == 1){
|
121
|
FeatureTree selectedFeatureTree = (FeatureTree) selection.getFirstElement();
|
122
|
((FeatureTreeEditorWizard) getWizard()).setSelectedFeatureTree(selectedFeatureTree);
|
123
|
|
124
|
}
|
125
|
|
126
|
setPageComplete(true);
|
127
|
|
128
|
button_remove.setEnabled(selection.size() >= 1);
|
129
|
}
|
130
|
|
131
|
/** {@inheritDoc} */
|
132
|
@Override
|
133
|
public boolean canFlipToNextPage() {
|
134
|
return ((IStructuredSelection) viewer.getSelection()).size() == 1;
|
135
|
}
|
136
|
|
137
|
/** {@inheritDoc} */
|
138
|
@Override
|
139
|
public void modifyText(ModifyEvent e) {
|
140
|
button_add.setEnabled(! text_title.getText().isEmpty());
|
141
|
}
|
142
|
|
143
|
private class AddButtonSelectionListener extends SelectionAdapter {
|
144
|
public void widgetSelected(SelectionEvent e) {
|
145
|
FeatureTree featureTree = FeatureTree.NewInstance();
|
146
|
featureTree.setTitleCache(text_title.getText(), true);
|
147
|
|
148
|
viewer.add(featureTree);
|
149
|
CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree);
|
150
|
text_title.setText("");
|
151
|
viewer.setSelection(new StructuredSelection(featureTree));
|
152
|
|
153
|
}
|
154
|
}
|
155
|
|
156
|
private class RemoveButtonSelectionListener extends SelectionAdapter {
|
157
|
public void widgetSelected(SelectionEvent e) {
|
158
|
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
|
159
|
for(Object element : selection.toArray()){
|
160
|
viewer.remove(element);
|
161
|
CdmStore.getService(IFeatureTreeService.class).delete((FeatureTree) element);
|
162
|
viewer.setSelection(new StructuredSelection(new Object[0]));
|
163
|
}
|
164
|
}
|
165
|
}
|
166
|
}
|