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();
}
}
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;
}
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);
}
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();
}
}
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();
}
Aggregations