use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class PackageComparator 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) {
PackageInfo p1 = (PackageInfo) e1;
PackageInfo p2 = (PackageInfo) e2;
int result;
switch(// $NON-NLS-1$
(Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
case PackageManager.COLUMN_ID:
result = Long.signum(p1.getId() - p2.getId());
break;
case PackageManager.COLUMN_DESCRIPTION:
result = p1.getDescription().compareToIgnoreCase(p2.getDescription());
break;
case PackageManager.COLUMN_FILE:
result = p1.getFileName().compareToIgnoreCase(p2.getFileName());
break;
case PackageManager.COLUMN_NAME:
result = p1.getName().compareToIgnoreCase(p2.getName());
break;
case PackageManager.COLUMN_PLATFORM:
result = p1.getPlatform().compareToIgnoreCase(p2.getPlatform());
break;
case PackageManager.COLUMN_VERSION:
result = p1.getVersion().compareToIgnoreCase(p2.getVersion());
break;
default:
result = 0;
}
return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class DataCollectionEditor method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
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[] names = { Messages.get().DataCollectionEditor_ColID, Messages.get().DataCollectionEditor_ColOrigin, Messages.get().DataCollectionEditor_ColDescription, Messages.get().DataCollectionEditor_ColParameter, Messages.get().DataCollectionEditor_ColDataType, Messages.get().DataCollectionEditor_ColPollingInterval, Messages.get().DataCollectionEditor_ColRetentionTime, Messages.get().DataCollectionEditor_ColStatus, Messages.get().DataCollectionEditor_ColThresholds, Messages.get().DataCollectionEditor_ColTemplate };
final int[] widths = { 60, 100, 250, 200, 90, 90, 90, 100, 200, 150 };
viewer = new SortableTableViewer(content, names, widths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new DciLabelProvider());
viewer.setComparator(new DciComparator((DciLabelProvider) viewer.getLabelProvider()));
filter = new DciFilter();
viewer.addFilter(filter);
// $NON-NLS-1$
WidgetHelper.restoreTableViewerSettings(viewer, settings, "DataCollectionEditor");
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
if (selection != null) {
actionEdit.setEnabled(selection.size() == 1);
actionDelete.setEnabled(selection.size() > 0);
actionCopy.setEnabled(selection.size() > 0);
actionMove.setEnabled(selection.size() > 0);
actionConvert.setEnabled(selection.size() > 0);
actionDuplicate.setEnabled(selection.size() > 0);
Iterator<?> it = selection.iterator();
boolean canActivate = false;
boolean canDisable = false;
while (it.hasNext() && (!canActivate || !canDisable)) {
DataCollectionObject dci = (DataCollectionObject) it.next();
if (dci.getStatus() != DataCollectionObject.ACTIVE)
canActivate = true;
if (dci.getStatus() != DataCollectionObject.DISABLED)
canDisable = true;
}
actionActivate.setEnabled(canActivate);
actionDisable.setEnabled(canDisable);
}
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
actionEdit.run();
}
});
viewer.getTable().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
// $NON-NLS-1$
WidgetHelper.saveTableViewerSettings(viewer, settings, "DataCollectionEditor");
settings.put("DataCollectionEditor.hideModificationWarnings", hideModificationWarnings);
}
});
// 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();
filterText.setCloseAction(new Action() {
@Override
public void run() {
enableFilter(false);
actionShowFilter.setChecked(false);
}
});
// Request server to open data collection configuration
new ConsoleJob(Messages.get().DataCollectionEditor_OpenJob_Title + object.getObjectName(), this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
dciConfig = session.openDataCollectionConfiguration(object.getObjectId());
dciConfig.setUserData(viewer);
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.setInput(dciConfig.getItems());
}
});
}
@Override
protected void jobFailureHandler() {
runInUIThread(new Runnable() {
@Override
public void run() {
DataCollectionEditor.this.getViewSite().getPage().hideView(DataCollectionEditor.this);
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().DataCollectionEditor_OpenJob_Error + object.getObjectName();
}
}.start();
// Set initial focus to filter input line
if (actionShowFilter.isChecked())
filterText.setFocus();
else
// Will hide filter area correctly
enableFilter(false);
hideModificationWarnings = getBooleanFromSettings("DataCollectionEditor.hideModificationWarnings", false);
activateContext();
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class AgentParameterComparator 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;
AgentParameter p1 = (AgentParameter) e1;
AgentParameter p2 = (AgentParameter) e2;
switch(// $NON-NLS-1$
(Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID")) {
case AbstractSelectParamDlg.COLUMN_NAME:
result = p1.getName().compareToIgnoreCase(p2.getName());
break;
case AbstractSelectParamDlg.COLUMN_TYPE:
result = DataCollectionDisplayInfo.getDataTypeName(p1.getDataType()).compareTo(DataCollectionDisplayInfo.getDataTypeName(p2.getDataType()));
break;
case AbstractSelectParamDlg.COLUMN_DESCRIPTION:
result = p1.getDescription().compareToIgnoreCase(p2.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 SummaryTableManager method createPartControl.
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
// Create interface area
tableArea = new Composite(parent, SWT.BORDER);
FormLayout formLayout = new FormLayout();
tableArea.setLayout(formLayout);
// Create filter
filterText = new FilterText(tableArea, SWT.NONE);
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
onFilterModify();
}
});
filterText.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
settings.put("SummaryTableManager.showFilter", initShowFilter);
}
});
final String[] names = { Messages.get().SummaryTableManager_ID, Messages.get().SummaryTableManager_MenuPath, Messages.get().SummaryTableManager_Title };
final int[] widths = { 90, 250, 200 };
viewer = new SortableTableViewer(tableArea, names, widths, COLUMN_MENU_PATH, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new SummaryTableLabelProvider());
viewer.setComparator(new SummaryTableComparator());
filter = new SummaryTableFilter();
viewer.addFilter(filter);
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
actionEdit.setEnabled(selection.size() == 1);
actionDelete.setEnabled(selection.size() > 0);
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
editSummaryTable();
}
});
// 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();
filterText.setCloseAction(actionShowFilter);
enableFilter(initShowFilter);
refresh();
listener = new SessionListener() {
@Override
public void notificationHandler(SessionNotification n) {
if (n.getCode() == SessionNotification.DCI_SUMMARY_TABLE_DELETED) {
final int id = (int) n.getSubCode();
getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (descriptors.remove(id) != null)
viewer.setInput(descriptors.values().toArray());
}
});
} else if (n.getCode() == SessionNotification.DCI_SUMMARY_TABLE_UPDATED) {
getSite().getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
refresh();
}
});
}
}
};
session.addListener(listener);
activateContext();
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class RuleServerActions method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
editor = (RuleEditor) getElement().getAdapter(RuleEditor.class);
rule = editor.getRule();
Composite dialogArea = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
final String[] columnNames = { Messages.get().RuleServerActions_Action };
final int[] columnWidths = { 300 };
viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new WorkbenchLabelProvider());
viewer.setComparator(new ObjectLabelComparator((ILabelProvider) viewer.getLabelProvider()));
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
int size = ((IStructuredSelection) viewer.getSelection()).size();
deleteButton.setEnabled(size > 0);
}
});
actions.putAll(editor.getEditorView().findServerActions(rule.getActions()));
viewer.setInput(actions.values().toArray());
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.heightHint = 0;
viewer.getControl().setLayoutData(gridData);
Composite buttons = new Composite(dialogArea, SWT.NONE);
RowLayout buttonLayout = new RowLayout();
buttonLayout.type = SWT.HORIZONTAL;
buttonLayout.pack = false;
buttonLayout.marginLeft = 0;
buttonLayout.marginRight = 0;
buttons.setLayout(buttonLayout);
gridData = new GridData();
gridData.horizontalAlignment = SWT.RIGHT;
buttons.setLayoutData(gridData);
addButton = new Button(buttons, SWT.PUSH);
addButton.setText(Messages.get().RuleServerActions_Add);
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
addAction();
}
});
RowData rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
addButton.setLayoutData(rd);
deleteButton = new Button(buttons, SWT.PUSH);
deleteButton.setText(Messages.get().RuleServerActions_Delete);
deleteButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
deleteAction();
}
});
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
deleteButton.setLayoutData(rd);
deleteButton.setEnabled(false);
return dialogArea;
}
Aggregations