1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.printpublisher.wizard;
|
5
|
|
6
|
import java.io.File;
|
7
|
import java.io.IOException;
|
8
|
import java.util.List;
|
9
|
|
10
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
11
|
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
12
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
13
|
import org.eclipse.jface.viewers.LabelProvider;
|
14
|
import org.eclipse.jface.viewers.ListViewer;
|
15
|
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
16
|
import org.eclipse.jface.viewers.StructuredSelection;
|
17
|
import org.eclipse.jface.viewers.Viewer;
|
18
|
import org.eclipse.swt.SWT;
|
19
|
import org.eclipse.swt.layout.GridData;
|
20
|
import org.eclipse.swt.layout.GridLayout;
|
21
|
import org.eclipse.swt.widgets.Composite;
|
22
|
|
23
|
import eu.etaxonomy.taxeditor.printpublisher.PrintUtil;
|
24
|
|
25
|
/**
|
26
|
* @author n.hoffmann
|
27
|
*
|
28
|
*/
|
29
|
public class SelectStylesheetWizardPage extends AbstractPublishWizardPage
|
30
|
implements ISelectionChangedListener, IHasPersistableSettings {
|
31
|
|
32
|
public static final String DIALOG_SETTING_STYLESHEET = "dialogSettingStylesheet";
|
33
|
|
34
|
private ListViewer viewer;
|
35
|
private IStructuredSelection selection;
|
36
|
|
37
|
protected SelectStylesheetWizardPage(String pageName) {
|
38
|
super(pageName);
|
39
|
setTitle("Select Stylesheet");
|
40
|
}
|
41
|
|
42
|
/* (non-Javadoc)
|
43
|
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
|
44
|
*/
|
45
|
@Override
|
46
|
public void createControl(Composite parent) {
|
47
|
setPageComplete(false);
|
48
|
|
49
|
final Composite composite = new Composite(parent, SWT.NULL);
|
50
|
composite.setLayout(new GridLayout());
|
51
|
|
52
|
viewer = new ListViewer(composite);
|
53
|
viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
54
|
viewer.setContentProvider(new StylesheetContentProvider());
|
55
|
viewer.setLabelProvider(new StylesheetLabelProvider());
|
56
|
|
57
|
viewer.addSelectionChangedListener(this);
|
58
|
|
59
|
refresh();
|
60
|
|
61
|
loadSettings();
|
62
|
|
63
|
setControl(composite);
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public void loadSettings() {
|
68
|
String stylesheet = getDialogSettingValue(DIALOG_SETTING_STYLESHEET);
|
69
|
|
70
|
if(stylesheet != null){
|
71
|
File lastSelection = new File(stylesheet);
|
72
|
viewer.setSelection(new StructuredSelection(lastSelection));
|
73
|
}
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* Refreshes the input of the viewer
|
78
|
*/
|
79
|
public void refresh() {
|
80
|
List<File> stylesheets;
|
81
|
try {
|
82
|
stylesheets = getOutputModule().getStylesheets();
|
83
|
viewer.setInput(stylesheets);
|
84
|
} catch (IOException e) {
|
85
|
PrintUtil.errorDialog("Problems reading stylesheet", getClass(), e.getMessage(), e);
|
86
|
}
|
87
|
}
|
88
|
|
89
|
/* (non-Javadoc)
|
90
|
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
|
91
|
*/
|
92
|
@Override
|
93
|
public void selectionChanged(SelectionChangedEvent event) {
|
94
|
selection = (IStructuredSelection) event.getSelection();
|
95
|
|
96
|
|
97
|
|
98
|
File stylesheet = (File) selection.getFirstElement();
|
99
|
|
100
|
setPageComplete(stylesheet != null);
|
101
|
|
102
|
getOutputModule().setXslt(stylesheet);
|
103
|
if(stylesheet != null) putDialogSettingValue(DIALOG_SETTING_STYLESHEET, stylesheet.getAbsolutePath());
|
104
|
|
105
|
setErrorMessage(null);
|
106
|
|
107
|
}
|
108
|
|
109
|
private class StylesheetContentProvider implements IStructuredContentProvider {
|
110
|
|
111
|
@Override
|
112
|
public void dispose() {}
|
113
|
|
114
|
@Override
|
115
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
|
116
|
|
117
|
@Override
|
118
|
public Object[] getElements(Object inputElement) {
|
119
|
if(inputElement instanceof List){
|
120
|
return ((List) inputElement).toArray();
|
121
|
}
|
122
|
return new Object[0];
|
123
|
}
|
124
|
|
125
|
}
|
126
|
|
127
|
private class StylesheetLabelProvider extends LabelProvider {
|
128
|
|
129
|
/*
|
130
|
* (non-Javadoc)
|
131
|
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
|
132
|
*/
|
133
|
@Override
|
134
|
public String getText(Object element) {
|
135
|
if(element instanceof File){
|
136
|
File file = (File) element;
|
137
|
if(file.exists()){
|
138
|
return file.getAbsolutePath();
|
139
|
}
|
140
|
}
|
141
|
return "no title cache";
|
142
|
}
|
143
|
|
144
|
}
|
145
|
}
|