Search in sources :

Example 11 with GraphSettings

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

the class TemplateGraphDynamicMenu 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) {
    Object selection = evalService.getCurrentState().getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
    if ((selection == null) || !(selection instanceof IStructuredSelection) || ((IStructuredSelection) selection).size() != 1)
        return;
    AbstractNode firstNode = null;
    for (Object o : ((IStructuredSelection) selection).toList()) {
        if (o instanceof AbstractNode) {
            firstNode = (AbstractNode) o;
            break;
        }
    }
    if (firstNode == null)
        return;
    final AbstractNode node = firstNode;
    // array should be already sorted
    GraphSettings[] settings = GraphTemplateCache.getInstance().getGraphTemplates();
    final Menu graphMenu = new Menu(menu);
    Map<String, Menu> menus = new HashMap<String, Menu>();
    int added = 0;
    for (int i = 0; i < settings.length; i++) {
        if (settings[i].isApplicableForNode(node)) {
            // $NON-NLS-1$
            String[] path = settings[i].getName().split("\\-\\>");
            Menu rootMenu = graphMenu;
            for (int j = 0; j < path.length - 1; j++) {
                // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                final String key = rootMenu.hashCode() + "@" + 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(settings[i]);
            item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
                    final GraphSettings gs = (GraphSettings) item.getData();
                    ConsoleJob job = new ConsoleJob("Get last values of " + node.getObjectName(), null, Activator.PLUGIN_ID, null) {

                        @Override
                        protected String getErrorMessage() {
                            return "Not possible to get last values for node" + node.getObjectName();
                        }

                        @Override
                        protected void runInternal(IProgressMonitor monitor) throws Exception {
                            final DciValue[] data = session.getLastValues(node.getObjectId());
                            GraphTemplateCache.execute(node, gs, data, getDisplay());
                        }
                    };
                    job.setUser(false);
                    job.start();
                }
            });
            added++;
        }
    }
    if (added > 0) {
        MenuItem graphMenuItem = new MenuItem(menu, SWT.CASCADE, index);
        graphMenuItem.setText("Graphs");
        graphMenuItem.setMenu(graphMenu);
    } else {
        graphMenu.dispose();
    }
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) HashMap(java.util.HashMap) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphSettings(org.netxms.client.datacollection.GraphSettings) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 12 with GraphSettings

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

the class NXCSession method getPredefinedGraphs.

/**
 * Get list of predefined graphs or graph templates
 *
 * @param graphTemplates defines if non template or template graph list should re requested
 * @return message with predefined graphs or with template graphs
 * @throws IOException  if socket or file I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public List<GraphSettings> getPredefinedGraphs(boolean graphTemplates) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_GRAPH_LIST);
    msg.setField(NXCPCodes.VID_GRAPH_TEMPALTE, graphTemplates);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_GRAPHS);
    List<GraphSettings> list = new ArrayList<GraphSettings>(count);
    long varId = NXCPCodes.VID_GRAPH_LIST_BASE;
    for (int i = 0; i < count; i++) {
        list.add(GraphSettings.createGraphSettings(response, varId));
        varId += 10;
    }
    return list;
}
Also used : GraphSettings(org.netxms.client.datacollection.GraphSettings) NXCPMessage(org.netxms.base.NXCPMessage) ArrayList(java.util.ArrayList) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 13 with GraphSettings

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

the class GraphBrowser method onCreateStep2.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.netxms.ui.android.main.activities.AbstractClientActivity#onCreateStep2
	 * (android.os.Bundle)
	 */
@Override
protected void onCreateStep2(Bundle savedInstanceState) {
    dialog = new ProgressDialog(this);
    setContentView(R.layout.graph_view);
    TextView title = (TextView) findViewById(R.id.ScreenTitlePrimary);
    title.setText(R.string.predefined_graphs_title);
    // keeps current list of graphs as datasource for listview
    adapter = new GraphAdapter(this, new ArrayList<String>(), new ArrayList<ArrayList<GraphSettings>>());
    listView = (ExpandableListView) findViewById(R.id.GraphList);
    listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            GraphSettings gs = (GraphSettings) adapter.getChild(groupPosition, childPosition);
            if (gs != null) {
                drawGraph(gs);
                return true;
            }
            return false;
        }
    });
    listView.setAdapter(adapter);
    registerForContextMenu(listView);
}
Also used : GraphAdapter(org.netxms.ui.android.main.adapters.GraphAdapter) GraphSettings(org.netxms.client.datacollection.GraphSettings) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) ProgressDialog(android.app.ProgressDialog) TextView(android.widget.TextView) View(android.view.View) ExpandableListView(android.widget.ExpandableListView) ExpandableListView(android.widget.ExpandableListView)

Example 14 with GraphSettings

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

the class DataSources method applyChanges.

/**
 * Apply changes
 *
 * @param isApply true if update operation caused by "Apply" button
 */
protected void applyChanges(final boolean isApply) {
    config.setDciList(dciList.toArray(new ChartDciConfig[dciList.size()]));
    if ((config instanceof GraphSettings) && isApply) {
        setValid(false);
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        new ConsoleJob(Messages.get().DataSources_JobName, null, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                session.saveGraph((GraphSettings) config, true);
            }

            @Override
            protected void jobFinalize() {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        DataSources.this.setValid(true);
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().DataSources_JobError;
            }
        }.start();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) GraphSettings(org.netxms.client.datacollection.GraphSettings) ChartDciConfig(org.netxms.client.datacollection.ChartDciConfig) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 15 with GraphSettings

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

the class HistoricalGraphView method saveGraph.

/**
 * Save this graph as predefined
 */
private void saveGraph(String graphName, String errorMessage, final boolean canBeOverwritten, final boolean asTemplate) {
    if (asTemplate && useMoreThanOneShoucrNode) {
        String templateError = "More than one node is used for template creation.\nThis may cause undefined behaviour.";
        errorMessage = errorMessage == null ? templateError : errorMessage + "\n\n" + templateError;
    }
    SaveGraphDlg dlg = new SaveGraphDlg(getSite().getShell(), graphName, errorMessage, canBeOverwritten);
    int result = dlg.open();
    if (result == Window.CANCEL)
        return;
    final GraphSettings gs = new GraphSettings(0, session.getUserId(), 0, new ArrayList<AccessListElement>(0));
    gs.setName(dlg.getName());
    gs.setConfig(settings);
    if (asTemplate) {
        gs.setFlags(GraphSettings.GRAPH_FLAG_TEMPLATE);
    }
    if (result == SaveGraphDlg.OVERRIDE) {
        new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                session.saveGraph(gs, canBeOverwritten);
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().HistoricalGraphView_SaveSettingsError;
            }
        }.start();
    } else {
        new ConsoleJob(Messages.get().HistoricalGraphView_SaveSettings, this, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                try {
                    session.saveGraph(gs, canBeOverwritten);
                } catch (NXCException e) {
                    if (e.getErrorCode() == RCC.OBJECT_ALREADY_EXISTS) {
                        runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExist, true, asTemplate);
                            }
                        });
                    } else {
                        if (e.getErrorCode() == RCC.ACCESS_DENIED) {
                            runInUIThread(new Runnable() {

                                @Override
                                public void run() {
                                    saveGraph(gs.getName(), Messages.get().HistoricalGraphView_NameAlreadyExistNoOverwrite, false, asTemplate);
                                }
                            });
                        } else {
                            throw e;
                        }
                    }
                }
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().HistoricalGraphView_SaveError;
            }
        }.start();
    }
    updateChart();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphSettings(org.netxms.client.datacollection.GraphSettings) SaveGraphDlg(org.netxms.ui.eclipse.perfview.dialogs.SaveGraphDlg) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) AccessListElement(org.netxms.client.AccessListElement) PartInitException(org.eclipse.ui.PartInitException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException)

Aggregations

GraphSettings (org.netxms.client.datacollection.GraphSettings)18 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)8 NXCSession (org.netxms.client.NXCSession)5 PartInitException (org.eclipse.ui.PartInitException)4 ChartDciConfig (org.netxms.client.datacollection.ChartDciConfig)4 ArrayList (java.util.ArrayList)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 NXCException (org.netxms.client.NXCException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Action (org.eclipse.jface.action.Action)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 PropertyDialog (org.eclipse.ui.internal.dialogs.PropertyDialog)2