Skip to content

Commit 5e0c4de

Browse files
authored
[28391] Einheitliche Basis für OS-spezifische Pfadauswahl (#956)
1 parent ec3afa5 commit 5e0c4de

9 files changed

Lines changed: 348 additions & 40 deletions

File tree

bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ public class Messages extends NLS {
10121012
public static String Core_Number;
10131013
public static String Core_Ok;
10141014
public static String Core_Open;
1015+
public static String Core_OperatingSystem;
10151016
public static String Core_Open_Template;
10161017
public static String Core_Organisation;
10171018
public static String Core_Other;

bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,8 @@ Core_Number = Nummer
21372137

21382138
Core_Ok = OK
21392139

2140+
Core_OperatingSystem = Betriebssystem
2141+
21402142
Core_Open = open
21412143

21422144
Core_Open_Template = Vorlage \u00F6ffnen

bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_de.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,6 +2121,8 @@ Core_Number = Nummer
21212121

21222122
Core_Ok = OK
21232123

2124+
Core_OperatingSystem = Betriebssystem
2125+
21242126
Core_Open = \u00D6ffnen
21252127

21262128
Core_Open_Template = Vorlage \u00F6ffnen

bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_en.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,8 @@ Core_Number = number
20792079
20802080
Core_Ok = OK
20812081
2082+
Core_OperatingSystem = Operating system
2083+
20822084
Core_Open = to open
20832085
20842086
Core_Open_Template = Open template

bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_fr.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,8 @@ Core_Number = Nombre
20732073

20742074
Core_Ok = D'ACCORD
20752075
2076+
Core_OperatingSystem = Système d'exploitation
2077+
20762078
Core_Open = Ouvrir
20772079

20782080
Core_Open_Template = Mod\u00E8le ouvert

bundles/ch.elexis.core.l10n/src/ch/elexis/core/l10n/messages_it.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,8 @@ Core_Number = Numero
20792079
20802080
Core_Ok = OK
20812081
2082+
Core_OperatingSystem = Sistema operativo
2083+
20822084
Core_Open = Aprire
20832085
20842086
Core_Open_Template = Modello aperto
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package ch.elexis.core.ui.e4.jface.preference;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.apache.commons.lang3.StringUtils;
7+
import org.eclipse.jface.preference.IPreferenceStore;
8+
import org.eclipse.jface.viewers.ArrayContentProvider;
9+
import org.eclipse.jface.viewers.ComboViewer;
10+
import org.eclipse.jface.viewers.LabelProvider;
11+
import org.eclipse.jface.viewers.StructuredSelection;
12+
import org.eclipse.swt.SWT;
13+
import org.eclipse.swt.layout.GridData;
14+
import org.eclipse.swt.layout.GridLayout;
15+
import org.eclipse.swt.widgets.Combo;
16+
import org.eclipse.swt.widgets.Composite;
17+
import org.eclipse.swt.widgets.Label;
18+
19+
import ch.elexis.core.l10n.Messages;
20+
import ch.elexis.core.utils.CoreUtil;
21+
import ch.elexis.core.utils.CoreUtil.OS;
22+
23+
/**
24+
* Several {@link URIFieldEditorComposite} sharing one operating system
25+
* selector. Use this instead of single {@link URIFieldEditorComposite} if a
26+
* preference page holds more than one path, so all paths of the page always
27+
* belong to the same operating system:
28+
*
29+
* <pre>
30+
* Betriebssystem [ WINDOWS v ]
31+
* Download [ ****************** ] [ Durchsuchen... ]
32+
* Upload [ ****************** ] [ Durchsuchen... ]
33+
* </pre>
34+
*
35+
* @since 3.14
36+
*/
37+
public class OsPathEditorGroup extends Composite {
38+
39+
private ComboViewer osCombo;
40+
41+
private final List<URIFieldEditorComposite> editors = new ArrayList<>();
42+
43+
private IPreferenceStore preferenceStore;
44+
45+
public OsPathEditorGroup(Composite parent, int style) {
46+
super(parent, style);
47+
setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
48+
49+
GridLayout layout = new GridLayout(2, false);
50+
layout.marginWidth = 0;
51+
layout.marginHeight = 0;
52+
layout.horizontalSpacing = 8;
53+
setLayout(layout);
54+
55+
createOsSelector();
56+
}
57+
58+
private void createOsSelector() {
59+
Label label = new Label(this, SWT.NONE);
60+
label.setText(Messages.Core_OperatingSystem);
61+
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
62+
63+
Combo combo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
64+
combo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
65+
osCombo = new ComboViewer(combo);
66+
osCombo.setContentProvider(ArrayContentProvider.getInstance());
67+
osCombo.setLabelProvider(new LabelProvider() {
68+
@Override
69+
public String getText(Object element) {
70+
return ((CoreUtil.OS) element).name();
71+
}
72+
});
73+
osCombo.setInput(CoreUtil.OS.values());
74+
75+
osCombo.addSelectionChangedListener(event -> {
76+
OS selection = (OS) event.getStructuredSelection().getFirstElement();
77+
for (URIFieldEditorComposite editor : getPathEditors()) {
78+
editor.setOperatingSystem(selection);
79+
}
80+
});
81+
82+
osCombo.setSelection(new StructuredSelection(CoreUtil.getOperatingSystemType()));
83+
}
84+
85+
public URIFieldEditorComposite addPathEditor(String preferenceName, String labelText) {
86+
URIFieldEditorComposite editor = new URIFieldEditorComposite(preferenceName, labelText, this, SWT.NONE);
87+
editor.setOsSelectorVisible(false);
88+
editor.setEmptyStringAllowed(true);
89+
editor.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
90+
editor.setOperatingSystem(getOperatingSystem());
91+
if (preferenceStore != null) {
92+
editor.setPreferenceStore(preferenceStore);
93+
}
94+
editors.add(editor);
95+
alignLabels();
96+
return editor;
97+
}
98+
99+
public void setPreferenceStore(IPreferenceStore preferenceStore) {
100+
this.preferenceStore = preferenceStore;
101+
for (URIFieldEditorComposite editor : getPathEditors()) {
102+
editor.setPreferenceStore(preferenceStore);
103+
}
104+
}
105+
106+
public OS getOperatingSystem() {
107+
return (OS) osCombo.getStructuredSelection().getFirstElement();
108+
}
109+
110+
public List<URIFieldEditorComposite> getPathEditors() {
111+
List<URIFieldEditorComposite> ret = new ArrayList<>(editors.size());
112+
for (URIFieldEditorComposite editor : editors) {
113+
if (!editor.isDisposed()) {
114+
ret.add(editor);
115+
}
116+
}
117+
return ret;
118+
}
119+
120+
public void adjustHorizontalSpan() {
121+
if (getParent().getLayout() instanceof GridLayout && getLayoutData() instanceof GridData) {
122+
((GridData) getLayoutData()).horizontalSpan = ((GridLayout) getParent().getLayout()).numColumns;
123+
}
124+
}
125+
126+
private void alignLabels() {
127+
int width = 0;
128+
for (URIFieldEditorComposite editor : getPathEditors()) {
129+
Label label = editor.getLabelControl();
130+
if (StringUtils.isNotBlank(label.getText())) {
131+
width = Math.max(width, label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x);
132+
}
133+
}
134+
for (URIFieldEditorComposite editor : getPathEditors()) {
135+
Label label = editor.getLabelControl();
136+
if (StringUtils.isNotBlank(label.getText())) {
137+
GridData labelData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
138+
labelData.widthHint = width;
139+
label.setLayoutData(labelData);
140+
}
141+
}
142+
}
143+
}

0 commit comments

Comments
 (0)