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);
}
}
use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.
the class EditorSelectionDialog method createDialogArea.
/**
* Creates and returns the contents of the upper part of the dialog (above the
* button bar).
*
* Subclasses should overide.
*
* @param parent the parent composite to contain the dialog area
* @return the dialog area control
*/
@Override
protected Control createDialogArea(Composite parent) {
Font font = parent.getFont();
// create main group
Composite contents = (Composite) super.createDialogArea(parent);
((GridLayout) contents.getLayout()).numColumns = 2;
// begin the layout
Label textLabel = new Label(contents, SWT.WRAP);
textLabel.setText(message);
GridData data = new GridData();
data.horizontalSpan = 2;
data.horizontalAlignment = SWT.FILL;
data.widthHint = TABLE_WIDTH;
textLabel.setLayoutData(data);
textLabel.setFont(font);
Composite group = new Composite(contents, SWT.SHADOW_NONE);
data = new GridData();
data.grabExcessHorizontalSpace = true;
data.horizontalAlignment = SWT.FILL;
data.horizontalSpan = 2;
group.setLayout(new RowLayout(SWT.HORIZONTAL));
group.setLayoutData(data);
internalButton = new Button(group, SWT.RADIO | SWT.LEFT);
internalButton.setText(WorkbenchMessages.EditorSelection_internal);
internalButton.addListener(SWT.Selection, listener);
internalButton.setFont(font);
externalButton = new Button(group, SWT.RADIO | SWT.LEFT);
externalButton.setText(WorkbenchMessages.EditorSelection_external);
externalButton.addListener(SWT.Selection, listener);
externalButton.setFont(font);
editorTable = new FilteredTree(contents, SWT.SINGLE | SWT.BORDER, new PatternFilter(), true);
editorTableViewer = editorTable.getViewer();
Tree tree = editorTableViewer.getTree();
tree.addListener(SWT.Selection, listener);
tree.addListener(SWT.DefaultSelection, listener);
tree.addListener(SWT.MouseDoubleClick, listener);
data = new GridData();
data.widthHint = convertHorizontalDLUsToPixels(TABLE_WIDTH);
data.horizontalAlignment = GridData.FILL;
data.grabExcessHorizontalSpace = true;
data.verticalAlignment = GridData.FILL;
data.grabExcessVerticalSpace = true;
data.horizontalSpan = 2;
editorTable.setLayoutData(data);
editorTable.setFont(font);
data.heightHint = tree.getItemHeight() * 12;
editorTableViewer.setContentProvider(new TreeArrayContentProvider());
editorTableViewer.setLabelProvider(createTextImageProvider(element -> {
IEditorDescriptor d = (IEditorDescriptor) element;
// $NON-NLS-1$
return TextProcessor.process(d.getLabel(), ".");
}, element -> {
IEditorDescriptor d = (IEditorDescriptor) element;
return (Image) resourceManager.get(d.getImageDescriptor());
}));
browseExternalEditorsButton = new Button(contents, SWT.PUSH);
browseExternalEditorsButton.setText(WorkbenchMessages.EditorSelection_browse);
browseExternalEditorsButton.addListener(SWT.Selection, listener);
data = new GridData();
int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
data.widthHint = Math.max(widthHint, browseExternalEditorsButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
data.horizontalSpan = 2;
browseExternalEditorsButton.setLayoutData(data);
browseExternalEditorsButton.setFont(font);
if (fileName != null) {
rememberEditorButton = new Button(contents, SWT.CHECK | SWT.LEFT);
rememberEditorButton.setText(NLS.bind(WorkbenchMessages.EditorSelection_rememberEditor, fileName));
rememberEditorButton.addListener(SWT.Selection, listener);
data = new GridData();
data.horizontalSpan = 2;
rememberEditorButton.setLayoutData(data);
rememberEditorButton.setFont(font);
String fileType = getFileType();
if (!fileType.isEmpty()) {
rememberTypeButton = new Button(contents, SWT.CHECK | SWT.LEFT);
rememberTypeButton.setText(NLS.bind(WorkbenchMessages.EditorSelection_rememberType, fileType));
rememberTypeButton.addListener(SWT.Selection, listener);
data = new GridData();
data.horizontalSpan = 2;
rememberTypeButton.setLayoutData(data);
rememberTypeButton.setFont(font);
}
}
initializeSuggestion();
// Place buttons to the appropriate state
restoreWidgetValues();
// Run async to restore selection on *visible* dialog - otherwise three won't
// scroll
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
if (editorTable.isDisposed()) {
return;
}
fillEditorTable();
updateEnableState();
});
return contents;
}
use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.
the class WorkingSetConfigurationBlock method createContent.
/**
* Add this block to the <code>parent</code>
*
* @param parent the parent to add the block to
*/
public void createContent(final Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
composite.setLayout(new GridLayout(3, false));
enableButton = new Button(composite, SWT.CHECK);
enableButton.setText(enableButtonLabel);
GridData enableData = new GridData(SWT.FILL, SWT.CENTER, true, false);
enableData.horizontalSpan = 2;
enableButton.setLayoutData(enableData);
enableButton.setSelection(selectedWorkingSets.length > 0);
newButton = new Button(composite, SWT.PUSH);
newButton.setText(this.newButtonLabel);
setButtonLayoutData(newButton);
newButton.addSelectionListener(widgetSelectedAdapter(e -> createNewWorkingSet(newButton.getShell())));
workingSetLabel = new Label(composite, SWT.NONE);
workingSetLabel.setText(comboLabel);
workingSetCombo = new Combo(composite, SWT.READ_ONLY | SWT.BORDER);
GridData textData = new GridData(SWT.FILL, SWT.CENTER, true, false);
textData.horizontalIndent = 0;
workingSetCombo.setLayoutData(textData);
selectButton = new Button(composite, SWT.PUSH);
selectButton.setText(selectLabel);
setButtonLayoutData(selectButton);
selectButton.addSelectionListener(widgetSelectedAdapter(e -> {
SimpleWorkingSetSelectionDialog dialog = new SimpleWorkingSetSelectionDialog(parent.getShell(), workingSetTypeIds, selectedWorkingSets, false);
dialog.setMessage(WorkbenchMessages.WorkingSetGroup_WorkingSetSelection_message);
if (dialog.open() == Window.OK) {
IWorkingSet[] result = dialog.getSelection();
if (result != null && result.length > 0) {
selectedWorkingSets = result;
PlatformUI.getWorkbench().getWorkingSetManager().addRecentWorkingSet(result[0]);
} else {
selectedWorkingSets = EMPTY_WORKING_SET_ARRAY;
}
updateWorkingSetSelection();
}
}));
enableButton.addSelectionListener(widgetSelectedAdapter(e -> updateEnableState(enableButton.getSelection())));
updateEnableState(enableButton.getSelection());
workingSetCombo.addSelectionListener(widgetSelectedAdapter(e -> updateSelectedWorkingSets()));
workingSetCombo.setItems(getHistoryEntries());
if (selectedWorkingSets.length == 0 && selectionHistory.size() > 0) {
workingSetCombo.select(historyIndex(selectionHistory.get(0)));
updateSelectedWorkingSets();
} else {
updateWorkingSetSelection();
}
}
use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.
the class InfoAboutHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
Dialog dialog = new InfoAboutDialog(window.getShell());
dialog.open();
return null;
}
Aggregations