Merge branch 'develop' into remoting-4.0
[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 private String openUrlServiceAccessPoint;
35 private String openUrlImageMaxWidth;
36 private String openUrlImageMaxHeight;
37
38 /*
39 * (non-Javadoc)
40 *
41 * @see
42 * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
43 */
44 @Override
45 public void init(IWorkbench workbench) {
46 setPreferenceStore(PreferencesUtil.getPreferenceStore());
47 }
48
49 /*
50 * (non-Javadoc)
51 *
52 * @see
53 * org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse
54 * .swt.widgets.Composite)
55 */
56 @Override
57 protected Control createContents(Composite parent) {
58 Composite container = new Composite(parent, SWT.NULL);
59 final GridLayout gridLayout = new GridLayout();
60 container.setLayout(gridLayout);
61
62 creatOpenUrlServiceAccessPoint(container);
63
64 createOpenUrlImageSize(container);
65
66 return container;
67 }
68
69 /**
70 * @param container
71 */
72 private void createOpenUrlImageSize(Composite container) {
73 openUrlImageMaxWidth = getPreferenceStore().getString(
74 IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH);
75 openUrlImageMaxHeight = getPreferenceStore().getString(
76 IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT);
77
78 Composite composite = new Composite(container, SWT.NULL);
79 final GridLayout gridLayout = new GridLayout(2, false);
80 composite.setLayout(gridLayout);
81
82 final CLabel labelWidth = new CLabel(composite, SWT.NULL);
83 labelWidth.setText("Image Maximum Width: ");
84
85 final Text textWidth = new Text(composite, SWT.BORDER);
86 textWidth.setText(openUrlImageMaxWidth);
87 textWidth.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
88
89 textWidth.addModifyListener(new ModifyListener() {
90
91 public void modifyText(ModifyEvent e) {
92 openUrlImageMaxWidth = textWidth.getText();
93 }
94 });
95
96 final CLabel labelHeight = new CLabel(composite, SWT.NULL);
97 labelHeight.setText("Image Maximum Height: ");
98
99 final Text textHeight = new Text(composite, SWT.BORDER);
100 textHeight.setText(openUrlImageMaxHeight);
101 textHeight.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
102
103 textHeight.addModifyListener(new ModifyListener() {
104
105 public void modifyText(ModifyEvent e) {
106 openUrlImageMaxHeight = textHeight.getText();
107 }
108 });
109 }
110
111 private void creatOpenUrlServiceAccessPoint(Composite composite) {
112 openUrlServiceAccessPoint = getPreferenceStore().getString(
113 IPreferenceKeys.OPENURL_ACCESS_POINT);
114
115 final CLabel label = new CLabel(composite, SWT.NULL);
116 label.setText("Mobot Open Url Service Access Point:");
117
118 final Text text = new Text(composite, SWT.BORDER);
119 text.setText(openUrlServiceAccessPoint);
120 text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
121
122 text.addModifyListener(new ModifyListener() {
123
124 public void modifyText(ModifyEvent e) {
125 openUrlServiceAccessPoint = text.getText();
126 }
127 });
128 }
129
130 /*
131 * (non-Javadoc)
132 *
133 * @see org.eclipse.jface.preference.PreferencePage#performOk()
134 */
135 @Override
136 public boolean performOk() {
137 getPreferenceStore().setValue(IPreferenceKeys.OPENURL_ACCESS_POINT,
138 openUrlServiceAccessPoint);
139 getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_WIDTH,
140 openUrlImageMaxWidth);
141 getPreferenceStore().setValue(IPreferenceKeys.OPENURL_IMAGE_MAX_HEIGHT,
142 openUrlImageMaxHeight);
143
144 return super.performOk();
145 }
146
147 }