use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_Text method test_addSelectionListenerWidgetSelectedAdapterLorg_eclipse_swt_events_SelectionListener.
@Test
public void test_addSelectionListenerWidgetSelectedAdapterLorg_eclipse_swt_events_SelectionListener() {
listenerCalled = false;
SelectionListener listener = SelectionListener.widgetSelectedAdapter(e -> listenerCalled = true);
text.addSelectionListener(listener);
text.setText("12345");
text.setSelection(1, 3);
assertFalse(":a:", listenerCalled);
text.removeSelectionListener(listener);
}
use of org.eclipse.swt.events.SelectionListener in project hale by halestudio.
the class ClassificationMappingParameterPage method createFromFileTabControl.
private Control createFromFileTabControl(Composite tabParent) {
// Parent composite for fromFileTab
Composite item2Content = new Composite(tabParent, SWT.NONE);
item2Content.setLayout(new GridLayout());
// Label to descripe what the user should do
Label l = new Label(item2Content, SWT.NONE);
l.setText("Select the project lookup table resource you want to use for the classification:");
// Get the Lookuptable Service
final LookupService lookupService = HaleUI.getServiceProvider().getService(LookupService.class);
// Composite for comboViewerComposite and Button
Composite parent = new Composite(item2Content, SWT.NONE);
parent.setLayout(new GridLayout(2, false));
parent.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
// Description Label
description = new Label(item2Content, SWT.WRAP);
description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
description.setText("");
description.setVisible(false);
// label with warning message
Composite warnComp = new Composite(item2Content, SWT.NONE);
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(warnComp);
GridDataFactory.fillDefaults().grab(true, false).applyTo(warnComp);
Label warnImage = new Label(warnComp, SWT.NONE);
warnImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.BEGINNING).applyTo(warnImage);
Label warn = new Label(warnComp, SWT.WRAP);
warn.setText("Classifications from a file resource will not function in another project where the alignment with the classification is imported or used as a base alignment.\n" + "If unsure, use the 'Explicit' mode instead and use the option to load the classification from a file.");
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).hint(300, SWT.DEFAULT).applyTo(warn);
// Composite for ComboViewer
Composite viewerComposite = new Composite(parent, SWT.NONE);
viewerComposite.setLayout(new FillLayout());
GridData layoutData = new GridData(SWT.FILL, SWT.NONE, true, false);
viewerComposite.setLayoutData(GridDataFactory.copyData(layoutData));
// ComboViewer
lookupTableComboViewer = new ComboViewer(viewerComposite, SWT.READ_ONLY);
lookupTableComboViewer.setContentProvider(ArrayContentProvider.getInstance());
lookupTableComboViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof String) {
return lookupService.getTable((String) element).getName();
}
return null;
}
});
lookupTableComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
// Show the description for the selected lookupTable
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
String desc = lookupService.getTable(selection.getFirstElement().toString()).getDescription();
if (desc != null) {
description.setText("Description: " + desc);
} else {
description.setText("");
}
if (!description.isVisible()) {
description.setVisible(true);
}
}
});
lookupTableComboViewer.setInput(lookupService.getTableIDs());
if (selectedLookupTableID != null) {
lookupTableComboViewer.setSelection(new StructuredSelection(selectedLookupTableID), true);
}
// Button to load a lookupTable if no one is loaded
final Button browseButton = new Button(parent, SWT.PUSH);
browseButton.setText("Add...");
browseButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
IOWizardAction action = new IOWizardAction("eu.esdihumboldt.hale.lookup.import");
action.run();
action.dispose();
// Refresh the viewer
lookupTableComboViewer.setInput(lookupService.getTableIDs());
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// nothing to do here
}
});
return item2Content;
}
use of org.eclipse.swt.events.SelectionListener in project hale by halestudio.
the class StackTraceErrorDialog method createDropDownList.
/**
* @see ErrorDialog#createDropDownList(Composite)
*/
@Override
protected List createDropDownList(Composite parent) {
_list = super.createDropDownList(parent);
_list.removeAll();
// replace context menu
_list.getMenu().dispose();
Menu copyMenu = new Menu(_list);
MenuItem copyItem = new MenuItem(copyMenu, SWT.NONE);
copyItem.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
copyToClipboard();
}
@Override
public void widgetSelected(SelectionEvent e) {
copyToClipboard();
}
});
// $NON-NLS-1$
copyItem.setText(JFaceResources.getString("copy"));
_list.setMenu(copyMenu);
// convert stack trace to string
String stackTrace = stackTraceToString(_status.getException());
if (stackTrace != null) {
// add stack trace to list
// $NON-NLS-1$ //$NON-NLS-2$
stackTrace = stackTrace.replaceAll("\r", "");
// $NON-NLS-1$ //$NON-NLS-2$
stackTrace = stackTrace.replaceAll("\t", " ");
// $NON-NLS-1$
String[] lines = stackTrace.split("\n");
for (String l : lines) {
_list.add(l);
}
}
return _list;
}
use of org.eclipse.swt.events.SelectionListener in project hale by halestudio.
the class RuleStylePage method createControl.
/**
* @see IDialogPage#createControl(Composite)
*/
@Override
public void createControl(Composite parent) {
changed = false;
Composite page = new Composite(parent, SWT.NONE);
page.setLayout(new GridLayout(2, false));
// DISABLED - this method seems to change the rule order - Rule[]
// ruleArray = SLD.rules(getParent().getStyle());
// use list instead:
List<Rule> ruleList;
try {
ruleList = getParent().getStyle().featureTypeStyles().get(0).rules();
} catch (Exception e) {
ruleList = new ArrayList<Rule>();
}
// init index
if (ruleList.size() > 0) {
currentIndex = 0;
} else {
currentIndex = -1;
}
currentEditor = null;
// populate rule map
rules = new ArrayList<RuleItem>(ruleList.size() + 5);
for (int i = 0; i < ruleList.size(); i++) {
Rule rule = ruleList.get(i);
if (rule != null) {
rules.add(new RuleItem(rule));
}
}
// rule list
Composite ruleArea = new Composite(page, SWT.NONE);
ruleArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
GridLayout leftLayout = new GridLayout(5, true);
leftLayout.horizontalSpacing = 1;
leftLayout.verticalSpacing = 1;
ruleArea.setLayout(leftLayout);
// label
Label rulesLabel = new Label(ruleArea, SWT.NONE);
rulesLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 5, 1));
rulesLabel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
rulesLabel.setText(Messages.RuleStylePage_RuleLabelText);
// viewer
listViewer = new ListViewer(ruleArea);
listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 5, 1));
listViewer.setContentProvider(new IStructuredContentProvider() {
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// ignore
}
@Override
public void dispose() {
// ignore
}
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(Object inputElement) {
try {
List<RuleItem> rules = (List<RuleItem>) inputElement;
return rules.toArray();
} catch (Exception e) {
return null;
}
}
});
listViewer.setInput(rules);
if (currentIndex >= 0 && currentIndex < rules.size()) {
listViewer.setSelection(new StructuredSelection(rules.get(currentIndex)));
}
listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
RuleItem item = (RuleItem) ((IStructuredSelection) event.getSelection()).getFirstElement();
int newIndex = rules.indexOf(item);
if (currentIndex != newIndex) {
try {
updateCurrentRule();
} catch (Exception e) {
log.userError("Invalid editor state, could not update rule.", e);
return;
}
currentIndex = newIndex;
updateEditor();
}
}
});
// buttons
addButton = new Button(ruleArea, SWT.PUSH);
addButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
addButton.setImage(addImage);
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
addRule();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
addButton.setToolTipText(Messages.RuleStylePage_AddRuleButtonToolTippText);
removeButton = new Button(ruleArea, SWT.PUSH);
removeButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
removeButton.setImage(removeImage);
removeButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
removeCurrentRule();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
removeButton.setToolTipText(Messages.RuleStylePage_RemoveRuleButtonToolTippText);
upButton = new Button(ruleArea, SWT.PUSH);
upButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
upButton.setImage(upImage);
upButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
moveCurrentRuleUp();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
upButton.setToolTipText(Messages.RuleStylePage_UpRuleButtonToolTippText);
downButton = new Button(ruleArea, SWT.PUSH);
downButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
downButton.setImage(downImage);
downButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
moveCurrentRuleDown();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
downButton.setToolTipText(Messages.RuleStylePage_DownRuleButtonToolTippText);
renameButton = new Button(ruleArea, SWT.PUSH);
renameButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
renameButton.setImage(renameImage);
renameButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
renameCurrentRule();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
// ignore
}
});
renameButton.setToolTipText(Messages.RuleStylePage_RenameRuleButtonToolTippText);
// editor area
editorArea = new Composite(page, SWT.NONE);
editorArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
editorArea.setLayout(new FillLayout());
setControl(page);
updateEditor();
}
use of org.eclipse.swt.events.SelectionListener in project pentaho-kettle by pentaho.
the class TableView method editButton.
private void editButton(TableItem row, int rownr, int colnr) {
beforeEdit = getItemText(row);
fieldChanged = false;
ColumnInfo colinfo = columns[colnr - 1];
if (colinfo.isReadOnly()) {
return;
}
if (colinfo.getDisabledListener() != null) {
boolean disabled = colinfo.getDisabledListener().isFieldDisabled(rownr);
if (disabled) {
return;
}
}
button = new Button(table, SWT.PUSH);
props.setLook(button, Props.WIDGET_STYLE_TABLE);
String buttonText = columns[colnr - 1].getButtonText();
if (buttonText != null) {
button.setText(buttonText);
}
button.setImage(GUIResource.getInstance().getImage("ui/images/edittext.svg"));
SelectionListener selAdpt = colinfo.getSelectionAdapter();
if (selAdpt != null) {
button.addSelectionListener(selAdpt);
}
buttonRownr = rownr;
buttonColnr = colnr;
// button.addTraverseListener(lsTraverse);
buttonContent = row.getText(colnr);
String tooltip = columns[colnr - 1].getToolTip();
if (tooltip != null) {
button.setToolTipText(tooltip);
} else {
button.setToolTipText("");
}
// hop to next field
button.addTraverseListener(lsTraverse);
button.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent arg0) {
closeActiveButton();
}
});
editor.horizontalAlignment = SWT.LEFT;
editor.verticalAlignment = SWT.TOP;
editor.grabHorizontal = false;
editor.grabVertical = false;
Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
editor.minimumWidth = size.x;
editor.minimumHeight = size.y - 2;
// setRowNums();
editor.layout();
// Open the text editor in the correct column of the selected row.
editor.setEditor(button);
button.setFocus();
// if the button loses focus, destroy it...
/*
* button.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { button.dispose(); } } );
*/
}
Aggregations