use of org.eclipse.swt.events.VerifyEvent in project tesb-studio-se by Talend.
the class ServiceMetadataCustomPropertiesTable method createTableViewer.
private void createTableViewer() {
tableViewer = new TableViewer(table);
tableViewer.setUseHashlookup(true);
tableViewer.setColumnProperties(columnNames);
CellEditor[] editors = new CellEditor[columnNames.length];
TextCellEditor textEditor = new TextCellEditor(table) {
protected Object doGetValue() {
Object value = super.doGetValue();
return null == value || ((String) value).trim().isEmpty() ? COLUMN_PROPERTY_NAME_DEFAULT_VALUE : value;
}
};
((Text) textEditor.getControl()).setTextLimit(64);
((Text) textEditor.getControl()).addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e) {
//$NON-NLS-1$
e.doit = !e.text.equals("\"");
// e.doit = !e.text.trim().isEmpty();
}
});
editors[0] = textEditor;
textEditor = new TextCellEditor(table);
((Text) textEditor.getControl()).setTextLimit(64);
((Text) textEditor.getControl()).addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent e) {
//$NON-NLS-1$
e.doit = !e.text.equals("\"");
}
});
editors[1] = textEditor;
tableViewer.setCellEditors(editors);
tableViewer.setCellModifier(new PropertyCellModifier(this));
}
use of org.eclipse.swt.events.VerifyEvent in project eclipse.platform.swt by eclipse.
the class Tab method log.
/**
* Logs an untyped event to the event console.
*/
void log(Event event) {
int i = 0;
while (i < EVENT_INFO.length) {
if (EVENT_INFO[i].type == event.type)
break;
i++;
}
String toString = EVENT_INFO[i].name + " [" + event.type + "]: ";
if (!untypedEvents) {
switch(event.type) {
case SWT.KeyDown:
case SWT.KeyUp:
toString += new KeyEvent(event).toString();
break;
case SWT.MouseDown:
case SWT.MouseUp:
case SWT.MouseMove:
case SWT.MouseEnter:
case SWT.MouseExit:
case SWT.MouseDoubleClick:
case SWT.MouseWheel:
case SWT.MouseHover:
toString += new MouseEvent(event).toString();
break;
case SWT.Paint:
toString += new PaintEvent(event).toString();
break;
case SWT.Move:
case SWT.Resize:
toString += new ControlEvent(event).toString();
break;
case SWT.Dispose:
toString += new DisposeEvent(event).toString();
break;
case SWT.Selection:
case SWT.DefaultSelection:
toString += new SelectionEvent(event).toString();
break;
case SWT.FocusIn:
case SWT.FocusOut:
toString += new FocusEvent(event).toString();
break;
case SWT.Expand:
case SWT.Collapse:
toString += new TreeEvent(event).toString();
break;
case SWT.Iconify:
case SWT.Deiconify:
case SWT.Close:
case SWT.Activate:
case SWT.Deactivate:
toString += new ShellEvent(event).toString();
break;
case SWT.Show:
case SWT.Hide:
toString += (event.widget instanceof Menu) ? new MenuEvent(event).toString() : event.toString();
break;
case SWT.Modify:
toString += new ModifyEvent(event).toString();
break;
case SWT.Verify:
toString += new VerifyEvent(event).toString();
break;
case SWT.Help:
toString += new HelpEvent(event).toString();
break;
case SWT.Arm:
toString += new ArmEvent(event).toString();
break;
case SWT.Traverse:
toString += new TraverseEvent(event).toString();
break;
case SWT.HardKeyDown:
case SWT.HardKeyUp:
case SWT.DragDetect:
case SWT.MenuDetect:
case SWT.SetData:
default:
toString += event.toString();
}
} else {
toString += event.toString();
}
log(toString);
/* Return values for event fields. */
int mask = EVENT_INFO[i].setFields;
if (!ignore && mask != 0) {
Event setFieldsEvent = EVENT_INFO[i].event;
if ((mask & DOIT) != 0)
event.doit = setFieldsEvent.doit;
if ((mask & DETAIL) != 0)
event.detail = setFieldsEvent.detail;
if ((mask & TEXT) != 0)
event.text = setFieldsEvent.text;
if ((mask & X) != 0)
event.x = setFieldsEvent.x;
if ((mask & Y) != 0)
event.y = setFieldsEvent.y;
if ((mask & WIDTH) != 0)
event.width = setFieldsEvent.width;
if ((mask & HEIGHT) != 0)
event.height = setFieldsEvent.height;
eventConsole.append(ControlExample.getResourceString("Returning"));
ignore = true;
log(event);
ignore = false;
}
}
use of org.eclipse.swt.events.VerifyEvent in project eclipse.platform.text by eclipse.
the class AbstractControlContentAssistSubjectAdapter method installControlListener.
/**
* Installs <code>fControlListener</code>, which handles VerifyEvents and KeyEvents by
* passing them to {@link #fVerifyKeyListeners} and {@link #fKeyListeners}.
*/
private void installControlListener() {
if (DEBUG)
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println("AbstractControlContentAssistSubjectAdapter#installControlListener() -> k: " + fKeyListeners.size() + ", v: " + fVerifyKeyListeners.size());
if (fControlListener != null)
return;
fControlListener = new Listener() {
@Override
public void handleEvent(Event e) {
if (!getControl().isFocusControl())
// SWT.TRAVERSE_MNEMONIC events can also come in to inactive widgets
return;
VerifyEvent verifyEvent = new VerifyEvent(e);
KeyEvent keyEvent = new KeyEvent(e);
switch(e.type) {
case SWT.Traverse:
if (DEBUG)
// $NON-NLS-1$
dump("before traverse", e, verifyEvent);
verifyEvent.doit = true;
for (VerifyKeyListener verifyKeyListener : fVerifyKeyListeners) {
verifyKeyListener.verifyKey(verifyEvent);
if (!verifyEvent.doit) {
e.detail = SWT.TRAVERSE_NONE;
e.doit = true;
if (DEBUG)
// $NON-NLS-1$
dump("traverse eaten by verify", e, verifyEvent);
return;
}
if (DEBUG)
// $NON-NLS-1$
dump("traverse OK", e, verifyEvent);
}
break;
case SWT.KeyDown:
for (VerifyKeyListener verifyKeyListener : fVerifyKeyListeners) {
verifyKeyListener.verifyKey(verifyEvent);
if (!verifyEvent.doit) {
e.doit = verifyEvent.doit;
if (DEBUG)
// $NON-NLS-1$
dump("keyDown eaten by verify", e, verifyEvent);
return;
}
}
if (DEBUG)
// $NON-NLS-1$
dump("keyDown OK", e, verifyEvent);
for (KeyListener keyListener : fKeyListeners) {
keyListener.keyPressed(keyEvent);
}
break;
default:
Assert.isTrue(false);
}
}
/**
* Dump the given events to "standard" output.
*
* @param who who dump's
* @param e the event
* @param ve the verify event
*/
private void dump(String who, Event e, VerifyEvent ve) {
// $NON-NLS-1$
StringBuilder sb = new StringBuilder("--- [AbstractControlContentAssistSubjectAdapter]\n");
sb.append(who);
// $NON-NLS-1$
sb.append(" - e: keyCode=" + e.keyCode + hex(e.keyCode));
// $NON-NLS-1$
sb.append("; character=" + e.character + hex(e.character));
// $NON-NLS-1$
sb.append("; stateMask=" + e.stateMask + hex(e.stateMask));
// $NON-NLS-1$
sb.append("; doit=" + e.doit);
// $NON-NLS-1$
sb.append("; detail=" + e.detail + hex(e.detail));
// $NON-NLS-1$
sb.append("; widget=" + e.widget);
// $NON-NLS-1$
sb.append("\n");
// $NON-NLS-1$
sb.append(" verifyEvent keyCode=" + e.keyCode + hex(e.keyCode));
// $NON-NLS-1$
sb.append("; character=" + e.character + hex(e.character));
// $NON-NLS-1$
sb.append("; stateMask=" + e.stateMask + hex(e.stateMask));
// $NON-NLS-1$
sb.append("; doit=" + ve.doit);
// $NON-NLS-1$
sb.append("; widget=" + e.widget);
System.out.println(sb);
}
private String hex(int i) {
// $NON-NLS-1$
return "[0x" + Integer.toHexString(i) + ']';
}
};
getControl().addListener(SWT.Traverse, fControlListener);
getControl().addListener(SWT.KeyDown, fControlListener);
if (DEBUG)
// $NON-NLS-1$
System.out.println("AbstractControlContentAssistSubjectAdapter#installControlListener() - installed");
}
use of org.eclipse.swt.events.VerifyEvent in project eclipse.platform.text by eclipse.
the class ContextInformationPopup method createContextSelector.
/**
* Creates the context selector in case the user has the choice between multiple valid contexts
* at a given offset.
*/
private void createContextSelector() {
if (Helper.okToUse(fContextSelectorShell))
return;
Control control = fContentAssistSubjectControlAdapter.getControl();
fContextSelectorShell = new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
fContextSelectorShell.setLayout(layout);
fContextSelectorShell.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_BLACK));
fContextSelectorShell.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
fContextSelectorPopupSize = fContextSelectorShell.getSize();
}
});
if (fViewer instanceof ITextViewerExtension) {
final ITextViewerExtension textViewerExtension = (ITextViewerExtension) fViewer;
final StyledText textWidget = fViewer.getTextWidget();
final VerifyKeyListener verifyListener = new VerifyKeyListener() {
@Override
public void verifyKey(VerifyEvent event) {
if (isActive() && event.keyCode == 13 && event.character == '\r' && event.widget == textWidget) {
event.doit = false;
insertSelectedContext();
hideContextSelector();
}
}
};
textViewerExtension.prependVerifyKeyListener(verifyListener);
fContextSelectorShell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
textViewerExtension.removeVerifyKeyListener(verifyListener);
}
});
}
fContextSelectorTable = new Table(fContextSelectorShell, SWT.H_SCROLL | SWT.V_SCROLL);
fContextSelectorTable.setLocation(1, 1);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = fContextSelectorTable.getItemHeight() * 10;
gd.widthHint = 300;
fContextSelectorTable.setLayoutData(gd);
Point size = fContentAssistant.restoreContextSelectorPopupSize();
if (size != null)
fContextSelectorShell.setSize(size);
else
fContextSelectorShell.pack(true);
Color c = fContentAssistant.getContextSelectorBackground();
if (c == null)
c = control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
fContextSelectorTable.setBackground(c);
c = fContentAssistant.getContextSelectorForeground();
if (c == null)
c = control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
fContextSelectorTable.setForeground(c);
fContextSelectorTable.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
insertSelectedContext();
hideContextSelector();
}
});
fPopupCloser.install(fContentAssistant, fContextSelectorTable);
fContextSelectorTable.setHeaderVisible(false);
fContentAssistant.addToLayout(this, fContextSelectorShell, ContentAssistant.LayoutManager.LAYOUT_CONTEXT_SELECTOR, fContentAssistant.getSelectionOffset());
}
use of org.eclipse.swt.events.VerifyEvent in project knime-core by knime.
the class StyledTextEditor method createStyledText.
private Control createStyledText(final Composite parent) {
m_styledText = new StyledText(parent, SWT.MULTI | SWT.WRAP | SWT.FULL_SELECTION);
// by default we are a workflow annotation editor
// can be changed by changing the default font (setDefaultFont(Font))
m_styledText.setFont(AnnotationEditPart.getWorkflowAnnotationDefaultFont());
m_styledText.setAlignment(SWT.LEFT);
m_styledText.setText("");
m_styledText.setTabs(TAB_SIZE);
m_styledText.addVerifyKeyListener(new VerifyKeyListener() {
@Override
public void verifyKey(final VerifyEvent event) {
if (event.character == SWT.CR && (event.stateMask & SWT.MOD1) != 0) {
event.doit = false;
}
}
});
// forward some events to the cell editor
m_styledText.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(final KeyEvent e) {
keyReleaseOccured(e);
}
});
m_styledText.addFocusListener(new FocusAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void focusLost(final org.eclipse.swt.events.FocusEvent e) {
// effect of an opening font editor, for instance)
if (m_allowFocusLost.get()) {
lostFocus();
}
}
});
m_styledText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
// super marks it dirty (otherwise no commit at the end)
fireEditorValueChanged(true, true);
}
});
m_styledText.addExtendedModifyListener(new ExtendedModifyListener() {
@Override
public void modifyText(final ExtendedModifyEvent event) {
if (event.length > 0) {
textInserted(event.start, event.length);
}
}
});
m_styledText.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(final SelectionEvent e) {
selectionChanged();
}
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
selectionChanged();
}
});
m_styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
addMenu(m_styledText);
// toolbar gets created first - enable its style buttons!
selectionChanged();
return m_styledText;
}
Aggregations