use of org.eclipse.swt.events.KeyAdapter in project yamcs-studio by yamcs.
the class AddToStackWizardPage1 method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
setControl(composite);
GridLayout gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
composite.setLayout(gl);
// add filter box
Text searchbox = new Text(composite, SWT.SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
searchbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// build tree table
ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), composite);
level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level1s.png"));
level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level2s.png"));
level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level3s.png"));
level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level4s.png"));
level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level5s.png"));
Composite tableWrapper = new Composite(composite, SWT.NONE);
tcl = new TreeColumnLayout();
tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper.setLayout(tcl);
commandsTreeTable = new TreeViewer(tableWrapper, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
commandsTreeTable.getTree().setHeaderVisible(true);
commandsTreeTable.getTree().setLinesVisible(false);
// column xtce path
TreeViewerColumn pathColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
pathColumn.getColumn().setText(COL_PATH);
pathColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
CommandInfo cmd = (CommandInfo) element;
return cmd.getName();
}
});
tcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
// column significance
TreeViewerColumn significanceColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
significanceColumn.getColumn().setText(COL_SIGN);
significanceColumn.getColumn().setToolTipText("Significance Level");
significanceColumn.getColumn().setAlignment(SWT.CENTER);
significanceColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
CommandInfo cmd = (CommandInfo) element;
if (cmd.getSignificance() == null)
return null;
switch(cmd.getSignificance().getConsequenceLevel()) {
case WATCH:
return level1Image;
case WARNING:
return level2Image;
case DISTRESS:
return level3Image;
case CRITICAL:
return level4Image;
case SEVERE:
return level5Image;
default:
return null;
}
}
});
tcl.setColumnData(significanceColumn.getColumn(), new ColumnPixelData(40));
// column qualified name
TreeViewerColumn nameColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
nameColumn.getColumn().setText(COL_QNAME);
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
CommandInfo cmd = (CommandInfo) element;
if (cmd.getAbstract()) {
// show a blank line if the command is abstract
return "";
}
return cmd.getQualifiedName();
}
});
tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
// on item selection update significance message and page completion status
commandsTreeTable.addSelectionChangedListener(evt -> {
IStructuredSelection sel = (IStructuredSelection) evt.getSelection();
if (sel.isEmpty()) {
setMessage(null);
return;
}
CommandInfo cmd = (CommandInfo) sel.getFirstElement();
setMessage(getMessage(cmd));
command.setMetaCommand(cmd);
command.setSelectedAliase(cmd.getQualifiedName());
setPageComplete(!cmd.getAbstract());
});
CommandTreeContentProvider commandTreeContentProvider = new CommandTreeContentProvider();
commandsTreeTable.setContentProvider(commandTreeContentProvider);
// load command list
Collection<CommandInfo> commandInfos = new ArrayList<>();
CommandingCatalogue.getInstance().getMetaCommands().forEach(cmd -> {
// add aliases columns
for (NamedObjectId alias : cmd.getAliasList()) {
String namespace = alias.getNamespace();
if (!namespaces.contains(namespace) && !namespace.startsWith("/")) {
namespaces.add(namespace);
addAliasColumn(namespace);
}
}
commandInfos.add(cmd);
});
commandsTreeTable.setInput(commandInfos);
commandsTreeTable.expandAll();
// with a small hack to display full data on the first column
for (TreeColumn tc : commandsTreeTable.getTree().getColumns()) tc.pack();
pathColumn.getColumn().setWidth(pathColumn.getColumn().getWidth() + 11 * commandTreeContentProvider.nbLevels);
for (TreeColumn tc : commandsTreeTable.getTree().getColumns()) {
if (tc.getWidth() > COLUMN_MAX_WIDTH)
tc.setWidth(COLUMN_MAX_WIDTH);
}
// filter
CommandInfoTreeViewerFilter filter = new CommandInfoTreeViewerFilter(commandTreeContentProvider);
commandsTreeTable.addFilter(filter);
searchbox.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent ke) {
filter.setSearchTerm(searchbox.getText());
commandsTreeTable.refresh();
commandsTreeTable.expandAll();
}
});
commandsTreeTable.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
CommandInfo c1 = (CommandInfo) o1;
CommandInfo c2 = (CommandInfo) o2;
return c1.getQualifiedName().compareTo(c2.getQualifiedName());
}
});
}
use of org.eclipse.swt.events.KeyAdapter in project yamcs-studio by yamcs.
the class MultipleSelectionCombo method createComponents.
/**
* Create SWT components
*
* @param parent
*/
private void createComponents(final Composite parent) {
display = parent.getDisplay();
final GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = 0;
setLayout(layout);
addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
switch(e.getPropertyName()) {
case "selection":
if (modify) {
break;
} else {
updateText();
break;
}
case "items":
setSelection(Collections.<T>emptyList());
break;
default:
break;
}
}
});
text = new Text(this, SWT.BORDER);
GridData gd = new GridData(SWT.FILL, 0, true, false);
text.setLayoutData(gd);
text.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
// Analyze text, update selection
final String items_text = text.getText();
modify = true;
setSelection(items_text);
modify = false;
}
});
text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(final KeyEvent e) {
switch(e.keyCode) {
case SWT.ARROW_DOWN:
drop(true);
return;
case SWT.ARROW_UP:
drop(false);
return;
case SWT.CR:
modify = false;
updateText();
}
}
});
drop_down = new Button(this, SWT.ARROW | SWT.DOWN);
gd = new GridData(SWT.FILL, SWT.FILL, false, false);
gd.heightHint = text.getBounds().height;
drop_down.setLayoutData(gd);
drop_down.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
// 0xFFFFFFFFL so that it can be treated as a signed long.
if ((e.time & 0xFFFFFFFFL) - lost_focus <= 300)
// Done
return;
// If list is not open, open it
if (!isDropped())
drop(true);
}
});
}
use of org.eclipse.swt.events.KeyAdapter in project yamcs-studio by yamcs.
the class MultipleSelectionCombo method createPopup.
/**
* Create shell that simulates drop-down
*/
private void createPopup() {
popup = new Shell(getShell(), SWT.NO_TRIM | SWT.ON_TOP);
popup.setLayout(new FillLayout());
list = new org.eclipse.swt.widgets.List(popup, SWT.MULTI | SWT.V_SCROLL);
list.setToolTipText(tool_tip);
// Position popup under the text box
Rectangle bounds = text.getBounds();
bounds.y += bounds.height;
// As high as necessary for items
bounds.height = 5 + 2 * list.getBorderWidth() + list.getItemHeight() * items.size();
// ..with limitation
bounds.height = Math.min(bounds.height, display.getBounds().height / 2);
// Map to screen coordinates
bounds = display.map(text, null, bounds);
popup.setBounds(bounds);
popup.open();
// Update text from changed list selection
list.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
updateSelectionFromList();
updateText();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
updateSelectionFromList();
updateText();
hidePopup();
}
});
String[] stringItems = new String[items.size()];
for (int i = 0; i < items.size(); i++) {
stringItems[i] = stringRepresention(items.get(i));
}
list.setItems(stringItems);
int[] intSelectionIndex = new int[selectionIndex.size()];
for (int i = 0; i < intSelectionIndex.length; i++) {
intSelectionIndex[i] = selectionIndex.get(i);
}
list.setSelection(intSelectionIndex);
list.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.keyCode == SWT.CR) {
hidePopup();
}
}
});
// Hide popup when loosing focus
list.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(final FocusEvent e) {
// This field is an unsigned integer and should be AND'ed with
// 0xFFFFFFFFL so that it can be treated as a signed long.
lost_focus = e.time & 0xFFFFFFFFL;
hidePopup();
}
});
list.setFocus();
}
use of org.eclipse.swt.events.KeyAdapter in project yamcs-studio by yamcs.
the class OPIRuntimePreferencePage method createFieldEditors.
@Override
protected void createFieldEditors() {
final Composite parent = getFieldEditorParent();
macrosEditor = new StringTableFieldEditor(PreferencesHelper.RUN_MACROS, "Macros: ", parent, new String[] { "Name", "Value" }, new boolean[] { true, true }, new MacroEditDialog(parent.getShell()), new int[] { 120, 120 }) {
@Override
public boolean isValid() {
String reason;
for (String[] row : items) {
reason = Verifier.checkElementName(row[0]);
if (reason != null) {
wrongMacroName = row[0];
return false;
}
}
return true;
}
@Override
protected void doStore() {
if (!isValid())
return;
super.doStore();
}
@Override
protected void doFillIntoGrid(Composite parent, int numColumns) {
super.doFillIntoGrid(parent, numColumns);
tableEditor.getTableViewer().getTable().addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
boolean valid = isValid();
fireStateChanged(IS_VALID, !valid, valid);
}
});
tableEditor.getTableViewer().getTable().addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
boolean valid = isValid();
fireStateChanged(IS_VALID, !valid, valid);
}
@Override
public void focusGained(FocusEvent e) {
boolean valid = isValid();
fireStateChanged(IS_VALID, !valid, valid);
}
});
}
};
addField(macrosEditor);
IntegerFieldEditor guiRefreshCycleEditor = new IntegerFieldEditor(PreferencesHelper.OPI_GUI_REFRESH_CYCLE, "OPI GUI Refresh Cycle (ms)", parent);
guiRefreshCycleEditor.setValidRange(10, 5000);
guiRefreshCycleEditor.getTextControl(parent).setToolTipText("The fastest refresh cycle for OPI GUI in millisecond");
addField(guiRefreshCycleEditor);
IntegerFieldEditor pulsingMinorPeriodFieldEditor = new IntegerFieldEditor(PreferencesHelper.PULSING_ALARM_MINOR_PERIOD, "Time period of MINOR alarm if pulsing alarm selected (ms)", parent);
pulsingMinorPeriodFieldEditor.setValidRange(100, 10000);
pulsingMinorPeriodFieldEditor.getTextControl(parent).setToolTipText("If the pulsing alarm box is checked for a widget that monitors a PV, " + "then what is the time period of the pulse with the PV is in MINOR alarm severity");
addField(pulsingMinorPeriodFieldEditor);
IntegerFieldEditor pulsingMajorPeriodFieldEditor = new IntegerFieldEditor(PreferencesHelper.PULSING_ALARM_MAJOR_PERIOD, "Time period of MAJOR alarm if pulsing alarm selected (ms)", parent);
pulsingMajorPeriodFieldEditor.setValidRange(100, 10000);
pulsingMajorPeriodFieldEditor.getTextControl(parent).setToolTipText("If the pulsing alarm box is checked for a widget that monitors a PV, " + "then what is the time period of the pulse with the PV is in MAJOR alarm severity");
addField(pulsingMajorPeriodFieldEditor);
String[] allPVFactories = SimplePVLayer.getAllPVFactoryExtensions();
String[][] entries = new String[allPVFactories.length][2];
for (int i = 0; i < allPVFactories.length; i++) {
entries[i][0] = allPVFactories[i];
entries[i][1] = allPVFactories[i];
}
ComboFieldEditor pvConnectionLayerEditor = new ComboFieldEditor(PreferencesHelper.PV_CONNECTION_LAYER, "PV Connection Layer", entries, parent);
addField(pvConnectionLayerEditor);
ComboFieldEditor popupConsoleEditor = new ComboFieldEditor(PreferencesHelper.POPUP_CONSOLE, "Console Popup Level", new String[][] { { "Error, Warning and Info", ConsolePopupLevel.ALL.toString() }, { "Only Info", ConsolePopupLevel.ONLY_INFO.toString() }, { "Don't Popup", ConsolePopupLevel.NO_POP.toString() } }, parent);
addField(popupConsoleEditor);
StringFieldEditor pythonPathEditor = new StringFieldEditor(PreferencesHelper.PYTHON_PATH, "PYTHONPATH", parent);
pythonPathEditor.getTextControl(parent).setToolTipText("The path to search python modules");
addField(pythonPathEditor);
BooleanFieldEditor showCompactModeDialogEditor = new BooleanFieldEditor(PreferencesHelper.SHOW_COMPACT_MODE_DIALOG, "Show tip dialog about how to exit compact mode", parent);
addField(showCompactModeDialogEditor);
BooleanFieldEditor showFullScreenDialogEditor = new BooleanFieldEditor(PreferencesHelper.SHOW_FULLSCREEN_DIALOG, "Show tip dialog about how to exit fullscreen", parent);
addField(showFullScreenDialogEditor);
BooleanFieldEditor startWindowInCompactEditor = new BooleanFieldEditor(PreferencesHelper.START_WINDOW_IN_COMPACT_MODE, "Start application window in compact mode.", parent);
addField(startWindowInCompactEditor);
}
use of org.eclipse.swt.events.KeyAdapter in project cubrid-manager by CUBRID.
the class BrowserEditorPart method initUrlBar.
private void initUrlBar(Composite parent) {
Label urlLabel = new Label(parent, SWT.None);
urlLabel.setLayoutData(createGridData(1, 1, -1, -1));
urlLabel.setText(Messages.lblLocation);
location = new Text(parent, SWT.BORDER);
location.setLayoutData(createGridData(FILL_HORIZONTAL, 1, 1, -1, -1));
location.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.character == SWT.LF || e.character == SWT.CR) {
e.doit = false;
go(location.getText());
}
}
});
}
Aggregations