use of org.eclipse.ui.model.WorkbenchLabelProvider in project sling by apache.
the class ConvertToContentProjectHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
final IProject project = (IProject) ((IStructuredSelection) selection).getFirstElement();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getDisplay().getActiveShell(), new WorkbenchLabelProvider(), new BaseWorkbenchContentProvider());
dialog.setMessage("Select content sync root location (containing the jcr root)");
dialog.setTitle("Content Sync Root");
IContainer initialContainer = ProjectHelper.getInferredContentProjectContentRoot(project);
if (initialContainer != null) {
dialog.setInitialElementSelections(Arrays.asList(initialContainer));
}
dialog.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IProject) {
return ((IProject) element).equals(project);
}
// display folders only
return element instanceof IContainer;
}
});
dialog.setInput(new IWorkbenchAdapter() {
@Override
public Object getParent(Object o) {
return null;
}
@Override
public String getLabel(Object o) {
return null;
}
@Override
public ImageDescriptor getImageDescriptor(Object object) {
return null;
}
@Override
public Object[] getChildren(Object o) {
return new Object[] { project };
}
});
// this is the root element
dialog.setAllowMultiple(false);
dialog.setValidator(new ISelectionStatusValidator() {
@Override
public IStatus validate(Object[] selection) {
if (selection.length > 0) {
final Object item = selection[0];
if (item instanceof IContainer) {
IContainer selectedContainer = (IContainer) item;
String errorMsg = ProjectHelper.validateContentPackageStructure(selectedContainer);
if (errorMsg != null) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, errorMsg);
} else {
return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
}
}
}
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "");
}
});
if (dialog.open() == ContainerSelectionDialog.OK) {
Object[] result = dialog.getResult();
if (result != null && result.length > 0) {
final IContainer container = (IContainer) result[0];
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
IResource jcrRoot = container.findMember("jcr_root");
if (jcrRoot == null || !(jcrRoot instanceof IFolder)) {
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", "jcr_root not found under " + container + " (or not a Folder)");
return;
}
ConfigurationHelper.convertToContentPackageProject(project, monitor, jcrRoot.getProjectRelativePath());
} catch (CoreException e) {
Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
}
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(r);
} catch (Exception e) {
Activator.getDefault().getPluginLogger().warn("Could not convert project", e);
MessageDialog.openError(getDisplay().getActiveShell(), "Could not convert project", e.getMessage());
}
}
}
}
return null;
}
use of org.eclipse.ui.model.WorkbenchLabelProvider in project linuxtools by eclipse.
the class SystemTapLaunchShortcut method chooseUnit.
/**
* Creates a dialog that prompts the user to select from the given list of
* ICElements
*
* @param list
* : list of ICElements
* @return
*/
private Object[] chooseUnit(List<ICContainer> list, int numberOfValidFiles) {
ListTreeContentProvider prov = new ListTreeContentProvider();
RuledTreeSelectionDialog dialog = new RuledTreeSelectionDialog(getActiveWorkbenchShell(), new WorkbenchLabelProvider(), prov);
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapLaunchShortcut.SelectFiles"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapLaunchShortcut.SelectFilesMsg"));
dialog.setInput(list);
dialog.setHelpAvailable(false);
dialog.setStatusLineAboveButtons(false);
dialog.setEmptyListMessage(Messages.getString(// $NON-NLS-1$
"SystemTapLaunchShortcut.NoFiles"));
dialog.setContainerMode(true);
Object[] topLevel = prov.findElements(list);
dialog.setInitialSelections(topLevel);
dialog.setSize(cap(topLevel.length * 10, 30, 55), cap((int) (topLevel.length * 1.5), 3, 13));
dialog.create();
Button okButton = dialog.getOkButton();
Object[] result = null;
if (testMode) {
okButton.setSelection(true);
result = list.toArray();
ArrayList<Object> output = new ArrayList<>();
try {
for (Object obj : result) {
if (obj instanceof ICContainer) {
ICElement[] array = ((ICContainer) obj).getChildren();
for (ICElement c : array) {
if (!(validElement(c))) {
continue;
}
if (c.getElementName().contains(MAIN_FUNC_NAME) && !output.contains(c)) {
output.add(c);
}
}
}
}
if (output.size() >= numberOfValidFiles) {
output.clear();
output.add(USER_SELECTED_ALL);
}
} catch (CModelException e) {
e.printStackTrace();
}
result = output.toArray();
} else {
if (dialog.open() == Window.CANCEL) {
return null;
}
result = dialog.getResult();
}
if (result == null) {
return null;
}
ArrayList<Object> output = new ArrayList<>();
try {
for (Object obj : result) {
if (obj instanceof ICContainer) {
ICElement[] array = ((ICContainer) obj).getChildren();
for (ICElement c : array) {
if (!(validElement(c))) {
continue;
}
if (!output.contains(c)) {
output.add(c);
}
}
} else if ((obj instanceof ICElement) && validElement((ICElement) obj) && !output.contains(obj)) {
output.add(obj);
}
}
if (output.size() >= numberOfValidFiles) {
output.clear();
output.add(USER_SELECTED_ALL);
}
} catch (CModelException e) {
e.printStackTrace();
}
return output.toArray();
}
use of org.eclipse.ui.model.WorkbenchLabelProvider in project linuxtools by eclipse.
the class SystemTapOptionsTab method createFileOption.
private void createFileOption(Composite top) {
Composite browseTop = new Composite(top, SWT.NONE);
browseTop.setLayout(new GridLayout(4, false));
browseTop.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Label suppFileLabel = new Label(browseTop, SWT.NONE);
// $NON-NLS-1$
suppFileLabel.setText(Messages.getString("SystemTapOptionsTab.ScriptSelector"));
scriptFile = new Text(browseTop, SWT.BORDER);
scriptFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
scriptFile.addModifyListener(modifyListener);
// $NON-NLS-1$
workspaceBrowseButton = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton"), null);
workspaceBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapOptionsTab.ResourceButton"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapOptionsTab.SuppresionsFile"));
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();
scriptFile.setText(workspacePath + arg);
}
}));
// $NON-NLS-1$
fileBrowseButton = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.FileSystem"), null);
fileBrowseButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String filePath = scriptFile.getText();
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
filePath = dialog.open();
if (filePath != null) {
scriptFile.setText(filePath);
}
}));
Label binaryFileLabel = new Label(browseTop, SWT.NONE);
// $NON-NLS-1$
binaryFileLabel.setText(Messages.getString("SystemTapOptionsTab.SelectBinary"));
binaryFile = new Text(browseTop, SWT.BORDER);
binaryFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
binaryFile.addModifyListener(modifyListener);
// $NON-NLS-1$
Button workspaceBrowseButton2 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton2"), null);
workspaceBrowseButton2.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
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();
binaryFile.setText(workspacePath + arg);
}
}));
// $NON-NLS-1$
Button fileBrowseButton2 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.BrowseFiles"), null);
fileBrowseButton2.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String filePath = binaryFile.getText();
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
filePath = dialog.open();
if (filePath != null) {
File file = new File(filePath);
if (file.exists())
binaryFile.setText(filePath);
}
}));
Label outputFileLabel = new Label(browseTop, SWT.NONE);
// $NON-NLS-1$
outputFileLabel.setText(Messages.getString("SystemTapOptionsTab.SelectOutput"));
outputFile = new Text(browseTop, SWT.BORDER);
outputFile.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
outputFile.addModifyListener(modifyListenerOutput);
outputFile.addFocusListener(focusListener);
// $NON-NLS-1$
Button workspaceBrowseButton3 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.WorkspaceButton2"), null);
workspaceBrowseButton3.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), new WorkbenchLabelProvider(), new WorkbenchContentProvider());
// $NON-NLS-1$
dialog.setTitle(Messages.getString("SystemTapOptionsTab.SelectResource"));
// $NON-NLS-1$
dialog.setMessage(Messages.getString("SystemTapOptionsTab.SelectSuppressions"));
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();
outputFile.setText(workspacePath + arg);
checkOverwrite();
updateLaunchConfigurationDialog();
}
}));
// $NON-NLS-1$
Button fileBrowseButton3 = createPushButton(browseTop, Messages.getString("SystemTapOptionsTab.BrowseFiles"), null);
fileBrowseButton3.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
String filePath = outputFile.getText();
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
filePath = dialog.open();
if (filePath != null) {
outputFile.setText(filePath);
checkOverwrite();
updateLaunchConfigurationDialog();
}
}));
useColourButton = new Button(browseTop, SWT.CHECK);
// $NON-NLS-1$
useColourButton.setText(Messages.getString("SystemTapOptionsTab.ColourCodes"));
useColourButton.addSelectionListener(selectListener);
useColourButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
use of org.eclipse.ui.model.WorkbenchLabelProvider in project linuxtools by eclipse.
the class ContainerCopyFromPage method createControl.
@Override
public void createControl(Composite parent) {
// page group
Composite composite = new Composite(parent, SWT.NULL);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(composite);
GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(6, 6).applyTo(composite);
Label targetLabel = new Label(composite, SWT.NULL);
targetLabel.setText(WizardMessages.getString(TARGET_LABEL));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(false, false).applyTo(targetLabel);
targetText = new Text(composite, SWT.BORDER | SWT.SINGLE);
targetText.addModifyListener(Listener);
targetText.setToolTipText(WizardMessages.getString(TARGET_TOOLTIP));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(targetText);
browseButton = new Button(composite, SWT.NONE);
browseButton.setText(WizardMessages.getString(BROWSE_LABEL));
browseButton.addSelectionListener(onBrowseSelect());
GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).span(1, 1).grab(false, false).applyTo(browseButton);
// Create a fake parent of the root to be the dialog input element.
// Use an empty label so that display of the element's full name
// doesn't include a confusing label
// $NON-NLS-1$
FileSystemElement input = new FileSystemElement("", null, true);
input.addChild(root);
root.setParent(input);
Composite selectionComposite = null;
if (canBrowseContainer) {
selectionComposite = new Composite(composite, SWT.NULL);
GridLayout selectionLayout = new GridLayout();
selectionComposite.setLayout(selectionLayout);
selectionGroup = new CheckboxTreeAndListGroup(selectionComposite, input, getFolderProvider(), getDynamicFolderProvider(), new WorkbenchLabelProvider(), getFileProvider(), new WorkbenchLabelProvider(), SWT.NONE, // since this page has no
SIZING_SELECTION_WIDGET_WIDTH, // other significantly-sized
SIZING_SELECTION_WIDGET_HEIGHT);
// hardcode the combined
// widget's
// size, otherwise it will open too small
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(3, 1).grab(true, false).applyTo(selectionComposite);
} else {
Label sourceLabel = new Label(composite, SWT.NONE);
sourceLabel.setText(WizardMessages.getString(SOURCE_LABEL));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(1, 1).grab(false, false).applyTo(sourceLabel);
sourceText = new Text(composite, SWT.BORDER | SWT.SINGLE);
sourceText.addModifyListener(Listener);
sourceText.setToolTipText(WizardMessages.getString(SOURCE_TOOLTIP));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(1, 1).grab(true, false).applyTo(sourceText);
}
if (canBrowseContainer) {
WorkbenchViewerComparator comparator = new WorkbenchViewerComparator();
selectionGroup.setTreeComparator(comparator);
selectionGroup.setListComparator(comparator);
selectionGroup.addCheckStateListener(CheckListener);
}
setControl(composite);
validate();
setPageComplete(false);
if (canBrowseContainer) {
selectionGroup.aboutToOpen();
}
}
use of org.eclipse.ui.model.WorkbenchLabelProvider in project linuxtools by eclipse.
the class OpenGCDialog method handleBrowseWorkspace.
protected 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.gcFile);
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() + "}");
}
}
Aggregations