use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class RuleSourceObjects method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
session = (NXCSession) ConsoleSharedData.getSession();
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);
checkInverted = new Button(dialogArea, SWT.CHECK);
checkInverted.setText(Messages.get().RuleSourceObjects_InvertRule);
checkInverted.setSelection(rule.isSourceInverted());
final String[] columnNames = { Messages.get().RuleSourceObjects_Object };
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);
}
});
for (AbstractObject o : session.findMultipleObjects(rule.getSources().toArray(new Long[0]), true)) objects.put(o.getObjectId(), o);
viewer.setInput(objects.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().RuleSourceObjects_Add);
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
addSourceObject();
}
});
RowData rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
addButton.setLayoutData(rd);
deleteButton = new Button(buttons, SWT.PUSH);
deleteButton.setText(Messages.get().RuleSourceObjects_Delete);
deleteButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
deleteEvent();
}
});
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
deleteButton.setLayoutData(rd);
return dialogArea;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class AgentTableComparator 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;
AgentTable p1 = (AgentTable) e1;
AgentTable p2 = (AgentTable) 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 = p1.getInstanceColumnsAsList().compareToIgnoreCase(p2.getInstanceColumnsAsList());
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 ConditionData method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite dialogArea = new Composite(parent, SWT.NONE);
object = (Condition) getElement().getAdapter(Condition.class);
if (// Paranoid check
object == null)
return dialogArea;
dciList = new ArrayList<ConditionDciInfo>();
for (ConditionDciInfo dci : object.getDciList()) dciList.add(new ConditionDciInfo(dci));
labelProvider = new DciListLabelProvider(dciList);
labelProvider.resolveDciNames(object.getDciList());
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.numColumns = 2;
dialogArea.setLayout(layout);
final String[] columnNames = { Messages.get().ConditionData_ColPosition, Messages.get().ConditionData_ColNode, Messages.get().ConditionData_ColParameter, Messages.get().ConditionData_ColFunction };
final int[] columnWidths = { 40, 130, 220, 80 };
viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(labelProvider);
viewer.disableSorting();
viewer.setInput(dciList.toArray());
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.heightHint = 0;
gridData.horizontalSpan = 2;
viewer.getControl().setLayoutData(gridData);
/* buttons on left side */
Composite leftButtons = new Composite(dialogArea, SWT.NONE);
RowLayout buttonLayout = new RowLayout();
buttonLayout.type = SWT.HORIZONTAL;
buttonLayout.pack = false;
buttonLayout.marginWidth = 0;
buttonLayout.marginLeft = 0;
leftButtons.setLayout(buttonLayout);
gridData = new GridData();
gridData.horizontalAlignment = SWT.LEFT;
leftButtons.setLayoutData(gridData);
upButton = new Button(leftButtons, SWT.PUSH);
upButton.setText(Messages.get().ConditionData_Up);
RowData rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
upButton.setLayoutData(rd);
upButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
moveUp();
}
});
upButton.setEnabled(false);
downButton = new Button(leftButtons, SWT.PUSH);
downButton.setText(Messages.get().ConditionData_Down);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
downButton.setLayoutData(rd);
downButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
moveDown();
}
});
downButton.setEnabled(false);
/* buttons on right side */
Composite rightButtons = new Composite(dialogArea, SWT.NONE);
buttonLayout = new RowLayout();
buttonLayout.type = SWT.HORIZONTAL;
buttonLayout.pack = false;
buttonLayout.marginWidth = 0;
buttonLayout.marginRight = 0;
rightButtons.setLayout(buttonLayout);
gridData = new GridData();
gridData.horizontalAlignment = SWT.RIGHT;
rightButtons.setLayoutData(gridData);
addButton = new Button(rightButtons, SWT.PUSH);
addButton.setText(Messages.get().ConditionData_Add);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
addButton.setLayoutData(rd);
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
addItem();
}
});
editButton = new Button(rightButtons, SWT.PUSH);
editButton.setText(Messages.get().ConditionData_Modify);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
editButton.setLayoutData(rd);
editButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
editItem();
}
});
editButton.setEnabled(false);
deleteButton = new Button(rightButtons, SWT.PUSH);
deleteButton.setText(Messages.get().ConditionData_Delete);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
deleteButton.setLayoutData(rd);
deleteButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
deleteItems();
}
});
deleteButton.setEnabled(false);
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
editButton.notifyListeners(SWT.Selection, new Event());
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
editButton.setEnabled(selection.size() == 1);
deleteButton.setEnabled(selection.size() > 0);
upButton.setEnabled(selection.size() == 1);
downButton.setEnabled(selection.size() == 1);
}
});
return dialogArea;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class ClusterResources method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite dialogArea = new Composite(parent, SWT.NONE);
object = (Cluster) getElement().getAdapter(Cluster.class);
if (// Paranoid check
object == null)
return dialogArea;
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
final String[] columnNames = { Messages.get().ClusterResources_ColName, Messages.get().ClusterResources_ColVIP };
final int[] columnWidths = { 250, 150 };
viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new ResourceListLabelProvider());
viewer.setComparator(new ResourceListComparator());
resources = new ArrayList<ClusterResource>(object.getResources().size());
for (ClusterResource r : object.getResources()) resources.add(new ClusterResource(r));
viewer.setInput(resources.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.marginWidth = 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().ClusterResources_Add);
RowData rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
addButton.setLayoutData(rd);
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
addResource();
}
});
editButton = new Button(buttons, SWT.PUSH);
editButton.setText(Messages.get().ClusterResources_Modify);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
editButton.setLayoutData(rd);
editButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
editResource();
}
});
deleteButton = new Button(buttons, SWT.PUSH);
deleteButton.setText(Messages.get().ClusterResources_Delete);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
deleteButton.setLayoutData(rd);
deleteButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
deleteResource();
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
editButton.notifyListeners(SWT.Selection, new Event());
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
editButton.setEnabled(selection.size() == 1);
deleteButton.setEnabled(selection.size() > 0);
}
});
return dialogArea;
}
use of org.netxms.ui.eclipse.widgets.SortableTableViewer in project netxms by netxms.
the class CustomAttributes method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite dialogArea = new Composite(parent, SWT.NONE);
object = (AbstractObject) getElement().getAdapter(AbstractObject.class);
if (// Paranoid check
object == null)
return dialogArea;
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
final String[] columnNames = { Messages.get().CustomAttributes_Name, Messages.get().CustomAttributes_Value };
final int[] columnWidths = { 150, 250 };
viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setLabelProvider(new AttrListLabelProvider());
viewer.setComparator(new AttrViewerComparator());
attributes = new HashMap<String, String>(object.getCustomAttributes());
viewer.setInput(attributes.entrySet());
if (// $NON-NLS-1$ //$NON-NLS-2$
!Platform.getPreferencesService().getBoolean("org.netxms.ui.eclipse.console", "SHOW_HIDDEN_ATTRIBUTES", false, null)) {
viewer.addFilter(new ViewerFilter() {
@SuppressWarnings("unchecked")
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
// $NON-NLS-1$
return !((Entry<String, String>) element).getKey().startsWith(".");
}
});
}
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.marginWidth = 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().CustomAttributes_Add);
RowData rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
addButton.setLayoutData(rd);
addButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
final AttributeEditDialog dlg = new AttributeEditDialog(CustomAttributes.this.getShell(), null, null);
if (dlg.open() == Window.OK) {
if (attributes.containsKey(dlg.getName())) {
MessageDialogHelper.openWarning(CustomAttributes.this.getShell(), Messages.get().CustomAttributes_Warning, String.format(Messages.get().CustomAttributes_WarningAlreadyExist, dlg.getName()));
} else {
attributes.put(dlg.getName(), dlg.getValue());
viewer.setInput(attributes.entrySet());
CustomAttributes.this.isModified = true;
}
}
}
});
editButton = new Button(buttons, SWT.PUSH);
editButton.setText(Messages.get().CustomAttributes_Modify);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
editButton.setLayoutData(rd);
editButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@SuppressWarnings("unchecked")
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() == 1) {
Entry<String, String> element = (Entry<String, String>) selection.getFirstElement();
final AttributeEditDialog dlg = new AttributeEditDialog(CustomAttributes.this.getShell(), element.getKey(), element.getValue());
if (dlg.open() == Window.OK) {
attributes.put(dlg.getName(), dlg.getValue());
viewer.setInput(attributes.entrySet());
CustomAttributes.this.isModified = true;
}
}
}
});
deleteButton = new Button(buttons, SWT.PUSH);
deleteButton.setText(Messages.get().CustomAttributes_Delete);
rd = new RowData();
rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
deleteButton.setLayoutData(rd);
deleteButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@SuppressWarnings("unchecked")
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Iterator<Entry<String, String>> it = selection.iterator();
if (it.hasNext()) {
while (it.hasNext()) {
Entry<String, String> element = it.next();
attributes.remove(element.getKey());
}
viewer.setInput(attributes.entrySet());
CustomAttributes.this.isModified = true;
}
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
editButton.notifyListeners(SWT.Selection, new Event());
}
});
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
editButton.setEnabled(selection.size() == 1);
deleteButton.setEnabled(selection.size() > 0);
}
});
return dialogArea;
}
Aggregations