From e79982b0468fc9efa7f63ca7558ec0bcdf743ee6 Mon Sep 17 00:00:00 2001 From: thuster Date: Wed, 19 Jun 2024 13:02:50 +0200 Subject: [PATCH] [26148] add fix scheme for uri editor and vfs uri dialog --- .../VirtualFilesystemUriEditorDialog.java | 101 ++++++++++++++++-- .../e4/jface/preference/URIFieldEditor.java | 14 ++- .../preference/URIFieldEditorComposite.java | 14 +++ 3 files changed, 118 insertions(+), 11 deletions(-) diff --git a/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/dialog/VirtualFilesystemUriEditorDialog.java b/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/dialog/VirtualFilesystemUriEditorDialog.java index bf080c69b4..82fe5aa39e 100644 --- a/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/dialog/VirtualFilesystemUriEditorDialog.java +++ b/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/dialog/VirtualFilesystemUriEditorDialog.java @@ -25,6 +25,7 @@ import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; @@ -43,6 +44,15 @@ public class VirtualFilesystemUriEditorDialog extends TitleAreaDialog { private IVirtualFilesystemService virtualFilesystemService; private MyURI uri; + private Button browseButton; + + private Label lblScheme; + private Label lblHost; + private Label lblPort; + private Label lblPath; + private Label lblUser; + private Label lblPassword; + private Text txtHost; private Text txtPort; private Text txtUser; @@ -51,6 +61,9 @@ public class VirtualFilesystemUriEditorDialog extends TitleAreaDialog { private Text txtUri; private Combo comboScheme; private boolean passwortPhase = false; + + private String fixedScheme; + /** * Create the dialog. * @@ -81,43 +94,46 @@ protected Control createDialogArea(Composite parent) { container.setLayout(new GridLayout(2, false)); container.setLayoutData(new GridData(GridData.FILL_BOTH)); - Label lblScheme = new Label(container, SWT.NONE); + lblScheme = new Label(container, SWT.NONE); lblScheme.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblScheme.setText("Scheme"); comboScheme = new Combo(container, SWT.NONE); comboScheme.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); comboScheme.setItems("smb", "file"); + comboScheme.addListener(SWT.Selection, l -> { + updateButtonState(); + }); - Label lblHost = new Label(container, SWT.NONE); + lblHost = new Label(container, SWT.NONE); lblHost.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblHost.setText("Host"); txtHost = new Text(container, SWT.BORDER); txtHost.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - Label lblPort = new Label(container, SWT.NONE); + lblPort = new Label(container, SWT.NONE); lblPort.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblPort.setText("Port"); txtPort = new Text(container, SWT.BORDER); txtPort.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - Label lblPath = new Label(container, SWT.NONE); + lblPath = new Label(container, SWT.NONE); lblPath.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblPath.setText("Path"); txtPath = new Text(container, SWT.BORDER); txtPath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - Label txtPath = new Label(container, SWT.NONE); - txtPath.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - txtPath.setText("User"); + lblUser = new Label(container, SWT.NONE); + lblUser.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); + lblUser.setText("User"); txtUser = new Text(container, SWT.BORDER); txtUser.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - Label lblPassword = new Label(container, SWT.NONE); + lblPassword = new Label(container, SWT.NONE); lblPassword.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); lblPassword.setText("Password"); @@ -153,9 +169,64 @@ public void focusLost(FocusEvent e) { txtUri = new Text(container, SWT.BORDER); txtUri.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); + updateUi(); + return area; } + private void updateUi() { + if (StringUtils.isNotBlank(fixedScheme)) { + hide(lblScheme); + hide(comboScheme); + if (fixedScheme.equals("file")) { + hide(lblHost); + hide(txtHost); + hide(lblPort); + hide(txtPort); + hide(lblUser); + hide(txtUser); + hide(lblPassword); + hide(txtPassword); + } + } else { + show(lblScheme); + show(comboScheme); + show(lblHost); + show(txtHost); + show(lblHost); + show(txtHost); + show(lblPort); + show(txtPort); + show(lblUser); + show(txtUser); + show(lblPassword); + show(txtPassword); + } + this.getShell().layout(true, true); + } + + private void hide(Control control) { + if (control.getLayoutData() instanceof GridData) { + ((GridData) control.getLayoutData()).exclude = true; + } + control.setVisible(false); + } + + private void show(Control control) { + if (control.getLayoutData() instanceof GridData) { + ((GridData) control.getLayoutData()).exclude = false; + } + control.setVisible(true); + } + + private void updateButtonState() { + if (fixedScheme == null) { + browseButton.setEnabled("file".equals(comboScheme.getText())); + } else { + browseButton.setEnabled("file".equals(fixedScheme)); + } + } + /** * Create contents of the button bar. * @@ -164,10 +235,12 @@ public void focusLost(FocusEvent e) { @Override protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.CLIENT_ID, "Test", false); - createButton(parent, 1025, JFaceResources.getString("openBrowse"), false); //$NON-NLS-1$ + browseButton = createButton(parent, 1025, JFaceResources.getString("openBrowse"), false); //$NON-NLS-1$ createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); m_bindingContext = initDataBindings(); + + updateButtonState(); } @Override @@ -410,4 +483,14 @@ protected void firePropertyChange(String propertyName, Object oldValue, Object n } } + + /** + * The dialog shows only the provided scheme. Possible values are "smb", "file", + * "davs", "dav". + * + * @param scheme + */ + public void setFixedScheme(String scheme) { + this.fixedScheme = scheme; + } } diff --git a/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/jface/preference/URIFieldEditor.java b/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/jface/preference/URIFieldEditor.java index ed09e2c85f..8025aa54c1 100644 --- a/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/jface/preference/URIFieldEditor.java +++ b/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/jface/preference/URIFieldEditor.java @@ -22,6 +22,8 @@ */ public class URIFieldEditor extends StringButtonFieldEditor { + private String scheme; + /** * * /** Creates a new directory field editor @@ -74,11 +76,19 @@ protected String changePressed() { } VirtualFilesystemUriEditorDialog dialog = new VirtualFilesystemUriEditorDialog(getShell(), virtualFilesystemService, inputUri); - int open = dialog.open(); - if (IDialogConstants.OK_ID == open) { + dialog.setFixedScheme(scheme); + if (IDialogConstants.OK_ID == dialog.open()) { return dialog.getValue().toString(); } return null; } + /** + * Fix the possible URI scheme to the provided scheme. + * + * @param scheme + */ + public void setFixedScheme(String scheme) { + this.scheme = scheme; + } } diff --git a/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/jface/preference/URIFieldEditorComposite.java b/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/jface/preference/URIFieldEditorComposite.java index 7703a9285a..31e2a6aa54 100644 --- a/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/jface/preference/URIFieldEditorComposite.java +++ b/bundles/ch.elexis.core.ui.e4/src/ch/elexis/core/ui/e4/jface/preference/URIFieldEditorComposite.java @@ -34,6 +34,8 @@ public class URIFieldEditorComposite extends Composite { private ComboViewer osCombo; + private String scheme; + public URIFieldEditorComposite(String defaultPreference, Composite parent, int style) { super(parent, style); setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1)); @@ -98,4 +100,16 @@ public String getText(Object element) { public FieldEditor getFieldEditor() { return storePath; } + + /** + * Fix the possible URI scheme to the provided scheme. + * + * @param scheme + */ + public void setFixedScheme(String scheme) { + this.scheme = scheme; + if (storePath != null) { + storePath.setFixedScheme("file"); + } + } }