4 package eu
.etaxonomy
.taxeditor
.printpublisher
.wizard
;
7 import java
.io
.IOException
;
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
;
23 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 public class SelectStylesheetWizardPage
extends AbstractPublishWizardPage
30 implements ISelectionChangedListener
, IHasPersistableSettings
{
32 public static final String DIALOG_SETTING_STYLESHEET
= "dialogSettingStylesheet";
34 private ListViewer viewer
;
35 private IStructuredSelection selection
;
37 protected SelectStylesheetWizardPage(String pageName
) {
39 setTitle("Select Stylesheet");
43 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
46 public void createControl(Composite parent
) {
47 setPageComplete(false);
49 final Composite composite
= new Composite(parent
, SWT
.NULL
);
50 composite
.setLayout(new GridLayout());
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());
57 viewer
.addSelectionChangedListener(this);
63 setControl(composite
);
67 public void loadSettings() {
68 String stylesheet
= getDialogSettingValue(DIALOG_SETTING_STYLESHEET
);
70 if(stylesheet
!= null){
71 File lastSelection
= new File(stylesheet
);
72 viewer
.setSelection(new StructuredSelection(lastSelection
));
77 * Refreshes the input of the viewer
79 public void refresh() {
80 List
<File
> stylesheets
;
82 stylesheets
= getOutputModule().getStylesheets();
83 viewer
.setInput(stylesheets
);
84 } catch (IOException e
) {
85 MessagingUtils
.messageDialog("Problems reading stylesheet", getClass(), e
.getMessage(), e
);
90 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
93 public void selectionChanged(SelectionChangedEvent event
) {
94 selection
= (IStructuredSelection
) event
.getSelection();
98 File stylesheet
= (File
) selection
.getFirstElement();
100 setPageComplete(stylesheet
!= null);
102 getOutputModule().setXslt(stylesheet
);
103 if(stylesheet
!= null) putDialogSettingValue(DIALOG_SETTING_STYLESHEET
, stylesheet
.getAbsolutePath());
105 setErrorMessage(null);
109 private class StylesheetContentProvider
implements IStructuredContentProvider
{
112 public void dispose() {}
115 public void inputChanged(Viewer viewer
, Object oldInput
, Object newInput
) {}
118 public Object
[] getElements(Object inputElement
) {
119 if(inputElement
instanceof List
){
120 return ((List
) inputElement
).toArray();
122 return new Object
[0];
127 private class StylesheetLabelProvider
extends LabelProvider
{
131 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
134 public String
getText(Object element
) {
135 if(element
instanceof File
){
136 File file
= (File
) element
;
138 return file
.getAbsolutePath();
141 return "no title cache";