use of org.netxms.client.objects.AbstractNode in project netxms by netxms.
the class TableLastValuesView method init.
/* (non-Javadoc)
* @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite)
*/
@Override
public void init(IViewSite site) throws PartInitException {
super.init(site);
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
// Secondary ID must by in form nodeId&dciId
// $NON-NLS-1$
String[] parts = site.getSecondaryId().split("&");
if (parts.length != 2)
// $NON-NLS-1$
throw new PartInitException("Internal error");
objectId = Long.parseLong(parts[0]);
AbstractObject object = session.findObjectById(objectId);
if ((object == null) || (!(object instanceof AbstractNode) && !(object instanceof Cluster) && !(object instanceof MobileDevice) && !(object instanceof Sensor)))
throw new PartInitException(Messages.get().TableLastValuesView_InvalidObjectID);
dciId = Long.parseLong(parts[1]);
// $NON-NLS-1$ //$NON-NLS-2$
setPartName(object.getObjectName() + ": [" + Long.toString(dciId) + "]");
}
use of org.netxms.client.objects.AbstractNode in project netxms by netxms.
the class NodeListComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
final AbstractNode node1 = (AbstractNode) e1;
final AbstractNode node2 = (AbstractNode) e2;
// $NON-NLS-1$
final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
int result;
switch(column) {
case NodesTab.COLUMN_SYS_DESCRIPTION:
result = node1.getSystemDescription().compareToIgnoreCase(node2.getSystemDescription());
break;
case NodesTab.COLUMN_PLATFORM:
result = node1.getPlatformName().compareToIgnoreCase(node2.getPlatformName());
break;
case NodesTab.COLUMN_AGENT_VERSION:
result = node1.getAgentVersion().compareToIgnoreCase(node2.getAgentVersion());
break;
case NodesTab.COLUMN_ID:
result = Long.signum(node1.getObjectId() - node2.getObjectId());
break;
case NodesTab.COLUMN_NAME:
result = node1.getObjectName().compareToIgnoreCase(node2.getObjectName());
break;
case NodesTab.COLUMN_STATUS:
result = node1.getStatus().compareTo(node2.getStatus());
break;
case NodesTab.COLUMN_IP_ADDRESS:
result = ComparatorHelper.compareInetAddresses(node1.getPrimaryIP().getAddress(), node2.getPrimaryIP().getAddress());
break;
case NodesTab.COLUMN_RACK:
Rack rack1 = session.findObjectById(node1.getRackId(), Rack.class);
Rack rack2 = session.findObjectById(node2.getRackId(), Rack.class);
if ((rack1 != null) && (rack2 != null)) {
result = rack1.getObjectName().compareToIgnoreCase(rack2.getObjectName());
if (result == 0) {
result = node1.getRackPosition() - node2.getRackPosition();
}
} else {
result = Long.signum(node1.getRackId() - node2.getRackId());
}
break;
default:
result = 0;
break;
}
return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
use of org.netxms.client.objects.AbstractNode in project netxms by netxms.
the class ObjectStatusWidget method paintControl.
/* (non-Javadoc)
* @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
*/
@Override
public void paintControl(PaintEvent e) {
Rectangle rect = getClientArea();
rect.width--;
rect.height--;
e.gc.setAntialias(SWT.ON);
e.gc.setTextAntialias(SWT.ON);
e.gc.setForeground(SharedColors.getColor(SharedColors.TEXT_NORMAL, getDisplay()));
e.gc.setLineWidth(1);
e.gc.setBackground(StatusDisplayInfo.getStatusColor(object.getStatus()));
e.gc.setAlpha(127);
e.gc.fillRoundRectangle(rect.x, rect.y, rect.width, rect.height, 8, 8);
e.gc.setAlpha(255);
e.gc.drawRoundRectangle(rect.x, rect.y, rect.width, rect.height, 8, 8);
final String text = (object instanceof AbstractNode) ? // $NON-NLS-1$
(object.getObjectName() + "\n" + ((AbstractNode) object).getPrimaryIP().getHostAddress()) : object.getObjectName();
rect.x += 4;
rect.y += 4;
rect.width -= 8;
rect.height -= 8;
int h = e.gc.textExtent(text).y;
e.gc.drawText(text, rect.x, rect.y + (rect.height - h) / 2, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
}
use of org.netxms.client.objects.AbstractNode 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.objects.AbstractNode in project netxms by netxms.
the class ShowVlans method selectionChanged.
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/
@Override
public void selectionChanged(IAction action, ISelection selection) {
if ((selection instanceof IStructuredSelection) && (((IStructuredSelection) selection).size() == 1)) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof AbstractNode) {
action.setEnabled(true);
objectId = ((AbstractObject) obj).getObjectId();
} else {
action.setEnabled(false);
objectId = 0;
}
} else {
action.setEnabled(false);
objectId = 0;
}
}
Aggregations