Skip to content

Commit ccde0c9

Browse files
authored
Select WORKSPACE file instead of a directory (#83)
1 parent 2db4803 commit ccde0c9

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

plugin-core/src/main/java/com/salesforce/bazel/eclipse/wizard/BazelImportWizardLocationControl.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
// adapted from M2Eclipse org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage
4545
package com.salesforce.bazel.eclipse.wizard;
4646

47+
import java.io.File;
4748
import java.util.ArrayList;
4849
import java.util.HashMap;
4950
import java.util.List;
@@ -53,6 +54,7 @@
5354
import org.eclipse.core.resources.ResourcesPlugin;
5455
import org.eclipse.core.runtime.IPath;
5556
import org.eclipse.core.runtime.Path;
57+
import org.eclipse.jface.dialogs.MessageDialog;
5658
import org.eclipse.swt.SWT;
5759
import org.eclipse.swt.events.FocusAdapter;
5860
import org.eclipse.swt.events.FocusEvent;
@@ -62,9 +64,9 @@
6264
import org.eclipse.swt.widgets.Button;
6365
import org.eclipse.swt.widgets.Combo;
6466
import org.eclipse.swt.widgets.Composite;
65-
import org.eclipse.swt.widgets.DirectoryDialog;
6667
import org.eclipse.swt.widgets.Display;
6768
import org.eclipse.swt.widgets.Event;
69+
import org.eclipse.swt.widgets.FileDialog;
6870
import org.eclipse.swt.widgets.Label;
6971
import org.eclipse.swt.widgets.Listener;
7072

@@ -95,7 +97,7 @@ public void addLocationControl(Composite composite) {
9597
if (showLocation || locations == null || locations.isEmpty()) {
9698
final Label selectRootDirectoryLabel = new Label(composite, SWT.NONE);
9799
selectRootDirectoryLabel.setLayoutData(new GridData());
98-
selectRootDirectoryLabel.setText("Workspace Directory:");
100+
selectRootDirectoryLabel.setText("WORKSPACE File:");
99101

100102
rootDirectoryCombo = new Combo(composite, SWT.NONE);
101103
rootDirectoryCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
@@ -112,19 +114,25 @@ public void addLocationControl(Composite composite) {
112114
browseButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
113115
browseButton.addSelectionListener(new SelectionAdapter() {
114116
public void widgetSelected(SelectionEvent e) {
115-
DirectoryDialog dialog = new DirectoryDialog(page.getShell(), SWT.NONE);
116-
dialog.setText("Locate the root directory of the Bazel workspace");
117+
FileDialog dialog = new FileDialog(page.getShell());
118+
dialog.setFileName("WORKSPACE");
119+
dialog.setText("Locate the Bazel WORKSPACE file");
117120
String path = rootDirectoryCombo.getText();
118121
if (path.length() == 0) {
119122
path = BazelPluginActivator.getResourceHelper().getEclipseWorkspaceRoot().getLocation().toPortableString();
120123
}
121124
dialog.setFilterPath(path);
122125

123-
String result = dialog.open();
124-
if (result != null) {
125-
rootDirectoryCombo.setText(result);
126-
if (rootDirectoryChanged()) {
127-
page.scanProjects();
126+
String selectedFile = dialog.open();
127+
if (selectedFile != null) {
128+
File workspaceFile = new File(selectedFile);
129+
if (!workspaceFile.isFile() || !workspaceFile.getName().equals("WORKSPACE")) {
130+
MessageDialog.openError(page.getShell(), "Import WORKSPACE", "You must select a Bazel WORKSPACE File");
131+
} else {
132+
rootDirectoryCombo.setText(workspaceFile.getParentFile().getAbsolutePath());
133+
if (rootDirectoryChanged()) {
134+
page.scanProjects();
135+
}
128136
}
129137
}
130138
}

0 commit comments

Comments
 (0)