use of org.eclipse.jface.viewers.ColumnPixelData in project yamcs-studio by yamcs.
the class SwitchProcessorDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
var area = (Composite) super.createDialogArea(parent);
var composite = new Composite(area, SWT.NONE);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setLayout(new GridLayout());
var tableWrapper = new Composite(composite, SWT.NONE);
var tcl = new TableColumnLayout();
tableWrapper.setLayoutData(new GridData(GridData.FILL_BOTH));
tableWrapper.setLayout(tcl);
processorsTable = new TableViewer(tableWrapper, SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
processorsTable.getTable().setHeaderVisible(true);
processorsTable.getTable().setLinesVisible(true);
var instanceColumn = new TableViewerColumn(processorsTable, SWT.NONE);
instanceColumn.getColumn().setText("Instance");
instanceColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var info = (ProcessorInfo) element;
return info.getInstance();
}
});
tcl.setColumnData(instanceColumn.getColumn(), new ColumnPixelData(100));
var nameColumn = new TableViewerColumn(processorsTable, SWT.NONE);
nameColumn.getColumn().setText("Processor");
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var info = (ProcessorInfo) element;
return info.getName();
}
});
tcl.setColumnData(nameColumn.getColumn(), new ColumnWeightData(100));
var typeColumn = new TableViewerColumn(processorsTable, SWT.NONE);
typeColumn.getColumn().setText("Type");
typeColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var info = (ProcessorInfo) element;
return info.getType();
}
});
tcl.setColumnData(typeColumn.getColumn(), new ColumnPixelData(100));
processorsTable.setContentProvider(ArrayContentProvider.getInstance());
processorsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
processorsTable.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 == null || e2 == null) {
return 0;
}
var p1 = (ProcessorInfo) e1;
var p2 = (ProcessorInfo) e2;
var c = p1.getInstance().compareTo(p2.getInstance());
return (c != 0) ? c : p1.getName().compareTo(p2.getName());
}
});
processorsTable.addSelectionChangedListener(event -> {
var okButton = getButton(IDialogConstants.OK_ID);
okButton.setEnabled(!event.getSelection().isEmpty());
});
var client = YamcsPlugin.getYamcsClient();
var filter = new InstanceFilter();
filter.setState(InstanceState.RUNNING);
client.listInstances(filter).whenComplete((response, exc) -> {
parent.getDisplay().asyncExec(() -> {
if (exc == null) {
var processors = new ArrayList<ProcessorInfo>();
for (var instance : response.getInstancesList()) {
processors.addAll(instance.getProcessorsList());
}
processorsTable.setInput(processors);
}
});
});
return composite;
}
use of org.eclipse.jface.viewers.ColumnPixelData in project yamcs-studio by yamcs.
the class CommandHistoryView method createColumns.
private void createColumns() {
var table = tableViewer.getTable();
var layout = new TableLayout();
var currentColumns = tableViewer.getTable().getColumns();
for (var currentColumn : currentColumns) {
currentColumn.dispose();
}
for (var def : columnData.getVisibleColumns()) {
if (def.name.equals(COL_COMPLETION)) {
var completionColumn = new TableViewerColumn(tableViewer, SWT.NONE);
completionColumn.getColumn().addControlListener(columnResizeListener);
completionColumn.getColumn().addSelectionListener(getSelectionAdapter(completionColumn.getColumn()));
completionColumn.getColumn().setImage(headerCompleteImage);
completionColumn.getColumn().setToolTipText("Completion");
completionColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
var command = ((CommandHistoryRecord) element).getCommand();
if (command.isSuccess()) {
return checkmarkImage;
} else if (command.isFailure()) {
return errorImage;
} else {
return null;
}
}
@Override
public String getText(Object element) {
var command = ((CommandHistoryRecord) element).getCommand();
if (command.isSuccess()) {
return "Completed";
} else if (command.isFailure()) {
return command.getError();
} else {
return null;
}
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_T)) {
var gentimeColumn = new TableViewerColumn(tableViewer, SWT.NONE);
gentimeColumn.getColumn().addControlListener(columnResizeListener);
gentimeColumn.getColumn().addSelectionListener(getSelectionAdapter(gentimeColumn.getColumn()));
gentimeColumn.getColumn().setText(COL_T);
gentimeColumn.getColumn().setToolTipText("Generation Time");
gentimeColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var generationTime = ((CommandHistoryRecord) element).getCommand().getGenerationTime();
return YamcsPlugin.getDefault().formatInstant(generationTime);
}
});
layout.addColumnData(new ColumnPixelData(def.width));
// Add chevron
table.setSortColumn(gentimeColumn.getColumn());
table.setSortDirection(SWT.UP);
} else if (def.name.equals(COL_COMMAND)) {
var nameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
nameColumn.getColumn().addSelectionListener(getSelectionAdapter(nameColumn.getColumn()));
nameColumn.getColumn().setText(COL_COMMAND);
nameColumn.getColumn().setToolTipText("Command String");
nameColumn.getColumn().addControlListener(columnResizeListener);
nameColumn.getColumn().addSelectionListener(getSelectionAdapter(nameColumn.getColumn()));
nameColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var rec = (CommandHistoryRecord) element;
return rec.getCommand().getSource();
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_USER)) {
var userColumn = new TableViewerColumn(tableViewer, SWT.NONE);
userColumn.getColumn().addSelectionListener(getSelectionAdapter(userColumn.getColumn()));
userColumn.getColumn().setText(COL_USER);
userColumn.getColumn().setToolTipText("User that issued the command");
userColumn.getColumn().addControlListener(columnResizeListener);
userColumn.getColumn().addSelectionListener(getSelectionAdapter(userColumn.getColumn()));
userColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var rec = (CommandHistoryRecord) element;
return rec.getCommand().getUsername();
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_ORIGIN)) {
var originColumn = new TableViewerColumn(tableViewer, SWT.NONE);
originColumn.getColumn().addSelectionListener(getSelectionAdapter(originColumn.getColumn()));
originColumn.getColumn().setText(COL_ORIGIN);
originColumn.getColumn().setToolTipText("Origin");
originColumn.getColumn().addControlListener(columnResizeListener);
originColumn.getColumn().addSelectionListener(getSelectionAdapter(originColumn.getColumn()));
originColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var rec = (CommandHistoryRecord) element;
return rec.getCommand().getOrigin();
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_ORIGIN_ID)) {
var seqIdColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
seqIdColumn.getColumn().addSelectionListener(getSelectionAdapter(seqIdColumn.getColumn()));
seqIdColumn.getColumn().setText(COL_ORIGIN_ID);
seqIdColumn.getColumn().addControlListener(columnResizeListener);
seqIdColumn.getColumn().addSelectionListener(getSelectionAdapter(seqIdColumn.getColumn()));
seqIdColumn.getColumn().setToolTipText("Client ID at origin");
seqIdColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var rec = (CommandHistoryRecord) element;
return String.valueOf(rec.getCommand().getSequenceNumber());
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_PTV)) {
var ptvColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
ptvColumn.getColumn().setText(COL_PTV);
ptvColumn.getColumn().addControlListener(columnResizeListener);
ptvColumn.getColumn().addSelectionListener(getSelectionAdapter(ptvColumn.getColumn()));
ptvColumn.getColumn().setToolTipText("Pre-Transmission Verification");
ptvColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
var rec = (CommandHistoryRecord) element;
var command = rec.getCommand();
if (command.isSuccess()) {
return greenBubble;
} else if (command.isFailure()) {
return redBubble;
} else {
return grayBubble;
}
}
@Override
public String getToolTipText(Object element) {
var rec = (CommandHistoryRecord) element;
var command = rec.getCommand();
if (command.getError() != null) {
return command.getError();
} else {
return super.getToolTipText(element);
}
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_QUEUED)) {
var queuedColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
queuedColumn.getColumn().setText(COL_QUEUED);
queuedColumn.getColumn().addControlListener(columnResizeListener);
queuedColumn.getColumn().addSelectionListener(getSelectionAdapter(queuedColumn.getColumn()));
queuedColumn.getColumn().setToolTipText("Queued acknowledgment");
queuedColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
var rec = (CommandHistoryRecord) element;
var ack = rec.getCommand().getQueuedAcknowledgment();
if (ack == null) {
return grayBubble;
} else {
switch(ack.getStatus()) {
case "NEW":
return grayBubble;
case "OK":
return greenBubble;
case "PENDING":
return waitingImage;
case "NOK":
return redBubble;
default:
log.warning("Unexpected ack state " + ack.getStatus());
return grayBubble;
}
}
}
@Override
public String getToolTipText(Object element) {
var rec = (CommandHistoryRecord) element;
var ack = rec.getCommand().getQueuedAcknowledgment();
return (ack != null) ? ack.getMessage() : null;
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_RELEASED)) {
var releasedColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
releasedColumn.getColumn().setText(COL_RELEASED);
releasedColumn.getColumn().addControlListener(columnResizeListener);
releasedColumn.getColumn().addSelectionListener(getSelectionAdapter(releasedColumn.getColumn()));
releasedColumn.getColumn().setToolTipText("Released acknowledgment");
releasedColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
var rec = (CommandHistoryRecord) element;
var ack = rec.getCommand().getReleasedAcknowledgment();
if (ack == null) {
return grayBubble;
} else {
switch(ack.getStatus()) {
case "NEW":
return grayBubble;
case "OK":
return greenBubble;
case "PENDING":
return waitingImage;
case "NOK":
return redBubble;
default:
log.warning("Unexpected ack state " + ack.getStatus());
return grayBubble;
}
}
}
@Override
public String getToolTipText(Object element) {
var rec = (CommandHistoryRecord) element;
var ack = rec.getCommand().getReleasedAcknowledgment();
return (ack != null) ? ack.getMessage() : null;
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (def.name.equals(COL_SENT)) {
var sentColumn = new TableViewerColumn(tableViewer, SWT.CENTER);
sentColumn.getColumn().setText(COL_SENT);
sentColumn.getColumn().addControlListener(columnResizeListener);
sentColumn.getColumn().addSelectionListener(getSelectionAdapter(sentColumn.getColumn()));
sentColumn.getColumn().setToolTipText("Sent acknowledgment");
sentColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
var rec = (CommandHistoryRecord) element;
var ack = rec.getCommand().getSentAcknowledgment();
if (ack == null) {
return grayBubble;
} else {
switch(ack.getStatus()) {
case "NEW":
return grayBubble;
case "OK":
return greenBubble;
case "PENDING":
return waitingImage;
case "NOK":
return redBubble;
default:
log.warning("Unexpected ack state " + ack.getStatus());
return grayBubble;
}
}
}
@Override
public String getToolTipText(Object element) {
var rec = (CommandHistoryRecord) element;
var ack = rec.getCommand().getSentAcknowledgment();
return (ack != null) ? ack.getMessage() : null;
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else if (dynamicColumns.contains(def.name)) {
var column = new TableViewerColumn(tableViewer, SWT.LEFT);
column.getColumn().setText(def.name);
column.getColumn().addControlListener(columnResizeListener);
column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn()));
if (def.name.startsWith("Verifier_") || def.name.startsWith("Acknowledge_")) {
column.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
var rec = (CommandHistoryRecord) element;
var command = rec.getCommand();
if (command.isSuccess()) {
return greenBubble;
} else if (command.isFailure()) {
return redBubble;
} else {
return grayBubble;
}
}
@Override
public String getToolTipText(Object element) {
var rec = (CommandHistoryRecord) element;
var ack = rec.getCommand().getAcknowledgment(def.name);
return (ack != null) ? ack.getMessage() : null;
}
});
layout.addColumnData(new ColumnPixelData(def.width));
} else {
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var rec = (CommandHistoryRecord) element;
var value = rec.getCommand().getAttribute(def.name);
if (value == null) {
return null;
} else if (value instanceof byte[]) {
return StringConverter.arrayToHexString((byte[]) value);
} else {
return String.valueOf(value);
}
}
});
}
layout.addColumnData(new ColumnPixelData(def.width));
}
}
table.setLayout(layout);
table.setHeaderVisible(true);
table.setLinesVisible(true);
// !! Ensures column widths are applied when recreating columns
table.layout(true);
// !! Ensures table renders correctly for old data when adding a new column
tableViewer.refresh();
saveColumnState();
}
use of org.eclipse.jface.viewers.ColumnPixelData in project yamcs-studio by yamcs.
the class CommandStackTableViewer method addFixedColumns.
private void addFixedColumns(TableColumnLayout tcl) {
var level0Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level0s.png"));
var level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level1s.png"));
var level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level2s.png"));
var level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level3s.png"));
var level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level4s.png"));
var level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(CommandStackTableViewer.class, "icons/level5s.png"));
var 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));
delayColumn = new TableViewerColumn(this, SWT.NONE);
delayColumn.getColumn().setText(COL_DELAY);
delayColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var cmd = (StackedCommand) element;
var delayMs = cmd.getDelayMs();
var decimalFormat = new DecimalFormat("#,##0");
var numberAsString = decimalFormat.format(delayMs);
return (delayMs > 0) ? numberAsString + " ms" : "-";
}
});
// the delay column is shown when the command stack is in automatic mode with
// stack delays.
tcl.setColumnData(delayColumn.getColumn(), new ColumnPixelData(0));
// this.hideDelayColumn();
var nameColumn = new TableViewerColumn(this, SWT.NONE);
nameColumn.getColumn().setText(COL_COMMAND);
nameColumn.setLabelProvider(new CommandSourceColumnLabelProvider(styleProvider));
tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(300));
var 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) {
var 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 level0Image;
}
}
@Override
public String getToolTipText(Object element) {
var 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));
var constraintsColumn = new TableViewerColumn(this, SWT.LEFT);
constraintsColumn.getColumn().setText(COL_CONSTRAINTS);
constraintsColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
var cmd = (StackedCommand) element;
var buf = new StringBuilder();
for (var i = 0; i < cmd.getMetaCommand().getConstraintCount(); i++) {
if (i != 0) {
buf.append(" and ");
}
var constraint = cmd.getMetaCommand().getConstraint(i);
buf.append(constraint.getExpression());
}
return buf.length() != 0 ? buf.toString() : "-";
}
});
tcl.setColumnData(constraintsColumn.getColumn(), new ColumnPixelData(250));
var 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) {
var cmd = (StackedCommand) element;
var timeout = -1L;
for (var constraint : cmd.getMetaCommand().getConstraintList()) {
timeout = Math.max(timeout, constraint.getTimeout());
}
return (timeout >= 0) ? Long.toString(timeout) + " ms" : "-";
}
});
tcl.setColumnData(constraintsTimeOutColumn.getColumn(), new ColumnPixelData(50));
var 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));
var 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) {
var cmd = (StackedCommand) element;
return cmd.getStackedState().getText();
}
@Override
public Color getBackground(Object element) {
var 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) {
var 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));
var qColumn = new TableViewerColumn(this, SWT.CENTER);
qColumn.getColumn().setText(COL_QUEUED);
qColumn.getColumn().setToolTipText("Queued");
qColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
var cmd = (StackedCommand) element;
if (cmd.getQueuedState() == null) {
return grayBubble;
}
switch(cmd.getQueuedState().getStatus()) {
case "NA":
case "OK":
return greenBubble;
case "PENDING":
return waitingImage;
case "NOK":
return redBubble;
default:
log.warning("Unexpected state " + cmd.getQueuedState());
return grayBubble;
}
}
});
tcl.setColumnData(qColumn.getColumn(), new ColumnPixelData(50));
var rColumn = new TableViewerColumn(this, SWT.CENTER);
rColumn.getColumn().setText(COL_RELEASED);
rColumn.getColumn().setToolTipText("Released");
rColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
var cmd = (StackedCommand) element;
if (cmd.getReleasedState() == null) {
return grayBubble;
}
switch(cmd.getReleasedState().getStatus()) {
case "NA":
case "OK":
return greenBubble;
case "PENDING":
return waitingImage;
case "NOK":
return redBubble;
default:
log.warning("Unexpected state " + cmd.getReleasedState());
return grayBubble;
}
}
});
tcl.setColumnData(rColumn.getColumn(), new ColumnPixelData(50));
var sColumn = new TableViewerColumn(this, SWT.CENTER);
sColumn.getColumn().setText(COL_SENT);
sColumn.getColumn().setToolTipText("Sent");
sColumn.setLabelProvider(new CenteredImageLabelProvider() {
@Override
public Image getImage(Object element) {
var cmd = (StackedCommand) element;
if (cmd.getSentState() == null) {
return grayBubble;
}
switch(cmd.getSentState().getStatus()) {
case "NA":
case "OK":
return greenBubble;
case "PENDING":
return waitingImage;
case "NOK":
return redBubble;
default:
log.warning("Unexpected state " + cmd.getSentState());
return grayBubble;
}
}
});
tcl.setColumnData(sColumn.getColumn(), new ColumnPixelData(50));
// column comment
var 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
var columns = new ArrayList<TableViewerColumn>();
columns.add(rowIdColumn);
columns.add(nameColumn);
columns.add(significanceColumn);
columns.add(constraintsColumn);
columns.add(constraintsTimeOutColumn);
columns.add(releaseColumn);
columns.add(qColumn);
columns.add(rColumn);
columns.add(sColumn);
columns.add(stateColumn);
columns.add(commentColumn);
for (var 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.jface.viewers.ColumnPixelData in project egit by eclipse.
the class RebaseInteractiveView method createColumns.
private void createColumns(TreeColumnLayout layout) {
String[] headings = { UIText.RebaseInteractiveView_HeadingStatus, UIText.RebaseInteractiveView_HeadingStep, UIText.RebaseInteractiveView_HeadingAction, UIText.RebaseInteractiveView_HeadingCommitId, UIText.RebaseInteractiveView_HeadingMessage, UIText.RebaseInteractiveView_HeadingAuthor, UIText.RebaseInteractiveView_HeadingAuthorDate, UIText.RebaseInteractiveView_HeadingCommitter, UIText.RebaseInteractiveView_HeadingCommitDate };
ColumnViewerToolTipSupport.enableFor(planTreeViewer, ToolTip.NO_RECREATE);
TreeViewerColumn infoColumn = createColumn(headings[0]);
layout.setColumnData(infoColumn.getColumn(), new ColumnPixelData(70));
infoColumn.setLabelProvider(new HighlightingColumnLabelProvider() {
@Override
public Image getImage(Object element) {
ElementType t = getType(element);
if (t != null) {
switch(t) {
case DONE_CURRENT:
return UIIcons.getImage(resources, UIIcons.CURRENT_STEP);
case DONE:
return UIIcons.getImage(resources, UIIcons.DONE_STEP);
default:
}
}
return null;
}
@Override
public String getToolTipText(Object element) {
ElementType t = getType(element);
if (t != null) {
switch(t) {
case DONE:
return UIText.RebaseInteractiveView_StatusDone;
case DONE_CURRENT:
return UIText.RebaseInteractiveView_StatusCurrent;
case TODO:
return UIText.RebaseInteractiveView_StatusTodo;
default:
}
}
// $NON-NLS-1$
return "";
}
@Override
public String getText(Object element) {
// $NON-NLS-1$
return "";
}
});
TreeViewerColumn stepColumn = createColumn(headings[1]);
layout.setColumnData(stepColumn.getColumn(), new ColumnPixelData(55));
stepColumn.setLabelProvider(new HighlightingColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof PlanElement) {
PlanElement planLine = (PlanElement) element;
// $NON-NLS-1$
return (planIndexer.indexOf(planLine) + 1) + ".";
}
return super.getText(element);
}
});
stepColumn.getColumn().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
Tree tree = planTreeViewer.getTree();
boolean orderReversed = tree.getSortDirection() == SWT.DOWN;
RebaseInteractivePreferences.setOrderReversed(!orderReversed);
int newDirection = (orderReversed ? SWT.UP : SWT.DOWN);
tree.setSortDirection(newDirection);
TreeItem topmostVisibleItem = tree.getTopItem();
refreshUI();
if (topmostVisibleItem != null)
tree.showItem(topmostVisibleItem);
}
});
int direction = (RebaseInteractivePreferences.isOrderReversed() ? SWT.DOWN : SWT.UP);
Tree planTree = planTreeViewer.getTree();
planTree.setSortColumn(stepColumn.getColumn());
planTree.setSortDirection(direction);
TreeViewerColumn actionColumn = createColumn(headings[2]);
layout.setColumnData(actionColumn.getColumn(), new ColumnPixelData(90));
actionColumn.setLabelProvider(new HighlightingColumnLabelProvider() {
@Override
public Image getImage(Object element) {
ElementAction a = getAction(element);
if (a != null) {
switch(a) {
case EDIT:
return UIIcons.getImage(resources, UIIcons.EDITCONFIG);
case FIXUP:
if (RebaseInteractivePreferences.isOrderReversed())
return UIIcons.getImage(resources, UIIcons.FIXUP_DOWN);
else
return UIIcons.getImage(resources, UIIcons.FIXUP_UP);
case PICK:
return UIIcons.getImage(resources, UIIcons.CHERRY_PICK);
case REWORD:
return UIIcons.getImage(resources, UIIcons.REWORD);
case SKIP:
return UIIcons.getImage(resources, UIIcons.REBASE_SKIP);
case SQUASH:
if (RebaseInteractivePreferences.isOrderReversed())
return UIIcons.getImage(resources, UIIcons.SQUASH_DOWN);
else
return UIIcons.getImage(resources, UIIcons.SQUASH_UP);
default:
}
}
return super.getImage(element);
}
@Override
public String getText(Object element) {
ElementAction a = getAction(element);
return (a != null) ? a.name() : super.getText(element);
}
private ElementAction getAction(Object element) {
if (element instanceof PlanElement) {
PlanElement planLine = (PlanElement) element;
return planLine.getPlanElementAction();
} else
return null;
}
});
TreeViewerColumn commitIDColumn = createColumn(headings[3]);
int minWidth;
GC gc = new GC(planTreeViewer.getControl().getDisplay());
try {
gc.setFont(planTreeViewer.getControl().getFont());
minWidth = // $NON-NLS-1$
Math.max(// $NON-NLS-1$
gc.stringExtent("0000000").x, gc.stringExtent(headings[3]).x) + 10;
} finally {
gc.dispose();
}
layout.setColumnData(commitIDColumn.getColumn(), new ColumnPixelData(minWidth));
commitIDColumn.setLabelProvider(new HighlightingColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof PlanElement) {
PlanElement planLine = (PlanElement) element;
return planLine.getCommit().name();
}
return super.getText(element);
}
});
TreeViewerColumn commitMessageColumn = createColumn(headings[4]);
layout.setColumnData(commitMessageColumn.getColumn(), new ColumnWeightData(200, 200));
commitMessageColumn.setLabelProvider(new HighlightingColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof PlanElement) {
PlanElement planLine = (PlanElement) element;
return planLine.getShortMessage();
}
return super.getText(element);
}
});
TreeViewerColumn authorColumn = createColumn(headings[5]);
layout.setColumnData(authorColumn.getColumn(), new ColumnWeightData(120, 120));
authorColumn.setLabelProvider(new HighlightingColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof PlanElement) {
PlanElement planLine = (PlanElement) element;
return planLine.getAuthor();
}
return super.getText(element);
}
});
TreeViewerColumn authoredDateColumn = createColumn(headings[6]);
layout.setColumnData(authoredDateColumn.getColumn(), new ColumnWeightData(80, 80));
authoredDateColumn.setLabelProvider(new HighlightingColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof PlanElement) {
PlanElement planLine = (PlanElement) element;
return planLine.getAuthoredDate(dateFormatter);
}
return super.getText(element);
}
});
TreeViewerColumn committerColumn = createColumn(headings[7]);
layout.setColumnData(committerColumn.getColumn(), new ColumnWeightData(120, 120));
committerColumn.setLabelProvider(new HighlightingColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof PlanElement) {
PlanElement planLine = (PlanElement) element;
return planLine.getCommitter();
}
return super.getText(element);
}
});
TreeViewerColumn commitDateColumn = createColumn(headings[8]);
layout.setColumnData(commitDateColumn.getColumn(), new ColumnWeightData(80, 80));
commitDateColumn.setLabelProvider(new HighlightingColumnLabelProvider() {
@Override
public String getText(Object element) {
if (element instanceof PlanElement) {
PlanElement planLine = (PlanElement) element;
return planLine.getCommittedDate(dateFormatter);
}
return super.getText(element);
}
});
dynamicColumns = new TreeViewerColumn[] { commitMessageColumn, authorColumn, authoredDateColumn, committerColumn, commitDateColumn };
}
use of org.eclipse.jface.viewers.ColumnPixelData in project portfolio by buchen.
the class DividendsYearMatrixTab method createYearColumn.
private void createYearColumn(TableViewer records, TableColumnLayout layout, LocalDate start, int index) {
TableViewerColumn column = new TableViewerColumn(records, SWT.RIGHT);
column.getColumn().setText(formatter.format(start));
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Line line = (DividendsViewModel.Line) element;
long value = 0;
for (int ii = index; ii < index + 12 && ii < line.getNoOfMonths(); ii++) value += line.getValue(ii);
return line.getVehicle() != null ? Values.Amount.formatNonZero(value) : Values.Amount.format(value);
}
@Override
public String getToolTipText(Object element) {
InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
return TextUtil.tooltip(vehicle != null ? vehicle.getName() : null);
}
@Override
public Font getFont(Object element) {
InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
return vehicle != null ? null : boldFont;
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(50));
}
Aggregations