Search in sources :

Example 6 with DataCollectionObject

use of org.netxms.client.datacollection.DataCollectionObject in project netxms by netxms.

the class DataCollectionEditor method editSelectedObject.

/**
 * Edit selected object
 */
private void editSelectedObject() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    DataCollectionObject dco = (DataCollectionObject) selection.getFirstElement();
    DialogData data = null;
    if (!hideModificationWarnings && dco.getTemplateId() != 0) {
        String message = DataCollectionObjectEditor.createModificationWarningMessage(dco);
        if (message != null) {
            data = MessageDialogHelper.openWarningWithCheckbox(getSite().getShell(), "Warning", "Don't show this message again", message);
            hideModificationWarnings = data.getSaveSelection();
        }
    }
    if ((data == null) || data.isOkPressed()) {
        // $NON-NLS-1$
        ExtendedPropertyDialog dlg = ExtendedPropertyDialog.createDialogOn(getSite().getShell(), null, dco, "");
        dlg.createAllPages();
        int result = dlg.open();
        if (((DataCollectionObject) selection.getFirstElement()).isNewItem() && result != SWT.OK) {
            viewer.remove(selection.getFirstElement());
        }
    }
}
Also used : DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) ExtendedPropertyDialog(org.netxms.ui.eclipse.tools.ExtendedPropertyDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DialogData(org.netxms.ui.eclipse.tools.DialogData)

Example 7 with DataCollectionObject

use of org.netxms.client.datacollection.DataCollectionObject in project netxms by netxms.

the class DciComparator 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;
    DataCollectionObject dci1 = (DataCollectionObject) e1;
    DataCollectionObject dci2 = (DataCollectionObject) e2;
    // $NON-NLS-1$
    int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
    switch(column) {
        case DataCollectionEditor.COLUMN_ID:
            result = (int) (dci1.getId() - dci2.getId());
            break;
        case DataCollectionEditor.COLUMN_DESCRIPTION:
            result = dci1.getDescription().compareToIgnoreCase(dci2.getDescription());
            break;
        case DataCollectionEditor.COLUMN_PARAMETER:
            result = dci1.getName().compareToIgnoreCase(dci2.getName());
            break;
        case DataCollectionEditor.COLUMN_INTERVAL:
            result = (int) (dci1.getComparablePollingInterval() - dci2.getComparablePollingInterval());
            break;
        case DataCollectionEditor.COLUMN_RETENTION:
            result = (int) (dci1.getComparableRetentionTime() - dci2.getComparableRetentionTime());
            break;
        case DataCollectionEditor.COLUMN_ORIGIN:
        case DataCollectionEditor.COLUMN_DATATYPE:
        case DataCollectionEditor.COLUMN_STATUS:
        case DataCollectionEditor.COLUMN_TEMPLATE:
            final String text1 = labelProvider.getColumnText(e1, column);
            final String text2 = labelProvider.getColumnText(e2, column);
            if (text1 != null && text2 != null) {
                result = text1.compareToIgnoreCase(text2);
            } else {
                if (text1 == null) {
                    if (text2 == null) {
                        result = 0;
                    } else {
                        result = -1;
                    }
                } else {
                    result = 1;
                }
            }
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 8 with DataCollectionObject

use of org.netxms.client.datacollection.DataCollectionObject in project netxms by netxms.

the class StartDataRecalculation method selectionChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
@Override
public void selectionChanged(IAction action, ISelection selection) {
    Set<DCI> dciList = null;
    if (selection instanceof IStructuredSelection) {
        dciList = new HashSet<DCI>();
        for (Object o : ((IStructuredSelection) selection).toList()) {
            if (o instanceof DciValue) {
                dciList.add(new DCI(((DciValue) o).getNodeId(), ((DciValue) o).getId()));
            } else if (o instanceof DataCollectionObject) {
                dciList.add(new DCI(((DataCollectionObject) o).getNodeId(), ((DataCollectionObject) o).getId()));
            } else {
                dciList = null;
                break;
            }
        }
    }
    objects = dciList;
    action.setEnabled((objects != null) && (objects.size() > 0));
}
Also used : DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) DciValue(org.netxms.client.datacollection.DciValue) DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 9 with DataCollectionObject

use of org.netxms.client.datacollection.DataCollectionObject in project netxms by netxms.

the class ForceDciPoll method selectionChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
@Override
public void selectionChanged(IAction action, ISelection selection) {
    Set<DCI> dciList = null;
    if (selection instanceof IStructuredSelection) {
        dciList = new HashSet<DCI>();
        for (Object o : ((IStructuredSelection) selection).toList()) {
            if (o instanceof DciValue) {
                dciList.add(new DCI(((DciValue) o).getNodeId(), ((DciValue) o).getId()));
            } else if (o instanceof DataCollectionObject) {
                dciList.add(new DCI(((DataCollectionObject) o).getNodeId(), ((DataCollectionObject) o).getId()));
            } else {
                dciList = null;
                break;
            }
        }
    }
    objects = dciList;
    action.setEnabled((objects != null) && (objects.size() > 0));
}
Also used : DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) DciValue(org.netxms.client.datacollection.DciValue) DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 10 with DataCollectionObject

use of org.netxms.client.datacollection.DataCollectionObject in project netxms by netxms.

the class DataCollectionEditor method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    content = new Composite(parent, SWT.NONE);
    content.setLayout(new FormLayout());
    // Create filter area
    filterText = new FilterText(content, SWT.NONE);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    final String[] names = { Messages.get().DataCollectionEditor_ColID, Messages.get().DataCollectionEditor_ColOrigin, Messages.get().DataCollectionEditor_ColDescription, Messages.get().DataCollectionEditor_ColParameter, Messages.get().DataCollectionEditor_ColDataType, Messages.get().DataCollectionEditor_ColPollingInterval, Messages.get().DataCollectionEditor_ColRetentionTime, Messages.get().DataCollectionEditor_ColStatus, Messages.get().DataCollectionEditor_ColThresholds, Messages.get().DataCollectionEditor_ColTemplate };
    final int[] widths = { 60, 100, 250, 200, 90, 90, 90, 100, 200, 150 };
    viewer = new SortableTableViewer(content, names, widths, 0, SWT.UP, SortableTableViewer.DEFAULT_STYLE);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new DciLabelProvider());
    viewer.setComparator(new DciComparator((DciLabelProvider) viewer.getLabelProvider()));
    filter = new DciFilter();
    viewer.addFilter(filter);
    // $NON-NLS-1$
    WidgetHelper.restoreTableViewerSettings(viewer, settings, "DataCollectionEditor");
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null) {
                actionEdit.setEnabled(selection.size() == 1);
                actionDelete.setEnabled(selection.size() > 0);
                actionCopy.setEnabled(selection.size() > 0);
                actionMove.setEnabled(selection.size() > 0);
                actionConvert.setEnabled(selection.size() > 0);
                actionDuplicate.setEnabled(selection.size() > 0);
                Iterator<?> it = selection.iterator();
                boolean canActivate = false;
                boolean canDisable = false;
                while (it.hasNext() && (!canActivate || !canDisable)) {
                    DataCollectionObject dci = (DataCollectionObject) it.next();
                    if (dci.getStatus() != DataCollectionObject.ACTIVE)
                        canActivate = true;
                    if (dci.getStatus() != DataCollectionObject.DISABLED)
                        canDisable = true;
                }
                actionActivate.setEnabled(canActivate);
                actionDisable.setEnabled(canDisable);
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            actionEdit.run();
        }
    });
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            // $NON-NLS-1$
            WidgetHelper.saveTableViewerSettings(viewer, settings, "DataCollectionEditor");
            settings.put("DataCollectionEditor.hideModificationWarnings", hideModificationWarnings);
        }
    });
    // Setup layout
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(filterText);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    viewer.getTable().setLayoutData(fd);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    filterText.setLayoutData(fd);
    createActions();
    contributeToActionBars();
    createPopupMenu();
    filterText.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
            actionShowFilter.setChecked(false);
        }
    });
    // Request server to open data collection configuration
    new ConsoleJob(Messages.get().DataCollectionEditor_OpenJob_Title + object.getObjectName(), this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            dciConfig = session.openDataCollectionConfiguration(object.getObjectId());
            dciConfig.setUserData(viewer);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    viewer.setInput(dciConfig.getItems());
                }
            });
        }

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

                @Override
                public void run() {
                    DataCollectionEditor.this.getViewSite().getPage().hideView(DataCollectionEditor.this);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().DataCollectionEditor_OpenJob_Error + object.getObjectName();
        }
    }.start();
    // Set initial focus to filter input line
    if (actionShowFilter.isChecked())
        filterText.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
    hideModificationWarnings = getBooleanFromSettings("DataCollectionEditor.hideModificationWarnings", false);
    activateContext();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) ExportToCsvAction(org.netxms.ui.eclipse.actions.ExportToCsvAction) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) DciLabelProvider(org.netxms.ui.eclipse.datacollection.views.helpers.DciLabelProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Iterator(java.util.Iterator) FilterText(org.netxms.ui.eclipse.widgets.FilterText) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) FormAttachment(org.eclipse.swt.layout.FormAttachment) DciFilter(org.netxms.ui.eclipse.datacollection.views.helpers.DciFilter) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) DciComparator(org.netxms.ui.eclipse.datacollection.views.helpers.DciComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider)

Aggregations

DataCollectionObject (org.netxms.client.datacollection.DataCollectionObject)13 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 PartInitException (org.eclipse.ui.PartInitException)6 NXCException (org.netxms.client.NXCException)6 AbstractObject (org.netxms.client.objects.AbstractObject)6 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)6 Template (org.netxms.client.objects.Template)4 DciValue (org.netxms.client.datacollection.DciValue)3 AbstractNode (org.netxms.client.objects.AbstractNode)2 Cluster (org.netxms.client.objects.Cluster)2 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)2 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)2 Iterator (java.util.Iterator)1 Action (org.eclipse.jface.action.Action)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1