@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()); } } };
/** * Initializes this dialog's controls. */ private void initializeDialog() { selectionGroup.addCheckStateListener(event -> getOkButton().setEnabled( selectionGroup.getCheckedElementCount() > 0)); if (getInitialElementSelections().isEmpty()) { getOkButton().setEnabled(false); } else { checkInitialSelections(); } }
/** * Creates a resource selection dialog rooted at the given element. * * @param parentShell the parent shell * @param rootElement the root element to populate this dialog with * @param message the message to be displayed at the top of this dialog, or * <code>null</code> to display a default message */ public ResourceSelectionDialog(Shell parentShell, IAdaptable rootElement, String message) { super(parentShell); setTitle(IDEWorkbenchMessages.ResourceSelectionDialog_title); root = rootElement; if (message != null) { setMessage(message); } else { setMessage(IDEWorkbenchMessages.ResourceSelectionDialog_message); } setShellStyle(getShellStyle() | SWT.SHEET); }
/** * Queries the user for the individual resources that are to be exported * and returns these resources as a collection. * * @param rootResource the resource to use as the root of the selection query * @return the resources selected for export (element type: * <code>IResource</code>), or <code>null</code> if the user canceled the * selection */ protected Object[] queryIndividualResourcesToExport(IAdaptable rootResource) { ResourceSelectionDialog dialog = new ResourceSelectionDialog( getContainer().getShell(), rootResource, IDEWorkbenchMessages.WizardExportPage_selectResourcesTitle); dialog.setInitialSelections(selectedResources .toArray(new Object[selectedResources.size()])); dialog.open(); return dialog.getResult(); }
input.add(root); createMessageArea(composite); selectionGroup = new CheckboxTreeAndListGroup(composite, input, getResourceProvider(IResource.FOLDER | IResource.PROJECT | IResource.ROOT), WorkbenchLabelProvider .getDecoratingWorkbenchLabelProvider(), getResourceProvider(IResource.FILE), WorkbenchLabelProvider .getDecoratingWorkbenchLabelProvider(), SWT.NONE,
/** * @param event the event */ public void checkStateChanged(CheckStateChangedEvent event) { getOkButton().setEnabled(selectionGroup.getCheckedElementCount() > 0); }
/** * Visually checks the previously-specified elements in the container (left) * portion of this dialog's resource selection viewer. */ private void checkInitialSelections() { Iterator itemsToCheck = getInitialElementSelections().iterator(); while (itemsToCheck.hasNext()) { IResource currentElement = (IResource) itemsToCheck.next(); if (currentElement.getType() == IResource.FILE) { selectionGroup.initialCheckListItem(currentElement); } else { selectionGroup.initialCheckTreeItem(currentElement); } } }