use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.
the class KeyAssistDialog method open.
/**
* Opens this dialog with the list of bindings for the user to select from.
*
* @return The return code from this dialog.
* @since 3.3
*/
public int open(Collection<Binding> bindings) {
matches = new TreeSet<>((a, b) -> {
Binding bindingA = a;
Binding bindingB = b;
ParameterizedCommand commandA = bindingA.getParameterizedCommand();
ParameterizedCommand commandB = bindingB.getParameterizedCommand();
try {
return commandA.getName().compareTo(commandB.getName());
} catch (NotDefinedException e) {
// should not happen
return 0;
}
});
matches.addAll(bindings);
// If the dialog is already open, dispose the shell and recreate it.
Shell shell = getShell();
if (shell != null) {
close(false, false);
return Window.OK;
}
create();
// Bug 369860. Stop ShellActivationListener from creating a context for this.
// $NON-NLS-1$
getShell().setData("org.eclipse.e4.ui.ignoreDialog", Boolean.TRUE);
// Configure the size and location.
Point size = configureSize();
configureLocation(size);
// Call the super method.
return super.open();
}
use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.
the class BrowserDescriptorDialog method createText.
protected Text createText(Composite comp, String txt, final StringModifyListener listener, boolean multiLine) {
int style = SWT.BORDER;
if (multiLine) {
style = SWT.BORDER | SWT.V_SCROLL | SWT.MULTI | SWT.WRAP;
}
final Text text = new Text(comp, style);
if (multiLine) {
text.addTraverseListener(event -> {
switch(event.detail) {
case SWT.TRAVERSE_RETURN:
case SWT.TRAVERSE_TAB_NEXT:
case SWT.TRAVERSE_TAB_PREVIOUS:
event.doit = true;
break;
}
});
}
// final Text text = SWTUtil.createMultilineText(comp, style);
if (txt != null)
text.setText(txt);
GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
data.widthHint = 450;
if (multiLine) {
// then expand this control as the dialog resizes
data.verticalAlignment = SWT.FILL;
data.grabExcessVerticalSpace = true;
data.heightHint = convertHeightInCharsToPixels(4);
}
text.setLayoutData(data);
if (listener != null)
text.addModifyListener(e -> listener.valueChanged(text.getText()));
return text;
}
use of org.eclipse.jface.dialogs.Dialog in project sonarlint-eclipse by SonarSource.
the class EditProjectExclusionDialog method selectFile.
/**
* Opens a dialog where the user can select a file path.
*/
private void selectFile() {
ISelectionStatusValidator validator = arr -> {
if (arr.length > 1) {
return ValidationStatus.error("Only one file can be selected");
}
if (arr.length == 0) {
return ValidationStatus.ok();
}
Object obj = arr[0];
ISonarLintFile file = Adapters.adapt(obj, ISonarLintFile.class);
return file != null ? ValidationStatus.ok() : ValidationStatus.error("Select a file");
};
var viewFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IFolder) {
var folder = (IFolder) element;
return SonarLintUtils.isSonarLintFileCandidate(folder);
}
if (element instanceof IFile) {
var file = Adapters.adapt(element, ISonarLintFile.class);
return file != null;
}
return false;
}
};
var lp = new WorkbenchLabelProvider();
var cp = new WorkbenchContentProvider();
var dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
dialog.setTitle("Select File");
dialog.setInput(project.getResource());
dialog.setAllowMultiple(false);
dialog.addFilter(viewFilter);
dialog.setValidator(validator);
dialog.setMessage("Select a project file to be excluded from SonarLint analysis");
if (editItem != null) {
dialog.setInitialSelection(editItem.item());
}
if (dialog.open() == Window.OK) {
var obj = dialog.getFirstResult();
var file = Adapters.adapt(obj, ISonarLintFile.class);
if (file != null) {
editItem = new ExclusionItem(Type.FILE, file.getProjectRelativePath());
fileField.setText(editItem.item());
}
}
}
use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.
the class WebBrowserPreferencePage method createContents.
/**
* Create the preference options.
*
* @param parent
* org.eclipse.swt.widgets.Composite
* @return org.eclipse.swt.widgets.Control
*/
@Override
protected Control createContents(Composite parent) {
initializeDialogUnits(parent);
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ContextIds.PREF_BROWSER);
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.horizontalSpacing = convertHorizontalDLUsToPixels(4);
layout.verticalSpacing = convertVerticalDLUsToPixels(3);
layout.marginWidth = 0;
layout.marginHeight = 0;
composite.setLayout(layout);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
composite.setLayoutData(data);
Label label = new Label(composite, SWT.WRAP);
label.setText(Messages.preferenceWebBrowserDescription);
data = new GridData(SWT.FILL, SWT.NONE, false, false);
data.horizontalSpan = 2;
data.widthHint = 275;
label.setLayoutData(data);
internal = new Button(composite, SWT.RADIO);
internal.setText(Messages.prefInternalBrowser);
data = new GridData(SWT.FILL, SWT.NONE, true, false);
data.horizontalSpan = 2;
internal.setLayoutData(data);
if (!WebBrowserUtil.canUseInternalWebBrowser())
internal.setEnabled(false);
external = new Button(composite, SWT.RADIO);
external.setText(Messages.prefExternalBrowser);
data = new GridData(SWT.FILL, SWT.NONE, true, false);
data.horizontalSpan = 2;
external.setLayoutData(data);
label = new Label(composite, SWT.NONE);
label.setText(Messages.browserList);
data = new GridData(SWT.FILL, SWT.CENTER, true, false);
data.horizontalSpan = 2;
label.setLayoutData(data);
table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
data = new GridData(SWT.FILL, SWT.FILL, true, true);
table.setLayoutData(data);
table.setHeaderVisible(false);
table.setLinesVisible(false);
TableLayout tableLayout = new TableLayout();
new TableColumn(table, SWT.NONE);
tableLayout.addColumnData(new ColumnWeightData(100));
table.setLayout(tableLayout);
tableViewer = new CheckboxTableViewer(table);
tableViewer.setContentProvider(new BrowserTableContentProvider());
tableViewer.setLabelProvider(new BrowserTableLabelProvider());
tableViewer.setInput(BrowserManager.getInstance());
// uncheck any other elements that might be checked and leave only the
// element checked to remain checked since one can only chose one
// brower at a time to be current.
tableViewer.addCheckStateListener(e -> {
checkNewDefaultBrowser(e.getElement());
checkedBrowser = (IBrowserDescriptor) e.getElement();
// if no other browsers are checked, don't allow the single one
// currently checked to become unchecked, and lose a current
// browser. That is, don't permit unchecking if no other item
// is checked which is supposed to be the case.
Object[] obj = tableViewer.getCheckedElements();
if (obj.length == 0)
tableViewer.setChecked(e.getElement(), true);
});
// set a default, checked browser based on the current browser. If there
// is not a current browser, but the first item exists, use that instead.
// This will work currently until workbench shutdown, because current
// browser is not yet persisted.
checkedBrowser = BrowserManager.getInstance().getCurrentWebBrowser();
if (checkedBrowser != null)
tableViewer.setChecked(checkedBrowser, true);
else {
Object obj = tableViewer.getElementAt(0);
if (obj != null)
tableViewer.setChecked(obj, true);
}
tableViewer.addSelectionChangedListener(event -> {
IStructuredSelection sele = tableViewer.getStructuredSelection();
boolean sel = sele.getFirstElement() != null && !(sele.getFirstElement() instanceof SystemBrowserDescriptor);
remove.setEnabled(sel);
edit.setEnabled(sel);
});
tableViewer.addDoubleClickListener(event -> {
IStructuredSelection sel = tableViewer.getStructuredSelection();
Object firstElem = sel.getFirstElement();
if (firstElem != null && !(firstElem instanceof SystemBrowserDescriptor)) {
IBrowserDescriptor browser2 = (IBrowserDescriptor) sel.getFirstElement();
IBrowserDescriptorWorkingCopy wc = browser2.getWorkingCopy();
BrowserDescriptorDialog dialog = new BrowserDescriptorDialog(getShell(), wc);
if (dialog.open() != Window.CANCEL) {
try {
tableViewer.refresh(wc.save());
} catch (Exception ex) {
// ignore
}
}
}
});
table.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.character == SWT.DEL) {
IStructuredSelection sel = tableViewer.getStructuredSelection();
if (sel.getFirstElement() != null) {
IBrowserDescriptor browser2 = (IBrowserDescriptor) sel.getFirstElement();
try {
browser2.delete();
tableViewer.remove(browser2);
// need here to ensure that if the item deleted was
// checked, ie. was
// the current browser, that the new current browser
// will be the first in the
// list, typically, the internal browser, which
// cannot be
// deleted, and be current
BrowserManager manager = BrowserManager.getInstance();
if (browser2 == checkedBrowser) {
if (manager.browsers.size() > 0) {
checkedBrowser = manager.browsers.get(0);
tableViewer.setChecked(checkedBrowser, true);
}
}
} catch (Exception ex) {
// ignore
}
}
}
}
});
Composite buttonComp = new Composite(composite, SWT.NONE);
layout = new GridLayout();
layout.horizontalSpacing = 0;
layout.verticalSpacing = convertVerticalDLUsToPixels(3);
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.numColumns = 1;
buttonComp.setLayout(layout);
data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
buttonComp.setLayoutData(data);
final Button add = SWTUtil.createButton(buttonComp, Messages.add);
add.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
BrowserDescriptorDialog dialog = new BrowserDescriptorDialog(getShell());
if (dialog.open() == Window.CANCEL)
return;
tableViewer.refresh();
if (checkedBrowser != null)
tableViewer.setChecked(checkedBrowser, true);
}));
edit = SWTUtil.createButton(buttonComp, Messages.edit);
edit.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
IStructuredSelection sel = tableViewer.getStructuredSelection();
IBrowserDescriptor browser2 = (IBrowserDescriptor) sel.getFirstElement();
IBrowserDescriptorWorkingCopy wc = browser2.getWorkingCopy();
BrowserDescriptorDialog dialog = new BrowserDescriptorDialog(getShell(), wc);
if (dialog.open() != Window.CANCEL) {
try {
tableViewer.refresh(wc.save());
} catch (Exception ex) {
// ignore
}
}
}));
remove = SWTUtil.createButton(buttonComp, Messages.remove);
remove.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
IStructuredSelection sel = tableViewer.getStructuredSelection();
IBrowserDescriptor browser2 = (IBrowserDescriptor) sel.getFirstElement();
try {
browser2.delete();
tableViewer.remove(browser2);
// need here to ensure that if the item deleted was checked,
// ie. was the current browser, that the new current browser
// will be
// the first in the list, typically, the internal browser, which
// cannot be
// deleted, and be current
BrowserManager manager = BrowserManager.getInstance();
if (browser2 == checkedBrowser) {
if (manager.browsers.size() > 0) {
checkedBrowser = manager.browsers.get(0);
tableViewer.setChecked(checkedBrowser, true);
}
}
} catch (Exception ex) {
// ignore
}
}));
search = SWTUtil.createButton(buttonComp, Messages.search);
data = (GridData) search.getLayoutData();
data.verticalIndent = 9;
search.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
final List<IBrowserDescriptorWorkingCopy> foundBrowsers = new ArrayList<>();
final List<String> existingPaths = WebBrowserUtil.getExternalBrowserPaths();
// select a target directory for the search
DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SHEET);
dialog.setMessage(Messages.selectDirectory);
dialog.setText(Messages.directoryDialogTitle);
String path = dialog.open();
if (path == null)
return;
final File rootDir = new File(path);
ProgressMonitorDialog pm = new ProgressMonitorDialog(getShell());
IRunnableWithProgress r = monitor -> {
monitor.beginTask(Messages.searchingTaskName, IProgressMonitor.UNKNOWN);
search(rootDir, existingPaths, foundBrowsers, new HashSet<>(), monitor);
monitor.done();
};
try {
pm.run(true, true, r);
} catch (InvocationTargetException ex) {
Trace.trace(Trace.SEVERE, // $NON-NLS-1$
"Invocation Exception occured running monitor: " + ex);
} catch (InterruptedException ex) {
Trace.trace(Trace.SEVERE, // $NON-NLS-1$
"Interrupted exception occured running monitor: " + ex);
return;
}
if (pm.getProgressMonitor().isCanceled())
return;
List<IBrowserDescriptorWorkingCopy> browsersToCreate = foundBrowsers;
if (browsersToCreate.isEmpty()) {
// no browsers found
WebBrowserUtil.openMessage(Messages.searchingNoneFound);
return;
}
Iterator<IBrowserDescriptorWorkingCopy> iterator = browsersToCreate.iterator();
while (iterator.hasNext()) {
IBrowserDescriptorWorkingCopy browser2 = iterator.next();
browser2.save();
}
tableViewer.refresh();
if (checkedBrowser != null)
tableViewer.setChecked(checkedBrowser, true);
}));
restore = SWTUtil.createButton(buttonComp, Messages.restore);
data = (GridData) restore.getLayoutData();
data.verticalIndent = 9;
restore.addSelectionListener(widgetSelectedAdapter(e -> addDefaults()));
tableViewer.addCheckStateListener(e -> {
checkNewDefaultBrowser(e.getElement());
checkedBrowser = (IBrowserDescriptor) e.getElement();
});
internal.setSelection(WebBrowserPreference.getBrowserChoice() == WebBrowserPreference.INTERNAL);
external.setSelection(WebBrowserPreference.getBrowserChoice() == WebBrowserPreference.EXTERNAL);
// boolean sel = !tableViewer.getSelection().isEmpty();
IStructuredSelection sele = tableViewer.getStructuredSelection();
boolean sel = sele.getFirstElement() != null && !(sele.getFirstElement() instanceof SystemBrowserDescriptor);
edit.setEnabled(sel);
remove.setEnabled(sel);
Dialog.applyDialogFont(composite);
return composite;
}
use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.
the class ChooseWorkspaceDialog method createRecentWorkspacesComposite.
/**
* The Recent Workspaces area of the dialog is only shown if Recent
* Workspaces are defined. It provides a faster way to launch a specific
* Workspace
*/
private void createRecentWorkspacesComposite(final Composite composite) {
FormToolkit toolkit = new FormToolkit(composite.getDisplay());
composite.addDisposeListener(c -> toolkit.dispose());
recentWorkspacesForm = toolkit.createForm(composite);
recentWorkspacesForm.setBackground(composite.getBackground());
recentWorkspacesForm.getBody().setLayout(new GridLayout());
ExpandableComposite recentWorkspacesExpandable = toolkit.createExpandableComposite(recentWorkspacesForm.getBody(), ExpandableComposite.TWISTIE);
recentWorkspacesForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
recentWorkspacesExpandable.setBackground(composite.getBackground());
recentWorkspacesExpandable.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_recentWorkspaces);
recentWorkspacesExpandable.setExpanded(launchData.isShowRecentWorkspaces());
recentWorkspacesExpandable.addExpansionListener(new ExpansionAdapter() {
@Override
public void expansionStateChanged(ExpansionEvent e) {
launchData.setShowRecentWorkspaces(((ExpandableComposite) e.getSource()).isExpanded());
Point size = getInitialSize();
Shell shell = getShell();
shell.setBounds(getConstrainedShellBounds(new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y)));
}
});
Composite panel = new Composite(recentWorkspacesExpandable, SWT.NONE);
recentWorkspacesExpandable.setClient(panel);
RowLayout layout = new RowLayout(SWT.VERTICAL);
layout.marginLeft = 14;
layout.spacing = 6;
panel.setLayout(layout);
recentWorkspacesLinks = new HashMap<>(launchData.getRecentWorkspaces().length);
Map<String, String> uniqueWorkspaceNames = createUniqueWorkspaceNameMap();
List<String> recentWorkspacesList = Arrays.asList(launchData.getRecentWorkspaces()).stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList());
List<Entry<String, String>> sortedList = uniqueWorkspaceNames.entrySet().stream().sorted((e1, e2) -> Integer.compare(recentWorkspacesList.indexOf(e1.getValue()), recentWorkspacesList.indexOf(e2.getValue()))).collect(Collectors.toList());
for (Entry<String, String> uniqueWorkspaceEntry : sortedList) {
final String recentWorkspace = uniqueWorkspaceEntry.getValue();
Link link = new Link(panel, SWT.WRAP);
link.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT));
// $NON-NLS-1$ //$NON-NLS-2$
link.setText("<a>" + uniqueWorkspaceEntry.getKey() + "</a>");
link.setToolTipText(recentWorkspace);
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
workspaceSelected(recentWorkspace);
}
});
recentWorkspacesLinks.put(recentWorkspace, link);
Menu menu = new Menu(link);
MenuItem forgetItem = new MenuItem(menu, SWT.PUSH);
forgetItem.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_removeWorkspaceSelection);
forgetItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
removeWorkspaceFromLauncher(recentWorkspace);
}
});
link.setMenu(menu);
}
}
Aggregations