Skip to content

Commit

Permalink
[26148] add fix scheme for uri editor and vfs uri dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
huthomas committed Jun 20, 2024
1 parent b93bb48 commit e79982b
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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.
*
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
public class URIFieldEditor extends StringButtonFieldEditor {

private String scheme;

/**
*
* /** Creates a new directory field editor
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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");
}
}
}

0 comments on commit e79982b

Please sign in to comment.