use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class LastValuesComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
int result;
DciValue v1 = (DciValue) e1;
DciValue v2 = (DciValue) e2;
switch(// $NON-NLS-1$
(Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
case LastValuesWidget.COLUMN_ID:
result = (int) (v1.getId() - v2.getId());
break;
case LastValuesWidget.COLUMN_DESCRIPTION:
result = v1.getDescription().compareToIgnoreCase(v2.getDescription());
break;
case LastValuesWidget.COLUMN_VALUE:
result = compareValue(v1, v2);
break;
case LastValuesWidget.COLUMN_TIMESTAMP:
result = v1.getTimestamp().compareTo(v2.getTimestamp());
break;
default:
result = 0;
break;
}
return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class DciComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
int result;
DataCollectionObject dci1 = (DataCollectionObject) e1;
DataCollectionObject dci2 = (DataCollectionObject) e2;
// $NON-NLS-1$
int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
switch(column) {
case DataCollectionEditor.COLUMN_ID:
result = (int) (dci1.getId() - dci2.getId());
break;
case DataCollectionEditor.COLUMN_DESCRIPTION:
result = dci1.getDescription().compareToIgnoreCase(dci2.getDescription());
break;
case DataCollectionEditor.COLUMN_PARAMETER:
result = dci1.getName().compareToIgnoreCase(dci2.getName());
break;
case DataCollectionEditor.COLUMN_INTERVAL:
result = (int) (dci1.getComparablePollingInterval() - dci2.getComparablePollingInterval());
break;
case DataCollectionEditor.COLUMN_RETENTION:
result = (int) (dci1.getComparableRetentionTime() - dci2.getComparableRetentionTime());
break;
case DataCollectionEditor.COLUMN_ORIGIN:
case DataCollectionEditor.COLUMN_DATATYPE:
case DataCollectionEditor.COLUMN_STATUS:
case DataCollectionEditor.COLUMN_TEMPLATE:
final String text1 = labelProvider.getColumnText(e1, column);
final String text2 = labelProvider.getColumnText(e2, column);
if (text1 != null && text2 != null) {
result = text1.compareToIgnoreCase(text2);
} else {
if (text1 == null) {
if (text2 == null) {
result = 0;
} else {
result = -1;
}
} else {
result = 1;
}
}
break;
default:
result = 0;
break;
}
return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class PackageManager method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
final String[] names = { Messages.get().PackageManager_ColumnID, Messages.get().PackageManager_ColumnName, Messages.get().PackageManager_ColumnVersion, Messages.get().PackageManager_ColumnPlatform, Messages.get().PackageManager_ColumnFile, Messages.get().PackageManager_ColumnDescription };
final int[] widths = { 70, 120, 90, 120, 150, 400 };
viewer = new SortableTableViewer(parent, names, widths, COLUMN_ID, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new PackageLabelProvider());
viewer.setComparator(new PackageComparator());
createActions();
contributeToActionBars();
createPopupMenu();
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
actionDeploy.setEnabled(selection.size() == 1);
actionRemove.setEnabled(selection.size() > 0);
}
});
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().PackageManager_OpenDatabase, this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
try {
session.lockPackageDatabase();
} catch (NXCException e) {
// New versions may not require package DB lock
if (e.getErrorCode() != RCC.NOT_IMPLEMENTED)
throw e;
}
runInUIThread(new Runnable() {
@Override
public void run() {
refresh();
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().PackageManager_OpenError;
}
}.start();
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class AccessControl method createContents.
@Override
protected Control createContents(Composite parent) {
session = ConsoleSharedData.getSession();
Composite dialogArea = new Composite(parent, SWT.NONE);
editor = (AlarmCategoryEditor) getElement().getAdapter(AlarmCategoryEditor.class);
category = editor.getObjectAsItem();
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
final String[] columnNames = { "Login Name" };
final int[] columnWidths = { 300 };
userList = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
userList.setContentProvider(new ArrayContentProvider());
userList.setLabelProvider(new WorkbenchLabelProvider());
userList.setComparator(new UserComparator());
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
userList.getControl().setLayoutData(gd);
Composite buttons = new Composite(dialogArea, SWT.NONE);
FillLayout buttonsLayout = new FillLayout();
buttonsLayout.spacing = WidgetHelper.INNER_SPACING;
buttons.setLayout(buttonsLayout);
gd = new GridData();
gd.horizontalAlignment = SWT.RIGHT;
gd.widthHint = 184;
buttons.setLayoutData(gd);
final Button addButton = new Button(buttons, SWT.PUSH);
addButton.setText("Add...");
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
SelectUserDialog dlg = new SelectUserDialog(AccessControl.this.getShell(), AbstractUserObject.class);
if (dlg.open() == Window.OK) {
AbstractUserObject[] selection = dlg.getSelection();
for (AbstractUserObject user : selection) accessMap.put(user.getId(), user);
userList.setInput(accessMap.values().toArray(new AbstractUserObject[accessMap.size()]));
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
final Button deleteButton = new Button(buttons, SWT.PUSH);
deleteButton.setText("Delete");
deleteButton.setEnabled(false);
deleteButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@SuppressWarnings("unchecked")
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selecion = (IStructuredSelection) userList.getSelection();
Iterator<AbstractUserObject> iterator = selecion.iterator();
while (iterator.hasNext()) {
AbstractUserObject element = iterator.next();
accessMap.remove(element.getId());
}
userList.setInput(accessMap.values().toArray());
}
});
userList.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
deleteButton.setEnabled(!userList.getSelection().isEmpty());
}
});
// Initial data
for (long userId : category.getAccessControl()) {
final AbstractUserObject user = session.findUserDBObjectById(userId);
if (user != null) {
accessMap.put(user.getId(), user);
}
}
userList.setInput(accessMap.values().toArray());
return dialogArea;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class ServerFileManager method createPartControl.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
session = (NXCSession) ConsoleSharedData.getSession();
content = new Composite(parent, SWT.NONE);
content.setLayout(new FormLayout());
// Create filter area
filterText = new FilterText(content, SWT.NONE);
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
final String[] columnNames = { Messages.get().ViewServerFile_FileName, Messages.get().ViewServerFile_FileType, Messages.get().ViewServerFile_FileSize, Messages.get().ViewServerFile_ModificationDate };
final int[] columnWidths = { 300, 150, 300, 300 };
viewer = new SortableTableViewer(content, columnNames, columnWidths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new ServerFileLabelProvider());
viewer.setComparator(new ServerFileComparator());
filter = new ServerFileFilter();
viewer.addFilter(filter);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection != null) {
actionDelete.setEnabled(selection.size() > 0);
}
}
});
viewer.getTable().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
WidgetHelper.saveTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
}
});
// Setup layout
FormData fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(filterText);
fd.right = new FormAttachment(100, 0);
fd.bottom = new FormAttachment(100, 0);
viewer.getTable().setLayoutData(fd);
fd = new FormData();
fd.left = new FormAttachment(0, 0);
fd.top = new FormAttachment(0, 0);
fd.right = new FormAttachment(100, 0);
filterText.setLayoutData(fd);
createActions();
contributeToActionBars();
createPopupMenu();
activateContext();
session.addListener(this);
filterText.setCloseAction(actionShowFilter);
// Set initial focus to filter input line
if (initShowFilter)
filterText.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
refreshFileList();
}
Aggregations