use of org.eclipse.ui.model.WorkbenchLabelProvider in project jbosstools-hibernate by jbosstools.
the class DialogSelectionHelper method chooseFolderEntries.
public static IPath[] chooseFolderEntries(Shell shell, IPath initialSelection, String title, String description, boolean allowMultiple) {
List<Class<?>> clazzes = new ArrayList<Class<?>>();
clazzes.add(IFolder.class);
clazzes.add(IProject.class);
Class<?>[] acceptedClasses = clazzes.toArray(new Class[clazzes.size()]);
TypedElementSelectionValidator validator = new TypedElementSelectionValidator(acceptedClasses, true);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource focus = initialSelection != null ? root.findMember(initialSelection) : null;
ElementTreeSelectionDialog dialog = null;
dialog = new FolderSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setValidator(validator);
dialog.setAllowMultiple(allowMultiple);
dialog.setTitle(title);
dialog.setMessage(description);
dialog.setInput(root);
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
dialog.setInitialSelection(focus);
if (dialog.open() == Window.OK) {
Object[] elements = dialog.getResult();
IPath[] res = new IPath[elements.length];
for (int i = 0; i < res.length; i++) {
IResource elem = (IResource) elements[i];
res[i] = elem.getFullPath();
}
return res;
}
return null;
}
use of org.eclipse.ui.model.WorkbenchLabelProvider in project egit by eclipse.
the class MergeResultDialog method createDialogArea.
@Override
public Control createDialogArea(final Composite parent) {
final Composite composite = (Composite) super.createDialogArea(parent);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
composite.setLayout(gridLayout);
// result
Label resultLabel = new Label(composite, SWT.NONE);
resultLabel.setText(UIText.MergeResultDialog_result);
resultLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
Text resultText = new Text(composite, SWT.READ_ONLY);
MergeStatus status = mergeResult.getMergeStatus();
resultText.setText(status.toString());
resultText.setSelection(resultText.getCaretPosition());
resultText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
if (status == MergeStatus.FAILED) {
resultText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
StringBuilder paths = new StringBuilder();
Label pathsLabel = new Label(composite, SWT.NONE);
pathsLabel.setText(UIText.MergeResultDialog_failed);
pathsLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
Text pathsText = new Text(composite, SWT.READ_ONLY);
pathsText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
Set<Entry<String, MergeFailureReason>> failedPaths = mergeResult.getFailingPaths().entrySet();
int n = 0;
for (Map.Entry<String, MergeFailureReason> e : failedPaths) {
if (n > 0)
paths.append(Text.DELIMITER);
paths.append(e.getValue());
// $NON-NLS-1$
paths.append("\t");
paths.append(e.getKey());
n++;
if (n > 10 && failedPaths.size() > 15)
break;
}
if (n < failedPaths.size()) {
paths.append(Text.DELIMITER);
paths.append(MessageFormat.format(UIText.MergeResultDialog_nMore, Integer.valueOf(n - failedPaths.size())));
}
pathsText.setText(paths.toString());
}
if (status == MergeStatus.FAST_FORWARD || status == MergeStatus.FAST_FORWARD_SQUASHED || status == MergeStatus.MERGED) {
// new head
Label newHeadLabel = new Label(composite, SWT.NONE);
newHeadLabel.setText(UIText.MergeResultDialog_newHead);
newHeadLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
Text newHeadText = new Text(composite, SWT.READ_ONLY);
ObjectId newHead = mergeResult.getNewHead();
if (newHead != null)
newHeadText.setText(getCommitMessage(newHead) + SPACE + abbreviate(mergeResult.getNewHead(), true));
newHeadText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
}
// Merge Input
Label mergeInputLabel = new Label(composite, SWT.NONE);
mergeInputLabel.setText(UIText.MergeResultDialog_mergeInput);
GridDataFactory.fillDefaults().align(SWT.LEAD, SWT.CENTER).span(2, 1).applyTo(mergeInputLabel);
TableViewer viewer = new TableViewer(composite);
viewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
// empty
}
@Override
public void inputChanged(Viewer theViewer, Object oldInput, Object newInput) {
// empty
}
@Override
public Object[] getElements(Object inputElement) {
return getCommits(mergeResult.getMergedCommits());
}
});
final IStyledLabelProvider styleProvider = new IStyledLabelProvider() {
private final WorkbenchLabelProvider wrapped = new WorkbenchLabelProvider();
@Override
public void removeListener(ILabelProviderListener listener) {
// Empty
}
@Override
public boolean isLabelProperty(Object element, String property) {
return false;
}
@Override
public void dispose() {
wrapped.dispose();
}
@Override
public void addListener(ILabelProviderListener listener) {
// Empty
}
@Override
public StyledString getStyledText(Object element) {
// supported
if (element instanceof RepositoryCommit)
return ((RepositoryCommit) element).getStyledText(element);
return new StyledString(wrapped.getText(element));
}
@Override
public Image getImage(Object element) {
return wrapped.getImage(element);
}
};
viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider));
applyDialogFont(composite);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(viewer.getControl());
viewer.setInput(mergeResult);
new OpenAndLinkWithEditorHelper(viewer) {
@Override
protected void linkToEditor(ISelection selection) {
// Not supported
}
@Override
protected void open(ISelection selection, boolean activate) {
handleOpen(selection, OpenStrategy.activateOnOpen());
}
@Override
protected void activate(ISelection selection) {
handleOpen(selection, true);
}
private void handleOpen(ISelection selection, boolean activateOnOpen) {
if (selection instanceof IStructuredSelection)
for (Object element : ((IStructuredSelection) selection).toArray()) if (element instanceof RepositoryCommit)
CommitEditor.openQuiet((RepositoryCommit) element, activateOnOpen);
}
};
return composite;
}
use of org.eclipse.ui.model.WorkbenchLabelProvider in project eclipse-cs by checkstyle.
the class CheckConfigurationWorkingSetEditor method createCheckConfigContents.
/**
* Creates the content regarding the management of check configurations.
*
* @param parent
* the parent composite
* @return the configuration area
*/
private Composite createCheckConfigContents(Composite parent) {
Composite configComposite = new Composite(parent, SWT.NULL);
configComposite.setLayout(new FormLayout());
final Control rightButtons = createButtonBar(configComposite);
FormData fd = new FormData();
fd.top = new FormAttachment(0);
fd.right = new FormAttachment(100);
fd.bottom = new FormAttachment(100);
rightButtons.setLayoutData(fd);
Composite tableAndDesc = new Composite(configComposite, SWT.NULL);
tableAndDesc.setLayout(new FormLayout());
fd = new FormData();
fd.left = new FormAttachment(0);
fd.top = new FormAttachment(0);
fd.right = new FormAttachment(rightButtons, -3, SWT.LEFT);
fd.bottom = new FormAttachment(100, 0);
tableAndDesc.setLayoutData(fd);
final Control table = createConfigTable(tableAndDesc);
fd = new FormData();
fd.left = new FormAttachment(0);
fd.top = new FormAttachment(0);
fd.right = new FormAttachment(100);
fd.bottom = new FormAttachment(70);
table.setLayoutData(fd);
Composite descArea = new Composite(tableAndDesc, SWT.NULL);
descArea.setLayout(new FormLayout());
fd = new FormData();
fd.left = new FormAttachment(0);
fd.top = new FormAttachment(table, 0);
fd.right = new FormAttachment(mIsShowUsage ? 60 : 100);
fd.bottom = new FormAttachment(100);
descArea.setLayoutData(fd);
Label lblDescription = new Label(descArea, SWT.NULL);
lblDescription.setText(Messages.CheckstylePreferencePage_lblDescription);
fd = new FormData();
fd.left = new FormAttachment(0);
fd.top = new FormAttachment(3);
fd.right = new FormAttachment(100);
lblDescription.setLayoutData(fd);
mConfigurationDescription = new Text(descArea, SWT.LEFT | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | SWT.BORDER | SWT.VERTICAL);
fd = new FormData();
fd.left = new FormAttachment(0);
fd.top = new FormAttachment(lblDescription);
fd.right = new FormAttachment(100);
fd.bottom = new FormAttachment(100);
mConfigurationDescription.setLayoutData(fd);
if (mIsShowUsage) {
Composite usageArea = new Composite(tableAndDesc, SWT.NULL);
usageArea.setLayout(new FormLayout());
fd = new FormData();
fd.left = new FormAttachment(60, 0);
fd.top = new FormAttachment(table, 3);
fd.right = new FormAttachment(100);
fd.bottom = new FormAttachment(100);
usageArea.setLayoutData(fd);
Label lblUsage = new Label(usageArea, SWT.NULL);
lblUsage.setText(Messages.CheckstylePreferencePage_lblProjectUsage);
fd = new FormData();
fd.left = new FormAttachment(0);
fd.top = new FormAttachment(0);
fd.right = new FormAttachment(100);
lblUsage.setLayoutData(fd);
mUsageView = new TableViewer(usageArea);
mUsageView.getControl().setBackground(usageArea.getBackground());
mUsageView.setContentProvider(new ArrayContentProvider());
mUsageView.setLabelProvider(new WorkbenchLabelProvider());
fd = new FormData();
fd.left = new FormAttachment(0);
fd.top = new FormAttachment(lblUsage);
fd.right = new FormAttachment(100);
fd.bottom = new FormAttachment(100);
mUsageView.getControl().setLayoutData(fd);
}
// enforce update of button enabled state
mController.selectionChanged(new SelectionChangedEvent(mViewer, new StructuredSelection()));
return configComposite;
}
use of org.eclipse.ui.model.WorkbenchLabelProvider in project InformationSystem by ObeoNetwork.
the class DocumentationLinkDialog method createWorkspaceValueEditor.
private void createWorkspaceValueEditor(Group grpDocumentationSettings) {
btnWorkspace = new Button(grpDocumentationSettings, SWT.RADIO);
btnWorkspace.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
btnWorkspace.addSelectionListener(new SelectionAdapter() {
/**
* {@inheritDoc}
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
valueText.setEnabled(false);
treeViewer.getControl().setEnabled(true);
}
});
// $NON-NLS-1$
btnWorkspace.setText(DocBridgeUI.getInstance().getString("DocumentationLinkDialog_WorkspaceEditor_title"));
treeViewer = new TreeViewer(grpDocumentationSettings, SWT.BORDER);
Tree tree = treeViewer.getTree();
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
tree.setEnabled(false);
treeViewer.setContentProvider(new WorkbenchContentProvider());
treeViewer.setLabelProvider(new WorkbenchLabelProvider());
treeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
if (event.getSelection() instanceof StructuredSelection) {
Object selection = ((StructuredSelection) event.getSelection()).getFirstElement();
if (selection instanceof IFile) {
value = DocumentationLink.WORKSPACE_PREFIX + ((IFile) selection).getFullPath().toString();
} else {
value = null;
}
updateButtons();
}
}
});
}
use of org.eclipse.ui.model.WorkbenchLabelProvider in project InformationSystem by ObeoNetwork.
the class SpecificWorkspaceResourceDialog method openFolderOrFileSelection.
public static IResource openFolderOrFileSelection(Shell parent, String title, String message, IPath suggestedPath, List<ViewerFilter> viewerFilters) {
final SpecificWorkspaceResourceDialog dialog = new SpecificWorkspaceResourceDialog(parent, new WorkbenchLabelProvider(), new WorkbenchContentProvider());
dialog.setAllowMultiple(false);
dialog.setTitle(title);
dialog.setMessage(message);
dialog.setShowNewFolderControl(true);
dialog.setShowFileControl(false);
dialog.addFilter(dialog.createDefaultViewerFilter(false));
if (viewerFilters != null) {
for (ViewerFilter viewerFilter : viewerFilters) {
dialog.addFilter(viewerFilter);
}
}
if (suggestedPath != null) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IResource resource = root.findMember(suggestedPath);
if (resource != null && resource.isAccessible()) {
if (resource instanceof IContainer) {
dialog.setInitialSelection(resource);
} else {
dialog.setInitialSelection(resource.getParent());
dialog.setFileText(resource.getName());
}
} else {
if (suggestedPath.segmentCount() > 1) {
if (resource == null) {
resource = root.getFile(suggestedPath);
}
if (resource.getProject().isAccessible()) {
IContainer container = resource.getParent();
for (; !container.isAccessible() && container != resource.getProject(); container = container.getParent()) {
// Do nothing
}
dialog.setInitialSelection(container);
suggestedPath = suggestedPath.removeFirstSegments(container.getFullPath().segmentCount());
dialog.setFileText(suggestedPath.toString());
suggestedPath = null;
}
}
if (suggestedPath != null) {
String fileText = suggestedPath.isAbsolute() ? suggestedPath.removeFirstSegments(1).toString() : suggestedPath.toString();
dialog.setFileText(fileText);
}
}
}
dialog.loadContents();
return dialog.open() == Window.OK ? dialog.getSelectedContainers()[0] : null;
}
Aggregations