use of org.yamcs.studio.core.ui.utils.CenteredImageLabelProvider in project yamcs-studio by yamcs.
the class CommandHistoryView method addFixedColumns.
private void addFixedColumns() {
TableViewerColumn stateColumn = new TableViewerColumn(tableViewer, SWT.NONE);
stateColumn.getColumn().setImage(headerCompleteImage);
stateColumn.getColumn().addSelectionListener(getSelectionAdapter(stateColumn.getColumn()));
stateColumn.getColumn().setToolTipText("Completion");
stateColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
switch(((CommandHistoryRecord) element).getCommandState()) {
case COMPLETED:
return checkmarkImage;
case FAILED:
return errorImage;
default:
return null;
}
}
@Override
public String getText(Object element) {
CommandHistoryRecord rec = (CommandHistoryRecord) element;
switch(((CommandHistoryRecord) element).getCommandState()) {
case COMPLETED:
return "Completed";
case FAILED:
return rec.getPTVInfo().getFailureMessage();
default:
return null;
}
}
});
tableLayout.addColumnData(new ColumnPixelData(90));
TableViewerColumn gentimeColumn = new TableViewerColumn(tableViewer, SWT.NONE);
gentimeColumn.getColumn().setText(COL_T);
gentimeColumn.getColumn().addSelectionListener(getSelectionAdapter(gentimeColumn.getColumn()));
gentimeColumn.getColumn().setToolTipText("Generation Time");
gentimeColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return ((CommandHistoryRecord) element).getGenerationTime();
}
});
tableLayout.addColumnData(new ColumnPixelData(150));
TableViewerColumn nameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
nameColumn.getColumn().setText(COL_COMMAND);
nameColumn.getColumn().setToolTipText("Command String");
nameColumn.getColumn().addSelectionListener(getSelectionAdapter(nameColumn.getColumn()));
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
CommandHistoryRecord rec = (CommandHistoryRecord) element;
return rec.getCommandString();
}
});
tableLayout.addColumnData(new ColumnPixelData(500));
TableViewerColumn originColumn = new TableViewerColumn(tableViewer, SWT.NONE);
originColumn.getColumn().setText(COL_SRC);
originColumn.getColumn().setToolTipText("Source (user@origin)");
originColumn.getColumn().addSelectionListener(getSelectionAdapter(originColumn.getColumn()));
originColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
CommandHistoryRecord rec = (CommandHistoryRecord) element;
return rec.getUsername() + "@" + rec.getOrigin();
}
});
tableLayout.addColumnData(new ColumnPixelData(200));
TableViewerColumn seqIdColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
seqIdColumn.getColumn().setText(COL_SRC_ID);
seqIdColumn.getColumn().addSelectionListener(getSelectionAdapter(seqIdColumn.getColumn()));
seqIdColumn.getColumn().setToolTipText("Client ID");
seqIdColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return String.valueOf(((CommandHistoryRecord) element).getSequenceNumber());
}
});
tableLayout.addColumnData(new ColumnPixelData(50));
TableViewerColumn ptvColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
ptvColumn.getColumn().setText(COL_PTV);
ptvColumn.getColumn().addSelectionListener(getSelectionAdapter(ptvColumn.getColumn()));
ptvColumn.getColumn().setToolTipText("Pre-Transmission Verification");
ptvColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
CommandHistoryRecord rec = (CommandHistoryRecord) element;
switch(rec.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 " + rec.getPTVInfo().getState());
return grayBubble;
}
}
@Override
public String getToolTipText(Object element) {
CommandHistoryRecord rec = (CommandHistoryRecord) element;
if (rec.getPTVInfo().getFailureMessage() != null) {
return rec.getPTVInfo().getFailureMessage();
} else {
return super.getToolTipText(element);
}
}
});
tableLayout.addColumnData(new ColumnPixelData(50));
TableViewerColumn finalSeqColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
finalSeqColumn.getColumn().setText(COL_SEQ_ID);
finalSeqColumn.getColumn().addSelectionListener(getSelectionAdapter(finalSeqColumn.getColumn()));
finalSeqColumn.getColumn().setToolTipText("Final Sequence Count");
finalSeqColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
CommandHistoryRecord rec = (CommandHistoryRecord) element;
return (rec.getFinalSequenceCount() != null) ? String.valueOf(rec.getFinalSequenceCount()) : "-";
}
});
tableLayout.addColumnData(new ColumnPixelData(50));
// Common properties to all columns
List<TableViewerColumn> columns = new ArrayList<>();
columns.add(gentimeColumn);
columns.add(nameColumn);
columns.add(originColumn);
columns.add(seqIdColumn);
columns.add(ptvColumn);
columns.add(finalSeqColumn);
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) {
checkMinWidth(column.getColumn());
}
});
}
// TODO use IMemento or something
tableViewer.getTable().setSortColumn(gentimeColumn.getColumn());
tableViewer.getTable().setSortDirection(SWT.DOWN);
getViewSite().setSelectionProvider(tableViewer);
}
use of org.yamcs.studio.core.ui.utils.CenteredImageLabelProvider 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.yamcs.studio.core.ui.utils.CenteredImageLabelProvider 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);
}
});
}
}
Aggregations