use of org.eclipse.gef4.zest.layouts.LayoutAlgorithm 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.eclipse.gef4.zest.layouts.LayoutAlgorithm in project netxms by netxms.
the class AbstractNetworkMapView method setLayoutAlgorithm.
/**
* Set layout algorithm for map
*
* @param alg Layout algorithm
* @param forceChange
*/
protected void setLayoutAlgorithm(MapLayoutAlgorithm alg, boolean forceChange) {
if (alg == MapLayoutAlgorithm.MANUAL) {
if (!automaticLayoutEnabled)
// manual layout already
return;
automaticLayoutEnabled = false;
// TODO: rewrite, enum value should not be used as index
actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(false);
actionEnableAutomaticLayout.setChecked(false);
return;
}
if (automaticLayoutEnabled && (alg == layoutAlgorithm) && !forceChange)
// nothing to change
return;
if (!automaticLayoutEnabled) {
actionEnableAutomaticLayout.setChecked(true);
automaticLayoutEnabled = true;
}
LayoutAlgorithm algorithm;
switch(alg) {
case SPRING:
algorithm = new SpringLayoutAlgorithm();
break;
case RADIAL:
algorithm = new RadialLayoutAlgorithm();
break;
case HTREE:
algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT);
break;
case VTREE:
algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
break;
case SPARSE_VTREE:
algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
((TreeLayoutAlgorithm) algorithm).setNodeSpace(new Dimension(100, 100));
break;
default:
algorithm = new GridLayoutAlgorithm();
break;
}
viewer.setLayoutAlgorithm(alwaysFitLayout ? algorithm : new CompositeLayoutAlgorithm(new LayoutAlgorithm[] { algorithm, new ExpansionAlgorithm() }));
actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(false);
layoutAlgorithm = alg;
actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(true);
}
use of org.eclipse.gef4.zest.layouts.LayoutAlgorithm in project netxms by netxms.
the class NetworkMapWidget method setLayoutAlgorithm.
/**
* Set layout algorithm for map
* @param alg
*/
public void setLayoutAlgorithm(MapLayoutAlgorithm alg) {
LayoutAlgorithm algorithm;
switch(alg) {
case SPRING:
algorithm = new SpringLayoutAlgorithm();
break;
case RADIAL:
algorithm = new RadialLayoutAlgorithm();
break;
case HTREE:
algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT);
break;
case VTREE:
algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
break;
case SPARSE_VTREE:
TreeLayoutAlgorithm mainLayoutAlgorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
viewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
return e1.toString().compareToIgnoreCase(e2.toString());
}
});
algorithm = new CompositeLayoutAlgorithm(new LayoutAlgorithm[] { mainLayoutAlgorithm, new SparseTree() });
break;
default:
algorithm = new GridLayoutAlgorithm();
break;
}
viewer.setLayoutAlgorithm(algorithm);
}
Aggregations