Search in sources :

Example 11 with DataCollectionObject

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

the class DataCollectionEditor method duplicateItems.

/**
 * Duplicate selected item(s)
 */
private void duplicateItems() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Iterator<?> it = selection.iterator();
    final long[] dciList = new long[selection.size()];
    for (int i = 0; (i < dciList.length) && it.hasNext(); i++) dciList[i] = ((DataCollectionObject) it.next()).getId();
    new ConsoleJob(Messages.get().DataCollectionEditor_DupJob_Title + object.getObjectName(), this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            dciConfig.copyObjects(dciConfig.getNodeId(), dciList);
            dciConfig.close();
            dciConfig.open();
            runInUIThread(new Runnable() {

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

        @Override
        protected String getErrorMessage() {
            return Messages.get().DataCollectionEditor_DupJob_Error + object.getObjectName();
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException)

Example 12 with DataCollectionObject

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

the class DataCollectionEditor method convertToTemplate.

/**
 * Convert selected item(s) to template items
 */
private void convertToTemplate() {
    final ObjectSelectionDialog dlg = new ObjectSelectionDialog(getSite().getShell(), null, ObjectSelectionDialog.createTemplateSelectionFilter());
    dlg.showFilterToolTip(false);
    if (dlg.open() != Window.OK)
        return;
    AbstractObject[] objects = dlg.getSelectedObjects(Template.class);
    if (objects.length == 0)
        return;
    final Template template = (Template) objects[0];
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Iterator<?> it = selection.iterator();
    final long[] dciList = new long[selection.size()];
    for (int i = 0; (i < dciList.length) && it.hasNext(); i++) dciList[i] = ((DataCollectionObject) it.next()).getId();
    new ConsoleJob(Messages.get().DataCollectionEditor_ConvertJob_TitlePrefix + object.getObjectName() + Messages.get().DataCollectionEditor_ConvertJob_TitleSuffix, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(Messages.get(getDisplay()).DataCollectionEditor_ConvertJob_TaskName, 4);
            boolean needApply = true;
            for (long id : template.getChildIdList()) {
                if (id == dciConfig.getNodeId()) {
                    needApply = false;
                    break;
                }
            }
            monitor.worked(1);
            dciConfig.copyObjects(template.getObjectId(), dciList);
            for (long id : dciList) dciConfig.deleteObject(id);
            dciConfig.close();
            monitor.worked(1);
            if (needApply) {
                boolean success = false;
                int retries = 5;
                do {
                    try {
                        session.applyTemplate(template.getObjectId(), dciConfig.getNodeId());
                        success = true;
                    } catch (NXCException e) {
                        if (e.getErrorCode() != RCC.COMPONENT_LOCKED)
                            throw e;
                        Thread.sleep(200);
                    }
                    retries--;
                } while (!success && (retries > 0));
            }
            monitor.worked(1);
            boolean success = false;
            int retries = 5;
            do {
                try {
                    Thread.sleep(500);
                    dciConfig.open();
                    success = true;
                } catch (NXCException e) {
                    if (e.getErrorCode() != RCC.COMPONENT_LOCKED)
                        throw e;
                }
                retries--;
            } while (!success && (retries > 0));
            runInUIThread(new Runnable() {

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

        @Override
        protected String getErrorMessage() {
            return Messages.get().DataCollectionEditor_ConvertJob_ErrorPrefix + object.getObjectName() + Messages.get().DataCollectionEditor_ConvertJob_ErrorSuffix;
        }
    }.start();
}
Also used : DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) Template(org.netxms.client.objects.Template) ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 13 with DataCollectionObject

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

the class DciLabelProvider method getColumnText.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
	 */
@Override
public String getColumnText(Object element, int columnIndex) {
    DataCollectionObject dci = (DataCollectionObject) element;
    switch(columnIndex) {
        case DataCollectionEditor.COLUMN_ID:
            return Long.toString(dci.getId());
        case DataCollectionEditor.COLUMN_ORIGIN:
            return originTexts.get(dci.getOrigin());
        case DataCollectionEditor.COLUMN_DESCRIPTION:
            return dci.getDescription();
        case DataCollectionEditor.COLUMN_PARAMETER:
            return dci.getName();
        case DataCollectionEditor.COLUMN_DATATYPE:
            if (dci instanceof DataCollectionItem)
                return DataCollectionDisplayInfo.getDataTypeName(((DataCollectionItem) dci).getDataType());
            return Messages.get().DciLabelProvider_Table;
        case DataCollectionEditor.COLUMN_INTERVAL:
            if (dci.isUseAdvancedSchedule())
                return Messages.get().DciLabelProvider_CustomSchedule;
            if (dci.getPollingInterval() <= 0)
                return Messages.get().DciLabelProvider_Default;
            return Integer.toString(dci.getPollingInterval());
        case DataCollectionEditor.COLUMN_RETENTION:
            if ((dci.getFlags() & DataCollectionItem.DCF_NO_STORAGE) != 0)
                return Messages.get().DciLabelProvider_None;
            int days = dci.getRetentionTime();
            if (days <= 0)
                return Messages.get().DciLabelProvider_Default;
            return Integer.toString(days) + ((days == 1) ? Messages.get().DciLabelProvider_Day : Messages.get().DciLabelProvider_Days);
        case DataCollectionEditor.COLUMN_STATUS:
            return statusTexts.get(dci.getStatus());
        case DataCollectionEditor.COLUMN_THRESHOLD:
            StringBuilder thresholds = new StringBuilder();
            if ((dci instanceof DataCollectionItem)) {
                ArrayList<Threshold> list = ((DataCollectionItem) dci).getThresholds();
                for (int i = 0; i < list.size(); i++) {
                    Threshold tr = list.get(i);
                    int f = tr.getFunction();
                    StringBuilder text = new StringBuilder(ThresholdLabelProvider.FUNCTIONS[f]);
                    text.append(tr.getSampleCount());
                    // $NON-NLS-1$
                    text.append(") ");
                    if (f != Threshold.F_SCRIPT) {
                        text.append(ThresholdLabelProvider.OPERATIONS[tr.getOperation()]);
                        text.append(' ');
                        text.append(tr.getValue());
                    }
                    thresholds.append(text);
                    if (i < list.size() - 1)
                        // $NON-NLS-1$
                        thresholds.append(", ");
                }
            }
            if ((dci instanceof DataCollectionTable)) {
                List<TableThreshold> list = ((DataCollectionTable) dci).getThresholds();
                for (int i = 0; i < list.size(); i++) {
                    thresholds.append(list.get(i).getConditionAsText());
                    if (i + 1 != list.size())
                        // $NON-NLS-1$
                        thresholds.append(", ");
                }
            }
            return thresholds.toString();
        case DataCollectionEditor.COLUMN_TEMPLATE:
            if (dci.getTemplateId() == 0)
                return null;
            AbstractObject object = session.findObjectById(dci.getTemplateId());
            if (object == null)
                return Messages.get().DciLabelProvider_Unknown;
            if (!(object instanceof Template))
                return object.getObjectName();
            Set<AbstractObject> parents = object.getAllParents(null);
            StringBuilder sb = new StringBuilder();
            for (AbstractObject parent : parents) {
                sb.append(parent.getObjectName());
                // $NON-NLS-1$
                sb.append("/");
            }
            sb.append(object.getObjectName());
            return sb.toString();
    }
    return null;
}
Also used : DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) AbstractObject(org.netxms.client.objects.AbstractObject) DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) TableThreshold(org.netxms.client.datacollection.TableThreshold) DataCollectionTable(org.netxms.client.datacollection.DataCollectionTable) Threshold(org.netxms.client.datacollection.Threshold) TableThreshold(org.netxms.client.datacollection.TableThreshold) Template(org.netxms.client.objects.Template)

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