use of org.eclipse.ui.views.navigator.ResourceComparator in project linuxtools by eclipse.
the class GprofNoGmonDialog method browseWorkspaceHandler.
/**
* Handle the case when the user browses the Workspace.
* @param parent
* @return gmon.out location or null if bad.
*/
private static String browseWorkspaceHandler(Shell shell, IProject project) {
// New tree Dialogue.
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// Set dialogue settings.
dialog.setTitle(GprofLaunchMessages.GprofNoGmonDialog_OpenGmon);
dialog.setMessage(GprofLaunchMessages.GprofNoGmonDialog_OpenGmon);
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setAllowMultiple(false);
dialog.setInitialSelection(project);
dialog.setValidator(selection -> {
if (selection.length != 1) {
// $NON-NLS-1$
return new Status(IStatus.ERROR, GprofLaunch.PLUGIN_ID, 0, "", null);
}
if (!(selection[0] instanceof IFile)) {
// $NON-NLS-1$
return new Status(IStatus.ERROR, GprofLaunch.PLUGIN_ID, 0, "", null);
}
// $NON-NLS-1$
return new Status(IStatus.OK, GprofLaunch.PLUGIN_ID, 0, "", null);
});
// Open dialogue.
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
// If things were ok, return the gmon path.
return resource.getLocation().toOSString();
} else {
return null;
}
}
use of org.eclipse.ui.views.navigator.ResourceComparator in project linuxtools by eclipse.
the class OpenGmonDialog method handleBrowseWorkspace.
private void handleBrowseWorkspace(String msg, Text text) {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setTitle(msg);
dialog.setMessage(msg);
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setAllowMultiple(false);
IContainer c = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(this.gmonFile);
if (c != null) {
dialog.setInitialSelection(c.getProject());
}
dialog.setValidator(selection -> {
if (selection.length != 1) {
// $NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null);
}
if (!(selection[0] instanceof IFile)) {
// $NON-NLS-1$
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "", null);
}
// $NON-NLS-1$
return new Status(IStatus.OK, Activator.PLUGIN_ID, 0, "", null);
});
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
// $NON-NLS-1$//$NON-NLS-2$
text.setText("${resource_loc:" + resource.getFullPath() + "}");
}
}
use of org.eclipse.ui.views.navigator.ResourceComparator in project linuxtools by eclipse.
the class ValgrindOptionsTab method createSuppressionsOption.
private void createSuppressionsOption(Composite top) {
Composite browseTop = new Composite(top, SWT.BORDER);
browseTop.setLayout(new GridLayout(2, false));
GridData browseData = new GridData(GridData.FILL_BOTH);
browseTop.setLayoutData(browseData);
Label suppFileLabel = new Label(browseTop, SWT.NONE);
// $NON-NLS-1$
suppFileLabel.setText(Messages.getString("ValgrindOptionsTab.suppressions_file"));
createVerticalSpacer(browseTop, 1);
suppFileList = new List(browseTop, SWT.BORDER);
suppFileList.setLayoutData(new GridData(GridData.FILL_BOTH));
Composite buttonTop = new Composite(browseTop, SWT.NONE);
GridLayout buttonLayout = new GridLayout();
buttonLayout.marginWidth = buttonLayout.marginHeight = 0;
buttonTop.setLayout(buttonLayout);
buttonTop.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));
// $NON-NLS-1$
Button workspaceBrowseButton = createPushButton(buttonTop, Messages.getString("ValgrindOptionsTab.Workspace"), null);
workspaceBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// $NON-NLS-1$
dialog.setTitle(Messages.getString("ValgrindOptionsTab.Select_a_Resource"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("ValgrindOptionsTab.Select_a_Suppressions_File"));
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == IDialogConstants.OK_ID) {
IResource resource = (IResource) dialog.getFirstResult();
String arg = resource.getFullPath().toString();
String fileLoc = VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression("workspace_loc", // $NON-NLS-1$
arg);
suppFileList.add(fileLoc);
updateLaunchConfigurationDialog();
}
}));
// $NON-NLS-1$
Button fileBrowseButton = createPushButton(buttonTop, Messages.getString("ValgrindOptionsTab.File_System"), null);
fileBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String filePath = null;
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
filePath = dialog.open();
if (filePath != null) {
suppFileList.add(filePath);
updateLaunchConfigurationDialog();
}
}));
// $NON-NLS-1$
Button removeButton = createPushButton(buttonTop, Messages.getString("ValgrindOptionsTab.Supp_remove"), null);
removeButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
int[] selected = suppFileList.getSelectionIndices();
if (selected.length > 0) {
suppFileList.remove(selected);
updateLaunchConfigurationDialog();
}
}));
}
use of org.eclipse.ui.views.navigator.ResourceComparator in project webtools.sourceediting by eclipse.
the class ResourceSelectionBlock method openWorkspaceResourceDialog.
protected IPath openWorkspaceResourceDialog() {
IResource currentResource = getResource();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setTitle(getMessage(WORKSPACE_DIALOG_TITLE));
dialog.setMessage(getMessage(WORKSPACE_DIALOG_MESSAGE));
dialog.setValidator(validator);
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IContainer)
return true;
if (resourceType != IResource.FILE)
return false;
IFile file = (IFile) element;
String[] extensions = getFileExtensions();
if (extensions == null)
return true;
String fileExt = file.getFileExtension();
if (fileExt != null) {
for (String ext : extensions) {
if (fileExt.equalsIgnoreCase(ext))
return true;
}
}
return false;
}
});
ViewerFilter filter = getResourceFilter();
if (filter != null)
dialog.addFilter(filter);
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setInitialSelection(currentResource);
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setAllowMultiple(false);
if (dialog.open() == Window.OK) {
Object[] elements = dialog.getResult();
if (elements.length > 0)
return ((IResource) elements[0]).getFullPath();
}
return null;
}
use of org.eclipse.ui.views.navigator.ResourceComparator in project webtools.sourceediting by eclipse.
the class AddWorkspaceFileAction method run.
@Override
public void run() {
// ViewerFilter filter= new StylesheetFilter(getSelectedJars());
ILabelProvider lp = new WorkbenchLabelProvider();
ITreeContentProvider cp = new WorkbenchContentProvider();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
dialog.setValidator(validator);
dialog.setTitle(Messages.AddWorkspaceFileAction_DialogTitle);
dialog.setMessage(Messages.AddWorkspaceFileAction_DialogMessage);
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (!(element instanceof IResource))
return false;
IResource resource = (IResource) element;
if (resource.getType() == IResource.FILE) {
if (!XSLCore.isXSLFile((IFile) resource))
return false;
}
return true;
}
});
dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == Window.OK) {
Object[] elements = dialog.getResult();
LaunchTransform[] res = new LaunchTransform[elements.length];
for (int i = 0; i < res.length; i++) {
IResource elem = (IResource) elements[i];
res[i] = new LaunchTransform(elem.getFullPath().toPortableString(), LaunchTransform.RESOURCE_TYPE);
}
addTransforms(res);
}
}
Aggregations