use of org.eclipse.jface.viewers.ColumnPixelData in project yamcs-studio by yamcs.
the class EventLogTableViewer method createColumns.
private void createColumns() {
var table = getTable();
var layout = new TableLayout();
var currentColumns = getTable().getColumns();
for (var currentColumn : currentColumns) {
currentColumn.dispose();
}
for (var def : columnData.getVisibleColumns()) {
if (def.name.equals(COL_SEVERITY)) {
var severityColumn = new TableViewerColumn(this, SWT.CENTER);
severityColumn.getColumn().setText(COL_SEVERITY);
severityColumn.getColumn().addControlListener(columnResizeListener);
severityColumn.getColumn().addSelectionListener(getSelectionAdapter(severityColumn.getColumn()));
severityColumn.getColumn().setToolTipText("Severity Level");
severityColumn.setLabelProvider(new EventLogColumnLabelProvider() {
@Override
public Image getImage(Object element) {
var event = ((EventLogItem) element).event;
if (event.hasSeverity()) {
switch(event.getSeverity()) {
case INFO:
return infoIcon;
case WATCH:
return watchIcon;
case WARNING:
return warningIcon;
case DISTRESS:
return distressIcon;
case CRITICAL:
return criticalIcon;
case SEVERE:
case ERROR:
return severeIcon;
}
}
return null;
}
@Override
public String getText(Object element) {
return null;
}
@Override
public String getToolTipText(Object element) {
var event = ((EventLogItem) element).event;
if (event.hasSeverity()) {
return "" + event.getSeverity();
} else {
return super.getToolTipText(element);
}
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_GENERATION)) {
var generationColumn = new TableViewerColumn(this, SWT.NONE);
generationColumn.getColumn().setText(COL_GENERATION);
generationColumn.getColumn().addControlListener(columnResizeListener);
generationColumn.getColumn().addSelectionListener(getSelectionAdapter(generationColumn.getColumn()));
generationColumn.setLabelProvider(new EventLogColumnLabelProvider() {
@Override
public String getText(Object element) {
var event = ((EventLogItem) element).event;
var generationTime = Instant.ofEpochSecond(event.getGenerationTime().getSeconds(), event.getGenerationTime().getNanos());
return YamcsPlugin.getDefault().formatInstant(generationTime);
}
});
layout.addColumnData(new ColumnPixelData(def.width));
// Add chevron
// !! Keep these values in sync with EventLogViewerComparator constructor
table.setSortColumn(generationColumn.getColumn());
table.setSortDirection(SWT.UP);
} else if (def.name.equals(COL_TYPE)) {
var typeColumn = new TableViewerColumn(this, SWT.NONE);
typeColumn.getColumn().setText(COL_TYPE);
typeColumn.getColumn().addControlListener(columnResizeListener);
typeColumn.getColumn().addSelectionListener(getSelectionAdapter(typeColumn.getColumn()));
typeColumn.setLabelProvider(new EventLogColumnLabelProvider() {
@Override
public String getText(Object element) {
var event = ((EventLogItem) element).event;
return event.hasType() ? event.getType() : "";
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_SOURCE)) {
var sourceColumn = new TableViewerColumn(this, SWT.NONE);
sourceColumn.getColumn().setText(COL_SOURCE);
sourceColumn.getColumn().addControlListener(columnResizeListener);
sourceColumn.getColumn().addSelectionListener(getSelectionAdapter(sourceColumn.getColumn()));
sourceColumn.setLabelProvider(new EventLogColumnLabelProvider() {
@Override
public String getText(Object element) {
var event = ((EventLogItem) element).event;
return event.hasSource() ? event.getSource() : "";
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_MESSAGE)) {
var messageColumn = new TableViewerColumn(this, SWT.NONE);
messageColumn.getColumn().setText(COL_MESSAGE);
messageColumn.getColumn().addControlListener(columnResizeListener);
messageColumn.getColumn().addSelectionListener(getSelectionAdapter(messageColumn.getColumn()));
messageColumn.setLabelProvider(new EventLogColumnLabelProvider() {
@Override
public String getText(Object element) {
var event = ((EventLogItem) element).event;
var message = event.getMessage();
if (messageLineCount > 0) {
var lineSeparator = "\n";
var messageLines = message.split(lineSeparator);
message = "";
var i = 0;
for (; i < messageLineCount && i < messageLines.length; i++) {
if (!message.isEmpty()) {
message += lineSeparator;
}
message += messageLines[i];
}
if (i + 1 < messageLines.length) {
message += " [...]";
}
}
return message;
}
@Override
public Font getFont(Object element) {
// Install a monospaced font, for alignment reasons
return JFaceResources.getFont(JFaceResources.TEXT_FONT);
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_RECEPTION)) {
var receptionColumn = new TableViewerColumn(this, SWT.NONE);
receptionColumn.getColumn().setText(COL_RECEPTION);
receptionColumn.getColumn().addControlListener(columnResizeListener);
receptionColumn.getColumn().addSelectionListener(getSelectionAdapter(receptionColumn.getColumn()));
receptionColumn.setLabelProvider(new EventLogColumnLabelProvider() {
@Override
public String getText(Object element) {
var event = ((EventLogItem) element).event;
var receptionTime = Instant.ofEpochSecond(event.getReceptionTime().getSeconds(), event.getReceptionTime().getNanos());
return YamcsPlugin.getDefault().formatInstant(receptionTime);
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_SEQNUM)) {
var seqNumColumn = new TableViewerColumn(this, SWT.RIGHT);
seqNumColumn.getColumn().setText(COL_SEQNUM);
seqNumColumn.getColumn().addControlListener(columnResizeListener);
seqNumColumn.getColumn().addSelectionListener(getSelectionAdapter(seqNumColumn.getColumn()));
seqNumColumn.setLabelProvider(new EventLogColumnLabelProvider() {
@Override
public String getText(Object element) {
var event = ((EventLogItem) element).event;
return "" + event.getSeqNumber();
}
});
layout.addColumnData(new ColumnPixelData(def.width));
}
}
table.setLayout(layout);
table.setHeaderVisible(true);
table.setLinesVisible(false);
// !! Ensures column widths are applied when recreating columns
table.layout(true);
// !! Ensures table renders correctly for old data when adding a new column
refresh();
saveColumnState();
}
use of org.eclipse.jface.viewers.ColumnPixelData in project yamcs-studio by yamcs.
the class AddParameterPage method createControl.
@Override
public void createControl(Composite parent) {
var composite = new Composite(parent, SWT.NONE);
setControl(composite);
var gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
gl.numColumns = 2;
gl.makeColumnsEqualWidth = false;
composite.setLayout(gl);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
var tableWrapper1 = new Composite(composite, SWT.NONE);
contentProvider = new ParameterContentProvider();
trcl = new TreeColumnLayout();
tableWrapper1.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper1.setLayout(trcl);
treeViewer = new TreeViewer(tableWrapper1, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
treeViewer.getTree().setHeaderVisible(true);
treeViewer.getTree().setLinesVisible(true);
// column container
var pathColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
pathColumn.getColumn().setText(COL_NAMESPACE);
pathColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var namespace = (String) element;
return namespace.substring(namespace.lastIndexOf("/") + 1);
}
});
trcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
treeViewer.addSelectionChangedListener(evt -> {
var sel = (IStructuredSelection) evt.getSelection();
if (sel.isEmpty()) {
contentProvider.setNamespace(null);
return;
}
contentProvider.setNamespace((String) sel.getFirstElement());
});
treeViewer.setContentProvider(new NamespaceContentProvider());
treeViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
var n1 = (String) o1;
var n2 = (String) o2;
return n1.compareTo(n2);
}
});
var tableWrapper2 = new Composite(composite, SWT.NONE);
tcl = new TableColumnLayout();
tableWrapper2.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper2.setLayout(tcl);
tableViewer = new TableViewer(tableWrapper2, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.getTable().setLinesVisible(true);
var nameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
nameColumn.getColumn().setText(COL_NAME);
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var obj = (ParameterInfo) element;
return obj.getQualifiedName();
}
});
tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
tableViewer.addSelectionChangedListener(evt -> {
var sel = (IStructuredSelection) evt.getSelection();
if (sel.isEmpty()) {
setParameter(new ArrayList<>());
return;
}
var parameters = new ArrayList<ParameterInfo>();
for (var obj : sel.toArray()) {
parameters.add((ParameterInfo) obj);
}
setParameter(parameters);
setPageComplete(true);
});
tableViewer.setContentProvider(contentProvider);
tableViewer.setInput(contentProvider);
YamcsPlugin.getMissionDatabase().getParameters().forEach(pmtr -> {
for (var alias : pmtr.getAliasList()) {
var namespace = alias.getNamespace();
if (!namespace.startsWith("/")) {
return;
}
if (!parameterInfos.containsKey(namespace)) {
parameterInfos.put(namespace, new ArrayList<>());
}
parameterInfos.get(namespace).add(pmtr);
var parentns = namespace.substring(0, namespace.lastIndexOf("/"));
while (!parentns.isEmpty()) {
if (!parameterInfos.containsKey(parentns)) {
parameterInfos.put(parentns, new ArrayList<>());
}
parentns = parentns.substring(0, parentns.lastIndexOf("/"));
}
}
});
treeViewer.setInput(parameterInfos.keySet());
tableViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
var n1 = (ParameterInfo) o1;
var n2 = (ParameterInfo) o2;
return n1.getQualifiedName().compareTo(n2.getQualifiedName());
}
});
}
use of org.eclipse.jface.viewers.ColumnPixelData in project yamcs-studio by yamcs.
the class AddToStackWizardPage1 method addAliasColumn.
// Add dynamically columns for each alias of a command
private void addAliasColumn(String namespace) {
var aliasColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
aliasColumn.getColumn().setText(namespace);
aliasColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof XtceCommandNode) {
var node = (XtceCommandNode) element;
var cmd = node.getCommandInfo();
var aliases = cmd.getAliasList();
for (var aliase : aliases) {
if (aliase.getNamespace().equals(namespace)) {
return aliase.getName();
}
}
}
return "";
}
});
tcl.setColumnData(aliasColumn.getColumn(), new ColumnPixelData(200));
}
use of org.eclipse.jface.viewers.ColumnPixelData in project yamcs-studio by yamcs.
the class AddToStackWizardPage1 method createControl.
@Override
public void createControl(Composite parent) {
var composite = new Composite(parent, SWT.NONE);
setControl(composite);
var gl = new GridLayout();
gl.marginHeight = 0;
gl.marginWidth = 0;
composite.setLayout(gl);
// grid for expand+filter box
var gl2 = new GridLayout(3, false);
gl2.marginHeight = 0;
gl2.marginWidth = 0;
var row = new Composite(composite, SWT.NONE);
row.setLayout(gl2);
row.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// add expand all / collapse all button
var expandAll = new Button(row, SWT.ARROW | SWT.DOWN);
var expandAllData = new GridData(SWT.NONE);
expandAll.setLayoutData(expandAllData);
expandAll.setText("Expand All");
expandAll.setToolTipText("Expand All");
expandAll.setVisible(false);
expandAllData.exclude = true;
var collapseAll = new Button(row, SWT.ARROW | SWT.RIGHT);
var collapseAllData = new GridData(SWT.NONE);
collapseAll.setLayoutData(collapseAllData);
collapseAll.setText("Collapse All");
collapseAll.setToolTipText("Collapse All");
collapseAll.setVisible(true);
// add filter box
var searchbox = new Text(row, SWT.SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
searchbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
expandAll.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
commandsTreeTable.expandAll();
expandAll.setVisible(false);
collapseAll.setVisible(true);
expandAllData.exclude = true;
collapseAllData.exclude = false;
expandAll.pack();
collapseAll.pack();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
commandsTreeTable.expandAll();
expandAll.setVisible(false);
collapseAll.setVisible(true);
expandAllData.exclude = true;
collapseAllData.exclude = false;
expandAll.pack();
collapseAll.pack();
}
});
collapseAll.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
commandsTreeTable.collapseAll();
expandAll.setVisible(true);
collapseAll.setVisible(false);
expandAllData.exclude = false;
collapseAllData.exclude = true;
expandAll.pack();
collapseAll.pack();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
commandsTreeTable.collapseAll();
expandAll.setVisible(true);
collapseAll.setVisible(false);
expandAllData.exclude = false;
collapseAllData.exclude = true;
expandAll.pack();
collapseAll.pack();
}
});
// build tree table
ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), composite);
level0Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level0s.png"));
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"));
var treeWrapper = new Composite(composite, SWT.NONE);
tcl = new TreeColumnLayout();
var gd = new GridData(GridData.FILL_BOTH);
gd.widthHint = 800;
gd.heightHint = 500;
treeWrapper.setLayoutData(gd);
treeWrapper.setLayout(tcl);
commandsTreeTable = new TreeViewer(treeWrapper, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
commandsTreeTable.getTree().setHeaderVisible(true);
commandsTreeTable.getTree().setLinesVisible(true);
// column xtce path
var pathColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
pathColumn.getColumn().setText(COL_PATH);
pathColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof XtceSubSystemNode) {
var node = (XtceSubSystemNode) element;
return node.getName();
} else {
var node = (XtceCommandNode) element;
return node.getCommandInfo().getName();
}
}
});
tcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(300));
// column significance
var 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) {
if (element instanceof XtceCommandNode) {
var node = (XtceCommandNode) element;
var cmd = node.getCommandInfo();
if (cmd.getSignificance() == null) {
return level0Image;
}
switch(cmd.getSignificance().getConsequenceLevel()) {
case NONE:
return level0Image;
case WATCH:
return level1Image;
case WARNING:
return level2Image;
case DISTRESS:
return level3Image;
case CRITICAL:
return level4Image;
case SEVERE:
return level5Image;
default:
return null;
}
}
return null;
}
});
tcl.setColumnData(significanceColumn.getColumn(), new ColumnPixelData(50));
// on item selection update significance message and page completion status
commandsTreeTable.addSelectionChangedListener(evt -> {
var sel = (IStructuredSelection) evt.getSelection();
if (sel.isEmpty()) {
setMessage(null);
return;
}
var selectedElement = sel.getFirstElement();
if (selectedElement instanceof XtceCommandNode) {
var cmd = ((XtceCommandNode) sel.getFirstElement()).getCommandInfo();
// setMessage(getMessage(cmd));
command.setMetaCommand(cmd);
setPageComplete(true);
} else {
setPageComplete(false);
}
});
var commandTreeContentProvider = new CommandTreeContentProvider();
commandsTreeTable.setContentProvider(commandTreeContentProvider);
commandsTreeTable.setInput(commandTreeContentProvider);
YamcsPlugin.getMissionDatabase().getCommands().forEach(cmd -> {
if (!cmd.hasAbstract() || !cmd.getAbstract()) {
// add aliases columns
for (var alias : cmd.getAliasList()) {
var namespace = alias.getNamespace();
if (!namespaces.contains(namespace) && !namespace.startsWith("/")) {
namespaces.add(namespace);
addAliasColumn(namespace);
}
}
commandTreeContentProvider.addElement(cmd.getQualifiedName(), cmd);
}
});
commandsTreeTable.expandAll();
var filter = new CommandTreeViewerFilter(commandTreeContentProvider);
commandsTreeTable.addFilter(filter);
searchbox.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent ke) {
if (ke.keyCode == SWT.ARROW_DOWN) {
var items = commandsTreeTable.getTree().getItems();
if (items.length > 0) {
IStructuredSelection sel = new StructuredSelection(items[0].getData());
commandsTreeTable.setSelection(sel);
commandsTreeTable.getTree().setFocus();
}
} else {
filter.setSearchTerm(searchbox.getText());
commandsTreeTable.refresh();
commandsTreeTable.expandAll();
}
}
});
commandsTreeTable.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
String n1;
String n2;
if (o1 instanceof XtceSubSystemNode) {
n1 = ((XtceSubSystemNode) o1).getName();
} else {
n1 = ((XtceCommandNode) o1).getCommandInfo().getQualifiedName();
}
if (o2 instanceof XtceSubSystemNode) {
n2 = ((XtceSubSystemNode) o2).getName();
} else {
n2 = ((XtceCommandNode) o2).getCommandInfo().getQualifiedName();
}
return n1.compareTo(n2);
}
});
}
use of org.eclipse.jface.viewers.ColumnPixelData in project yamcs-studio by yamcs.
the class ConnectionsDialog method createServerPanel.
private Composite createServerPanel(Composite parent, ResourceManager resourceManager) {
var serverPanel = new Composite(parent, SWT.NONE);
var gd = new GridData(GridData.FILL_BOTH);
serverPanel.setLayoutData(gd);
var tcl = new TableColumnLayout();
serverPanel.setLayout(tcl);
var serverImage = resourceManager.createImage(getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server.gif"));
connViewer = new TableViewer(serverPanel, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
connViewer.getTable().setHeaderVisible(true);
connViewer.getTable().setLinesVisible(true);
var urlColumn = new TableViewerColumn(connViewer, SWT.NONE);
urlColumn.getColumn().setText("Server URL");
urlColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
return serverImage;
}
@Override
public String getText(Object element) {
var conf = (YamcsConfiguration) element;
return conf.getURL();
}
});
tcl.setColumnData(urlColumn.getColumn(), new ColumnPixelData(200));
var instanceColumn = new TableViewerColumn(connViewer, SWT.NONE);
instanceColumn.getColumn().setText("Instance");
instanceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var conf = (YamcsConfiguration) element;
return conf.getInstance();
}
});
tcl.setColumnData(instanceColumn.getColumn(), new ColumnPixelData(90));
var userColumn = new TableViewerColumn(connViewer, SWT.NONE);
userColumn.getColumn().setText("User");
userColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var conf = (YamcsConfiguration) element;
if (conf.getAuthType() != AuthType.KERBEROS) {
return conf.getUser();
} else {
return null;
}
}
});
tcl.setColumnData(userColumn.getColumn(), new ColumnPixelData(90));
var nameColumn = new TableViewerColumn(connViewer, SWT.NONE);
nameColumn.getColumn().setText("Comment");
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var conf = (YamcsConfiguration) element;
return conf.getComment();
}
});
tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(200));
IContentProvider contentProvider = (IStructuredContentProvider) inputElement -> connections.toArray();
connViewer.setContentProvider(contentProvider);
connViewer.setInput(contentProvider);
connViewer.addSelectionChangedListener(evt -> {
var sel = (IStructuredSelection) evt.getSelection();
if (sel.getFirstElement() != null) {
var conf = (YamcsConfiguration) sel.getFirstElement();
yamcsInstanceText.setText(forceString(conf.getInstance()));
yamcsURLText.setText(forceString(conf.getURL()));
// / caCertFileText.setText(forceString(conf.getCaCertFile()));
commentText.setText(forceString(conf.getComment()));
var authType = (conf.getAuthType() == null) ? AuthType.STANDARD : conf.getAuthType();
if (authType == AuthType.STANDARD) {
authTypeCombo.select(0);
yamcsUserText.setText(forceString(conf.getUser()));
} else if (authType == AuthType.KERBEROS) {
authTypeCombo.select(1);
yamcsUserText.setText("");
} else {
throw new IllegalArgumentException("Unexpected auth type " + authType);
}
updateState();
}
});
connViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object o1, Object o2) {
var c1 = (YamcsConfiguration) o1;
var c2 = (YamcsConfiguration) o2;
if (c1.getURL() != null && c2.getURL() != null) {
return c1.getURL().compareTo(c2.getURL());
} else {
return 0;
}
}
});
return serverPanel;
}
Aggregations