77b9350029918ba51182478437cd979dc001917f
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / MobotOpenUrlPreferences.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.preference;
12
13 import org.eclipse.jface.preference.PreferencePage;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.custom.CLabel;
16 import org.eclipse.swt.events.ModifyEvent;
17 import org.eclipse.swt.events.ModifyListener;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Control;
22 import org.eclipse.swt.widgets.Text;
23 import org.eclipse.ui.IWorkbench;
24 import org.eclipse.ui.IWorkbenchPreferencePage;
25
26 /**
27 * @author n.hoffmann
28 * @created Feb 4, 2011
29 * @version 1.0
30 */
31 public class MobotOpenUrlPreferences extends PreferencePage implements
32 IWorkbenchPreferencePage {
33
34
35 private String openUrlServiceAccessPoint;
36 private String openUrlImageMaxWidth;
37 private String openUrlImageMaxHeight;
38
39 /* (non-Javadoc)
40 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
41 */
42 @Override
43 public void init(IWorkbench workbench) {
44 setPreferenceStore(PreferencesUtil.getPreferenceStore());
45 }
46
47 /* (non-Javadoc)
48 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
49 */
50 @Override
51 protected Control createContents(Composite parent) {
52 Composite container = new Composite(parent, SWT.NULL);
53 final GridLayout gridLayout = new GridLayout();
54 container.setLayout(gridLayout);
55
56 creatOpenUrlServiceAccessPoint(container);
57
58 createOpenUrlImageSize(container);
59
60 return container;
61 }
62
63 /**
64 * @param container
65 */
66 private void createOpenUrlImageSize(Composite container) {
67 openUrlImageMaxWidth = getPreferenceStore().getString(IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH);
68 openUrlImageMaxHeight = getPreferenceStore().getString(IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT);
69
70 Composite composite = new Composite(container, SWT.NULL);
71 final GridLayout gridLayout = new GridLayout(2, false);
72 composite.setLayout(gridLayout);
73
74 final CLabel labelWidth = new CLabel(composite, SWT.NULL);
75 labelWidth.setText("Image Maximum Width: ");
76
77 final Text textWidth = new Text(composite, SWT.BORDER);
78 textWidth.setText(openUrlImageMaxWidth);
79 textWidth.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
80
81 textWidth.addModifyListener(new ModifyListener() {
82
83 public void modifyText(ModifyEvent e) {
84 openUrlImageMaxWidth = textWidth.getText();
85 }
86 });
87
88 final CLabel labelHeight = new CLabel(composite, SWT.NULL);
89 labelHeight.setText("Image Maximum Height: ");
90
91 final Text textHeight = new Text(composite, SWT.BORDER);
92 textHeight.setText(openUrlImageMaxHeight);
93 textHeight.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
94
95 textHeight.addModifyListener(new ModifyListener() {
96
97 public void modifyText(ModifyEvent e) {
98 openUrlImageMaxHeight = textHeight.getText();
99 }
100 });
101 }
102
103 private void creatOpenUrlServiceAccessPoint(Composite composite) {
104 openUrlServiceAccessPoint = getPreferenceStore().getString(IPreferenceKeys.OPENURL_ACCESS_POINT);
105
106 final CLabel label = new CLabel(composite, SWT.NULL);
107 label.setText("Mobot Open Url Service Access Point:");
108
109 final Text text = new Text(composite, SWT.BORDER);
110 text.setText(openUrlServiceAccessPoint);
111 text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
112
113 text.addModifyListener(new ModifyListener() {
114
115 public void modifyText(ModifyEvent e) {
116 openUrlServiceAccessPoint = text.getText();
117 }
118 });
119 }
120
121 /* (non-Javadoc)
122 * @see org.eclipse.jface.preference.PreferencePage#performOk()
123 */
124 @Override
125 public boolean performOk() {
126 getPreferenceStore().setValue(IPreferenceKeys.OPENURL_ACCESS_POINT, openUrlServiceAccessPoint);
127 getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH, openUrlImageMaxWidth);
128 getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT, openUrlImageMaxHeight);
129
130 return super.performOk();
131 }
132
133 }