use of org.netxms.client.maps.NetworkMapLink in project netxms by netxms.
the class AbstractNetworkMapView method openLinkDci.
/**
* Handler for opening network map dci on double click
*/
private void openLinkDci() {
final NetworkMapLink link = (NetworkMapLink) currentSelection.getFirstElement();
if (!link.hasDciData())
return;
new ConsoleJob("Open link dci job", this, Activator.PLUGIN_ID, Activator.PLUGIN_ID) {
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.jobs.ConsoleJob#runInternal(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
DciValue[] values = session.getLastValues(link.getDciAsList());
final StringBuilder sb = new StringBuilder();
for (DciValue v : values) {
sb.append("&");
sb.append(Integer.toString(v instanceof SimpleDciValue ? ChartDciConfig.ITEM : ChartDciConfig.TABLE));
sb.append("@");
sb.append(Long.toString(v.getNodeId()));
sb.append("@");
sb.append(Long.toString(v.getId()));
sb.append("@");
sb.append(URLEncoder.encode(v.getDescription(), "UTF-8"));
sb.append("@");
sb.append(URLEncoder.encode(v.getName(), "UTF-8"));
}
runInUIThread(new Runnable() {
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try {
getSite().getPage().showView(HistoricalGraphView.ID, sb.toString(), IWorkbenchPage.VIEW_ACTIVATE);
} catch (PartInitException e) {
MessageDialogHelper.openError(getSite().getShell(), "Error", String.format("Error opening view: %s", e.getLocalizedMessage()));
}
}
});
}
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.jobs.ConsoleJob#getErrorMessage()
*/
@Override
protected String getErrorMessage() {
return "Cannot open dci link historical graph view";
}
}.start();
}
use of org.netxms.client.maps.NetworkMapLink in project netxms by netxms.
the class AbstractNetworkMapView method createPartControl.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.ViewPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public final void createPartControl(Composite parent) {
FillLayout layout = new FillLayout();
parent.setLayout(layout);
viewer = new ExtendedGraphViewer(parent, SWT.NONE);
viewer.setContentProvider(new MapContentProvider(viewer));
labelProvider = new MapLabelProvider(viewer);
viewer.setLabelProvider(labelProvider);
viewer.setBackgroundColor(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND).getRGB());
IDialogSettings settings = Activator.getDefault().getDialogSettings();
try {
// $NON-NLS-1$
alwaysFitLayout = settings.getBoolean(viewId + ".alwaysFitLayout");
} catch (Exception e) {
}
// Zoom level restore and save
try {
// $NON-NLS-1$
viewer.zoomTo(settings.getDouble(viewId + ".zoom"));
} catch (NumberFormatException e) {
}
viewer.getGraphControl().addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
IDialogSettings settings = Activator.getDefault().getDialogSettings();
// $NON-NLS-1$
settings.put(viewId + ".zoom", viewer.getZoom());
}
});
getSite().setSelectionProvider(this);
ISelectionChangedListener listener = new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent e) {
if (bendpointEditor != null) {
bendpointEditor.stop();
bendpointEditor = null;
}
currentSelection = transformSelection(e.getSelection());
if (currentSelection.size() == 1) {
int selectionType = analyzeSelection(currentSelection);
if (selectionType == SELECTION_OBJECTS) {
AbstractObject object = (AbstractObject) currentSelection.getFirstElement();
actionOpenDrillDownObject.setEnabled(object.getDrillDownObjectId() != 0);
} else {
actionOpenDrillDownObject.setEnabled(false);
if (selectionType == SELECTION_LINKS) {
NetworkMapLink link = (NetworkMapLink) currentSelection.getFirstElement();
actionLockLink.setChecked(link.isLocked());
if (!link.isLocked() && link.getRouting() == NetworkMapLink.ROUTING_BENDPOINTS) {
bendpointEditor = new BendpointEditor(link, (GraphConnection) viewer.getGraphControl().getSelection().get(0), viewer);
}
}
}
} else {
actionOpenDrillDownObject.setEnabled(false);
}
if (selectionListeners.isEmpty())
return;
SelectionChangedEvent event = new SelectionChangedEvent(AbstractNetworkMapView.this, currentSelection);
for (ISelectionChangedListener l : selectionListeners) {
l.selectionChanged(event);
}
}
};
viewer.addPostSelectionChangedListener(listener);
viewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
int selectionType = analyzeSelection(currentSelection);
if (selectionType == SELECTION_EMPTY)
return;
if (selectionType == SELECTION_OBJECTS) {
AbstractObject object = (AbstractObject) currentSelection.getFirstElement();
if (object instanceof Rack) {
openRackView(Long.toString(object.getObjectId()));
return;
}
for (DoubleClickHandlerData h : doubleClickHandlers) {
if ((h.enabledFor == null) || (h.enabledFor.isInstance(object))) {
if (h.handler.onDoubleClick(object)) {
return;
}
}
}
} else if (((NetworkMapLink) currentSelection.getFirstElement()).isLocked() && selectionType == SELECTION_LINKS) {
openLinkDci();
}
// Default behavior
actionOpenDrillDownObject.run();
}
});
sessionListener = new SessionListener() {
@Override
public void notificationHandler(final SessionNotification n) {
if (n.getCode() == SessionNotification.OBJECT_CHANGED) {
viewer.getControl().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
onObjectChange((AbstractObject) n.getObject());
}
});
}
}
};
session.addListener(sessionListener);
createActions();
contributeToActionBars();
createPopupMenu();
if (automaticLayoutEnabled) {
setLayoutAlgorithm(layoutAlgorithm, true);
} else {
viewer.setLayoutAlgorithm(new ManualLayout());
}
activateContext();
registerDoubleClickHandlers();
setupMapControl();
refreshMap();
}
use of org.netxms.client.maps.NetworkMapLink in project netxms by netxms.
the class AbstractNetworkMapView method onObjectChange.
/**
* Called by session listener when NetXMS object was changed.
*
* @param object changed NetXMS object
*/
protected void onObjectChange(final AbstractObject object) {
NetworkMapObject element = mapPage.findObjectElement(object.getObjectId());
if (element != null)
viewer.refresh(element, true);
List<NetworkMapLink> links = mapPage.findLinksWithStatusObject(object.getObjectId());
if (links != null) {
for (NetworkMapLink l : links) viewer.refresh(l);
addDciToRequestList();
}
if (object.getObjectId() == rootObject.getObjectId())
rootObject = object;
}
use of org.netxms.client.maps.NetworkMapLink in project netxms by netxms.
the class AbstractNetworkMapView method analyzeSelection.
/**
* Tests if given selection contains only NetXMS objects
*
* @param selection
* @return
*/
@SuppressWarnings("rawtypes")
private int analyzeSelection(IStructuredSelection selection) {
if (selection.isEmpty())
return SELECTION_EMPTY;
Iterator it = selection.iterator();
Object first = it.next();
int type;
Class firstClass;
if (first instanceof AbstractObject) {
type = SELECTION_OBJECTS;
firstClass = AbstractObject.class;
} else if (first instanceof NetworkMapElement) {
type = SELECTION_ELEMENTS;
firstClass = NetworkMapElement.class;
} else if (first instanceof NetworkMapLink) {
type = SELECTION_LINKS;
firstClass = NetworkMapLink.class;
} else {
return SELECTION_MIXED;
}
while (it.hasNext()) {
final Object o = it.next();
if (!firstClass.isInstance(o))
return SELECTION_MIXED;
}
return type;
}
use of org.netxms.client.maps.NetworkMapLink in project netxms by netxms.
the class PredefinedMap method linkSelectedObjects.
/**
* Link currently selected objects
*/
private void linkSelectedObjects() {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
if (selection.size() != 2)
return;
Object[] objects = selection.toArray();
long id1 = ((NetworkMapObject) objects[0]).getId();
long id2 = ((NetworkMapObject) objects[1]).getId();
mapPage.addLink(new NetworkMapLink(NetworkMapLink.NORMAL, id1, id2));
saveMap();
}
Aggregations