--- /dev/null
+/**
+ *
+ */
+package eu.etaxonomy.taxeditor.printpublisher.wizard;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+
+import eu.etaxonomy.taxeditor.printpublisher.PrintUtil;
+
+/**
+ * @author n.hoffmann
+ *
+ */
+public class SelectStylesheetWizardPage extends AbstractPublishWizardPage
+ implements ISelectionChangedListener, IHasPersistableSettings {
+
+ public static final String DIALOG_SETTING_STYLESHEET = "dialogSettingStylesheet";
+
+ private ListViewer viewer;
+ private IStructuredSelection selection;
+
+ protected SelectStylesheetWizardPage(String pageName) {
+ super(pageName);
+ setTitle("Select Stylesheet");
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ public void createControl(Composite parent) {
+ setPageComplete(false);
+
+ final Composite composite = new Composite(parent, SWT.NULL);
+ composite.setLayout(new GridLayout());
+
+ viewer = new ListViewer(composite);
+ viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ viewer.setContentProvider(new StylesheetContentProvider());
+ viewer.setLabelProvider(new StylesheetLabelProvider());
+
+ viewer.addSelectionChangedListener(this);
+
+ refresh();
+
+ loadSettings();
+
+ setControl(composite);
+ }
+
+ @Override
+ public void loadSettings() {
+ String stylesheet = getDialogSettingValue(DIALOG_SETTING_STYLESHEET);
+
+ if(stylesheet != null){
+ File lastSelection = new File(stylesheet);
+ viewer.setSelection(new StructuredSelection(lastSelection));
+ }
+ }
+
+ /**
+ * Refreshes the input of the viewer
+ */
+ public void refresh() {
+ List<File> stylesheets;
+ try {
+ stylesheets = getOutputModule().getStylesheets();
+ viewer.setInput(stylesheets);
+ } catch (IOException e) {
+ PrintUtil.errorDialog("Problems reading stylesheet", getClass(), e.getMessage(), e);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ */
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ selection = (IStructuredSelection) event.getSelection();
+
+
+
+ File stylesheet = (File) selection.getFirstElement();
+
+ setPageComplete(stylesheet != null);
+
+ getOutputModule().setXslt(stylesheet);
+ if(stylesheet != null) putDialogSettingValue(DIALOG_SETTING_STYLESHEET, stylesheet.getAbsolutePath());
+
+ setErrorMessage(null);
+
+ }
+
+ private class StylesheetContentProvider implements IStructuredContentProvider {
+
+ @Override
+ public void dispose() {}
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+
+ @Override
+ public Object[] getElements(Object inputElement) {
+ if(inputElement instanceof List){
+ return ((List) inputElement).toArray();
+ }
+ return new Object[0];
+ }
+
+ }
+
+ private class StylesheetLabelProvider extends LabelProvider {
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText(Object element) {
+ if(element instanceof File){
+ File file = (File) element;
+ if(file.exists()){
+ return file.getAbsolutePath();
+ }
+ }
+ return "no title cache";
+ }
+
+ }
+}