Skip to content

Instantly share code, notes, and snippets.

@Codegass
Created August 22, 2023 04:41
Show Gist options
  • Select an option

  • Save Codegass/41c3ae521eedbe7435e6e59ffce8ccfd to your computer and use it in GitHub Desktop.

Select an option

Save Codegass/41c3ae521eedbe7435e6e59ffce8ccfd to your computer and use it in GitHub Desktop.
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.DirectoryDialog;
public class YourPluginClass {
// ... [Your other fields and imports]
private File input;
private String outputBase;
private IWorkbenchWindow window;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
// Select input file and output folder
String inputFilePath = selectFile("Select Input File");
if (inputFilePath != null) {
input = new File(inputFilePath);
}
outputBase = selectFolder("Select Output Folder");
try {
fun1();
} catch (CsvValidationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (CsvException e) {
e.printStackTrace();
}
MessageDialog.openInformation(window.getShell(), "Plugin1", "Hello, Eclipse world");
return null;
}
/**
* This method uses the FileDialog to allow user to select a file.
*
* @param title The title of the dialog.
* @return The selected file path or null if no file was selected.
*/
private String selectFile(String title) {
FileDialog dialog = new FileDialog(window.getShell());
dialog.setText(title);
return dialog.open();
}
/**
* This method uses the DirectoryDialog to allow user to select a folder.
*
* @param title The title of the dialog.
* @return The selected folder path or null if no folder was selected.
*/
private String selectFolder(String title) {
DirectoryDialog dialog = new DirectoryDialog(window.getShell());
dialog.setMessage(title);
dialog.setText(title);
return dialog.open();
}
// ... [Your other methods]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment