use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class NodeListComparator 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) {
final AbstractNode node1 = (AbstractNode) e1;
final AbstractNode node2 = (AbstractNode) e2;
// $NON-NLS-1$
final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
int result;
switch(column) {
case NodesTab.COLUMN_SYS_DESCRIPTION:
result = node1.getSystemDescription().compareToIgnoreCase(node2.getSystemDescription());
break;
case NodesTab.COLUMN_PLATFORM:
result = node1.getPlatformName().compareToIgnoreCase(node2.getPlatformName());
break;
case NodesTab.COLUMN_AGENT_VERSION:
result = node1.getAgentVersion().compareToIgnoreCase(node2.getAgentVersion());
break;
case NodesTab.COLUMN_ID:
result = Long.signum(node1.getObjectId() - node2.getObjectId());
break;
case NodesTab.COLUMN_NAME:
result = node1.getObjectName().compareToIgnoreCase(node2.getObjectName());
break;
case NodesTab.COLUMN_STATUS:
result = node1.getStatus().compareTo(node2.getStatus());
break;
case NodesTab.COLUMN_IP_ADDRESS:
result = ComparatorHelper.compareInetAddresses(node1.getPrimaryIP().getAddress(), node2.getPrimaryIP().getAddress());
break;
case NodesTab.COLUMN_RACK:
Rack rack1 = session.findObjectById(node1.getRackId(), Rack.class);
Rack rack2 = session.findObjectById(node2.getRackId(), Rack.class);
if ((rack1 != null) && (rack2 != null)) {
result = rack1.getObjectName().compareToIgnoreCase(rack2.getObjectName());
if (result == 0) {
result = node1.getRackPosition() - node2.getRackPosition();
}
} else {
result = Long.signum(node1.getRackId() - node2.getRackId());
}
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 ObjectToolsEditor 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();
// Initiate loading of required plugins if they was not loaded yet
try {
// $NON-NLS-1$
Platform.getAdapterManager().loadAdapter(new AccessListElement(0, 0), "org.eclipse.ui.model.IWorkbenchAdapter");
} catch (Exception e) {
}
// Create interface area
objectToolsArea = new Composite(parent, SWT.BORDER);
FormLayout formLayout = new FormLayout();
objectToolsArea.setLayout(formLayout);
// Create filter
filterText = new FilterText(objectToolsArea, SWT.NONE);
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
filterText.setCloseAction(new Action() {
@Override
public void run() {
enableFilter(false);
actionShowFilter.setChecked(initShowFilter);
}
});
final String[] columnNames = { Messages.get().ObjectToolsEditor_ColId, Messages.get().ObjectToolsEditor_ColName, Messages.get().ObjectToolsEditor_ColType, Messages.get().ObjectToolsEditor_ColDescr };
final int[] columnWidths = { 90, 200, 100, 200 };
viewer = new SortableTableViewer(objectToolsArea, columnNames, columnWidths, COLUMN_NAME, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
WidgetHelper.restoreTableViewerSettings(viewer, Activator.getDefault().getDialogSettings(), TABLE_CONFIG_PREFIX);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new ObjectToolsLabelProvider());
filter = new ObjectToolsFilter();
viewer.addFilter(filter);
viewer.setComparator(new ObjectToolsComparator());
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection != null) {
actionEdit.setEnabled(selection.size() == 1);
actionClone.setEnabled(selection.size() == 1);
actionDelete.setEnabled(selection.size() > 0);
actionDisable.setEnabled(containsEnabled(selection));
actionEnable.setEnabled(containsDisabled(selection));
}
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
actionEdit.run();
}
});
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.getControl().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);
// Set initial focus to filter input line
if (initShowFilter)
filterText.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
refreshToolList();
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class ObjectToolsComparator 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) {
ObjectTool tool1 = (ObjectTool) e1;
ObjectTool tool2 = (ObjectTool) e2;
// $NON-NLS-1$
final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
int result;
switch(column) {
case ObjectToolsEditor.COLUMN_ID:
result = Long.signum(tool1.getId() - tool2.getId());
break;
case ObjectToolsEditor.COLUMN_NAME:
result = tool1.getName().compareToIgnoreCase(tool2.getName());
break;
case ObjectToolsEditor.COLUMN_TYPE:
final ObjectToolsLabelProvider labelProvider = (ObjectToolsLabelProvider) ((SortableTableViewer) viewer).getLabelProvider();
result = labelProvider.getToolTypeName(tool1).compareTo(labelProvider.getToolTypeName(tool2));
break;
case ObjectToolsEditor.COLUMN_DESCRIPTION:
result = tool1.getDescription().compareToIgnoreCase(tool2.getDescription());
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 SoftwareInventory method createTableViewer.
/**
* Create viewer for table mode
*/
private void createTableViewer() {
viewer = new SortableTableViewer(this, names, widths, 0, SWT.UP, SWT.MULTI | SWT.FULL_SELECTION);
WidgetHelper.restoreColumnViewerSettings(viewer, Activator.getDefault().getDialogSettings(), configPrefix);
viewer.getControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
WidgetHelper.saveColumnViewerSettings(viewer, Activator.getDefault().getDialogSettings(), configPrefix);
}
});
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new SoftwarePackageLabelProvider(false));
viewer.setComparator(new SoftwarePackageComparator());
if (menuManager != null) {
Menu menu = menuManager.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
viewPart.getSite().registerContextMenu(menuManager, viewer);
}
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class PersistentStorageView method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
// GridLayout layout = new GridLayout();
// layout.verticalSpacing = WidgetHelper.INNER_SPACING;
// layout.marginWidth = 0;
// layout.marginHeight = 0;
// parent.setLayout(layout);
final String[] setColumnNames = { "Key", "Value" };
final int[] setColumnWidths = { 150, 200 };
viewerSetValue = new SortableTableViewer(parent, setColumnNames, setColumnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
viewerSetValue.setContentProvider(new ArrayContentProvider());
viewerSetValue.setLabelProvider(new AttributeLabelProvider());
viewerSetValue.setComparator(new ObjectLabelComparator((ILabelProvider) viewerSetValue.getLabelProvider()));
viewerSetValue.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
int size = ((IStructuredSelection) viewerSetValue.getSelection()).size();
actionEdit.setEnabled(size == 1);
actionDelete.setEnabled(size > 0);
}
});
createActions();
contributeToActionBars();
createPopupMenu();
refresh();
}
Aggregations