4444// adapted from M2Eclipse org.eclipse.m2e.core.ui.internal.wizards.MavenImportWizardPage
4545package com .salesforce .bazel .eclipse .wizard ;
4646
47+ import java .io .File ;
4748import java .util .ArrayList ;
4849import java .util .HashMap ;
4950import java .util .List ;
5354import org .eclipse .core .resources .ResourcesPlugin ;
5455import org .eclipse .core .runtime .IPath ;
5556import org .eclipse .core .runtime .Path ;
57+ import org .eclipse .jface .dialogs .MessageDialog ;
5658import org .eclipse .swt .SWT ;
5759import org .eclipse .swt .events .FocusAdapter ;
5860import org .eclipse .swt .events .FocusEvent ;
6264import org .eclipse .swt .widgets .Button ;
6365import org .eclipse .swt .widgets .Combo ;
6466import org .eclipse .swt .widgets .Composite ;
65- import org .eclipse .swt .widgets .DirectoryDialog ;
6667import org .eclipse .swt .widgets .Display ;
6768import org .eclipse .swt .widgets .Event ;
69+ import org .eclipse .swt .widgets .FileDialog ;
6870import org .eclipse .swt .widgets .Label ;
6971import 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