Search in sources :

Example 1 with DciSummaryTableDescriptor

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

the class SummaryTablesDynamicMenu method fill.

/* (non-Javadoc)
	 * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Menu, int)
	 */
@Override
public void fill(Menu menu, int index) {
    final Object selection = evalService.getCurrentState().getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
    if ((selection == null) || !(selection instanceof IStructuredSelection))
        return;
    final AbstractObject baseObject = (AbstractObject) ((IStructuredSelection) selection).getFirstElement();
    if (!(baseObject instanceof Container) && !(baseObject instanceof Cluster) && !(baseObject instanceof ServiceRoot) && !(baseObject instanceof Subnet) && !(baseObject instanceof Zone) && !(baseObject instanceof EntireNetwork))
        return;
    final Menu tablesMenu = new Menu(menu);
    DciSummaryTableDescriptor[] tables = SummaryTablesCache.getInstance().getTables();
    Arrays.sort(tables, new Comparator<DciSummaryTableDescriptor>() {

        @Override
        public int compare(DciSummaryTableDescriptor arg0, DciSummaryTableDescriptor arg1) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            return arg0.getMenuPath().replace("&", "").compareToIgnoreCase(arg1.getMenuPath().replace("&", ""));
        }
    });
    Map<String, Menu> menus = new HashMap<String, Menu>();
    int added = 0;
    for (int i = 0; i < tables.length; i++) {
        if (tables[i].getMenuPath().isEmpty())
            continue;
        // $NON-NLS-1$
        String[] path = tables[i].getMenuPath().split("\\-\\>");
        Menu rootMenu = tablesMenu;
        for (int j = 0; j < path.length - 1; j++) {
            // $NON-NLS-1$ //$NON-NLS-2$
            String key = path[j].replace("&", "");
            Menu currMenu = menus.get(key);
            if (currMenu == null) {
                currMenu = new Menu(rootMenu);
                MenuItem item = new MenuItem(rootMenu, SWT.CASCADE);
                item.setText(path[j]);
                item.setMenu(currMenu);
                menus.put(key, currMenu);
            }
            rootMenu = currMenu;
        }
        final MenuItem item = new MenuItem(rootMenu, SWT.PUSH);
        item.setText(path[path.length - 1]);
        item.setData(tables[i]);
        item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                queryTable(baseObject.getObjectId(), ((DciSummaryTableDescriptor) item.getData()).getId());
            }
        });
        added++;
    }
    if (added > 0) {
        MenuItem tablesMenuItem = new MenuItem(menu, SWT.CASCADE, index);
        tablesMenuItem.setText(Messages.get().SummaryTablesDynamicMenu_MenuName);
        tablesMenuItem.setMenu(tablesMenu);
    } else {
        tablesMenu.dispose();
    }
}
Also used : HashMap(java.util.HashMap) Zone(org.netxms.client.objects.Zone) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Cluster(org.netxms.client.objects.Cluster) MenuItem(org.eclipse.swt.widgets.MenuItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EntireNetwork(org.netxms.client.objects.EntireNetwork) DciSummaryTableDescriptor(org.netxms.client.datacollection.DciSummaryTableDescriptor) ServiceRoot(org.netxms.client.objects.ServiceRoot) Container(org.netxms.client.objects.Container) AbstractObject(org.netxms.client.objects.AbstractObject) SelectionEvent(org.eclipse.swt.events.SelectionEvent) AbstractObject(org.netxms.client.objects.AbstractObject) Menu(org.eclipse.swt.widgets.Menu) Subnet(org.netxms.client.objects.Subnet)

Example 2 with DciSummaryTableDescriptor

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

the class SummaryTableManager method refresh.

/**
 * Refresh viewer
 */
private void refresh() {
    new // $NON-NLS-1$
    ConsoleJob(// $NON-NLS-1$
    "Get configured DCI summary tables", // $NON-NLS-1$
    this, // $NON-NLS-1$
    Activator.PLUGIN_ID, // $NON-NLS-1$
    null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<DciSummaryTableDescriptor> list = session.listDciSummaryTables();
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    descriptors.clear();
                    for (DciSummaryTableDescriptor d : list) descriptors.put(d.getId(), d);
                    viewer.setInput(descriptors.values().toArray());
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SummaryTableManager_JobError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) PartInitException(org.eclipse.ui.PartInitException) DciSummaryTableDescriptor(org.netxms.client.datacollection.DciSummaryTableDescriptor)

Example 3 with DciSummaryTableDescriptor

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

the class SummaryTableManager method editSummaryTable.

/**
 * Edit existing dataset
 */
private void editSummaryTable() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    final DciSummaryTableDescriptor d = (DciSummaryTableDescriptor) selection.getFirstElement();
    new ConsoleJob(Messages.get().SummaryTableManager_ReadJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final DciSummaryTable t = session.getDciSummaryTable(d.getId());
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    PropertyDialog dlg = PropertyDialog.createDialogOn(getSite().getShell(), null, t);
                    dlg.getShell().setText(Messages.get().SummaryTableManager_TitleEdit);
                    dlg.open();
                    d.updateFromTable(t);
                    viewer.update(d, null);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().SummaryTableManager_ReadJobError;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DciSummaryTable(org.netxms.client.datacollection.DciSummaryTable) PropertyDialog(org.eclipse.ui.internal.dialogs.PropertyDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) DciSummaryTableDescriptor(org.netxms.client.datacollection.DciSummaryTableDescriptor) PartInitException(org.eclipse.ui.PartInitException)

Example 4 with DciSummaryTableDescriptor

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

the class SummaryTableSelectionDialog method createDialogArea.

/* (non-Javadoc)
    * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
    */
@Override
protected Control createDialogArea(Composite parent) {
    final Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    dialogArea.setLayout(layout);
    viewer = new TableViewer(dialogArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return ((DciSummaryTableDescriptor) element).getTitle() + " (" + ((DciSummaryTableDescriptor) element).getMenuPath().replace("&", "") + ")";
        }
    });
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            String n1 = ((DciSummaryTableDescriptor) e1).getTitle() + " (" + ((DciSummaryTableDescriptor) e1).getMenuPath().replace("&", "") + ")";
            String n2 = ((DciSummaryTableDescriptor) e2).getTitle() + " (" + ((DciSummaryTableDescriptor) e2).getMenuPath().replace("&", "") + ")";
            return n1.compareToIgnoreCase(n2);
        }
    });
    viewer.setInput(SummaryTablesCache.getInstance().getTables());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 400;
    viewer.getControl().setLayoutData(gd);
    return dialogArea;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider) DciSummaryTableDescriptor(org.netxms.client.datacollection.DciSummaryTableDescriptor)

Example 5 with DciSummaryTableDescriptor

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

the class ExportFileBuilder method doExport.

/**
 * Do export operation and call completion handler when done
 *
 * @param completionHandler
 */
private void doExport(final ExportCompletionHandler completionHandler) {
    final long[] eventList = new long[events.size()];
    int i = 0;
    for (EventObject o : events.values()) eventList[i++] = o.getCode();
    final long[] templateList = new long[templates.size()];
    i = 0;
    for (Template t : templates.values()) templateList[i++] = t.getObjectId();
    final long[] trapList = new long[traps.size()];
    i = 0;
    for (SnmpTrap t : traps.values()) trapList[i++] = t.getId();
    final UUID[] ruleList = new UUID[rules.size()];
    i = 0;
    for (EventProcessingPolicyRule r : rules.values()) ruleList[i++] = r.getGuid();
    final long[] scriptList = new long[scripts.size()];
    i = 0;
    for (Script s : scripts.values()) scriptList[i++] = s.getId();
    final long[] toolList = new long[tools.size()];
    i = 0;
    for (ObjectTool t : tools.values()) toolList[i++] = t.getId();
    final long[] summaryTableList = new long[summaryTables.size()];
    i = 0;
    for (DciSummaryTableDescriptor t : summaryTables.values()) summaryTableList[i++] = t.getId();
    final long[] actionList = new long[actions.size()];
    i = 0;
    for (ServerAction a : actions.values()) actionList[i++] = a.getId();
    final String descriptionText = description.getText();
    new ConsoleJob(Messages.get().ExportFileBuilder_ExportJobName, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final String xml = session.exportConfiguration(descriptionText, eventList, trapList, templateList, ruleList, scriptList, toolList, summaryTableList, actionList);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    completionHandler.exportCompleted(xml);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ExportFileBuilder_ExportJobError;
        }
    }.start();
}
Also used : EventProcessingPolicyRule(org.netxms.client.events.EventProcessingPolicyRule) Script(org.netxms.client.Script) SnmpTrap(org.netxms.client.snmp.SnmpTrap) EventObject(org.netxms.client.events.EventObject) DciSummaryTableDescriptor(org.netxms.client.datacollection.DciSummaryTableDescriptor) Template(org.netxms.client.objects.Template) EventTemplate(org.netxms.client.events.EventTemplate) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) UUID(java.util.UUID) ServerAction(org.netxms.client.ServerAction) ObjectTool(org.netxms.client.objecttools.ObjectTool)

Aggregations

DciSummaryTableDescriptor (org.netxms.client.datacollection.DciSummaryTableDescriptor)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 PartInitException (org.eclipse.ui.PartInitException)3 DciSummaryTable (org.netxms.client.datacollection.DciSummaryTable)3 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)3 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 PropertyDialog (org.eclipse.ui.internal.dialogs.PropertyDialog)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 UUID (java.util.UUID)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1