use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class SummaryTableComparator 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) {
DciSummaryTableDescriptor d1 = (DciSummaryTableDescriptor) e1;
DciSummaryTableDescriptor d2 = (DciSummaryTableDescriptor) e2;
int result;
switch(// $NON-NLS-1$
(Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
case SummaryTableManager.COLUMN_ID:
result = d1.getId() - d2.getId();
break;
case SummaryTableManager.COLUMN_MENU_PATH:
result = d1.getMenuPath().compareToIgnoreCase(d2.getMenuPath());
break;
case SummaryTableManager.COLUMN_TITLE:
result = d1.getTitle().compareToIgnoreCase(d2.getTitle());
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 ObjectSearchResultComparator 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 AbstractObject object1 = (AbstractObject) e1;
final AbstractObject object2 = (AbstractObject) e2;
// $NON-NLS-1$
final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
int result;
switch(column) {
case ObjectFinder.COL_ID:
result = Long.signum(object1.getObjectId() - object2.getObjectId());
break;
case ObjectFinder.COL_IP_ADDRESS:
InetAddressEx a1 = getIpAddress(object1);
InetAddressEx a2 = getIpAddress(object2);
result = ComparatorHelper.compareInetAddresses(a1.getAddress(), a2.getAddress());
break;
case ObjectFinder.COL_NAME:
result = object1.getObjectName().compareToIgnoreCase(object2.getObjectName());
break;
case ObjectFinder.COL_CLASS:
case ObjectFinder.COL_PARENT:
case ObjectFinder.COL_ZONE:
String t1 = ((ITableLabelProvider) ((SortableTableViewer) viewer).getLabelProvider()).getColumnText(object1, column);
String t2 = ((ITableLabelProvider) ((SortableTableViewer) viewer).getLabelProvider()).getColumnText(object2, column);
result = t1.compareToIgnoreCase(t2);
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 ObjectFinder method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
session = ConsoleSharedData.getSession();
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
parent.setLayout(layout);
Composite conditionGroup = new Composite(parent, SWT.NONE);
conditionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
layout = new GridLayout();
layout.numColumns = session.isZoningEnabled() ? 3 : 2;
conditionGroup.setLayout(layout);
/**
* Full text search **
*/
Composite fullTextSearchGroup = new Composite(conditionGroup, SWT.NONE);
fullTextSearchGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
layout = new GridLayout();
fullTextSearchGroup.setLayout(layout);
text = new LabeledText(fullTextSearchGroup, SWT.NONE);
text.setLabel("Search string");
text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
TraverseListener traverseListener = new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN)
startSearch();
}
};
text.addTraverseListener(traverseListener);
Group searchModeGroup = new Group(fullTextSearchGroup, SWT.NONE);
searchModeGroup.setText("Search mode");
layout = new GridLayout();
searchModeGroup.setLayout(layout);
radioPlainText = new Button(searchModeGroup, SWT.RADIO);
radioPlainText.setText("&Normal");
radioPlainText.setSelection(true);
radioPattern = new Button(searchModeGroup, SWT.RADIO);
radioPattern.setText("&Pattern (* = any string, ? = any character)");
radioRegularExpression = new Button(searchModeGroup, SWT.RADIO);
radioRegularExpression.setText("&Regular expression");
/**
* Class filter **
*/
Composite classFilterGroup = new Composite(conditionGroup, SWT.NONE);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.verticalSpan = 2;
classFilterGroup.setLayoutData(gd);
layout = new GridLayout();
classFilterGroup.setLayout(layout);
Label classFilterTitle = new Label(classFilterGroup, SWT.NONE);
classFilterTitle.setText("Class filter");
classList = CheckboxTableViewer.newCheckList(classFilterGroup, SWT.BORDER | SWT.CHECK);
classList.setContentProvider(new ArrayContentProvider());
classList.setInput(OBJECT_CLASSES);
classList.setAllChecked(true);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.heightHint = 100;
classList.getTable().setLayoutData(gd);
Composite classListButtons = new Composite(classFilterGroup, SWT.NONE);
RowLayout rlayout = new RowLayout();
rlayout.marginLeft = 0;
classListButtons.setLayout(rlayout);
Button selectAll = new Button(classListButtons, SWT.PUSH);
selectAll.setText("Select &all");
RowData rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
selectAll.setLayoutData(rd);
selectAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
classList.setAllChecked(true);
}
});
Button clearAll = new Button(classListButtons, SWT.PUSH);
clearAll.setText("&Clear all");
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
clearAll.setLayoutData(rd);
clearAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
classList.setAllChecked(false);
}
});
/**
* Zone filter **
*/
if (session.isZoningEnabled()) {
Composite zoneFilterGroup = new Composite(conditionGroup, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.verticalSpan = 2;
zoneFilterGroup.setLayoutData(gd);
layout = new GridLayout();
zoneFilterGroup.setLayout(layout);
Label zoneFilterTitle = new Label(zoneFilterGroup, SWT.NONE);
zoneFilterTitle.setText("Zone filter");
zoneList = CheckboxTableViewer.newCheckList(zoneFilterGroup, SWT.BORDER | SWT.CHECK);
zoneList.setContentProvider(new ArrayContentProvider());
List<Zone> zones = session.getAllZones();
zoneList.setLabelProvider(new WorkbenchLabelProvider());
zoneList.setInput(zones);
zoneList.setAllChecked(true);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.heightHint = 100;
zoneList.getTable().setLayoutData(gd);
Composite zoneListButtons = new Composite(zoneFilterGroup, SWT.NONE);
rlayout = new RowLayout();
rlayout.marginLeft = 0;
zoneListButtons.setLayout(rlayout);
selectAll = new Button(zoneListButtons, SWT.PUSH);
selectAll.setText("Select &all");
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
selectAll.setLayoutData(rd);
selectAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
zoneList.setAllChecked(true);
}
});
clearAll = new Button(zoneListButtons, SWT.PUSH);
clearAll.setText("&Clear all");
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
clearAll.setLayoutData(rd);
clearAll.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
zoneList.setAllChecked(false);
}
});
}
/**
* IP filter **
*/
Group ipFilterGroup = new Group(conditionGroup, SWT.NONE);
ipFilterGroup.setText("IP Range");
ipFilterGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
layout = new GridLayout();
layout.numColumns = 3;
ipFilterGroup.setLayout(layout);
ipRangeStart = new Text(ipFilterGroup, SWT.BORDER);
ipRangeStart.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
ipRangeStart.addTraverseListener(traverseListener);
new Label(ipFilterGroup, SWT.NONE).setText(" - ");
ipRangeEnd = new Text(ipFilterGroup, SWT.BORDER);
ipRangeEnd.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
ipRangeEnd.addTraverseListener(traverseListener);
/**
* Search button **
*/
Button searchButton = new Button(conditionGroup, SWT.PUSH);
searchButton.setText("&Search");
gd = new GridData(SWT.LEFT, SWT.BOTTOM, true, false);
gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT;
searchButton.setLayoutData(gd);
searchButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
startSearch();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
final String[] names = { "ID", "Class", "Name", "IP Address", "Parent", "Zone" };
final int[] widths = { 90, 120, 300, 250, 300, 200 };
results = new SortableTableViewer(parent, names, widths, 0, SWT.UP, SWT.MULTI | SWT.FULL_SELECTION);
if (!ConsoleSharedData.getSession().isZoningEnabled())
results.removeColumnById(COL_ZONE);
results.setContentProvider(new ArrayContentProvider());
results.setLabelProvider(new ObjectSearchResultLabelProvider());
results.setComparator(new ObjectSearchResultComparator());
results.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final IDialogSettings settings = Activator.getDefault().getDialogSettings();
WidgetHelper.restoreTableViewerSettings(results, settings, "ResultTable");
results.getTable().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
WidgetHelper.saveTableViewerSettings(results, settings, "ResultTable");
}
});
getSite().setSelectionProvider(results);
createResultsContextMenu();
activateContext();
createActions();
contributeToActionBars();
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class ZoneSelectionDialog method createDialogArea.
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
IDialogSettings settings = Activator.getDefault().getDialogSettings();
Composite dialogArea = (Composite) super.createDialogArea(parent);
NXCSession session = (NXCSession) ConsoleSharedData.getSession();
GridLayout layout = new GridLayout();
layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
dialogArea.setLayout(layout);
filterText = new FilterText(dialogArea, SWT.NONE, null, false);
GridData gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
filterText.setLayoutData(gd);
// $NON-NLS-1$
final String filterString = settings.get("SelectZone.Filter");
if (filterString != null)
filterText.setText(filterString);
final String[] names = { "Name" };
final int[] widths = { 200 };
zoneList = new SortableTableViewer(dialogArea, names, widths, 0, SWT.UP, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE | SWT.V_SCROLL);
zoneList.setContentProvider(new ArrayContentProvider());
zoneList.setComparator(new ZoneSelectionDialogComparator());
zoneList.setLabelProvider(new WorkbenchLabelProvider());
filter = new ZoneSelectionDialogFilter();
if (filterString != null)
filter.setFilterString(filterString);
zoneList.addFilter(filter);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
zoneList.getTable().setLayoutData(gd);
zoneList.setInput(session.getAllZones());
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
filter.setFilterString(filterText.getText());
zoneList.refresh();
}
});
zoneList.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
ZoneSelectionDialog.this.okPressed();
}
});
filterText.setFocus();
return dialogArea;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class MappingTables method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
final int[] widths = { 80, 160, 80, 400 };
final String[] names = { Messages.get().MappingTables_ColID, Messages.get().MappingTables_ColName, Messages.get().MappingTables_ColFlags, Messages.get().MappingTables_ColDescription };
viewer = new SortableTableViewer(parent, names, widths, COLUMN_NAME, SWT.UP, SWT.FULL_SELECTION | SWT.MULTI);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new MappingTableListLabelProvider());
viewer.setComparator(new MappingTableListComparator());
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
editTable();
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
actionEditTable.setEnabled(selection.size() == 1);
actionDeleteTables.setEnabled(selection.size() > 0);
}
});
final IDialogSettings settings = Activator.getDefault().getDialogSettings();
// $NON-NLS-1$
WidgetHelper.restoreTableViewerSettings(viewer, settings, "MappingTablesList");
viewer.getTable().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
// $NON-NLS-1$
WidgetHelper.saveTableViewerSettings(viewer, settings, "MappingTablesList");
}
});
createActions();
contributeToActionBars();
createPopupMenu();
session = ConsoleSharedData.getSession();
refresh(0);
final Display display = getSite().getShell().getDisplay();
listener = new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
if (n.getCode() == SessionNotification.MAPPING_TABLE_UPDATED) {
final Integer id = (int) n.getSubCode();
display.asyncExec(new Runnable() {
@Override
public void run() {
refresh(id);
}
});
} else if (n.getCode() == SessionNotification.MAPPING_TABLE_DELETED) {
final Integer id = (int) n.getSubCode();
display.asyncExec(new Runnable() {
@Override
public void run() {
mappingTables.remove(id);
viewer.setInput(mappingTables.values().toArray());
}
});
}
}
};
session.addListener(listener);
}
Aggregations