Search in sources :

Example 1 with DashboardElement

use of org.netxms.client.dashboards.DashboardElement in project netxms by netxms.

the class ExportDashboard method run.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
	 */
@Override
public void run(IAction action) {
    if (dashboard == null)
        return;
    final Set<Long> objects = new HashSet<Long>();
    final Map<Long, Long> items = new HashMap<Long, Long>();
    // $NON-NLS-1$
    final StringBuilder xml = new StringBuilder("<dashboard>\n\t<name>");
    xml.append(dashboard.getObjectName());
    // $NON-NLS-1$
    xml.append("</name>\n\t<columns>");
    xml.append(dashboard.getNumColumns());
    // $NON-NLS-1$
    xml.append("</columns>\n\t<options>");
    xml.append(dashboard.getOptions());
    // $NON-NLS-1$
    xml.append("</options>\n\t<elements>\n");
    for (DashboardElement e : dashboard.getElements()) {
        // $NON-NLS-1$
        xml.append("\t\t<dashboardElement>\n\t\t\t<type>");
        xml.append(e.getType());
        // $NON-NLS-1$
        xml.append("</type>\n");
        xml.append(e.getLayout());
        xml.append('\n');
        xml.append(e.getData());
        // $NON-NLS-1$
        xml.append("\n\t\t</dashboardElement>\n");
        DashboardElementConfig config = (DashboardElementConfig) Platform.getAdapterManager().getAdapter(e, DashboardElementConfig.class);
        if (config != null) {
            objects.addAll(config.getObjects());
            items.putAll(config.getDataCollectionItems());
        }
    }
    // $NON-NLS-1$
    xml.append("\t</elements>\n");
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    new ConsoleJob(Messages.get().ExportDashboard_JobTitle, wbPart, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            // Add object ID mapping
            // $NON-NLS-1$
            xml.append("\t<objectMap>\n");
            for (Long id : objects) {
                AbstractObject o = session.findObjectById(id);
                if (o != null) {
                    // $NON-NLS-1$
                    xml.append("\t\t<object id=\"");
                    xml.append(id);
                    // $NON-NLS-1$
                    xml.append("\" class=\"");
                    xml.append(o.getObjectClass());
                    // $NON-NLS-1$
                    xml.append("\">");
                    xml.append(o.getObjectName());
                    // $NON-NLS-1$
                    xml.append("</object>\n");
                }
            }
            // $NON-NLS-1$
            xml.append("\t</objectMap>\n\t<dciMap>\n");
            // Add DCI ID mapping
            long[] nodeList = new long[items.size()];
            long[] dciList = new long[items.size()];
            int pos = 0;
            for (Entry<Long, Long> dci : items.entrySet()) {
                dciList[pos] = dci.getKey();
                nodeList[pos] = dci.getValue();
                pos++;
            }
            String[] names = session.dciIdsToNames(nodeList, dciList);
            for (int i = 0; i < names.length; i++) {
                // $NON-NLS-1$
                xml.append("\t\t<dci id=\"");
                xml.append(dciList[i]);
                // $NON-NLS-1$
                xml.append("\" node=\"");
                xml.append(nodeList[i]);
                // $NON-NLS-1$
                xml.append("\">");
                xml.append(names[i]);
                // $NON-NLS-1$
                xml.append("</dci>\n");
            }
            // $NON-NLS-1$
            xml.append("\t</dciMap>\n</dashboard>\n");
            // $NON-NLS-1$
            OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(dashboard.getObjectName() + ".xml"), "UTF-8");
            try {
                out.write(xml.toString());
            } finally {
                out.close();
                final File dashboardFile = new File(dashboard.getObjectName() + ".xml");
                if (dashboardFile.length() > 0) {
                    DownloadServiceHandler.addDownload(dashboardFile.getName(), dashboardFile.getName(), dashboardFile, "application/octet-stream");
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            DownloadServiceHandler.startDownload(dashboardFile.getName());
                        }
                    });
                }
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().ExportDashboard_ErrorText;
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) HashMap(java.util.HashMap) DashboardElement(org.netxms.client.dashboards.DashboardElement) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Entry(java.util.Map.Entry) DashboardElementConfig(org.netxms.ui.eclipse.dashboard.widgets.internal.DashboardElementConfig) AbstractObject(org.netxms.client.objects.AbstractObject) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) File(java.io.File) HashSet(java.util.HashSet)

Example 2 with DashboardElement

use of org.netxms.client.dashboards.DashboardElement in project netxms by netxms.

the class DashboardElements method editElementXml.

/**
 * Edit selected element's configuration directly as XML
 */
private void editElementXml() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    DashboardElement element = (DashboardElement) selection.getFirstElement();
    EditElementXmlDlg dlg = new EditElementXmlDlg(getShell(), element.getData());
    if (dlg.open() == Window.OK) {
        element.setData(dlg.getValue());
        viewer.update(element, null);
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EditElementXmlDlg(org.netxms.ui.eclipse.dashboard.dialogs.EditElementXmlDlg) DashboardElement(org.netxms.client.dashboards.DashboardElement)

Example 3 with DashboardElement

use of org.netxms.client.dashboards.DashboardElement in project netxms by netxms.

the class DashboardElements method moveUp.

/**
 * Move currently selected element up
 */
private void moveUp() {
    final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() == 1) {
        DashboardElement element = (DashboardElement) selection.getFirstElement();
        int index = elements.indexOf(element);
        if (index > 0) {
            Collections.swap(elements, index - 1, index);
            viewer.setInput(elements.toArray());
            viewer.setSelection(new StructuredSelection(element));
        }
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DashboardElement(org.netxms.client.dashboards.DashboardElement)

Example 4 with DashboardElement

use of org.netxms.client.dashboards.DashboardElement in project netxms by netxms.

the class DashboardElements method editElement.

/**
 * Edit selected element
 */
private void editElement() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    DashboardElement element = (DashboardElement) selection.getFirstElement();
    DashboardElementConfig config = (DashboardElementConfig) AdapterManager.getDefault().getAdapter(element, DashboardElementConfig.class);
    if (config != null) {
        try {
            config.setLayout(DashboardElementLayout.createFromXml(element.getLayout()));
            PropertyDialog dlg = PropertyDialog.createDialogOn(getShell(), null, config);
            if (dlg.open() == Window.CANCEL)
                // element creation cancelled
                return;
            element.setData(config.createXml());
            element.setLayout(config.getLayout().createXml());
            viewer.update(element, null);
        } catch (Exception e) {
            MessageDialogHelper.openError(getShell(), Messages.get().DashboardElements_InternalErrorTitle, Messages.get().DashboardElements_InternalErrorText + e.getMessage());
        }
    } else {
        MessageDialogHelper.openError(getShell(), Messages.get().DashboardElements_InternalErrorTitle, Messages.get().DashboardElements_InternalErrorText2);
    }
}
Also used : PropertyDialog(org.eclipse.ui.internal.dialogs.PropertyDialog) DashboardElementConfig(org.netxms.ui.eclipse.dashboard.widgets.internal.DashboardElementConfig) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DashboardElement(org.netxms.client.dashboards.DashboardElement)

Example 5 with DashboardElement

use of org.netxms.client.dashboards.DashboardElement in project netxms by netxms.

the class DashboardControl method addAlarmBrowser.

/**
 * Add alarm browser widget to dashboard
 */
public void addAlarmBrowser() {
    DashboardElement e = new DashboardElement(DashboardElement.ALARM_VIEWER, DEFAULT_OBJECT_REFERENCE_CONFIG);
    addElement(e);
}
Also used : DashboardElement(org.netxms.client.dashboards.DashboardElement)

Aggregations

DashboardElement (org.netxms.client.dashboards.DashboardElement)23 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 NXCSession (org.netxms.client.NXCSession)3 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)3 NXCObjectModificationData (org.netxms.client.NXCObjectModificationData)2 AbstractObject (org.netxms.client.objects.AbstractObject)2 DashboardElementConfig (org.netxms.ui.eclipse.dashboard.widgets.internal.DashboardElementConfig)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1