下面列出了怎么用org.eclipse.ui.dialogs.ResourceSelectionDialog的API类实例代码及写法,或者点击链接到github查看源代码。
public void createResourceSelection(Supplier<IAdaptable> rootSupplier) {
createSelectionButton();
browseButton.addSelectionListener(widgetSelectedAdapter(e -> {
ResourceSelectionDialog dialog = new ResourceSelectionDialog(browseButton.getShell(), rootSupplier.get(),
this.labelString);
dialog.setTitle(Messages.LaunchUI_selection);
int returnCode = dialog.open();
Object[] results = dialog.getResult();
if (returnCode == 0 && results.length > 0) {
text.setText(((IResource) results[0]).getFullPath().makeRelative().toString());
editListener.modifyText(null);
}
}));
}
/**
* Creates a new button
* <p>
* The <code>Dialog</code> implementation of this framework method creates a standard push
* button, registers for selection events including button presses and registers default buttons
* with its shell. The button id is stored as the buttons client data. Note that the parent's
* layout is assumed to be a GridLayout and the number of columns in this layout is incremented.
* Subclasses may override.
* </p>
*
* @param parent the parent composite
* @param label the label from the button
* @param defaultButton <code>true</code> if the button is to be the default button, and <code>false</code>
* otherwise
* @param text the text
* @return the button
*/
protected Button addButton(Composite parent, String label, boolean defaultButton, final Text text) {
Button button = new Button(parent, SWT.PUSH);
button.setText(label);
if (defaultButton) {
Shell shell = parent.getShell();
if (shell != null) {
shell.setDefaultButton(button);
}
button.setFocus();
}
button.setFont(parent.getFont());
SelectionListener listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ResourceSelectionDialog dialog = new ResourceSelectionDialog(getShell(), currentContainer,
"Selection Dialog");
dialog.setTitle("Selection Dialog");
dialog.setMessage("Please select a file:");
dialog.open();
Object[] result = dialog.getResult();
if (result[0] != null) {
IResource res = (IResource) result[0];
text.setText(res.getProjectRelativePath().toOSString());
}
}
};
button.addSelectionListener(listener);
return button;
}