Search in sources :

Example 6 with TableRow

use of org.netxms.client.TableRow in project netxms by netxms.

the class TableLabelProvider method getForeground.

/* (non-Javadoc)
    * @see org.eclipse.jface.viewers.ITableColorProvider#getForeground(java.lang.Object, int)
    */
@Override
public Color getForeground(Object element, int columnIndex) {
    TableRow row = (TableRow) element;
    if (columnIndex >= row.size())
        return null;
    TableCell cell = row.get(columnIndex);
    return (cell.getStatus() >= 0) && (cell.getStatus() < FOREGROUND_COLORS.length) ? FOREGROUND_COLORS[cell.getStatus()] : null;
}
Also used : TableCell(org.netxms.client.TableCell) TableRow(org.netxms.client.TableRow)

Example 7 with TableRow

use of org.netxms.client.TableRow in project netxms by netxms.

the class TableLabelProvider method getBackground.

/* (non-Javadoc)
    * @see org.eclipse.jface.viewers.ITableColorProvider#getBackground(java.lang.Object, int)
    */
@Override
public Color getBackground(Object element, int columnIndex) {
    TableRow row = (TableRow) element;
    if (columnIndex >= row.size())
        return null;
    TableCell cell = row.get(columnIndex);
    return (cell.getStatus() > 0) ? StatusDisplayInfo.getStatusColor(cell.getStatus()) : null;
}
Also used : TableCell(org.netxms.client.TableCell) TableRow(org.netxms.client.TableRow)

Example 8 with TableRow

use of org.netxms.client.TableRow in project netxms by netxms.

the class AlarmLogViewer method showIssue.

/**
 * Show in web browser helpdesk ticket (issue) linked to selected alarm
 */
private void showIssue() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final long id = Long.parseLong(((TableRow) selection.getFirstElement()).get(0).getValue());
    new ConsoleJob("Show helpdesk ticket", this, Activator.PLUGIN_ID, JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final String url = session.getHelpdeskIssueUrl(id);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    try {
                        final IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser();
                        browser.openURL(new URL(url));
                    } catch (Exception e) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        Activator.logError("Exception in AlarmList.showIssue (url=\"" + url + "\")", e);
                        MessageDialogHelper.openError(getSite().getShell(), "Error", "Internal error: unable to open web browser");
                    }
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return "Cannot get URL for helpdesk ticket";
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TableRow(org.netxms.client.TableRow) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) IOException(java.io.IOException) NXCException(org.netxms.client.NXCException) URL(java.net.URL)

Example 9 with TableRow

use of org.netxms.client.TableRow in project netxms by netxms.

the class ObjectSelectionProvider method getSelection.

/* (non-Javadoc)
    * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
    */
@Override
public ISelection getSelection() {
    IStructuredSelection selection = (IStructuredSelection) parent.getSelection();
    if ((selection == null) || selection.isEmpty())
        return selection;
    List<AbstractObject> objects = new ArrayList<AbstractObject>(selection.size());
    for (Object o : selection.toList()) {
        if (!(o instanceof TableRow))
            continue;
        AbstractObject object = session.findObjectById(((TableRow) o).getObjectId());
        if (object != null)
            objects.add(object);
    }
    return new StructuredSelection(objects);
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject) TableRow(org.netxms.client.TableRow) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 10 with TableRow

use of org.netxms.client.TableRow in project netxms by netxms.

the class SummaryTableWidget method update.

/**
 * Update viewer with fresh table data
 *
 * @param table table
 */
public void update(final Table table) {
    if (!viewer.isInitialized()) {
        final String[] names = table.getColumnDisplayNames();
        final int[] widths = new int[names.length];
        Arrays.fill(widths, 100);
        viewer.createColumns(names, widths, 0, SWT.UP);
        final IDialogSettings settings = Activator.getDefault().getDialogSettings();
        // $NON-NLS-1$
        final String key = viewPart.getViewSite().getId() + ".SummaryTable." + Integer.toString(tableId);
        WidgetHelper.restoreTreeViewerSettings(viewer, settings, key);
        // $NON-NLS-1$
        String value = settings.get(key + ".useMultipliers");
        if (value != null)
            useMultipliers = Boolean.parseBoolean(value);
        labelProvider.setUseMultipliers(useMultipliers);
        viewer.getControl().addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                WidgetHelper.saveTreeViewerSettings(viewer, settings, key);
                // $NON-NLS-1$
                settings.put(key + ".useMultipliers", useMultipliers);
            }
        });
        viewer.setComparator(new SummaryTableItemComparator(table));
    }
    labelProvider.setColumnDataTypes(table.getColumnDataTypes());
    if (sortingColumnList != null && sortingColumnList.size() > 0) {
        List<SortItem> sortItem = new ArrayList<SortItem>();
        for (int i = 0; i < sortingColumnList.size(); i++) {
            boolean isDesc = sortingColumnList.get(i).charAt(0) == '>' ? true : false;
            int index = table.getColumnIndex(sortingColumnList.get(i).substring(1));
            if (index >= 0) {
                sortItem.add(new SortItem(index, isDesc));
            }
        }
        // find index of columns to compare and desc or asc
        final List<SortItem> sortItemFin = sortItem;
        table.sort(new Comparator<TableRow>() {

            public int compare(TableRow row1, TableRow row2) {
                // compare lines
                int result = 0;
                int i = 0;
                while (result == 0 && i < sortItemFin.size()) {
                    result = compareItem(row1, row2, sortItemFin.get(i).colIndex, sortItemFin.get(i).isDesc);
                    i++;
                }
                return result;
            }

            private int compareItem(TableRow row1, TableRow row2, int index, boolean sortDesc) {
                TableCell c1 = row1.get(index);
                TableCell c2 = row2.get(index);
                String s1 = (c1 != null) ? c1.getValue() : "";
                String s2 = (c2 != null) ? c2.getValue() : "";
                int result = 0;
                try {
                    double value1 = Double.parseDouble(s1);
                    double value2 = Double.parseDouble(s2);
                    result = Double.compare(value1, value2);
                } catch (NumberFormatException e) {
                    result = s1.compareToIgnoreCase(s2);
                }
                return sortDesc ? -result : result;
            }
        });
        viewer.setComparator(null);
    }
    if (showLineCount > 0)
        viewer.setInput(table.getFirstRows(showLineCount));
    else
        viewer.setInput(table);
    viewer.expandAll();
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SummaryTableItemComparator(org.netxms.ui.eclipse.datacollection.widgets.internal.SummaryTableItemComparator) ArrayList(java.util.ArrayList) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Point(org.eclipse.swt.graphics.Point) TableCell(org.netxms.client.TableCell) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) TableRow(org.netxms.client.TableRow)

Aggregations

TableRow (org.netxms.client.TableRow)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 ArrayList (java.util.ArrayList)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 TableCell (org.netxms.client.TableCell)4 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)4 IOException (java.io.IOException)3 Point (org.eclipse.swt.graphics.Point)3 NXCException (org.netxms.client.NXCException)3 AbstractObject (org.netxms.client.objects.AbstractObject)3 NXCSession (org.netxms.client.NXCSession)2 Table (org.netxms.client.Table)2 URL (java.net.URL)1 Date (java.util.Date)1 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 PartInitException (org.eclipse.ui.PartInitException)1 IWebBrowser (org.eclipse.ui.browser.IWebBrowser)1