use of org.eclipse.swt.events.ControlListener 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.ControlListener in project yamcs-studio by yamcs.
the class CommandHistoryView method processCommandHistoryEntry.
public void processCommandHistoryEntry(CommandHistoryEntry cmdhistEntry) {
// Maybe we need to update structure
for (CommandHistoryAttribute attr : cmdhistEntry.getAttrList()) {
if (IGNORED_ATTRIBUTES.contains(attr.getName()))
continue;
String shortName = CommandHistoryRecordContentProvider.toHumanReadableName(attr);
if (!dynamicColumns.contains(shortName)) {
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.LEFT);
column.getColumn().setText(shortName);
column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn()));
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((CommandHistoryRecord) element).getTextForColumn(shortName, showRelativeTime);
}
@Override
public String getToolTipText(Object element) {
return ((CommandHistoryRecord) element).getTooltipForColumn(shortName);
}
@Override
public Image getImage(Object element) {
String imgLoc = ((CommandHistoryRecord) element).getImageForColumn(shortName);
if (CommandHistoryRecordContentProvider.GREEN.equals(imgLoc))
return greenBubble;
else if (CommandHistoryRecordContentProvider.RED.equals(imgLoc))
return redBubble;
else
return null;
}
});
dynamicColumns.add(shortName);
tableLayout.addColumnData(new ColumnPixelData(90));
column.getColumn().setWidth(90);
column.getColumn().addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
checkMinWidth(column.getColumn());
}
});
}
}
// Now add content
tableContentProvider.processCommandHistoryEntry(cmdhistEntry);
updateSummaryLine();
}
use of org.eclipse.swt.events.ControlListener in project yamcs-studio by yamcs.
the class CommandQueuedTableViewer method addFixedColumns.
private void addFixedColumns(TableColumnLayout tcl) {
TableViewerColumn nameColumn = new TableViewerColumn(this, SWT.NONE);
nameColumn.getColumn().setText(COL_QUEUE);
nameColumn.getColumn().setToolTipText("The queue which contains the command");
tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(200));
TableViewerColumn userColumn = new TableViewerColumn(this, SWT.NONE);
userColumn.getColumn().setText(COL_USER);
userColumn.getColumn().setToolTipText("The user who submitted the command");
tcl.setColumnData(userColumn.getColumn(), new ColumnWeightData(200));
TableViewerColumn stringColumn = new TableViewerColumn(this, SWT.CENTER);
stringColumn.getColumn().setText(COL_STRING);
stringColumn.getColumn().setToolTipText("Command source code");
tcl.setColumnData(stringColumn.getColumn(), new ColumnWeightData(200));
TableViewerColumn timeColumn = new TableViewerColumn(this, SWT.LEFT);
timeColumn.getColumn().setText(COL_TIME);
timeColumn.getColumn().setToolTipText("Time");
tcl.setColumnData(timeColumn.getColumn(), new ColumnWeightData(200));
// Common properties to all columns
List<TableViewerColumn> columns = new ArrayList<>();
columns.add(nameColumn);
columns.add(userColumn);
columns.add(stringColumn);
columns.add(timeColumn);
for (TableViewerColumn column : columns) {
// prevent resize to 0
column.getColumn().addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
if (column.getColumn().getWidth() < 5)
column.getColumn().setWidth(5);
}
});
}
}
use of org.eclipse.swt.events.ControlListener in project yamcs-studio by yamcs.
the class CommandStackTableViewer method addFixedColumns.
private void addFixedColumns(TableColumnLayout tcl) {
Image level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level1s.png"));
Image level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level2s.png"));
Image level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level3s.png"));
Image level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level4s.png"));
Image level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level5s.png"));
TableViewerColumn rowIdColumn = new TableViewerColumn(this, SWT.CENTER);
rowIdColumn.getColumn().setText(COL_ROW_ID);
rowIdColumn.getColumn().setToolTipText("Sequence Number within Stack");
rowIdColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return String.valueOf(contentProvider.indexOf(element) + 1);
}
});
rowIdColumn.getColumn().setWidth(50);
tcl.setColumnData(rowIdColumn.getColumn(), new ColumnPixelData(50));
TableViewerColumn nameColumn = new TableViewerColumn(this, SWT.NONE);
nameColumn.getColumn().setText(COL_COMMAND);
nameColumn.setLabelProvider(new CommandSourceColumnLabelProvider(styleProvider));
tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(300));
TableViewerColumn significanceColumn = new TableViewerColumn(this, SWT.CENTER);
significanceColumn.getColumn().setText(COL_SIGNIFICANCE);
significanceColumn.getColumn().setToolTipText("Significance Level");
significanceColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
StackedCommand cmd = (StackedCommand) element;
if (cmd.getMetaCommand().getSignificance() == null)
return null;
switch(cmd.getMetaCommand().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;
}
}
@Override
public String getToolTipText(Object element) {
StackedCommand cmd = (StackedCommand) element;
if (cmd.getMetaCommand().getSignificance() == null)
return super.getToolTipText(element);
return cmd.getMetaCommand().getSignificance().getReasonForWarning();
}
});
significanceColumn.getColumn().setWidth(50);
tcl.setColumnData(significanceColumn.getColumn(), new ColumnPixelData(50));
TableViewerColumn constraintsColumn = new TableViewerColumn(this, SWT.LEFT);
constraintsColumn.getColumn().setText(COL_CONSTRAINTS);
constraintsColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
StackedCommand cmd = (StackedCommand) element;
StringBuilder buf = new StringBuilder();
for (int i = 0; i < cmd.getMetaCommand().getConstraintCount(); i++) {
if (i != 0)
buf.append(" and ");
TransmissionConstraintInfo constraint = cmd.getMetaCommand().getConstraint(i);
for (int j = 0; j < constraint.getComparisonCount(); j++) {
if (j != 0)
buf.append(", ");
appendConstraint(constraint.getComparison(j), buf);
}
}
return buf.length() != 0 ? buf.toString() : "-";
}
});
tcl.setColumnData(constraintsColumn.getColumn(), new ColumnPixelData(250));
TableViewerColumn constraintsTimeOutColumn = new TableViewerColumn(this, SWT.CENTER);
constraintsTimeOutColumn.getColumn().setText(COL_CONSTRAINTS_TIMEOUT);
constraintsTimeOutColumn.getColumn().setToolTipText("Constraints Timeout");
constraintsTimeOutColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
StackedCommand cmd = (StackedCommand) element;
long timeout = -1;
for (TransmissionConstraintInfo constraint : cmd.getMetaCommand().getConstraintList()) timeout = Math.max(timeout, constraint.getTimeout());
return (timeout >= 0) ? Long.toString(timeout) + " ms" : "-";
}
});
tcl.setColumnData(constraintsTimeOutColumn.getColumn(), new ColumnPixelData(50));
TableViewerColumn releaseColumn = new TableViewerColumn(this, SWT.CENTER);
releaseColumn.getColumn().setText(COL_RELEASE);
releaseColumn.getColumn().setToolTipText("Release Time");
releaseColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return "ASAP";
}
});
tcl.setColumnData(releaseColumn.getColumn(), new ColumnPixelData(80));
TableViewerColumn ptvColumn = new TableViewerColumn(this, SWT.CENTER);
ptvColumn.getColumn().setText(COL_PTV);
ptvColumn.getColumn().setToolTipText("Pre-Transmission Verification");
ptvColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
StackedCommand cmd = (StackedCommand) element;
switch(cmd.getPTVInfo().getState()) {
case UNDEF:
return grayBubble;
case NA:
case OK:
return greenBubble;
case PENDING:
return waitingImage;
case NOK:
return redBubble;
default:
log.warning("Unexpected PTV state " + cmd.getPTVInfo().getState());
return grayBubble;
}
}
@Override
public String getToolTipText(Object element) {
StackedCommand cmd = (StackedCommand) element;
if (cmd.getPTVInfo().getFailureMessage() != null)
return cmd.getPTVInfo().getFailureMessage();
else
return super.getToolTipText(element);
}
});
tcl.setColumnData(ptvColumn.getColumn(), new ColumnPixelData(50));
TableViewerColumn stateColumn = new TableViewerColumn(this, SWT.CENTER);
stateColumn.getColumn().setText(COL_STATE);
stateColumn.getColumn().setToolTipText("Stack State");
stateColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
StackedCommand cmd = (StackedCommand) element;
return cmd.getStackedState().getText();
}
@Override
public Color getBackground(Object element) {
StackedCommand cmd = (StackedCommand) element;
if (cmd.isArmed())
return getTable().getDisplay().getSystemColor(SWT.COLOR_YELLOW);
else if (cmd.getStackedState() == StackedState.ISSUED)
return getTable().getDisplay().getSystemColor(SWT.COLOR_GREEN);
else if (cmd.getStackedState() == StackedState.REJECTED)
return styleProvider.getErrorBackgroundColor();
return super.getBackground(element);
}
@Override
public Color getForeground(Object element) {
StackedCommand cmd = (StackedCommand) element;
if (cmd.getStackedState() == StackedState.REJECTED)
return getTable().getDisplay().getSystemColor(SWT.COLOR_RED);
return super.getForeground(element);
}
});
tcl.setColumnData(stateColumn.getColumn(), new ColumnPixelData(80));
// column comment
TableViewerColumn commentColumn = new TableViewerColumn(this, SWT.LEFT);
commentColumn.getColumn().setText(COL_COMMENT);
commentColumn.getColumn().setToolTipText("Free Text Comment");
commentColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((StackedCommand) element).getComment();
}
});
tcl.setColumnData(commentColumn.getColumn(), new ColumnPixelData(80));
// Common properties to all columns
List<TableViewerColumn> columns = new ArrayList<>();
columns.add(rowIdColumn);
columns.add(nameColumn);
columns.add(significanceColumn);
columns.add(constraintsColumn);
columns.add(constraintsTimeOutColumn);
columns.add(releaseColumn);
columns.add(ptvColumn);
columns.add(stateColumn);
columns.add(commentColumn);
for (TableViewerColumn column : columns) {
// prevent resize to 0
column.getColumn().addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
if (column.getColumn().getWidth() < 5)
column.getColumn().setWidth(5);
}
});
}
}
use of org.eclipse.swt.events.ControlListener in project yamcs-studio by yamcs.
the class EventLogTableViewer method addFixedColumns.
private void addFixedColumns() {
// sort listener common for all columns
Listener sortListener = event -> {
TableColumn column = (TableColumn) event.widget;
// TODO should this sort logic not move up into this class? Why are columns passed?
EventLogContentProvider contentProvider = (EventLogContentProvider) getContentProvider();
contentProvider.sort(column);
};
TableViewerColumn messageColumn = new TableViewerColumn(this, SWT.NONE);
messageColumn.getColumn().setText(COL_MESSAGE);
messageColumn.getColumn().addListener(SWT.Selection, sortListener);
tableLayout.addColumnData(new ColumnPixelData(300));
TableViewerColumn sourceColumn = new TableViewerColumn(this, SWT.NONE);
sourceColumn.getColumn().setText(COL_SOURCE);
sourceColumn.getColumn().addListener(SWT.Selection, sortListener);
tableLayout.addColumnData(new ColumnPixelData(150));
TableViewerColumn generationColumn = new TableViewerColumn(this, SWT.NONE);
generationColumn.getColumn().setText(COL_GENERATION);
generationColumn.getColumn().addListener(SWT.Selection, sortListener);
tableLayout.addColumnData(new ColumnPixelData(150));
TableViewerColumn receptionColumn = new TableViewerColumn(this, SWT.NONE);
receptionColumn.getColumn().setText(COL_RECEPTION);
receptionColumn.getColumn().addListener(SWT.Selection, sortListener);
tableLayout.addColumnData(new ColumnPixelData(150));
TableViewerColumn seqNumColum = new TableViewerColumn(this, SWT.RIGHT);
seqNumColum.getColumn().setText(COL_SEQNUM);
seqNumColum.getColumn().addListener(SWT.Selection, sortListener);
tableLayout.addColumnData(new ColumnPixelData(80));
if (!EventLogPreferences.isShowSequenceNumberColumn()) {
tableLayout.addColumnData(new ColumnPixelData(0));
seqNumColum.getColumn().setResizable(false);
}
if (!EventLogPreferences.isShowGenerationColumn()) {
tableLayout.addColumnData(new ColumnPixelData(0));
generationColumn.getColumn().setResizable(false);
}
if (!EventLogPreferences.isShowReceptionColumn()) {
tableLayout.addColumnData(new ColumnPixelData(0));
receptionColumn.getColumn().setResizable(false);
}
for (TableColumn tableColumn : getTable().getColumns()) {
tableColumn.setMoveable(true);
// prevent resize to 0
tableColumn.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
if (tableColumn.getWidth() < 5)
tableColumn.setWidth(5);
}
});
}
// TODO use IMemento or something
// !! Keep these values in sync with EventLogViewerComparator constructor
getTable().setSortColumn(receptionColumn.getColumn());
getTable().setSortDirection(SWT.UP);
}
Aggregations