2 * Copyright (C) 2007 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.
10 package eu
.etaxonomy
.taxeditor
.printpublisher
.wizard
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
17 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.jface
.viewers
.LabelProvider
;
20 import org
.eclipse
.jface
.viewers
.ListViewer
;
21 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
22 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
23 import org
.eclipse
.jface
.viewers
.Viewer
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.events
.SelectionAdapter
;
26 import org
.eclipse
.swt
.events
.SelectionEvent
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.layout
.GridLayout
;
29 import org
.eclipse
.swt
.widgets
.Button
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.jdom
.Element
;
33 import eu
.etaxonomy
.cdm
.print
.IXMLEntityFactory
;
34 import eu
.etaxonomy
.cdm
.print
.XMLHelper
;
37 * <p>SelectFeatureTreeWizardPage class.</p>
40 * @created Aug 6, 2010
43 public class SelectFeatureTreeWizardPage
extends AbstractPublishWizardPage
44 implements ISelectionChangedListener
, IHasPersistableSettings
{
46 private static final String DIALOG_SETTING_FEATURE_TREE_UUID
= "dialogSettingFeatureTreeUuid";
47 private ListViewer viewer
;
50 * <p>Constructor for SelectFeatureTreeWizardPage.</p>
52 * @param pageName a {@link java.lang.String} object.
54 protected SelectFeatureTreeWizardPage(String pageName
) {
56 setTitle("Select Feature Tree");
60 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
64 public void createControl(Composite parent
) {
65 setPageComplete(false);
67 Composite composite
= new Composite(parent
, SWT
.NULL
);
68 composite
.setLayout(new GridLayout());
70 viewer
= new ListViewer(composite
);
71 viewer
.getControl().setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
72 viewer
.setContentProvider(new FeatureTreeContentProvider());
73 viewer
.setLabelProvider(new FeatureTreeLabelProvider());
75 viewer
.addSelectionChangedListener(this);
77 // offer feature tree editor when local
78 if(getConfigurator().isLocal()){
79 final Button button_openFeatureTree
= new Button(composite
, SWT
.PUSH
);
80 button_openFeatureTree
.setText("Open FeatureTree Editor");
82 button_openFeatureTree
.addSelectionListener(new SelectionAdapter() {
84 public void widgetSelected(SelectionEvent e
) {
85 //FIXME: this wizard page has been removed by implementing #6694
86 //If print publishing is used again the selection has to be re-implemented
88 // FeatureTreeEditorWizard featureTreeEditorDialog = new FeatureTreeEditorWizard();
89 // WizardDialog dialog = new WizardDialog(getShell(), featureTreeEditorDialog);
91 // if(dialog.open() == IStatus.OK){
98 // when using a local factory we can set the input right here
99 if(getConfigurator() != null && getConfigurator().isLocal()){
105 setControl(composite
);
109 public void loadSettings() {
110 String featureTreeUuidString
= getDialogSettingValue(DIALOG_SETTING_FEATURE_TREE_UUID
);
112 if(featureTreeUuidString
!= null){
113 setSelectedFeatureTree(featureTreeUuidString
);
120 public void selectionChanged(SelectionChangedEvent event
) {
121 IStructuredSelection selection
= (IStructuredSelection
) event
.getSelection();
123 if(selection
.isEmpty()){
127 setPageComplete(true);
130 Element featureTreeElement
= (Element
) selection
.getFirstElement();
132 UUID featureTreeUuid
= XMLHelper
.getUuid(featureTreeElement
);
134 setFeatureTree(featureTreeUuid
.toString());
137 private void setSelectedFeatureTree(String featureTreeUuid
){
138 List
<Element
> input
= (ArrayList
<Element
>) viewer
.getInput();
140 for(Element element
: input
){
141 UUID uuid
= XMLHelper
.getUuid(element
);
142 if(uuid
.toString().equals(featureTreeUuid
)){
143 viewer
.setSelection(new StructuredSelection(element
));
149 public void setFeatureTree(String featureTreeUuidString
){
150 putDialogSettingValue(DIALOG_SETTING_FEATURE_TREE_UUID
, featureTreeUuidString
);
151 UUID featureTreeUuid
= UUID
.fromString(featureTreeUuidString
);
152 getConfigurator().setFeatureTree(featureTreeUuid
);
153 setPageComplete(featureTreeUuid
!= null);
158 public boolean canFlipToNextPage() {
159 return isPageComplete();
163 * Refreshes the input of the viewer
165 public void refresh() {
166 IXMLEntityFactory factory
= getConfigurator().getFactory();
168 List
<Element
> featureTrees
= factory
.getFeatureTrees();
169 List
<Element
> realFeatureTrees
= new ArrayList
<Element
>();
170 for(Element featureTree
: featureTrees
){
171 if(XMLHelper
.getClazz(featureTree
).equals("FeatureTree")){
172 realFeatureTrees
.add(featureTree
);
175 viewer
.setInput(realFeatureTrees
);
178 private class FeatureTreeContentProvider
implements IStructuredContentProvider
{
181 public void dispose() {}
184 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {}
187 public Object
[] getElements(Object inputElement
) {
188 if(inputElement
instanceof List
){
189 return ((List
) inputElement
).toArray();
191 return new Object
[0];
196 private class FeatureTreeLabelProvider
extends LabelProvider
{
200 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
203 public String
getText(Object element
) {
204 if(element
instanceof Element
){
205 Element xmlElement
= (Element
) element
;
206 return XMLHelper
.getTitleCache(xmlElement
);
208 return "no title cache";