Search in sources :

Example 1 with TreeLayoutAlgorithm

use of org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm in project hale by halestudio.

the class TypeCellSelectionDialog method setupViewer.

/**
 * @see eu.esdihumboldt.hale.ui.util.selector.AbstractViewerSelectionDialog#setupViewer(org.eclipse.jface.viewers.StructuredViewer,
 *      java.lang.Object)
 */
@Override
protected void setupViewer(final GraphViewer viewer, Cell initialSelection) {
    // content and label provider
    viewer.setContentProvider(new ReverseCellGraphContentProvider());
    viewer.setLabelProvider(new GraphLabelProvider(viewer, HaleUI.getServiceProvider()));
    // layout
    final TreeLayoutAlgorithm layout = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.RIGHT_LEFT);
    viewer.getControl().addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            int width = viewer.getControl().getSize().x;
            layout.setNodeSpace(new Dimension((width - 10) / 3, 30));
        }
    });
    viewer.setLayoutAlgorithm(layout, true);
    viewer.applyLayout();
    // input and selection
    AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
    viewer.setInput(as.getAlignment().getTypeCells());
    if (initialSelection != null)
        viewer.setSelection(new StructuredSelection(initialSelection));
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) GraphLabelProvider(eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider) ReverseCellGraphContentProvider(eu.esdihumboldt.hale.ui.common.graph.content.ReverseCellGraphContentProvider) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Dimension(org.eclipse.draw2d.geometry.Dimension) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 2 with TreeLayoutAlgorithm

use of org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm in project hale by halestudio.

the class AbstractMappingView method createLayout.

/**
 * Create the initial layout to use
 *
 * @return the layout
 */
protected LayoutAlgorithm createLayout() {
    LayoutAlgorithm layout;
    layout = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.RIGHT_LEFT);
    return layout;
}
Also used : TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) LayoutAlgorithm(org.eclipse.zest.layouts.LayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm)

Example 3 with TreeLayoutAlgorithm

use of org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm in project archi by archimatetool.

the class SimpleSwingExample method start.

public void start() {
    // $NON-NLS-1$
    mainFrame = new JFrame("Simple Swing Layout Example");
    toolBar = new JToolBar();
    mainFrame.getContentPane().setLayout(new BorderLayout());
    mainFrame.getContentPane().add(toolBar, BorderLayout.NORTH);
    // $NON-NLS-1$
    lblProgress = new JLabel("Progress: ");
    mainFrame.getContentPane().add(lblProgress, BorderLayout.SOUTH);
    createMainPanel();
    mainFrame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            stop();
            mainFrame.dispose();
        }
    });
    // $NON-NLS-1$
    btnContinuous = new JToggleButton("continuous", false);
    // $NON-NLS-1$
    btnAsynchronous = new JToggleButton("asynchronous", false);
    toolBar.add(btnContinuous);
    toolBar.add(btnAsynchronous);
    // $NON-NLS-1$
    btnStop = new JButton("Stop");
    btnStop.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            stop();
        }
    });
    toolBar.add(btnStop);
    // $NON-NLS-1$
    JButton btnCreateGraph = new JButton("New graph");
    btnCreateGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            stop();
            createGraph(true);
        }
    });
    toolBar.add(btnCreateGraph);
    // $NON-NLS-1$
    JButton btnCreateTree = new JButton("New tree");
    btnCreateTree.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            stop();
            createGraph(false);
        }
    });
    toolBar.add(btnCreateTree);
    createGraph(false);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    mainFrame.setLocation((int) (screenSize.getWidth() - INITIAL_PANEL_WIDTH) / 2, (int) (screenSize.getHeight() - INITIAL_PANEL_HEIGHT) / 2);
    mainFrame.pack();
    mainFrame.setVisible(true);
    mainFrame.repaint();
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                SPRING = new SpringLayoutAlgorithm(LayoutStyles.NONE);
                TREE_VERT = new TreeLayoutAlgorithm(LayoutStyles.NONE);
                TREE_HORIZ = new HorizontalTreeLayoutAlgorithm(LayoutStyles.NONE);
                RADIAL = new RadialLayoutAlgorithm(LayoutStyles.NONE);
                GRID = new GridLayoutAlgorithm(LayoutStyles.NONE);
                HORIZ = new HorizontalLayoutAlgorithm(LayoutStyles.NONE);
                VERT = new VerticalLayoutAlgorithm(LayoutStyles.NONE);
                SPRING.setIterations(1000);
                // initialize layouts
                TREE_VERT.setComparator(new Comparator() {

                    @Override
                    public int compare(Object o1, Object o2) {
                        if (o1 instanceof Comparable && o2 instanceof Comparable) {
                            return ((Comparable) o1).compareTo(o2);
                        }
                        return 0;
                    }
                });
                GRID.setRowPadding(20);
                // $NON-NLS-1$
                addAlgorithm(SPRING, "Spring", false);
                // $NON-NLS-1$
                addAlgorithm(TREE_VERT, "Tree-V", false);
                // $NON-NLS-1$
                addAlgorithm(TREE_HORIZ, "Tree-H", false);
                // $NON-NLS-1$
                addAlgorithm(RADIAL, "Radial", false);
                // $NON-NLS-1$
                addAlgorithm(GRID, "Grid", false);
                // $NON-NLS-1$
                addAlgorithm(HORIZ, "Horiz", false);
                // $NON-NLS-1$
                addAlgorithm(VERT, "Vert", false);
                for (int i = 0; i < algorithms.size(); i++) {
                    final LayoutAlgorithm algorithm = (LayoutAlgorithm) algorithms.get(i);
                    final String algorithmName = (String) algorithmNames.get(i);
                    // final boolean algorithmAnimate = ((Boolean)algorithmAnimates.get(i)).booleanValue();
                    JButton algorithmButton = new JButton(algorithmName);
                    algorithmButton.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            currentLayoutAlgorithm = algorithm;
                            currentLayoutAlgorithmName = algorithmName;
                            algorithm.setEntityAspectRatio((double) mainPanel.getWidth() / (double) mainPanel.getHeight());
                            // animate = algorithmAnimate;
                            performLayout();
                        }
                    });
                    toolBar.add(algorithmButton);
                }
            }
        });
    } catch (InterruptedException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (InvocationTargetException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) HorizontalTreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) RadialLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm) VerticalLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.VerticalLayoutAlgorithm) HorizontalLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.HorizontalLayoutAlgorithm) Comparator(java.util.Comparator) BorderLayout(java.awt.BorderLayout) JToggleButton(javax.swing.JToggleButton) HorizontalTreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm) VerticalLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.VerticalLayoutAlgorithm) LayoutAlgorithm(org.eclipse.zest.layouts.LayoutAlgorithm) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) GridLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm) SpringLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm) HorizontalLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.HorizontalLayoutAlgorithm) RadialLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.RadialLayoutAlgorithm) JFrame(javax.swing.JFrame) SpringLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.SpringLayoutAlgorithm) JLabel(javax.swing.JLabel) JToolBar(javax.swing.JToolBar) Dimension(java.awt.Dimension) HorizontalTreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.HorizontalTreeLayoutAlgorithm) InvocationTargetException(java.lang.reflect.InvocationTargetException) GridLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.GridLayoutAlgorithm) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent)

Example 4 with TreeLayoutAlgorithm

use of org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm in project archi by archimatetool.

the class Graph method applyLayoutInternal.

private void applyLayoutInternal() {
    hasPendingLayoutRequest = false;
    if ((this.getNodes().size() == 0)) {
        return;
    }
    int layoutStyle = 0;
    if ((nodeStyle & ZestStyles.NODES_NO_LAYOUT_RESIZE) > 0) {
        layoutStyle = LayoutStyles.NO_LAYOUT_NODE_RESIZING;
    }
    if (layoutAlgorithm == null) {
        layoutAlgorithm = new TreeLayoutAlgorithm(layoutStyle);
    }
    layoutAlgorithm.setStyle(layoutAlgorithm.getStyle() | layoutStyle);
    // calculate the size for the layout algorithm
    Dimension d = this.getViewport().getSize();
    d.width = d.width - 10;
    d.height = d.height - 10;
    if (this.preferredSize.width >= 0) {
        d.width = preferredSize.width;
    }
    if (this.preferredSize.height >= 0) {
        d.height = preferredSize.height;
    }
    if (d.isEmpty()) {
        return;
    }
    LayoutRelationship[] connectionsToLayout = getConnectionsToLayout(nodes);
    LayoutEntity[] nodesToLayout = getNodesToLayout(getNodes());
    try {
        if ((nodeStyle & ZestStyles.NODES_NO_LAYOUT_ANIMATION) == 0 && animationEnabled) {
            Animation.markBegin();
        }
        layoutAlgorithm.applyLayout(nodesToLayout, connectionsToLayout, 0, 0, d.width, d.height, false, false);
        if ((nodeStyle & ZestStyles.NODES_NO_LAYOUT_ANIMATION) == 0 && animationEnabled) {
            Animation.run(animationTime);
        }
        getLightweightSystem().getUpdateManager().performUpdate();
    } catch (InvalidLayoutConfiguration e) {
        e.printStackTrace();
    }
}
Also used : TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) Dimension(org.eclipse.draw2d.geometry.Dimension) LayoutEntity(org.eclipse.zest.layouts.LayoutEntity) Point(org.eclipse.draw2d.geometry.Point) LayoutConstraint(org.eclipse.zest.layouts.constraints.LayoutConstraint) LayoutRelationship(org.eclipse.zest.layouts.LayoutRelationship) InvalidLayoutConfiguration(org.eclipse.zest.layouts.InvalidLayoutConfiguration)

Example 5 with TreeLayoutAlgorithm

use of org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm in project hale by halestudio.

the class GraphMLDialog method open.

/**
 * Opens the dialog for displaying the graph
 *
 * @throws IOException may be thrown if the graph string from the database
 *             can fails to convert
 */
public void open() throws IOException {
    Shell parent = super.getParent();
    final Shell shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.MIN | SWT.MODELESS);
    shell.setFocus();
    shell.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            shell.setMinimized(true);
        }

        @Override
        public void focusGained(FocusEvent e) {
        // ignore
        }
    });
    shell.setLayout(GridLayoutFactory.fillDefaults().create());
    shell.setText(getText());
    final Composite viewerContainer = new Composite(shell, SWT.EMBEDDED);
    viewerContainer.setLayout(new FillLayout());
    viewerContainer.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    TinkerGraph tgraph = new TinkerGraph();
    GraphMLReader greader = new GraphMLReader(tgraph);
    ByteArrayInputStream in;
    in = new ByteArrayInputStream(graphString.getBytes(("UTF-8")));
    greader.inputGraph(in);
    GraphViewer viewer = new GraphViewer(viewerContainer, SWT.NONE);
    TreeLayoutAlgorithm la = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.RIGHT_LEFT);
    viewer.setLabelProvider(new GraphMLLabelProvider());
    viewer.setContentProvider(new GraphMLContentProvider());
    viewer.setInput(tgraph.getEdges());
    viewer.setLayoutAlgorithm(la, true);
    viewer.applyLayout();
    viewerContainer.pack();
    viewerContainer.setVisible(true);
    shell.open();
    Display display = parent.getDisplay();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) TreeLayoutAlgorithm(org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm) FillLayout(org.eclipse.swt.layout.FillLayout) FocusEvent(org.eclipse.swt.events.FocusEvent) Shell(org.eclipse.swt.widgets.Shell) GraphViewer(org.eclipse.zest.core.viewers.GraphViewer) ByteArrayInputStream(java.io.ByteArrayInputStream) GraphMLReader(com.tinkerpop.blueprints.util.io.graphml.GraphMLReader) FocusListener(org.eclipse.swt.events.FocusListener) Display(org.eclipse.swt.widgets.Display)

Aggregations

TreeLayoutAlgorithm (org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm)6 Dimension (org.eclipse.draw2d.geometry.Dimension)3 Point (org.eclipse.draw2d.geometry.Point)2 InvalidLayoutConfiguration (org.eclipse.zest.layouts.InvalidLayoutConfiguration)2 LayoutAlgorithm (org.eclipse.zest.layouts.LayoutAlgorithm)2 LayoutEntity (org.eclipse.zest.layouts.LayoutEntity)2 LayoutRelationship (org.eclipse.zest.layouts.LayoutRelationship)2 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)1 GraphMLReader (com.tinkerpop.blueprints.util.io.graphml.GraphMLReader)1 ReverseCellGraphContentProvider (eu.esdihumboldt.hale.ui.common.graph.content.ReverseCellGraphContentProvider)1 GraphLabelProvider (eu.esdihumboldt.hale.ui.common.graph.labels.GraphLabelProvider)1 AlignmentService (eu.esdihumboldt.hale.ui.service.align.AlignmentService)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1