use of org.eclipse.jface.viewers.ViewerComparator in project nebula.widgets.nattable by eclipse.
the class PersistenceDialog method createDialogArea.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
* .Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite control = (Composite) super.createDialogArea(parent);
Label viewerLabel = new Label(control, SWT.NONE);
viewerLabel.setText(// $NON-NLS-1$
Messages.getString("PersistenceDialog.viewerLabel"));
GridDataFactory.fillDefaults().grab(true, false).applyTo(viewerLabel);
this.viewer = new TableViewer(control);
this.viewer.setContentProvider(new ArrayContentProvider());
this.viewer.setLabelProvider(new ViewConfigurationNameLabelProvider());
// sort in alphabetical order
this.viewer.setComparator(new ViewerComparator());
GridDataFactory.fillDefaults().grab(true, true).applyTo(this.viewer.getControl());
// layout textbox
Composite nameContainer = new Composite(control, SWT.NONE);
GridLayout layout = new GridLayout(2, false);
layout.marginWidth = 0;
nameContainer.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, false).applyTo(nameContainer);
Label label = new Label(nameContainer, SWT.NONE);
// $NON-NLS-1$
label.setText(Messages.getString("PersistenceDialog.nameLabel"));
this.configNameText = new Text(nameContainer, SWT.BORDER);
GridDataFactory.fillDefaults().grab(true, false).applyTo(this.configNameText);
this.configNameText.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if ((event.keyCode == SWT.CR && event.stateMask == 0) || (event.keyCode == SWT.KEYPAD_CR && event.stateMask == 0)) {
buttonPressed(SAVE_ID);
}
}
});
this.configNameText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
if (PersistenceDialog.this.configNameText.getText().length() != 0) {
PersistenceDialog.this.configNameDeco.hide();
}
}
});
this.configNameDeco = new ControlDecoration(this.configNameText, SWT.RIGHT);
Image image = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage();
this.configNameDeco.setDescriptionText(Messages.getString(// $NON-NLS-1$
"PersistenceDialog.nameErrorText"));
this.configNameDeco.setImage(image);
this.configNameDeco.hide();
// add click listener on viewer
this.viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection != null && selection instanceof IStructuredSelection) {
String configName = ((IStructuredSelection) selection).getFirstElement().toString();
PersistenceDialog.this.configNameText.setText(configName);
}
}
});
// add double click listener
this.viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
buttonPressed(LOAD_ID);
}
});
this.viewer.add(PersistenceHelper.getAvailableStates(this.properties).toArray());
return control;
}
use of org.eclipse.jface.viewers.ViewerComparator in project hale by halestudio.
the class RootElementPage method createContent.
/**
* @see HaleWizardPage#createContent(Composite)
*/
@Override
protected void createContent(Composite page) {
page.setLayout(new GridLayout(1, false));
// add filter text
filterText = new Text(page, SWT.SINGLE | SWT.BORDER);
filterText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
// $NON-NLS-1$
filterText.setText("");
// add filtered list
list = new ListViewer(page, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
list.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof XmlElement) {
QName name = ((XmlElement) element).getName();
return name.getLocalPart() + " (" + name.getNamespaceURI() + ")";
}
if (element instanceof Definition) {
return ((Definition<?>) element).getDisplayName();
}
return super.getText(element);
}
});
list.setContentProvider(ArrayContentProvider.getInstance());
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
layoutData.widthHint = SWT.DEFAULT;
layoutData.heightHint = 8 * list.getList().getItemHeight();
list.getControl().setLayoutData(layoutData);
// page status update
list.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
setPageComplete(!selection.isEmpty());
}
});
list.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
if (canFlipToNextPage()) {
getContainer().showPage(getNextPage());
return;
}
}
});
// search filter & update
list.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
String filter = filterText.getText();
// handle empty filter
if (filter == null || filter.isEmpty()) {
return true;
}
if (element instanceof Definition) {
Definition<?> def = (Definition<?>) element;
filter = filter.toLowerCase();
if (def.getDisplayName().toLowerCase().contains(filter)) {
return true;
}
}
return false;
}
});
list.setComparator(new ViewerComparator());
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
// refilter
list.refresh();
}
});
updateList();
}
use of org.eclipse.jface.viewers.ViewerComparator in project hale by halestudio.
the class WebTemplatesDialog method setupViewer.
@Override
protected void setupViewer(final TreeViewer viewer, WebTemplate initialSelection) {
// this label provider is used for filtering (I guess)
viewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof WebTemplate) {
return ((WebTemplate) element).getName();
}
return super.getText(element);
}
});
viewer.getTree().setHeaderVisible(true);
// viewer.getTree().setLinesVisible(true);
// main column
TreeViewerColumn mainColumn = new TreeViewerColumn(viewer, SWT.NONE);
mainColumn.setLabelProvider(new StyledCellLabelProvider() {
@Override
public void update(ViewerCell cell) {
Object element = cell.getElement();
StyledString text = new StyledString();
if (element instanceof WebTemplate) {
WebTemplate template = (WebTemplate) element;
text.append(template.getName());
} else {
text.append(element.toString());
}
cell.setText(text.getString());
cell.setStyleRanges(text.getStyleRanges());
super.update(cell);
}
});
mainColumn.getColumn().setText("Template");
layout.setColumnData(mainColumn.getColumn(), new ColumnWeightData(7));
// link column
if (Desktop.isDesktopSupported()) {
TreeViewerColumn linkColumn = new TreeViewerColumn(viewer, SWT.CENTER);
linkColumn.setLabelProvider(new LinkLabels());
// listener that reacts on link cell clicks
viewer.getTree().addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
if (e.button == 1) {
ViewerCell cell = viewer.getCell(new Point(e.x, e.y));
if (cell != null && cell.getColumnIndex() == 1 && cell.getTextBounds().contains(e.x, e.y)) {
Object element = cell.getElement();
if (element instanceof WebTemplate) {
try {
Desktop.getDesktop().browse(((WebTemplate) element).getSite());
} catch (IOException e1) {
log.error("Could not launch browser", e1);
}
}
}
}
}
});
layout.setColumnData(linkColumn.getColumn(), new ColumnWeightData(1));
}
viewer.setComparator(new ViewerComparator());
viewer.setContentProvider(new WebTemplatesContentProvider());
viewer.setInput(templates);
}
use of org.eclipse.jface.viewers.ViewerComparator in project Palladio-Editors-Sirius by PalladioSimulator.
the class NewPalladioTemplateWizardPage method createControl.
/**
* @see IDialogPage#createControl(Composite)
*/
@Override
public void createControl(final Composite parent) {
final Composite container = new Composite(parent, SWT.NONE);
final GridLayout layout = new GridLayout();
layout.verticalSpacing = 10;
container.setLayout(layout);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
useTemplateCheckBox = new Button(container, useTemplate ? (SWT.CHECK | SWT.SELECTED) : SWT.CHECK);
useTemplateCheckBox.setText("Create a Palladio project using one of the initiator templates.");
advancedViewCheckBox = new Button(container, advancedView ? (SWT.CHECK | SWT.SELECTED) : SWT.CHECK);
advancedViewCheckBox.setText("Show advanced view (all examples).");
GridData gd = new GridData();
sashForm = new SashForm(container, SWT.HORIZONTAL);
gd = new GridData(GridData.FILL_BOTH);
// limit the width of the sash form to avoid the wizard
// opening very wide. This is just preferred size -
// it can be made bigger by the wizard
// See bug #83356
gd.widthHint = 300;
gd.heightHint = 300;
sashForm.setLayoutData(gd);
useTemplateCheckBox.addSelectionListener(SelectionListener.widgetSelectedAdapter(this::updateEnabledStateOfSelection));
advancedViewCheckBox.addSelectionListener(SelectionListener.widgetSelectedAdapter(it -> updateWizardTreeViewerInput()));
this.wizardTreeViewer = new TreeViewer(sashForm, SWT.BORDER);
this.wizardTreeViewer.setContentProvider(new TreeContentProvider());
updateWizardTreeViewerInput();
this.wizardTreeViewer.setLabelProvider(new TemplateTreeLabelProvider());
this.wizardTreeViewer.setComparator(new ViewerComparator());
this.wizardTreeViewer.addSelectionChangedListener(this);
createDescriptionIn(sashForm);
setControl(container);
// set correct colors and enabled state for initial state of useTemplate
updateEnabledStateOfSelection(null);
}
use of org.eclipse.jface.viewers.ViewerComparator in project archi by archimatetool.
the class NewModelFromTemplateWizardPage method createControl.
@Override
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout());
setControl(container);
// Help
PlatformUI.getWorkbench().getHelpSystem().setHelp(container, getHelpID());
GridData gd;
SashForm sash1 = new SashForm(container, SWT.HORIZONTAL);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 800;
gd.heightHint = 500;
sash1.setLayoutData(gd);
Composite tableComposite = new Composite(sash1, SWT.BORDER);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.verticalSpacing = 0;
tableComposite.setLayout(layout);
// Inbuilt Templates
gd = new GridData(SWT.FILL, SWT.FILL, true, false);
fInbuiltTableViewer = createGroupsTableViewer(tableComposite, Messages.NewModelFromTemplateWizardPage_2, gd);
fInbuiltTableViewer.setInput(new Object[] { fTemplateManager.getInbuiltTemplateGroup(), OPEN, MANAGE });
// Mouse UP actions...
fInbuiltTableViewer.getControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
Object o = ((IStructuredSelection) fInbuiltTableViewer.getSelection()).getFirstElement();
// Open...
if (o == OPEN) {
handleOpenAction();
} else // Manage...
if (o == MANAGE) {
handleManageTemplatesAction();
}
}
});
// My Templates
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
fUserTableViewer = createGroupsTableViewer(tableComposite, Messages.NewModelFromTemplateWizardPage_3, gd);
fUserTableViewer.setComparator(new ViewerComparator() {
@Override
public int category(Object element) {
if (element == fTemplateManager.AllUserTemplatesGroup) {
return 0;
}
return 1;
}
});
fUserTableViewer.setInput(fTemplateManager);
SashForm sash2 = new SashForm(sash1, SWT.VERTICAL);
Composite galleryComposite = new Composite(sash2, SWT.NULL);
layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
// layout.verticalSpacing = 0;
galleryComposite.setLayout(layout);
fGallery = new Gallery(galleryComposite, SWT.V_SCROLL | SWT.BORDER);
fGallery.setLayoutData(new GridData(GridData.FILL_BOTH));
// Renderers
final NoGroupRenderer groupRenderer = new NoGroupRenderer();
groupRenderer.setItemSize(DEFAULT_GALLERY_ITEM_SIZE, DEFAULT_GALLERY_ITEM_SIZE);
groupRenderer.setAutoMargin(true);
groupRenderer.setMinMargin(10);
fGallery.setGroupRenderer(groupRenderer);
final DefaultGalleryItemRenderer itemRenderer = new DefaultGalleryItemRenderer();
itemRenderer.setDropShadows(true);
itemRenderer.setDropShadowsSize(7);
itemRenderer.setShowRoundedSelectionCorners(false);
fGallery.setItemRenderer(itemRenderer);
// Root Group
fGalleryRoot = new GalleryItem(fGallery, SWT.NONE);
// Slider
final Scale scale = new Scale(galleryComposite, SWT.HORIZONTAL);
gd = new GridData(SWT.END, SWT.NONE, false, false);
gd.widthHint = 120;
scale.setLayoutData(gd);
scale.setMaximum(480);
scale.setMinimum(64);
scale.setIncrement(8);
scale.setPageIncrement(64);
scale.setSelection(DEFAULT_GALLERY_ITEM_SIZE);
scale.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
int inc = scale.getSelection();
itemRenderer.setDropShadows(inc >= DEFAULT_GALLERY_ITEM_SIZE);
groupRenderer.setItemSize(inc, inc);
}
});
// Description
fDescriptionText = new StyledText(sash2, SWT.V_SCROLL | SWT.READ_ONLY | SWT.WRAP | SWT.BORDER);
fGallery.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (e.item instanceof GalleryItem) {
ITemplate template = (ITemplate) ((GalleryItem) e.item).getData();
updateWizard(template);
} else {
updateWizard(null);
}
}
});
// Double-clicks
fGallery.addListener(SWT.MouseDoubleClick, new Listener() {
@Override
public void handleEvent(Event event) {
GalleryItem item = fGallery.getItem(new Point(event.x, event.y));
if (item != null) {
((ExtendedWizardDialog) getContainer()).finishPressed();
}
}
});
// Mouse move shows thumbnails
registerMouseMoveHandler();
// Select first group on table
selectFirstTableItem();
sash1.setWeights(new int[] { 30, 70 });
sash2.setWeights(new int[] { 70, 30 });
// Yes it's OK
setPageComplete(true);
}
Aggregations