use of org.eclipse.jface.viewers.IStructuredContentProvider in project archi by archimatetool.
the class UserPropertiesSection method createTableControl.
private void createTableControl(Composite parent) {
// Table Composite
Composite tableComp = createTableComposite(parent, SWT.NULL);
TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
// Table Viewer
fTableViewer = new TableViewer(tableComp, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION);
// Font
UIUtils.setFontFromPreferences(fTableViewer.getTable(), IPreferenceConstants.PROPERTIES_TABLE_FONT, true);
// Mac Silicon Item height
UIUtils.fixMacSiliconItemHeight(fTableViewer.getTable());
// Edit cell on double-click and add Tab key traversal
TableViewerEditor.create(fTableViewer, new ColumnViewerEditorActivationStrategy(fTableViewer) {
@Override
protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {
return super.isEditorActivationEvent(event) || (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION);
}
}, ColumnViewerEditor.TABBING_HORIZONTAL | ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEEP_EDITOR_ON_DOUBLE_CLICK | ColumnViewerEditor.KEYBOARD_ACTIVATION);
fTableViewer.getTable().setHeaderVisible(true);
fTableViewer.getTable().setLinesVisible(true);
addDragSupport();
addDropSupport();
// Help ID on table
PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
// Columns
TableViewerColumn columnBlank = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
tableLayout.setColumnData(columnBlank.getColumn(), new ColumnWeightData(3, false));
columnBlank.getColumn().setWidth(38);
TableViewerColumn columnKey = new TableViewerColumn(fTableViewer, SWT.NONE, 1);
columnKey.getColumn().setText(Messages.UserPropertiesSection_0);
tableLayout.setColumnData(columnKey.getColumn(), new ColumnWeightData(20, true));
columnKey.setEditingSupport(new KeyEditingSupport(fTableViewer));
// Click on Key Table Header
columnKey.getColumn().addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
sortKeys();
}
});
TableViewerColumn columnValue = new TableViewerColumn(fTableViewer, SWT.NONE, 2);
columnValue.getColumn().setText(Messages.UserPropertiesSection_1);
tableLayout.setColumnData(columnValue.getColumn(), new ColumnWeightData(77, true));
columnValue.setEditingSupport(new ValueEditingSupport(fTableViewer));
// Content Provider
fTableViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return ((IProperties) inputElement).getProperties().toArray();
}
});
// Label Provider
fTableViewer.setLabelProvider(new LabelCellProvider());
// Enable tooltips
ColumnViewerToolTipSupport.enableFor(fTableViewer);
// Toolbar
ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.VERTICAL);
getWidgetFactory().adapt(toolBar);
GridDataFactory.fillDefaults().align(SWT.END, SWT.TOP).applyTo(toolBar);
ToolBarManager toolBarmanager = new ToolBarManager(toolBar);
// New Property
fActionNewProperty = new Action(Messages.UserPropertiesSection_2) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
// complete any current editing
fTableViewer.applyEditorValue();
int index = -1;
IProperty selected = (IProperty) ((IStructuredSelection) fTableViewer.getSelection()).getFirstElement();
if (selected != null) {
index = fPropertiesElement.getProperties().indexOf(selected) + 1;
}
IProperty property = IArchimateFactory.eINSTANCE.createProperty();
executeCommand(new NewPropertyCommand(fPropertiesElement.getProperties(), property, index));
fTableViewer.editElement(property, 1);
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_PLUS);
}
};
// New Multiple Properties
fActionNewMultipleProperty = new Action(Messages.UserPropertiesSection_3) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
MultipleAddDialog dialog = new MultipleAddDialog(fPage.getSite().getShell());
if (dialog.open() == Window.OK) {
executeCommand(dialog.getCommand());
}
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_MUTIPLE);
}
};
// Remove Property
fActionRemoveProperty = new Action(Messages.UserPropertiesSection_4) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
CompoundCommand compoundCmd = new EObjectNonNotifyingCompoundCommand(fPropertiesElement) {
@Override
public String getLabel() {
return getCommands().size() > 1 ? Messages.UserPropertiesSection_5 : Messages.UserPropertiesSection_6;
}
};
for (Object o : ((IStructuredSelection) fTableViewer.getSelection()).toList()) {
Command cmd = new RemovePropertyCommand(fPropertiesElement.getProperties(), (IProperty) o);
compoundCmd.add(cmd);
}
executeCommand(compoundCmd);
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_SMALL_X);
}
};
fActionRemoveProperty.setEnabled(false);
// Manage
fActionShowKeyEditor = new Action(Messages.UserPropertiesSection_7) {
@Override
public void run() {
if (isAlive(fPropertiesElement)) {
UserPropertiesManagerDialog dialog = new UserPropertiesManagerDialog(fPage.getSite().getShell(), getArchimateModel());
dialog.open();
}
}
@Override
public String getToolTipText() {
return getText();
}
@Override
public ImageDescriptor getImageDescriptor() {
return IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_COG);
}
};
toolBarmanager.add(fActionNewProperty);
toolBarmanager.add(fActionNewMultipleProperty);
toolBarmanager.add(fActionRemoveProperty);
toolBarmanager.add(fActionShowKeyEditor);
toolBarmanager.update(true);
/*
* Selection Listener
*/
fTableViewer.addSelectionChangedListener((e) -> {
fActionRemoveProperty.setEnabled(!e.getSelection().isEmpty());
});
/*
* Table Double-click
*/
fTableViewer.getTable().addListener(SWT.MouseDoubleClick, (e) -> {
// Get Table item
Point pt = new Point(e.x, e.y);
TableItem item = fTableViewer.getTable().getItem(pt);
// Double-click into empty table creates new Property
if (item == null) {
fActionNewProperty.run();
} else // Double-clicked in column 0 with item
if (item.getData() instanceof IProperty) {
Rectangle rect = item.getBounds(0);
if (rect.contains(pt)) {
handleDoubleClick((IProperty) item.getData());
}
}
});
/*
* Edit table row on key press
*/
fTableViewer.getTable().addKeyListener(KeyListener.keyPressedAdapter(e -> {
if (e.keyCode == SWT.CR) {
Object selected = fTableViewer.getStructuredSelection().getFirstElement();
if (selected != null) {
fTableViewer.editElement(selected, 1);
}
}
}));
hookContextMenu();
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project archi by archimatetool.
the class ExportJasperReportsWizardPage2 method createControl.
@Override
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout());
setControl(container);
PlatformUI.getWorkbench().getHelpSystem().setHelp(container, HELP_ID);
Composite fieldContainer = new Composite(container, SWT.NULL);
fieldContainer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fieldContainer.setLayout(new GridLayout(2, false));
// Template Combo
Label label = new Label(fieldContainer, SWT.NONE);
label.setText(Messages.ExportJasperReportsWizardPage2_4);
fComboTemplateViewer = new ComboViewer(new Combo(fieldContainer, SWT.READ_ONLY | SWT.BORDER));
fComboTemplateViewer.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fComboTemplateViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
Template template = (Template) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (template.location == null) {
// Custom...
handleCustomDialog();
} else {
fLastSelectedTemplate = template;
}
}
});
fComboTemplateViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
return fTemplates.toArray();
}
});
fComboTemplateViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((Template) element).name;
}
});
// $NON-NLS-1$
fComboTemplateViewer.setInput("");
fComboTemplateViewer.setSelection(new StructuredSelection(fTemplates.get(0)));
// Locale Combo
label = new Label(fieldContainer, SWT.NONE);
label.setText(Messages.ExportJasperReportsWizardPage2_6);
fComboLocale = new ComboViewer(new Combo(fieldContainer, SWT.READ_ONLY | SWT.BORDER));
fComboLocale.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fComboLocale.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
Locale locale = (Locale) ((IStructuredSelection) event.getSelection()).getFirstElement();
fSelectedLocale = locale;
}
});
fComboLocale.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object inputElement) {
Locale[] locales = Locale.getAvailableLocales();
Comparator<Locale> localeComparator = new Comparator<Locale>() {
@Override
public int compare(Locale locale1, Locale locale2) {
return locale1.toString().compareTo(locale2.toString());
}
};
Arrays.sort(locales, localeComparator);
return locales;
}
});
fComboLocale.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((Locale) element).toLanguageTag();
}
});
// $NON-NLS-1$
fComboLocale.setInput("");
fComboLocale.setSelection(new StructuredSelection(fSelectedLocale));
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project xtext-eclipse by eclipse.
the class TypeChooser method choose.
public JvmDeclaredType choose(final List<JvmDeclaredType> candidateTypes, Iterable<TypeUsage> usages, final XtextResource resource) {
XtextEditor activeXtextEditor = EditorUtils.getActiveXtextEditor();
if (activeXtextEditor == null)
return null;
revealInEditor(activeXtextEditor, usages, resource);
Shell shell = Display.getDefault().getActiveShell();
IStructuredContentProvider contentProvider = new ContentProvider();
Dialog dialog = new Dialog(shell, new LabelProvider(labelProvider), contentProvider);
dialog.setInput(candidateTypes);
dialog.setInitialSelections((Object[]) new JvmDeclaredType[] { candidateTypes.get(0) });
int result = dialog.open();
if (originalSelection != null)
activeXtextEditor.getSelectionProvider().setSelection(originalSelection);
if (result == Window.OK && dialog.getResult().length > 0)
return (JvmDeclaredType) dialog.getResult()[0];
else
return null;
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project linuxtools by eclipse.
the class JavaImageTab method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
Label connLbl = new Label(composite, SWT.NONE);
connLbl.setText(Messages.ImageSelectionDialog_connection_label);
connCmb = new ComboViewer(composite, SWT.READ_ONLY);
connCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
connCmb.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
for (IDockerConnection conn : DockerConnectionManager.getInstance().getAllConnections()) {
try {
((DockerConnection) conn).open(false);
} catch (DockerException e) {
}
}
return DockerConnectionManager.getInstance().getAllConnections().stream().filter(c -> c.isOpen()).toArray(size -> new IDockerConnection[size]);
}
});
// $NON-NLS-1$
connCmb.setInput("place_holder");
Label imageLbl = new Label(composite, SWT.NONE);
imageLbl.setText(Messages.ImageSelectionDialog_image_label);
imageCmb = new ComboViewer(composite, SWT.READ_ONLY);
imageCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
imageCmb.setContentProvider(new IStructuredContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
IDockerConnection conn = (IDockerConnection) inputElement;
if (conn == null || conn.getImages() == null) {
return new Object[0];
} else {
return conn.getImages().stream().filter(// $NON-NLS-1$
i -> !i.repoTags().get(0).equals("<none>:<none>")).toArray(size -> new IDockerImage[size]);
}
}
});
imageCmb.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
IDockerImage img = (IDockerImage) element;
return img.repoTags().get(0);
}
});
imageCmb.setInput(null);
connCmb.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = event.getStructuredSelection();
IDockerConnection conn = (IDockerConnection) sel.getFirstElement();
selectedConnection = conn;
imageCmb.setInput(conn);
updateLaunchConfigurationDialog();
}
});
imageCmb.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection sel = event.getStructuredSelection();
IDockerImage img = (IDockerImage) sel.getFirstElement();
selectedImage = img;
updateLaunchConfigurationDialog();
}
});
Group dirGroup = new Group(composite, SWT.NONE);
dirGroup.setText(Messages.JavaImageTab_additional_dirs);
dirGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
dirGroup.setLayout(new GridLayout(2, false));
directoryList = new List(dirGroup, SWT.SINGLE | SWT.V_SCROLL);
directoryList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
directoryList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
removeButton.setEnabled(true);
}
});
addButton = createPushButton(dirGroup, Messages.JavaImageTab_button_add, null);
addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(getShell());
String directory = dialog.open();
if (directory != null && !listContains(directoryList, directory)) {
directoryList.add(directory);
updateLaunchConfigurationDialog();
}
}
});
removeButton = createPushButton(dirGroup, Messages.JavaImageTab_button_remove, null);
removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true));
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int i = directoryList.getSelectionIndex();
if (i >= 0) {
directoryList.remove(i);
updateLaunchConfigurationDialog();
}
if (directoryList.getItemCount() == 0) {
removeButton.setEnabled(false);
}
}
});
removeButton.setEnabled(false);
setControl(composite);
}
use of org.eclipse.jface.viewers.IStructuredContentProvider in project linuxtools by eclipse.
the class FileSystemSelectionArea method createContents.
/**
* Create the contents of the receiver in composite.
* @param composite Parent composite for created components.
*/
public void createContents(Composite composite) {
fileSystemTitle = new Label(composite, SWT.NONE);
fileSystemTitle.setText(ResourceSelectorWidgetMessages.fileSystemSelectionText);
fileSystemTitle.setFont(composite.getFont());
fileSystems = new ComboViewer(composite, SWT.READ_ONLY);
fileSystems.getControl().setFont(composite.getFont());
fileSystems.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((FileSystemElement) element).getSchemeLabel();
}
});
fileSystems.setContentProvider(new IStructuredContentProvider() {
@Override
public void dispose() {
// Nothing to do
}
@Override
public Object[] getElements(Object inputElement) {
return getSchemes();
}
@Override
public void inputChanged(org.eclipse.jface.viewers.Viewer viewer, Object oldInput, Object newInput) {
// Nothing to do
}
});
fileSystems.setInput(this);
Iterator<FileSystemElement> fsEltItr = fsElements.iterator();
boolean foundDefault = false;
while (fsEltItr.hasNext()) {
FileSystemElement fsElt = fsEltItr.next();
if (fsElt.getIsDefault()) {
if (foundDefault) {
ProfileLaunchPlugin.log(IStatus.WARNING, ResourceSelectorWidgetMessages.FileSystemSelectionArea_found_multiple_default_extensions + fsElt.getScheme());
// use only the first one we found marked as default
continue;
}
fileSystems.setSelection(new StructuredSelection(fsElt));
foundDefault = true;
}
}
}
Aggregations