Search in sources :

Example 1 with RuleListFilter

use of org.netxms.ui.eclipse.epp.dialogs.helpers.RuleListFilter 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;
}
Also used : RuleComparator(org.netxms.ui.eclipse.epp.dialogs.helpers.RuleComparator) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) RuleListFilter(org.netxms.ui.eclipse.epp.dialogs.helpers.RuleListFilter) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RuleLabelProvider(org.netxms.ui.eclipse.epp.dialogs.helpers.RuleLabelProvider) EventProcessingPolicy(org.netxms.client.events.EventProcessingPolicy) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) FilterText(org.netxms.ui.eclipse.widgets.FilterText) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 NXCSession (org.netxms.client.NXCSession)1 EventProcessingPolicy (org.netxms.client.events.EventProcessingPolicy)1 RuleComparator (org.netxms.ui.eclipse.epp.dialogs.helpers.RuleComparator)1 RuleLabelProvider (org.netxms.ui.eclipse.epp.dialogs.helpers.RuleLabelProvider)1 RuleListFilter (org.netxms.ui.eclipse.epp.dialogs.helpers.RuleListFilter)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1 FilterText (org.netxms.ui.eclipse.widgets.FilterText)1