use of org.eclipse.swt.events.FocusAdapter in project tdi-studio-se by Talend.
the class OverviewSection method createControls.
/*
* @see AbstractJvmPropertySection#createControls(Composite)
*/
@Override
protected void createControls(final Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
composite.setLayout(layout);
viewer = new PropertiesFilteredTree(composite, getActionBars()) {
private ShowInTimelineAction showInTimelineAction;
@Override
protected List<Action> createActions(IActionBars actionBars) {
List<Action> actions = new ArrayList<Action>();
CopyAction copyAction = CopyAction.createCopyAction(actionBars);
actions.add(copyAction);
showInTimelineAction = new MyShowInTimelineAction(OverviewSection.this);
actions.add(showInTimelineAction);
return actions;
}
@Override
public void menuAboutToshow() {
// do nothing
}
}.getViewer();
viewer.setContentProvider(new OverviewContentProvider(overviewProperties));
viewer.setLabelProvider(new OverviewLabelProvider());
((Tree) viewer.getControl()).addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
storeTreeExpansionState();
}
});
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.OVERVIEW_PAGE);
}
use of org.eclipse.swt.events.FocusAdapter in project bndtools by bndtools.
the class PkgPatternsListPart method createSection.
protected void createSection(Section section, FormToolkit toolkit) {
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
ToolBar toolbar = new ToolBar(section, SWT.FLAT);
section.setTextClient(toolbar);
final ToolItem addItem = new ToolItem(toolbar, SWT.PUSH);
addItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ADD));
addItem.setToolTipText("Add");
final ToolItem insertItem = new ToolItem(toolbar, SWT.PUSH);
insertItem.setImage(imgInsert);
insertItem.setToolTipText("Insert");
insertItem.setEnabled(false);
final ToolItem removeItem = new ToolItem(toolbar, SWT.PUSH);
removeItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE));
removeItem.setDisabledImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_TOOL_DELETE_DISABLED));
removeItem.setToolTipText("Remove");
removeItem.setEnabled(false);
Table table = toolkit.createTable(composite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER);
viewer = new TableViewer(table);
viewer.setUseHashlookup(false);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(labelProvider);
toolbar = new ToolBar(composite, SWT.FLAT | SWT.HORIZONTAL | SWT.RIGHT);
final ToolItem btnMoveUp = new ToolItem(toolbar, SWT.PUSH);
btnMoveUp.setText("Up");
btnMoveUp.setImage(imgUp);
btnMoveUp.setEnabled(false);
final ToolItem btnMoveDown = new ToolItem(toolbar, SWT.PUSH);
btnMoveDown.setText("Down");
btnMoveDown.setImage(imgDown);
btnMoveDown.setEnabled(false);
// Listeners
table.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
ISelection selection = viewer.getSelection();
if (!selection.isEmpty())
managedForm.fireSelectionChanged(PkgPatternsListPart.this, selection);
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
List<C> oldSelection = selection;
IStructuredSelection structSel = (IStructuredSelection) event.getSelection();
@SuppressWarnings("unchecked") List<C> newSelection = structSel.toList();
selection = newSelection;
propChangeSupport.firePropertyChange(PROP_SELECTION, oldSelection, selection);
managedForm.fireSelectionChanged(PkgPatternsListPart.this, event.getSelection());
boolean enabled = !viewer.getSelection().isEmpty();
insertItem.setEnabled(enabled);
removeItem.setEnabled(enabled);
btnMoveUp.setEnabled(enabled);
btnMoveDown.setEnabled(enabled);
}
});
viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer(), ResourceTransfer.getInstance(), TextTransfer.getInstance() }, new PackageDropAdapter<C>(viewer) {
@Override
protected C createNewEntry(String packageName) {
return newHeaderClause(packageName);
}
@Override
protected void addRows(int index, Collection<C> rows) {
doAddClauses(rows, index, true);
}
@Override
protected int indexOf(Object object) {
return clauses.indexOf(object);
}
});
table.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.character == SWT.DEL) {
doRemoveSelectedClauses();
} else if (e.character == '+') {
doAddClausesAfterSelection(generateClauses());
}
}
});
addItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doAddClausesAfterSelection(generateClauses());
}
});
insertItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doInsertClausesAtSelection(generateClauses());
}
});
removeItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doRemoveSelectedClauses();
}
});
btnMoveUp.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doMoveUp();
}
});
btnMoveDown.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doMoveDown();
}
});
// Layout
GridLayout layout;
layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
layout.horizontalSpacing = 0;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.widthHint = 75;
gd.heightHint = 75;
table.setLayoutData(gd);
toolbar.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
}
use of org.eclipse.swt.events.FocusAdapter in project knime-core by knime.
the class SearchQueryContributionItem method createControl.
/**
* {@inheritDoc}
*/
@Override
protected Control createControl(final Composite parent) {
m_text = new Text(parent, SWT.SINGLE | SWT.BORDER | SWT.BORDER_SOLID);
m_text.addKeyListener(this);
if (Platform.OS_MACOSX.equals(Platform.getOS())) {
m_text.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent fe) {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(DefaultRepositoryView.ID);
// You would think that this would be ripe for an infinite loop, but luckily SWT is doing the
// correct thing and not notifying focusGained for an already focused item (and similarly
// the workbench is not re-focusing and already focus'd view, which temporarily robs
// the SWT focus of its subcomponent...)
Display.getDefault().asyncExec(() -> {
m_text.setFocus();
});
} catch (PartInitException e) {
LOGGER.warn("Exception encountered attempting to give focus to node repository view.", e);
}
}
});
}
m_text.setToolTipText("Filter contents");
return m_text;
}
use of org.eclipse.swt.events.FocusAdapter in project knime-core by knime.
the class SubnodeLayoutJSONEditorPage method createJSONEditorComposite.
private Composite createJSONEditorComposite(final Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, true));
composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
if (isWindows()) {
Composite embedComposite = new Composite(composite, SWT.EMBEDDED | SWT.NO_BACKGROUND);
final GridLayout gridLayout = new GridLayout();
gridLayout.verticalSpacing = 0;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
gridLayout.horizontalSpacing = 0;
embedComposite.setLayout(gridLayout);
embedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Frame frame = SWT_AWT.new_Frame(embedComposite);
Panel heavyWeightPanel = new Panel();
heavyWeightPanel.setLayout(new BoxLayout(heavyWeightPanel, BoxLayout.Y_AXIS));
frame.add(heavyWeightPanel);
frame.setFocusTraversalKeysEnabled(false);
// Use JApplet with JRootPane as layer in between heavyweightPanel and RTextScrollPane
// This reduces flicker on resize in RSyntaxTextArea
JApplet applet = new JApplet();
JRootPane root = applet.getRootPane();
Container contentPane = root.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
heavyWeightPanel.add(applet);
m_textArea = new RSyntaxTextArea(10, 60);
m_textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
m_textArea.setCodeFoldingEnabled(true);
m_textArea.setAntiAliasingEnabled(true);
RTextScrollPane sp = new RTextScrollPane(m_textArea);
sp.setDoubleBuffered(true);
m_textArea.setText(m_jsonDocument);
m_textArea.setEditable(true);
m_textArea.setEnabled(true);
contentPane.add(sp);
Dimension size = sp.getPreferredSize();
embedComposite.setSize(size.width, size.height);
// forward focus to RSyntaxTextArea
embedComposite.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
ViewUtils.runOrInvokeLaterInEDT(new Runnable() {
@Override
public void run() {
m_textArea.requestFocus();
m_textArea.setCaretPosition(m_caretPosition);
}
});
}
@Override
public void focusLost(final FocusEvent e) {
// do nothing
}
});
// delete content of status line, when something is inserted or deleted
m_textArea.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void changedUpdate(final DocumentEvent arg0) {
if (!composite.isDisposed()) {
composite.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (m_statusLine != null && !m_statusLine.isDisposed()) {
m_statusLine.setText("");
updateModelFromJson();
}
}
});
}
}
@Override
public void insertUpdate(final DocumentEvent arg0) {
/* do nothing */
}
@Override
public void removeUpdate(final DocumentEvent arg0) {
/* do nothing */
}
});
// remember caret position
m_textArea.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(final CaretEvent arg0) {
m_caretPosition = arg0.getDot();
}
});
} else {
m_text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
GridData layoutData = new GridData(GridData.FILL_BOTH);
layoutData.widthHint = 600;
layoutData.heightHint = 400;
m_text.setLayoutData(layoutData);
m_text.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
m_jsonDocument = m_text.getText();
if (m_statusLine != null && !m_statusLine.isDisposed()) {
m_statusLine.setText("");
updateModelFromJson();
}
}
});
m_text.setText(m_jsonDocument);
}
// add status line
m_statusLine = new Label(composite, SWT.SHADOW_NONE | SWT.WRAP);
GridData statusGridData = new GridData(SWT.LEFT | SWT.FILL, SWT.BOTTOM, true, false);
int maxHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(3);
statusGridData.heightHint = maxHeight + 5;
// seems to have no impact on the layout. The height will still be 3 rows (at least on Windows 8)
statusGridData.minimumHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(1);
m_statusLine.setLayoutData(statusGridData);
compareNodeIDs();
return composite;
}
use of org.eclipse.swt.events.FocusAdapter 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