Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.util.Map;

import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
Expand All @@ -19,7 +18,6 @@
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;
import org.eclipse.swt.widgets.DirectoryDialog;
Expand All @@ -41,25 +39,22 @@
public class DirectorySelectionDialog extends TitleAreaDialog
{

private Shell shell;
private Text text;
private String idfDirPath;
private String pythonExecutablePath;
private Combo pythonVersionCombo;
private Map<String, String> pythonVersions;
private String gitPath;
private Text gitLocationtext;
private Text pythonLocationtext;
private String commandId;
private static final String pythonPathNodeKey = "PYTHON_EXECUTABLE"; //$NON-NLS-1$
private static final String gitPathNodeKey = "GIT_EXECUTABLE"; //$NON-NLS-1$

protected DirectorySelectionDialog(Shell parentShell, String commandId, String pythonExecutablePath,
Map<String, String> pythonVersions, String idfPath, String gitExecutablePath)
{
super(parentShell);
setShellStyle(getShellStyle() | SWT.RESIZE);
this.shell = parentShell;
this.pythonExecutablePath = getPythonPreferenceOrDefault(pythonExecutablePath);
this.pythonVersions = pythonVersions;
this.idfDirPath = idfPath;
Expand Down Expand Up @@ -154,73 +149,55 @@ public void widgetSelected(SelectionEvent event)
});

// Python version selection
if (Platform.OS_WIN32.equals(Platform.getOS()) && pythonVersions != null && !pythonVersions.isEmpty())
{
new Label(composite, SWT.NONE).setText(Messages.DirectorySelectionDialog_ChoosePyVersion);
addPythonVersionSelectionControls(composite);

pythonVersionCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
GridData gridData = new GridData(SWT.NONE, SWT.NONE, true, false, 2, 1);
gridData.widthHint = 250;
pythonVersionCombo.setLayoutData(gridData);
Dialog.applyDialogFont(composite);
return composite;
}

String[] versions = pythonVersions.keySet().toArray(new String[pythonVersions.size()]);
pythonVersionCombo.setItems(versions);
pythonVersionCombo.select(0); // select the first one
private void addPythonVersionSelectionControls(Composite composite)
{
// Python executable location
new Label(composite, SWT.NONE).setText(Messages.DirectorySelectionDialog_PyExeLocation);

}
else
pythonLocationtext = new Text(composite, SWT.BORDER);
GridData data = new GridData();
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
pythonLocationtext.setLayoutData(data);

pythonLocationtext.setText(pythonExecutablePath != null ? pythonExecutablePath : StringUtil.EMPTY);
pythonLocationtext.addModifyListener(new ModifyListener()
{
new Label(composite, SWT.NONE).setText(Messages.DirectorySelectionDialog_PyExeLocation);

pythonLocationtext = new Text(composite, SWT.BORDER);
data = new GridData();
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
pythonLocationtext.setLayoutData(data);
pythonLocationtext.setText(pythonExecutablePath != null ? pythonExecutablePath : StringUtil.EMPTY);
pythonLocationtext.addModifyListener(new ModifyListener()
@Override
public void modifyText(ModifyEvent e)
{
@Override
public void modifyText(ModifyEvent e)
{
validate();
}
});
validate();
}
});

Button pyBrowseBtn = new Button(composite, SWT.PUSH);
pyBrowseBtn.setText(Messages.DirectorySelectionDialog_Browse);
pyBrowseBtn.addSelectionListener(new SelectionAdapter()
Button pyBrowseBtn = new Button(composite, SWT.PUSH);
pyBrowseBtn.setText(Messages.DirectorySelectionDialog_Browse);
pyBrowseBtn.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent event)
{
@Override
public void widgetSelected(SelectionEvent event)
FileDialog dlg = new FileDialog(Display.getDefault().getActiveShell());
dlg.setText(Messages.DirectorySelectionDialog_PyExecutableLocation);
String pythonLocationPathString = dlg.open();
if (pythonLocationPathString != null)
{
FileDialog dlg = new FileDialog(Display.getDefault().getActiveShell());
dlg.setText(Messages.DirectorySelectionDialog_PyExecutableLocation);

String dir = dlg.open();
if (dir != null)
{
pythonLocationtext.setText(dir);
}
pythonLocationtext.setText(pythonLocationPathString);
}
});
}

Dialog.applyDialogFont(composite);
return composite;
}
});
}

protected void validate()
{
idfDirPath = text.getText();
if (pythonVersionCombo != null)
{
String version = pythonVersionCombo.getText();
pythonExecutablePath = pythonVersions.getOrDefault(version, null);
}
else
{
pythonExecutablePath = pythonLocationtext.getText();
}
pythonExecutablePath = pythonLocationtext.getText();

gitPath = gitLocationtext.getText();

if (StringUtil.isEmpty(pythonExecutablePath) || StringUtil.isEmpty(gitPath) || StringUtil.isEmpty(idfDirPath))
Expand Down Expand Up @@ -254,12 +231,12 @@ private String getPythonPreferenceOrDefault(String pythonExecutablePath)
{
return getPreferences().get(pythonPathNodeKey, pythonExecutablePath);
}
private String getGitPreferenceOrDefault(String gitExecutablePath)

private String getGitPreferenceOrDefault(String gitExecutablePath)
{
return getPreferences().get(gitPathNodeKey, gitExecutablePath);
}

public String getIDFDirectory()
{
return idfDirPath;
Expand All @@ -279,15 +256,8 @@ public String getGitExecutable()
protected void okPressed()
{
idfDirPath = text.getText();
if (pythonVersionCombo != null)
{
String version = pythonVersionCombo.getText();
pythonExecutablePath = pythonVersions.getOrDefault(version, null);
}
else
{
pythonExecutablePath = pythonLocationtext.getText();
}
pythonExecutablePath = pythonLocationtext.getText();

gitPath = gitLocationtext.getText();

super.okPressed();
Expand Down