use of org.netxms.ui.eclipse.epp.dialogs.helpers.RuleComparator in project netxms by netxms.
the class RuleSelectionDialog 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);
GridLayout layout = new GridLayout();
layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
layout.numColumns = 2;
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("SelectRule.Filter");
if (filterString != null)
filterText.setText(filterString);
viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION | (multiSelection ? SWT.MULTI : SWT.SINGLE) | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.getTable().setLinesVisible(true);
viewer.getTable().setHeaderVisible(true);
TableColumn column = new TableColumn(viewer.getTable(), SWT.LEFT);
column.setText("Rule #");
column.setWidth(60);
column = new TableColumn(viewer.getTable(), SWT.LEFT);
column.setText("Rule Name");
column.setWidth(250);
viewer.setContentProvider(new ArrayContentProvider());
viewer.setComparator(new RuleComparator());
viewer.setLabelProvider(new RuleLabelProvider());
filter = new RuleListFilter();
if (filterString != null)
filter.setFilterString(filterString);
viewer.addFilter(filter);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.horizontalSpan = 2;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.heightHint = 350;
viewer.getTable().setLayoutData(gd);
filterText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
filter.setFilterString(filterText.getText());
viewer.refresh();
}
});
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
RuleSelectionDialog.this.okPressed();
}
});
if (rulesCache == null) {
viewer.getTable().setEnabled(false);
getButton(IDialogConstants.OK_ID).setEnabled(false);
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
ConsoleJob job = new ConsoleJob(Messages.get().RuleSelectionDialog_JobTitle, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final EventProcessingPolicy policy = session.getEventProcessingPolicy();
runInUIThread(new Runnable() {
@Override
public void run() {
viewer.getTable().setEnabled(true);
getButton(IDialogConstants.OK_ID).setEnabled(true);
viewer.setInput(policy.getRules().toArray());
}
});
}
@Override
protected String getErrorMessage() {
return Messages.get().RuleSelectionDialog_JobError;
}
};
job.setUser(false);
job.start();
} else {
viewer.setInput(rulesCache.toArray());
}
return dialogArea;
}
Aggregations