use of org.eclipse.swt.events.ControlListener in project cubrid-manager by CUBRID.
the class InformationWindow method createContents.
protected Control createContents(Composite parent) {
final Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new FillLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
infoText = new StyledText(composite, SWT.None);
infoText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
infoText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
infoText.setEditable(false);
infoText.setEnabled(false);
infoText.addMouseTrackListener(new MouseTrackListener() {
public void mouseHover(MouseEvent e) {
increaseAlpha();
}
public void mouseExit(MouseEvent e) {
reduceAlpha();
}
public void mouseEnter(MouseEvent e) {
increaseAlpha();
}
});
parentShell.addControlListener(new ControlListener() {
public void controlResized(ControlEvent e) {
updateLocation();
}
public void controlMoved(ControlEvent e) {
updateLocation();
}
});
if (Platform.getOS().equals(Platform.OS_WIN32)) {
parentShell.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
updateLocation();
}
});
}
this.getShell().setAlpha(minAlpha);
updateLocation();
return parent;
}
use of org.eclipse.swt.events.ControlListener in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_widgets_Control method test_addControlListenerControlResizedAdapterLorg_eclipse_swt_events_ControlListener.
@Test
public void test_addControlListenerControlResizedAdapterLorg_eclipse_swt_events_ControlListener() {
ControlListener listener = ControlListener.controlResizedAdapter(e -> eventOccurred = true);
control.addControlListener(listener);
eventOccurred = false;
control.notifyListeners(SWT.Resize, new Event());
assertTrue(eventOccurred);
eventOccurred = false;
control.notifyListeners(SWT.Move, new Event());
assertFalse(eventOccurred);
control.removeControlListener(listener);
eventOccurred = false;
control.notifyListeners(SWT.Resize, new Event());
assertFalse(eventOccurred);
control.notifyListeners(SWT.Move, new Event());
assertFalse(eventOccurred);
}
use of org.eclipse.swt.events.ControlListener in project hale by halestudio.
the class GenericParameterPage method createField.
/**
* Creates a text field for the given function parameter and given initial
* value. Does not call updateState!
*
* @param parent the composite in which to place the text field
* @param fp the function parameter
* @param initialValue initial value or <code>null</code>
* @param fixed whether the field may never be removed under any
* circumstances (-> no remove button)
* @return the created text field
*/
private Pair<AttributeEditor<?>, Button> createField(Composite parent, final FunctionParameterDefinition fp, ParameterValue initialValue, boolean fixed) {
// create editor, button and pair
final AttributeEditor<?> editor = ParameterEditorExtension.getInstance().createEditor(parent, getWizard().getFunctionId(), fp, initialValue);
// listen to valid changes
editor.setPropertyChangeListener(new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
if (AttributeEditor.IS_VALID.equals(event.getProperty()))
updateState();
}
});
// listen for resizes of the editor
// needed for the editor chooser editor
editor.getControl().addControlListener(new ControlListener() {
@Override
public void controlResized(ControlEvent e) {
/*
* call layoutAndPack() later as a call now breaks the wizard
* dialog sizing (at least on Linux) and makes the button bar
* disappear.
*/
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
layoutAndPack();
}
});
}
@Override
public void controlMoved(ControlEvent e) {
// ignore
}
});
final Pair<AttributeEditor<?>, Button> pair;
final Button removeButton;
if (fixed)
removeButton = null;
else
removeButton = new Button(parent, SWT.NONE);
pair = new Pair<AttributeEditor<?>, Button>(editor, removeButton);
// configure text
editor.getControl().setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
// configure button
if (removeButton != null) {
removeButton.setImage(removeImage);
removeButton.setEnabled(false);
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// remove last text field
List<Pair<AttributeEditor<?>, Button>> texts = inputFields.get(fp);
texts.remove(pair);
updateState();
removeButton.dispose();
editor.getControl().dispose();
addButtons.get(fp).setEnabled(true);
if (texts.size() == fp.getMinOccurrence())
for (Pair<AttributeEditor<?>, Button> otherPair : texts) otherPair.getSecond().setEnabled(false);
layoutAndPack();
}
});
}
// add field to map
inputFields.put(fp, pair);
return pair;
}
use of org.eclipse.swt.events.ControlListener in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method createTemplateTree.
/**
* Create the tree to display templates.
*
* @param parent the parent composite
*/
private void createTemplateTree(Composite parent) {
Composite treeComposite = new Composite(parent, SWT.NONE);
GridData data = new GridData(GridData.FILL_BOTH);
treeComposite.setLayoutData(data);
TreeColumnLayout columnLayout = new TreeColumnLayout();
treeComposite.setLayout(columnLayout);
fTemplatesTree = new Tree(treeComposite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
fTemplatesTree.setHeaderVisible(true);
fTemplatesTree.setLinesVisible(true);
PixelConverter pixelConverter = new PixelConverter(fTemplatesTree);
TreeColumn columnName = new TreeColumn(fTemplatesTree, SWT.NONE);
columnName.setText(TemplatesMessages.TemplatesPage_column_name);
int minWidth = fPreferenceStore.getInt(COLUMN_NAME_WIDTH_PREF_ID);
if (minWidth == 0) {
minWidth = pixelConverter.convertWidthInCharsToPixels(30);
}
columnLayout.setColumnData(columnName, new ColumnPixelData(minWidth, true));
columnName.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
int nameWidth = ((TreeColumn) e.getSource()).getWidth();
fPreferenceStore.setValue(COLUMN_NAME_WIDTH_PREF_ID, nameWidth);
}
});
TreeColumn columnDescription = new TreeColumn(fTemplatesTree, SWT.NONE);
columnDescription.setText(TemplatesMessages.TemplatesPage_column_description);
minWidth = fPreferenceStore.getInt(COLUMN_DESCRIPTION_WIDTH_PREF_ID);
if (minWidth == 0) {
minWidth = pixelConverter.convertWidthInCharsToPixels(45);
}
columnLayout.setColumnData(columnDescription, new ColumnPixelData(minWidth, false));
columnDescription.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
int descriptionWidth = ((TreeColumn) e.getSource()).getWidth();
fPreferenceStore.setValue(COLUMN_DESCRIPTION_WIDTH_PREF_ID, descriptionWidth);
}
});
createTreeViewer(fTemplatesTree);
}
use of org.eclipse.swt.events.ControlListener in project yamcs-studio by yamcs.
the class ClientsTableViewer method addFixedColumns.
private void addFixedColumns() {
TableViewerColumn idColumn = new TableViewerColumn(this, SWT.CENTER);
idColumn.getColumn().setText(COL_ID);
idColumn.getColumn().setWidth(30);
idColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return String.valueOf(client.getId());
}
});
TableViewerColumn userColumn = new TableViewerColumn(this, SWT.LEFT);
userColumn.getColumn().setText(COL_USER);
userColumn.getColumn().setWidth(100);
userColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return String.valueOf(client.getUsername());
}
});
TableViewerColumn applicationColumn = new TableViewerColumn(this, SWT.LEFT);
applicationColumn.getColumn().setText(COL_APPLICATION);
applicationColumn.getColumn().setWidth(100);
applicationColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return client.getApplicationName();
}
});
TableViewerColumn instanceColumn = new TableViewerColumn(this, SWT.LEFT);
instanceColumn.getColumn().setText(COL_INSTANCE);
instanceColumn.getColumn().setWidth(100);
instanceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return client.getInstance();
}
});
TableViewerColumn processorColumn = new TableViewerColumn(this, SWT.LEFT);
processorColumn.getColumn().setText(COL_PROCESSOR);
processorColumn.getColumn().setWidth(100);
processorColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
ClientInfo client = (ClientInfo) element;
return client.getProcessorName();
}
});
// prevent resize to 0
for (TableColumn column : getTable().getColumns()) {
column.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
if (column.getWidth() < 5) {
column.setWidth(5);
}
}
});
}
}
Aggregations