Search in sources :

Example 6 with RuleEditor

use of org.netxms.ui.eclipse.epp.widgets.RuleEditor in project netxms by netxms.

the class EventProcessingPolicyEditor method savePolicy.

/**
 * Save policy to server
 */
private void savePolicy() {
    actionSave.setEnabled(false);
    new ConsoleJob(Messages.get().EventProcessingPolicyEditor_SaveJob_Title, this, Activator.PLUGIN_ID, JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            EventProcessingPolicy newPolicy = new EventProcessingPolicy(ruleEditors.size());
            for (RuleEditor editor : ruleEditors) newPolicy.addRule(editor.getRule());
            session.saveEventProcessingPolicy(policy);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    modified = false;
                    firePropertyChange(PROP_DIRTY);
                }
            });
        }

        @Override
        protected void jobFinalize() {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    actionSave.setEnabled(modified);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().EventProcessingPolicyEditor_SaveJob_Error;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) EventProcessingPolicy(org.netxms.client.events.EventProcessingPolicy) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) RuleEditor(org.netxms.ui.eclipse.epp.widgets.RuleEditor)

Example 7 with RuleEditor

use of org.netxms.ui.eclipse.epp.widgets.RuleEditor in project netxms by netxms.

the class EventProcessingPolicyEditor method initPolicyEditor.

/**
 * Init policy editor
 */
private void initPolicyEditor() {
    for (EventProcessingPolicyRule rule : policy.getRules()) {
        if (isRuleVisible(rule)) {
            RuleEditor editor = new RuleEditor(dataArea, rule, this);
            ruleEditors.add(editor);
            GridData gd = new GridData();
            gd.horizontalAlignment = SWT.FILL;
            gd.grabExcessHorizontalSpace = true;
            editor.setLayoutData(gd);
        }
    }
    dataArea.layout();
    Rectangle r = scroller.getClientArea();
    scroller.setMinSize(dataArea.computeSize(r.width, SWT.DEFAULT));
}
Also used : EventProcessingPolicyRule(org.netxms.client.events.EventProcessingPolicyRule) GridData(org.eclipse.swt.layout.GridData) Rectangle(org.eclipse.swt.graphics.Rectangle) RuleEditor(org.netxms.ui.eclipse.epp.widgets.RuleEditor)

Example 8 with RuleEditor

use of org.netxms.ui.eclipse.epp.widgets.RuleEditor in project netxms by netxms.

the class EventProcessingPolicyEditor method insertRule.

/**
 * Insert new rule at given position
 *
 * @param position
 */
private void insertRule(int position) {
    EventProcessingPolicyRule rule = new EventProcessingPolicyRule();
    rule.setRuleNumber(position + 1);
    policy.insertRule(rule, position);
    RuleEditor editor = new RuleEditor(dataArea, rule, this);
    ruleEditors.add(position, editor);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    editor.setLayoutData(gd);
    for (int i = position + 1; i < ruleEditors.size(); i++) ruleEditors.get(i).setRuleNumber(i + 1);
    if (position < ruleEditors.size() - 1) {
        RuleEditor anchor = null;
        for (int i = position + 1; i < ruleEditors.size(); i++) if (!ruleEditors.get(i).isDisposed()) {
            anchor = ruleEditors.get(i);
            break;
        }
        if (anchor != null)
            editor.moveAbove(anchor);
    }
    updateEditorAreaLayout();
    setModified(true);
}
Also used : EventProcessingPolicyRule(org.netxms.client.events.EventProcessingPolicyRule) GridData(org.eclipse.swt.layout.GridData) RuleEditor(org.netxms.ui.eclipse.epp.widgets.RuleEditor)

Example 9 with RuleEditor

use of org.netxms.ui.eclipse.epp.widgets.RuleEditor in project netxms by netxms.

the class EventProcessingPolicyEditor method createPartControl.

/*
    * (non-Javadoc)
    * 
    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
    */
@Override
public void createPartControl(Composite parent) {
    session = (NXCSession) ConsoleSharedData.getSession();
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    // $NON-NLS-1$
    filterEnabled = settings.getBoolean("EventProcessingPolicyEditor.filterEnabled");
    // Initiate loading of required plugins if they was not loaded yet
    try {
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(new EventTemplate(0), "org.eclipse.ui.model.IWorkbenchAdapter");
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(new ServerAction(0), "org.eclipse.ui.model.IWorkbenchAdapter");
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(session.getTopLevelObjects()[0], "org.eclipse.ui.model.IWorkbenchAdapter");
    } catch (Exception e) {
    }
    // $NON-NLS-1$
    imageStop = Activator.getImageDescriptor("icons/stop.png").createImage();
    // $NON-NLS-1$
    imageAlarm = Activator.getImageDescriptor("icons/alarm.png").createImage();
    // $NON-NLS-1$
    imageSituation = Activator.getImageDescriptor("icons/situation.gif").createImage();
    // $NON-NLS-1$
    imageExecute = Activator.getImageDescriptor("icons/execute.png").createImage();
    // $NON-NLS-1$
    imageTerminate = Activator.getImageDescriptor("icons/terminate.png").createImage();
    imageCollapse = SharedIcons.COLLAPSE.createImage();
    imageExpand = SharedIcons.EXPAND.createImage();
    imageEdit = SharedIcons.EDIT.createImage();
    parent.setLayout(new FormLayout());
    // Create filter area
    filterControl = new FilterText(parent, SWT.NONE);
    filterControl.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    filterControl.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
        }
    });
    scroller = new ScrolledComposite(parent, SWT.V_SCROLL);
    dataArea = new Composite(scroller, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    dataArea.setLayout(layout);
    dataArea.setBackground(BACKGROUND_COLOR);
    scroller.setContent(dataArea);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);
    scroller.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            Rectangle r = scroller.getClientArea();
            scroller.setMinSize(dataArea.computeSize(r.width, SWT.DEFAULT));
        }
    });
    // Setup layout
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(filterControl);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    scroller.setLayoutData(fd);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    filterControl.setLayoutData(fd);
    normalFont = JFaceResources.getDefaultFont();
    boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            processSessionNotification(n);
        }
    };
    session.addListener(sessionListener);
    selection = new TreeSet<RuleEditor>(new Comparator<RuleEditor>() {

        @Override
        public int compare(RuleEditor arg0, RuleEditor arg1) {
            return arg0.getRuleNumber() - arg1.getRuleNumber();
        }
    });
    createActions();
    contributeToActionBars();
    openEventProcessingPolicy();
    activateContext();
    // Set initial focus to filter input line
    if (filterEnabled)
        filterControl.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ServerAction(org.netxms.client.ServerAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) EventTemplate(org.netxms.client.events.EventTemplate) Rectangle(org.eclipse.swt.graphics.Rectangle) Comparator(java.util.Comparator) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FilterText(org.netxms.ui.eclipse.widgets.FilterText) SessionListener(org.netxms.client.SessionListener) RuleEditor(org.netxms.ui.eclipse.epp.widgets.RuleEditor) ControlEvent(org.eclipse.swt.events.ControlEvent) ServerAction(org.netxms.client.ServerAction) SessionNotification(org.netxms.client.SessionNotification) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 10 with RuleEditor

use of org.netxms.ui.eclipse.epp.widgets.RuleEditor in project netxms by netxms.

the class EventProcessingPolicyEditor method addToSelection.

/**
 * Add rule to selection
 *
 * @param e rule editor
 */
public void addToSelection(RuleEditor e, boolean allFromPrevSelection) {
    if (allFromPrevSelection && (lastSelectedRule != -1)) {
        int direction = Integer.signum(e.getRuleNumber() - lastSelectedRule);
        for (int i = lastSelectedRule + direction; i != e.getRuleNumber(); i += direction) {
            RuleEditor r = ruleEditors.get(i - 1);
            selection.add(r);
            r.setSelected(true);
        }
    }
    selection.add(e);
    e.setSelected(true);
    lastSelectedRule = e.getRuleNumber();
    onSelectionChange();
}
Also used : RuleEditor(org.netxms.ui.eclipse.epp.widgets.RuleEditor)

Aggregations

RuleEditor (org.netxms.ui.eclipse.epp.widgets.RuleEditor)12 GridData (org.eclipse.swt.layout.GridData)4 EventProcessingPolicyRule (org.netxms.client.events.EventProcessingPolicyRule)4 Rectangle (org.eclipse.swt.graphics.Rectangle)2 EventProcessingPolicy (org.netxms.client.events.EventProcessingPolicy)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Action (org.eclipse.jface.action.Action)1 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 ControlAdapter (org.eclipse.swt.events.ControlAdapter)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 FormAttachment (org.eclipse.swt.layout.FormAttachment)1 FormData (org.eclipse.swt.layout.FormData)1 FormLayout (org.eclipse.swt.layout.FormLayout)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1