Search in sources :

Example 1 with RuleLabelProvider

use of org.netxms.ui.eclipse.serverconfig.views.helpers.RuleLabelProvider in project netxms by netxms.

the class ExportFileBuilder method createRuleSection.

/**
 * Create "Rules" section
 */
private void createRuleSection() {
    Section section = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
    section.setText(Messages.get().ExportFileBuilder_SectionRules);
    TableWrapData td = new TableWrapData();
    td.align = TableWrapData.FILL;
    td.grabHorizontal = true;
    section.setLayoutData(td);
    Composite clientArea = toolkit.createComposite(section);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    clientArea.setLayout(layout);
    section.setClient(clientArea);
    ruleViewer = new TableViewer(clientArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    ruleViewer.getTable().setLinesVisible(true);
    ruleViewer.getTable().setHeaderVisible(true);
    TableColumn column = new TableColumn(ruleViewer.getTable(), SWT.LEFT);
    column.setText("Rule #");
    column.setWidth(60);
    column = new TableColumn(ruleViewer.getTable(), SWT.LEFT);
    column.setText("Rule Name");
    column.setWidth(250);
    toolkit.adapt(ruleViewer.getTable());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 200;
    gd.verticalSpan = 2;
    ruleViewer.getTable().setLayoutData(gd);
    ruleViewer.setContentProvider(new ArrayContentProvider());
    ruleViewer.setLabelProvider(new RuleLabelProvider());
    ruleViewer.setComparator(new RuleComparator());
    ruleViewer.getTable().setSortDirection(SWT.UP);
    final ImageHyperlink linkAdd = toolkit.createImageHyperlink(clientArea, SWT.NONE);
    linkAdd.setText(Messages.get().ExportFileBuilder_Add);
    linkAdd.setImage(SharedIcons.IMG_ADD_OBJECT);
    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;
    linkAdd.setLayoutData(gd);
    linkAdd.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent e) {
            if (rulesCache == null) {
                new ConsoleJob(Messages.get().ExportFileBuilder_EPPLoadJobName, ExportFileBuilder.this, Activator.PLUGIN_ID, null) {

                    @Override
                    protected void runInternal(IProgressMonitor monitor) throws Exception {
                        rulesCache = session.getEventProcessingPolicy().getRules();
                        runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                addRules();
                            }
                        });
                    }

                    @Override
                    protected String getErrorMessage() {
                        return Messages.get().ExportFileBuilder_EPPLoadJobError;
                    }
                }.start();
            } else {
                addRules();
            }
        }
    });
    final ImageHyperlink linkRemove = toolkit.createImageHyperlink(clientArea, SWT.NONE);
    linkRemove.setText(Messages.get().ExportFileBuilder_Remove);
    linkRemove.setImage(SharedIcons.IMG_DELETE_OBJECT);
    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;
    linkRemove.setLayoutData(gd);
    linkRemove.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent e) {
            removeObjects(ruleViewer, rules);
        }
    });
}
Also used : RuleComparator(org.netxms.ui.eclipse.serverconfig.views.helpers.RuleComparator) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Composite(org.eclipse.swt.widgets.Composite) ImageHyperlink(org.eclipse.ui.forms.widgets.ImageHyperlink) Section(org.eclipse.ui.forms.widgets.Section) TableColumn(org.eclipse.swt.widgets.TableColumn) TableWrapData(org.eclipse.ui.forms.widgets.TableWrapData) GridLayout(org.eclipse.swt.layout.GridLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RuleLabelProvider(org.netxms.ui.eclipse.serverconfig.views.helpers.RuleLabelProvider) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TableViewer(org.eclipse.jface.viewers.TableViewer) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)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 HyperlinkAdapter (org.eclipse.ui.forms.events.HyperlinkAdapter)1 HyperlinkEvent (org.eclipse.ui.forms.events.HyperlinkEvent)1 ImageHyperlink (org.eclipse.ui.forms.widgets.ImageHyperlink)1 Section (org.eclipse.ui.forms.widgets.Section)1 TableWrapData (org.eclipse.ui.forms.widgets.TableWrapData)1 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)1 RuleComparator (org.netxms.ui.eclipse.serverconfig.views.helpers.RuleComparator)1 RuleLabelProvider (org.netxms.ui.eclipse.serverconfig.views.helpers.RuleLabelProvider)1