Search in sources :

Example 1 with DataType

use of org.netxms.client.constants.DataType in project netxms by netxms.

the class TableColumns method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = (Composite) super.createContents(parent);
    dci = editor.getObjectAsTable();
    editor.setCallback(new TableColumnDataProvider());
    columns = new ArrayList<ColumnDefinition>();
    for (ColumnDefinition c : dci.getColumns()) columns.add(new ColumnDefinition(c));
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    Composite columnListArea = new Composite(dialogArea, SWT.NONE);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalSpan = 2;
    columnListArea.setLayoutData(gd);
    layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.INNER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    columnListArea.setLayout(layout);
    new Label(columnListArea, SWT.NONE).setText(Messages.get().TableColumns_Columns);
    columnList = new TableViewer(columnListArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalSpan = 2;
    columnList.getControl().setLayoutData(gd);
    setupColumnList();
    columnList.setInput(columns.toArray());
    Composite leftButtons = new Composite(columnListArea, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.LEFT;
    leftButtons.setLayoutData(gd);
    RowLayout buttonsLayout = new RowLayout(SWT.HORIZONTAL);
    buttonsLayout.marginBottom = 0;
    buttonsLayout.marginLeft = 0;
    buttonsLayout.marginRight = 0;
    buttonsLayout.marginTop = 0;
    buttonsLayout.spacing = WidgetHelper.OUTER_SPACING;
    buttonsLayout.fill = true;
    buttonsLayout.pack = false;
    leftButtons.setLayout(buttonsLayout);
    upButton = new Button(leftButtons, SWT.PUSH);
    upButton.setText(Messages.get().TableColumns_Up);
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    upButton.setLayoutData(rd);
    upButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveSelectionUp();
        }
    });
    downButton = new Button(leftButtons, SWT.PUSH);
    downButton.setText(Messages.get().TableColumns_Down);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    downButton.setLayoutData(rd);
    downButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveSelectionDown();
        }
    });
    Composite buttons = new Composite(columnListArea, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    buttons.setLayoutData(gd);
    buttonsLayout = new RowLayout(SWT.HORIZONTAL);
    buttonsLayout.marginBottom = 0;
    buttonsLayout.marginLeft = 0;
    buttonsLayout.marginRight = 0;
    buttonsLayout.marginTop = 0;
    buttonsLayout.spacing = WidgetHelper.OUTER_SPACING;
    buttonsLayout.fill = true;
    buttonsLayout.pack = false;
    buttons.setLayout(buttonsLayout);
    queryButton = new Button(buttons, SWT.PUSH);
    queryButton.setText("&Query...");
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    queryButton.setLayoutData(rd);
    queryButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            queryColumns();
        }
    });
    addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().TableColumns_Add);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addButton.setLayoutData(rd);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            addColumn();
        }
    });
    modifyButton = new Button(buttons, SWT.PUSH);
    modifyButton.setText(Messages.get().TableColumns_Edit);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    modifyButton.setLayoutData(rd);
    modifyButton.setEnabled(false);
    modifyButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            editColumn();
        }
    });
    deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().TableColumns_Delete);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.setEnabled(false);
    deleteButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteColumns();
        }
    });
    /**
     * Selection change listener for column list **
     */
    columnList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            deleteButton.setEnabled(selection.size() > 0);
            if (selection.size() == 1) {
                modifyButton.setEnabled(true);
                upButton.setEnabled(columns.indexOf(selection.getFirstElement()) > 0);
                downButton.setEnabled(columns.indexOf(selection.getFirstElement()) < columns.size() - 1);
            } else {
                modifyButton.setEnabled(false);
                upButton.setEnabled(false);
                downButton.setEnabled(false);
            }
        }
    });
    columnList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editColumn();
        }
    });
    final DataCollectionObjectListener listener = new DataCollectionObjectListener() {

        @Override
        public void onSelectItem(int origin, String name, String description, DataType dataType) {
        }

        @Override
        public void onSelectTable(int origin, String name, String description) {
            if (origin == DataCollectionObject.AGENT)
                updateColumnsFromAgent(name, false, null);
        }
    };
    dialogArea.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            editor.removeListener(listener);
        }
    });
    editor.addListener(listener);
    return dialogArea;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ColumnDefinition(org.netxms.client.datacollection.ColumnDefinition) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) DataCollectionObjectListener(org.netxms.ui.eclipse.datacollection.api.DataCollectionObjectListener) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataType(org.netxms.client.constants.DataType) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with DataType

use of org.netxms.client.constants.DataType in project netxms by netxms.

the class ShowDataComparisonChart method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    if (currentSelection != null) {
        // $NON-NLS-1$
        String id = Long.toString(uniqueId++) + "&" + Integer.toString(getChartType());
        for (int i = 0; i < currentSelection.length; i++) {
            long dciId = 0, nodeId = 0;
            int source = 0;
            DataType dataType = DataType.INT32;
            String name = null, description = null;
            try {
                if (currentSelection[i] instanceof DciValue) {
                    dciId = ((DciValue) currentSelection[i]).getId();
                    nodeId = ((DciValue) currentSelection[i]).getNodeId();
                    source = ((DciValue) currentSelection[i]).getSource();
                    dataType = ((DciValue) currentSelection[i]).getDataType();
                    // $NON-NLS-1$
                    name = URLEncoder.encode(((DciValue) currentSelection[i]).getName(), "UTF-8");
                    // $NON-NLS-1$
                    description = URLEncoder.encode(((DciValue) currentSelection[i]).getDescription(), "UTF-8");
                } else if (currentSelection[i] instanceof DataCollectionItem) {
                    dciId = ((DataCollectionItem) currentSelection[i]).getId();
                    nodeId = ((DataCollectionItem) currentSelection[i]).getNodeId();
                    source = ((DataCollectionItem) currentSelection[i]).getOrigin();
                    dataType = ((DataCollectionItem) currentSelection[i]).getDataType();
                    // $NON-NLS-1$
                    name = URLEncoder.encode(((DataCollectionItem) currentSelection[i]).getName(), "UTF-8");
                    // $NON-NLS-1$
                    description = URLEncoder.encode(((DataCollectionItem) currentSelection[i]).getDescription(), "UTF-8");
                }
            } catch (UnsupportedEncodingException e) {
                description = Messages.get().ShowDataComparisonChart_DescriptionUnavailable;
            }
            id += // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            "&" + Long.toString(nodeId) + "@" + Long.toString(dciId) + "@" + Integer.toString(source) + "@" + Integer.toString(dataType.getValue()) + "@" + name + "@" + // $NON-NLS-1$ //$NON-NLS-2$
            description;
        }
        try {
            window.getActivePage().showView(DataComparisonView.ID, id, IWorkbenchPage.VIEW_ACTIVATE);
        } catch (PartInitException e) {
            MessageDialogHelper.openError(window.getShell(), Messages.get().ShowDataComparisonChart_Error, String.format(Messages.get().ShowDataComparisonChart_ErrorOpeningView, e.getMessage()));
        } catch (IllegalArgumentException e) {
            MessageDialogHelper.openError(window.getShell(), Messages.get().ShowDataComparisonChart_14, String.format(Messages.get().ShowDataComparisonChart_15, e.getMessage()));
        }
    }
}
Also used : DciValue(org.netxms.client.datacollection.DciValue) DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) DataType(org.netxms.client.constants.DataType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PartInitException(org.eclipse.ui.PartInitException)

Example 3 with DataType

use of org.netxms.client.constants.DataType in project netxms by netxms.

the class NXCSession method parseDataRows.

/**
 * Parse data from raw message CMD_DCI_DATA.
 * This method is intended for calling by client internal methods only. It made public to
 * allow access from client extensions.
 *
 * @param input Raw data
 * @param data  Data object to add rows to
 * @return number of received data rows
 */
public int parseDataRows(final byte[] input, DciData data) {
    final NXCPDataInputStream inputStream = new NXCPDataInputStream(input);
    int rows = 0;
    DciDataRow row = null;
    try {
        // DCI ID
        inputStream.skipBytes(4);
        rows = inputStream.readInt();
        final DataType dataType = DataType.getByValue(inputStream.readInt());
        data.setDataType(dataType);
        // padding
        inputStream.skipBytes(4);
        for (int i = 0; i < rows; i++) {
            // convert to milliseconds
            long timestamp = inputStream.readUnsignedInt() * 1000;
            Object value;
            switch(dataType) {
                case INT32:
                    value = new Long(inputStream.readInt());
                    break;
                case UINT32:
                case COUNTER32:
                    value = new Long(inputStream.readUnsignedInt());
                    break;
                case INT64:
                case UINT64:
                case COUNTER64:
                    // padding
                    inputStream.skipBytes(4);
                    value = new Long(inputStream.readLong());
                    break;
                case FLOAT:
                    // padding
                    inputStream.skipBytes(4);
                    value = new Double(inputStream.readDouble());
                    break;
                case STRING:
                    StringBuilder sb = new StringBuilder(256);
                    int count;
                    for (count = MAX_DCI_STRING_VALUE_LENGTH; count > 0; count--) {
                        char ch = inputStream.readChar();
                        if (ch == 0) {
                            count--;
                            break;
                        }
                        sb.append(ch);
                    }
                    inputStream.skipBytes(count * 2);
                    value = sb.toString();
                    break;
                default:
                    value = null;
                    break;
            }
            if (timestamp > 0) {
                row = new DciDataRow(new Date(timestamp), value);
                data.addDataRow(row);
            } else {
                // raw value for previous entry
                if (row != null)
                    row.setRawValue(value);
            }
        }
    } catch (IOException e) {
    }
    inputStream.close();
    return rows;
}
Also used : DciDataRow(org.netxms.client.datacollection.DciDataRow) AtomicLong(java.util.concurrent.atomic.AtomicLong) DataType(org.netxms.client.constants.DataType) DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject) WinPerfObject(org.netxms.client.datacollection.WinPerfObject) AbstractUserObject(org.netxms.client.users.AbstractUserObject) AbstractObject(org.netxms.client.objects.AbstractObject) EventObject(org.netxms.client.events.EventObject) UnknownObject(org.netxms.client.objects.UnknownObject) GenericObject(org.netxms.client.objects.GenericObject) IOException(java.io.IOException) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint) Date(java.util.Date) NXCPDataInputStream(org.netxms.base.NXCPDataInputStream)

Example 4 with DataType

use of org.netxms.client.constants.DataType in project netxms by netxms.

the class TableItemComparator 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) {
    // $NON-NLS-1$
    final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
    final DataType format = (column < formats.length) ? formats[column] : DataType.STRING;
    final String value1 = ((TableRow) e1).get(column).getValue();
    final String value2 = ((TableRow) e2).get(column).getValue();
    int result;
    switch(format) {
        case STRING:
            result = value1.compareToIgnoreCase(value2);
            break;
        case INT32:
            try {
                result = Integer.parseInt(value1) - Integer.parseInt(value2);
            } catch (NumberFormatException e) {
                result = 0;
            }
            break;
        case UINT32:
        case INT64:
        case UINT64:
        case COUNTER32:
        case COUNTER64:
            try {
                result = Long.signum(Long.parseLong(value1) - Long.parseLong(value2));
            } catch (NumberFormatException e) {
                result = 0;
            }
            break;
        case FLOAT:
            try {
                result = (int) Math.signum(Double.parseDouble(value1) - Double.parseDouble(value2));
            } catch (NumberFormatException e) {
                result = 0;
            }
            break;
        default:
            result = 0;
            break;
    }
    return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : DataType(org.netxms.client.constants.DataType) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer)

Example 5 with DataType

use of org.netxms.client.constants.DataType in project netxms by netxms.

the class SummaryTableItemComparator 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) {
    // $NON-NLS-1$
    final int column = (Integer) ((SortableTreeViewer) viewer).getTree().getSortColumn().getData("ID");
    final DataType format = (column < formats.length) ? formats[column] : DataType.STRING;
    final String value1 = getCellValue((TableRow) e1, column);
    final String value2 = getCellValue((TableRow) e2, column);
    int result;
    switch(format) {
        case INT32:
            result = safeParseInt(value1) - safeParseInt(value2);
            break;
        case UINT32:
        case COUNTER32:
        case INT64:
        case UINT64:
        case COUNTER64:
            result = Long.signum(safeParseLong(value1) - safeParseLong(value2));
            break;
        case FLOAT:
            result = (int) Math.signum(safeParseDouble(value1) - safeParseDouble(value2));
            break;
        default:
            result = value1.compareToIgnoreCase(value2);
            break;
    }
    return (((SortableTreeViewer) viewer).getTree().getSortDirection() == SWT.UP) ? result : -result;
}
Also used : SortableTreeViewer(org.netxms.ui.eclipse.widgets.SortableTreeViewer) DataType(org.netxms.client.constants.DataType)

Aggregations

DataType (org.netxms.client.constants.DataType)6 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Date (java.util.Date)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowData (org.eclipse.swt.layout.RowData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1