use of org.eclipse.jface.viewers.ViewerComparator 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.ViewerComparator 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.ViewerComparator 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;
}
use of org.eclipse.jface.viewers.ViewerComparator in project hale by halestudio.
the class InstanceValidationReportDetailsPage method createControls.
/**
* @see CustomReportDetailsPage#createControls(Composite)
*/
@Override
public Control createControls(Composite parent) {
// filtered tree sets itself GridData, so set layout to gridlayout
parent.setLayout(GridLayoutFactory.fillDefaults().create());
// create pattern filter for FilteredTree
PatternFilter filter = new TreePathPatternFilter();
filter.setIncludeLeadingWildcard(true);
// create FilteredTree
FilteredTree filteredTree = new TreePathFilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
treeViewer = filteredTree.getViewer();
// set content provider
contentProvider = new InstanceValidationReportDetailsContentProvider();
treeViewer.setContentProvider(contentProvider);
// set label provider
treeViewer.setLabelProvider(new InstanceValidationReportDetailsLabelProvider(contentProvider));
// set comparator
treeViewer.setComparator(new ViewerComparator() {
/**
* @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
*/
@Override
public int category(Object element) {
if (element instanceof QName || element instanceof Definition<?>)
// Path
return 0;
else if (element instanceof String)
// Category
return 1;
else
// InstanceValidationMessage
return 2;
}
});
// add menu on right-click
MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
if (getValidSelection() == null)
return;
// selection is valid, offer link to transformed data view
manager.add(new ShowExampleAction());
}
});
// remove previous menus
menuMgr.setRemoveAllWhenShown(true);
// add menu to tree
treeViewer.getTree().setMenu(menu);
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
showSelectionInDataView();
}
});
Image noReportBaseImage = InstanceValidationUIPlugin.getDefault().getImageRegistry().get(InstanceValidationUIPlugin.IMG_INSTANCE_VALIDATION);
reportImage = new DecorationOverlayIcon(noReportBaseImage, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING), IDecoration.BOTTOM_LEFT).createImage();
return filteredTree;
}
use of org.eclipse.jface.viewers.ViewerComparator in project hale by halestudio.
the class ReportList method createViewControl.
/**
* Create contents of the view part.
*
* @param parent parent element
*/
@Override
public void createViewControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
TreeColumnLayout layout = new TreeColumnLayout();
composite.setLayout(layout);
{
_treeViewer = new TreeViewer(composite, SWT.BORDER);
final Tree tree = _treeViewer.getTree();
tree.setHeaderVisible(false);
tree.setLinesVisible(false);
// create column for reports
TreeViewerColumn col1 = new TreeViewerColumn(_treeViewer, SWT.NONE);
// add the label provider
col1.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelProvider()));
// and layout
layout.setColumnData(col1.getColumn(), new ColumnWeightData(3));
// create column for reports
TreeViewerColumn col2 = new TreeViewerColumn(_treeViewer, SWT.NONE);
// add the label provider
col2.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelDateProvider()));
// create column for reports
layout.setColumnData(col2.getColumn(), new ColumnWeightData(1));
new ReportListMenu(getSite(), _treeViewer);
}
createActions();
initializeToolBar();
initializeMenu();
// set label provider
// _treeViewer.setLabelProvider(new ReportListLabelProvider());
// set content provider
_treeViewer.setContentProvider(new ReportListContentProvider());
// disable this if it uses too much memory
// but should maintain the list much faster
_treeViewer.setUseHashlookup(true);
// order the sessions from latest to oldest
_treeViewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
if (e1 instanceof ReportSession && e2 instanceof ReportSession) {
long first = ((ReportSession) e1).getId();
long second = ((ReportSession) e2).getId();
if (first > second) {
return -1;
} else if (first < second) {
return 1;
} else {
return 0;
}
} else if (e1 instanceof Report<?> && e2 instanceof Report<?>) {
Report<?> first = (Report<?>) e1;
Report<?> second = (Report<?>) e2;
if (first.getStartTime() == null && second.getStartTime() == null) {
return 0;
} else if (first.getStartTime() == null) {
return 1;
} else if (second.getStartTime() == null) {
return -1;
} else if (first.getStartTime().getTime() > second.getStartTime().getTime()) {
return -1;
} else if (first.getStartTime().getTime() < second.getStartTime().getTime()) {
return 1;
} else {
return 0;
}
}
return 0;
}
});
// set selection provider
getSite().setSelectionProvider(_treeViewer);
_treeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
OpenPropertiesHandler.unpinAndOpenPropertiesView(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
}
});
// load all added reports
this.loadReports();
}
Aggregations