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
.ui
.openurl
;
13 import java
.util
.List
;
15 import org
.eclipse
.jface
.operation
.IRunnableWithProgress
;
16 import org
.eclipse
.jface
.wizard
.WizardPage
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.events
.SelectionEvent
;
19 import org
.eclipse
.swt
.events
.SelectionListener
;
20 import org
.eclipse
.swt
.layout
.GridData
;
21 import org
.eclipse
.swt
.layout
.GridLayout
;
22 import org
.eclipse
.swt
.widgets
.Button
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Label
;
25 import org
.eclipse
.ui
.forms
.widgets
.ScrolledForm
;
27 import eu
.etaxonomy
.cdm
.ext
.openurl
.OpenUrlReference
;
28 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.ImageElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.RootElement
;
35 * @created Jan 31, 2011
38 public class OpenUrlReferencePage
extends WizardPage
implements SelectionListener
{
40 public static final String NAME
= "OpenUrlReferencePage";
42 private static final int NEXT
= 1;
43 private static final int PREVIOUS
= -1;
45 private ImageElement imageElement
;
46 private RootElement rootElement
;
47 private ScrolledForm scrolledForm
;
48 private Button button_next
;
49 private Button button_previous
;
51 private Composite container
;
53 private Label label_pageNumber
;
58 protected OpenUrlReferencePage() {
63 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
66 public void createControl(Composite parent
) {
67 container
= getWizard().getFormFactory().createComposite(parent
, SWT
.NULL
);
69 container
.setLayout(new GridLayout());
70 container
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
72 scrolledForm
= getWizard().getFormFactory().createScrolledForm(container
);
73 scrolledForm
.getBody().setLayout(LayoutConstants
.LAYOUT(3, false));
74 scrolledForm
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, true, true));
76 Composite buttonContainer
= getWizard().getFormFactory().createComposite(container
);
77 buttonContainer
.setLayout(new GridLayout(3, true));
78 buttonContainer
.setLayoutData(new GridData(SWT
.FILL
, SWT
.BOTTOM
, true, false));
80 button_previous
= getWizard().getFormFactory().createButton(buttonContainer
, "Previous", SWT
.PUSH
);
81 button_previous
.addSelectionListener(this);
82 button_previous
.setLayoutData(new GridData(SWT
.LEFT
, SWT
.BOTTOM
, true, false));
84 label_pageNumber
= getWizard().getFormFactory().createLabel(buttonContainer
, " ");
85 label_pageNumber
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, true, false));
87 button_next
= getWizard().getFormFactory().createButton(buttonContainer
, "Next", SWT
.PUSH
);
88 button_next
.addSelectionListener(this);
89 button_next
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.BOTTOM
, true, false));
91 scrolledForm
.getBody().setLayoutData(LayoutConstants
.FILL());
93 rootElement
= new RootElement(getWizard().getFormFactory(), scrolledForm
.getBody());
95 imageElement
= getWizard().getFormFactory().createImageElement(rootElement
, null, SWT
.BORDER
);
97 setControl(container
);
100 public OpenUrlSelectorWizard
getWizard(){
101 return (OpenUrlSelectorWizard
) super.getWizard();
107 public void displayImage() {
108 URI imageUri
= getWizard().getOpenUrlReferenceImageUri();
110 imageElement
.initImageUri(imageUri
);
112 IRunnableWithProgress runnable
= imageElement
.getLoadImageRunnable(new Runnable(){
114 * @see java.lang.Runnable#run()
124 getWizard().getContainer().run(true, false, runnable
);
125 } catch (Exception e
) {
126 MessagingUtils
.messageDialog("Could not load image", getClass(), e
.getMessage() + ": " + imageUri
, e
);
133 private void configurePageBar() {
134 setTitle(getWizard().getOpenUrlReference().getTitleCache());
135 String pageNumber
= getWizard().getOpenUrlReference().getPages();
136 label_pageNumber
.setText(pageNumber
);
137 button_previous
.setEnabled(canPage(PREVIOUS
));
138 button_next
.setEnabled(canPage(NEXT
));
142 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
145 public void widgetSelected(SelectionEvent e
) {
146 if(e
.getSource() == button_next
){
149 pageResult(PREVIOUS
);
153 private void pageResult(int direction
){
155 List
<OpenUrlReference
> referenceList
= getWizard().getOpenUrlServiceWrapper().doPage(getWizard().getOpenUrlReference(), direction
);
156 OpenUrlReference openUrlReference
= referenceList
.iterator().next();
157 getWizard().setOpenUrlReference(openUrlReference
);
159 setErrorMessage(null);
160 } catch (IllegalArgumentException e
) {
161 setErrorMessage(String
.format("Could not page: %s", e
.getLocalizedMessage()));
162 } catch (Exception e
) {
163 MessagingUtils
.error(getClass(), e
);
167 private boolean canPage(int direction
){
169 getWizard().getOpenUrlServiceWrapper().doPage(getWizard().getOpenUrlReference(), direction
);
170 }catch (IllegalArgumentException e
) {
177 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
180 public void widgetDefaultSelected(SelectionEvent e
) {}