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.printpublisher.wizard;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.eclipse.core.runtime.IStatus;
|
18
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
19
|
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
20
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21
|
import org.eclipse.jface.viewers.LabelProvider;
|
22
|
import org.eclipse.jface.viewers.ListViewer;
|
23
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
24
|
import org.eclipse.jface.viewers.Viewer;
|
25
|
import org.eclipse.jface.wizard.WizardDialog;
|
26
|
import org.eclipse.swt.SWT;
|
27
|
import org.eclipse.swt.events.SelectionAdapter;
|
28
|
import org.eclipse.swt.events.SelectionEvent;
|
29
|
import org.eclipse.swt.layout.GridData;
|
30
|
import org.eclipse.swt.layout.GridLayout;
|
31
|
import org.eclipse.swt.widgets.Button;
|
32
|
import org.eclipse.swt.widgets.Composite;
|
33
|
import org.jdom.Element;
|
34
|
|
35
|
import eu.etaxonomy.cdm.print.IXMLEntityFactory;
|
36
|
import eu.etaxonomy.cdm.print.XMLHelper;
|
37
|
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeEditorWizard;
|
38
|
|
39
|
/**
|
40
|
* <p>SelectFeatureTreeWizardPage class.</p>
|
41
|
*
|
42
|
* @author n.hoffmann
|
43
|
* @created Aug 6, 2010
|
44
|
* @version 1.0
|
45
|
*/
|
46
|
public class SelectFeatureTreeWizardPage extends AbstractPublishWizardPage implements ISelectionChangedListener{
|
47
|
|
48
|
private ListViewer viewer;
|
49
|
private IStructuredSelection selection;
|
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
|
setTitle("Select Feature Tree");
|
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
|
setPageComplete(false);
|
68
|
|
69
|
Composite composite = new Composite(parent, SWT.NULL);
|
70
|
composite.setLayout(new GridLayout());
|
71
|
|
72
|
viewer = new ListViewer(composite);
|
73
|
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
74
|
viewer.setContentProvider(new FeatureTreeContentProvider());
|
75
|
viewer.setLabelProvider(new FeatureTreeLabelProvider());
|
76
|
|
77
|
viewer.addSelectionChangedListener(this);
|
78
|
|
79
|
// offer feature tree editor when local
|
80
|
if(getConfigurator().isLocal()){
|
81
|
final Button button_openFeatureTree = new Button(composite, SWT.PUSH);
|
82
|
button_openFeatureTree.setText("Open FeatureTree Editor");
|
83
|
|
84
|
button_openFeatureTree.addSelectionListener(new SelectionAdapter() {
|
85
|
@Override
|
86
|
public void widgetSelected(SelectionEvent e) {
|
87
|
FeatureTreeEditorWizard featureTreeEditorDialog = new FeatureTreeEditorWizard();
|
88
|
WizardDialog dialog = new WizardDialog(getShell(), featureTreeEditorDialog);
|
89
|
|
90
|
if(dialog.open() == IStatus.OK){
|
91
|
refresh();
|
92
|
}
|
93
|
}
|
94
|
});
|
95
|
}
|
96
|
|
97
|
// when using a local factory we can set the input right here
|
98
|
if(getConfigurator() != null && getConfigurator().isLocal()){
|
99
|
refresh();
|
100
|
}
|
101
|
|
102
|
setControl(composite);
|
103
|
}
|
104
|
|
105
|
/** {@inheritDoc} */
|
106
|
@Override
|
107
|
public void selectionChanged(SelectionChangedEvent event) {
|
108
|
selection = (IStructuredSelection) event.getSelection();
|
109
|
|
110
|
setPageComplete(selection.size() == 1);
|
111
|
|
112
|
if(selection.size() == 1){
|
113
|
Element featureTreeElement = (Element) selection.getFirstElement();
|
114
|
|
115
|
UUID featureTreeUuid = XMLHelper.getUuid(featureTreeElement);
|
116
|
|
117
|
getConfigurator().setFeatureTree(featureTreeUuid);
|
118
|
setErrorMessage(null);
|
119
|
}else if(selection.size() > 1){
|
120
|
setErrorMessage("Please select only one feature tree.");
|
121
|
}
|
122
|
}
|
123
|
|
124
|
/** {@inheritDoc} */
|
125
|
@Override
|
126
|
public boolean canFlipToNextPage() {
|
127
|
return (isPageComplete() && selection.size() == 1);
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
* Refreshes the input of the viewer
|
132
|
*/
|
133
|
public void refresh() {
|
134
|
IXMLEntityFactory factory = getConfigurator().getFactory();
|
135
|
|
136
|
List<Element> featureTrees = factory.getFeatureTrees();
|
137
|
List<Element> realFeatureTrees = new ArrayList<Element>();
|
138
|
for(Element featureTree : featureTrees){
|
139
|
if(XMLHelper.getClazz(featureTree).equals("FeatureTree")){
|
140
|
realFeatureTrees.add(featureTree);
|
141
|
}
|
142
|
}
|
143
|
viewer.setInput(realFeatureTrees);
|
144
|
}
|
145
|
|
146
|
private class FeatureTreeContentProvider implements IStructuredContentProvider {
|
147
|
|
148
|
@Override
|
149
|
public void dispose() {}
|
150
|
|
151
|
@Override
|
152
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
|
153
|
|
154
|
@Override
|
155
|
public Object[] getElements(Object inputElement) {
|
156
|
if(inputElement instanceof List){
|
157
|
return ((List) inputElement).toArray();
|
158
|
}
|
159
|
return new Object[0];
|
160
|
}
|
161
|
|
162
|
}
|
163
|
|
164
|
private class FeatureTreeLabelProvider extends LabelProvider {
|
165
|
|
166
|
/*
|
167
|
* (non-Javadoc)
|
168
|
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
|
169
|
*/
|
170
|
@Override
|
171
|
public String getText(Object element) {
|
172
|
if(element instanceof Element){
|
173
|
Element xmlElement = (Element) element;
|
174
|
return XMLHelper.getTitleCache(xmlElement);
|
175
|
}
|
176
|
return "no title cache";
|
177
|
}
|
178
|
|
179
|
}
|
180
|
}
|