Search in sources :

Example 1 with CompositeLayoutAlgorithm

use of org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm 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);
}
Also used : SpringLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm) LayoutAlgorithm(org.eclipse.gef4.zest.layouts.LayoutAlgorithm) RadialLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm) SpringLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm) GridLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm) CompositeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm) MapLayoutAlgorithm(org.netxms.client.maps.MapLayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm) ExpansionAlgorithm(org.netxms.ui.eclipse.networkmaps.algorithms.ExpansionAlgorithm) CompositeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm) RadialLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm) Dimension(org.eclipse.draw2d.geometry.Dimension) GridLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm)

Example 2 with CompositeLayoutAlgorithm

use of org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm 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);
}
Also used : SpringLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm) SparseTree(org.netxms.ui.eclipse.networkmaps.algorithms.SparseTree) RadialLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm) SpringLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm) GridLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm) CompositeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm) MapLayoutAlgorithm(org.netxms.client.maps.MapLayoutAlgorithm) LayoutAlgorithm(org.eclipse.gef4.zest.layouts.LayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) CompositeLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm) ExtendedGraphViewer(org.netxms.ui.eclipse.networkmaps.views.helpers.ExtendedGraphViewer) Viewer(org.eclipse.jface.viewers.Viewer) AbstractObject(org.netxms.client.objects.AbstractObject) NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject) RadialLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm) GridLayoutAlgorithm(org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm)

Aggregations

LayoutAlgorithm (org.eclipse.gef4.zest.layouts.LayoutAlgorithm)2 CompositeLayoutAlgorithm (org.eclipse.gef4.zest.layouts.algorithms.CompositeLayoutAlgorithm)2 GridLayoutAlgorithm (org.eclipse.gef4.zest.layouts.algorithms.GridLayoutAlgorithm)2 RadialLayoutAlgorithm (org.eclipse.gef4.zest.layouts.algorithms.RadialLayoutAlgorithm)2 SpringLayoutAlgorithm (org.eclipse.gef4.zest.layouts.algorithms.SpringLayoutAlgorithm)2 TreeLayoutAlgorithm (org.eclipse.gef4.zest.layouts.algorithms.TreeLayoutAlgorithm)2 MapLayoutAlgorithm (org.netxms.client.maps.MapLayoutAlgorithm)2 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 NetworkMapObject (org.netxms.client.maps.elements.NetworkMapObject)1 AbstractObject (org.netxms.client.objects.AbstractObject)1 ExpansionAlgorithm (org.netxms.ui.eclipse.networkmaps.algorithms.ExpansionAlgorithm)1 SparseTree (org.netxms.ui.eclipse.networkmaps.algorithms.SparseTree)1 ExtendedGraphViewer (org.netxms.ui.eclipse.networkmaps.views.helpers.ExtendedGraphViewer)1