use of eu.esdihumboldt.hale.ui.service.values.OccurringValuesListener in project hale by halestudio.
the class OccurringValuesSection method createControls.
@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
super.createControls(parent, aTabbedPropertySheetPage);
Composite page = getWidgetFactory().createComposite(parent);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(page);
// refresh button
refresh = getWidgetFactory().createButton(page, null, SWT.PUSH);
refresh.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_REFRESH));
refresh.setToolTipText("Update the occurring values");
refresh.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
service.updateOccurringValues((PropertyEntityDefinition) getEntity());
}
});
GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING).grab(false, false).applyTo(refresh);
// values table
values = new TableViewer(getWidgetFactory().createTable(page, SWT.MULTI | SWT.BORDER));
GridDataFactory.fillDefaults().grab(true, true).span(1, 2).applyTo(values.getControl());
values.setContentProvider(new ArrayContentProvider() {
@Override
public Object[] getElements(Object inputElement) {
if (inputElement instanceof OccurringValues) {
return ((OccurringValues) inputElement).getValues().entrySet().toArray();
}
return new Object[] {};
}
});
values.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof Entry) {
// XXX use styled label provider instead?
Entry<?> entry = (Entry<?>) element;
if (entry.getCount() > 1) {
return super.getText(entry.getElement()) + "\t(\u00d7" + entry.getCount() + ")";
} else
return super.getText(entry.getElement());
}
return super.getText(element);
}
});
values.setInput(null);
// values context menu
MenuManager manager = new MenuManager();
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
// populate context menu
// get selection
ISelection selection = values.getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
Object[] sels = ((IStructuredSelection) selection).toArray();
List<String> values = new ArrayList<String>();
for (Object sel : sels) {
if (sel instanceof Entry<?>) {
values.add(((Entry<?>) sel).getElement().toString());
}
}
if (!values.isEmpty()) {
manager.add(new AddConditionAction(getEntity(), values, false));
manager.add(new AddParentConditionAction(getEntity(), values, false));
if (values.size() > 1) {
manager.add(new Separator());
manager.add(new AddConditionAction(getEntity(), values, true));
manager.add(new AddParentConditionAction(getEntity(), values, true));
}
}
}
}
});
manager.setRemoveAllWhenShown(true);
final Menu valuesMenu = manager.createContextMenu(values.getControl());
values.getControl().setMenu(valuesMenu);
// copy button
copy = getWidgetFactory().createButton(page, null, SWT.PUSH);
copy.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_COPY));
copy.setToolTipText("Copy values to the clipboard");
copy.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
copyToClipboard();
}
});
GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING).grab(false, false).applyTo(copy);
// add listener to service
service.addListener(ovlistener = new OccurringValuesListener() {
@Override
public void occurringValuesUpdated(PropertyEntityDefinition property) {
if (property.equals(OccurringValuesSection.this.getEntity())) {
update();
}
}
@Override
public void occurringValuesInvalidated(SchemaSpaceID schemaSpace) {
if (schemaSpace.equals(OccurringValuesSection.this.getEntity().getSchemaSpace())) {
update();
}
}
});
update();
}
Aggregations