Search in sources :

Example 6 with EdgeDescriptor

use of org.eclipse.titanium.graph.components.EdgeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class ModuleGraphGenerator method createGraph.

@Override
protected void createGraph() {
    // analyze the project if needed
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(project);
    if (sourceParser.getLastTimeChecked() == null) {
        WorkspaceJob job = sourceParser.analyzeAll();
        while (job == null) {
            try {
                Thread.sleep(500);
                job = sourceParser.analyzeAll();
            } catch (InterruptedException e) {
                ErrorReporter.logExceptionStackTrace("Error while waiting for analyzis result", e);
            }
        }
        try {
            job.join();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace("Error while parsing the project", e);
        }
    }
    final List<IProject> visitedProjects = ProjectBasedBuilder.getProjectBasedBuilder(project).getAllReachableProjects();
    final Map<String, Identifier> globalKnownModules = new HashMap<String, Identifier>();
    for (int i = 0; i < visitedProjects.size(); ++i) {
        final IProject currentProject = visitedProjects.get(i);
        final ProjectStructureDataCollector collector = GlobalProjectStructureTracker.getDataCollector(currentProject);
        collector.evaulateMissingModules();
        // adding known modules
        for (final Identifier moduleName : collector.knownModules.values()) {
            final NodeDescriptor actNode = new NodeDescriptor(moduleName.getDisplayName(), moduleName.getName(), currentProject, false, moduleName.getLocation());
            globalKnownModules.put(moduleName.getName(), moduleName);
            if (!graph.containsVertex(actNode)) {
                graph.addVertex(actNode);
                labels.put(actNode.getName(), actNode);
            }
        }
        // adding missing modules
        for (final Identifier moduleName : collector.missingModules.values()) {
            if (!globalKnownModules.containsKey(moduleName.getName())) {
                final NodeDescriptor actNode = new NodeDescriptor(moduleName.getDisplayName(), moduleName.getName(), currentProject, true, moduleName.getLocation());
                if (!graph.containsVertex(actNode)) {
                    graph.addVertex(actNode);
                    labels.put(actNode.getName(), actNode);
                }
            }
        }
        // building edges
        for (final String from : collector.importations.keySet()) {
            for (final String to : collector.importations.get(from)) {
                final EdgeDescriptor edge = new EdgeDescriptor(from + "->" + to, Color.black);
                // if(!graph.containsEdge(edge))
                graph.addEdge(edge, labels.get(from), labels.get(to), EdgeType.DIRECTED);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IProject(org.eclipse.core.resources.IProject) Identifier(org.eclipse.titan.designer.AST.Identifier) ProjectStructureDataCollector(org.eclipse.titan.designer.parsers.ProjectStructureDataCollector)

Example 7 with EdgeDescriptor

use of org.eclipse.titanium.graph.components.EdgeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class ClusterTransformer method groupCluster.

/**
 * Calculate positions for one cluster
 *
 * @param vertices
 *            : the set of vertices inside the cluster
 */
protected void groupCluster(final Set<NodeDescriptor> vertices) {
    if (vertices.size() < mainLayout.getGraph().getVertexCount()) {
        final Point2D center = mainLayout.apply(vertices.iterator().next());
        final DirectedSparseGraph<NodeDescriptor, EdgeDescriptor> subGraph = new DirectedSparseGraph<NodeDescriptor, EdgeDescriptor>();
        for (final NodeDescriptor v : vertices) {
            subGraph.addVertex(v);
        }
        final Layout<NodeDescriptor, EdgeDescriptor> subLayout = new CircleLayout<NodeDescriptor, EdgeDescriptor>(subGraph);
        subLayout.setInitializer(mainLayout);
        // TODO Could we calculate the needed space for one cluster?
        final Dimension canvasSize = new Dimension(100, 100);
        subLayout.setSize(canvasSize);
        mainLayout.put(subLayout, center);
    }
}
Also used : CircleLayout(edu.uci.ics.jung.algorithms.layout.CircleLayout) Point2D(java.awt.geom.Point2D) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) Dimension(java.awt.Dimension) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor) DirectedSparseGraph(edu.uci.ics.jung.graph.DirectedSparseGraph)

Example 8 with EdgeDescriptor

use of org.eclipse.titanium.graph.components.EdgeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class GraphEditor method initWindow.

/**
 * This method creates the items to show on the {@link Frame} , and adds
 * actions
 */
protected void initWindow() {
    drawArea = new JPanel();
    window.add(drawArea, BorderLayout.CENTER);
    drawArea.setSize(windowSize.width, windowSize.height);
    drawArea.setPreferredSize(new Dimension(windowSize.width, windowSize.height));
    menuBar = new JMenuBar();
    window.add(menuBar, BorderLayout.NORTH);
    final JMenu mnFile = new JMenu("File");
    final ActionListener saveGraph = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            String path = "";
            try {
                path = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path"));
            } catch (CoreException exc) {
                errorHandler.reportException("Error while reading persistent property", exc);
            }
            final String oldPath = path;
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    FileDialog dialog = new FileDialog(editorComposite.getShell(), SWT.SAVE);
                    dialog.setText("Save Pajek file");
                    dialog.setFilterPath(oldPath);
                    dialog.setFilterExtensions(new String[] { "*.net", "*.dot" });
                    String graphFilePath = dialog.open();
                    if (graphFilePath == null) {
                        return;
                    }
                    String newPath = graphFilePath.substring(0, graphFilePath.lastIndexOf(File.separator) + 1);
                    try {
                        QualifiedName name = new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path");
                        project.setPersistentProperty(name, newPath);
                        if ("dot".equals(graphFilePath.substring(graphFilePath.lastIndexOf('.') + 1, graphFilePath.length()))) {
                            GraphHandler.saveGraphToDot(graph, graphFilePath, project.getName());
                        } else {
                            GraphHandler.saveGraphToPajek(graph, graphFilePath);
                        }
                    } catch (BadLayoutException be) {
                        ErrorReporter.logExceptionStackTrace("Error while saving image to " + newPath, be);
                        errorHandler.reportErrorMessage("Bad layout\n\n" + be.getMessage());
                    } catch (Exception ce) {
                        ErrorReporter.logExceptionStackTrace("Error while saving image to " + newPath, ce);
                        errorHandler.reportException("Error while setting persistent property", ce);
                    }
                }
            });
        }
    };
    final JMenuItem mntmSave = new JMenuItem("Save (Ctrl+S)");
    mntmSave.addActionListener(saveGraph);
    mnFile.add(mntmSave);
    final ActionListener exportImage = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            String path = "";
            try {
                path = project.getPersistentProperty(new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path"));
            } catch (CoreException exc) {
                errorHandler.reportException("Error while reading persistent property", exc);
            }
            final String oldPath = path;
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    ExportImagePreferencesDialog prefDialog = new ExportImagePreferencesDialog(editorComposite.getShell());
                    ImageExportType mode = prefDialog.open();
                    FileDialog dialog = new FileDialog(editorComposite.getShell(), SWT.SAVE);
                    dialog.setText("Export image");
                    dialog.setFilterPath(oldPath);
                    dialog.setFilterExtensions(new String[] { "*.png" });
                    String graphFilePath = dialog.open();
                    if (graphFilePath == null) {
                        return;
                    }
                    String newPath = graphFilePath.substring(0, graphFilePath.lastIndexOf(File.separator) + 1);
                    try {
                        QualifiedName name = new QualifiedName(ProjectBuildPropertyData.QUALIFIER, "Graph_Save_Path");
                        project.setPersistentProperty(name, newPath);
                        handler.saveToImage(graphFilePath, mode);
                    } catch (BadLayoutException be) {
                        errorHandler.reportException("Error while saving image", be);
                        errorHandler.reportErrorMessage(be.getMessage());
                    } catch (CoreException ce) {
                        errorHandler.reportException("Error while setting persistent property", ce);
                    }
                }
            });
        }
    };
    final JMenuItem mntmExportToImage = new JMenuItem("Export to image file (Ctrl+E)");
    mntmExportToImage.addActionListener(exportImage);
    mnFile.add(mntmExportToImage);
    layoutMenu = new JMenu("Layout");
    layoutGroup = new ButtonGroup();
    layoutListener = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            final IProgressMonitor monitor = Job.getJobManager().createProgressGroup();
            monitor.beginTask("Change layout", 100);
            if (!(e.getSource() instanceof LayoutEntry)) {
                errorHandler.reportErrorMessage("Unexpected error\n\nAn unusual error has been logged" + LOGENTRYNOTE);
                ErrorReporter.logError("The layout changing event's source is not of type \"LayoutEntry\"!");
                return;
            }
            final LayoutEntry layout = (LayoutEntry) e.getSource();
            if (handler.getVisualizator() != null) {
                drawArea.remove(handler.getVisualizator());
            }
            try {
                handler.changeLayout(layout, windowSize);
                drawArea.add(handler.getVisualizator());
                if (satView != null) {
                    satView.add(handler.getSatelliteViewer());
                }
                window.pack();
            } catch (BadLayoutException exc) {
                layout.setSelected(false);
                chosenLayout.setSelected(true);
                if (exc.getType() == ErrorType.EMPTY_GRAPH || exc.getType() == ErrorType.NO_OBJECT) {
                    return;
                }
                try {
                    handler.changeLayout(chosenLayout, windowSize);
                    drawArea.add(handler.getVisualizator());
                    if (satView != null) {
                        satView.add(handler.getSatelliteViewer());
                    }
                    window.pack();
                    monitor.done();
                } catch (BadLayoutException exc2) {
                    monitor.done();
                    if (exc2.getType() != ErrorType.CYCLIC_GRAPH && exc2.getType() != ErrorType.EMPTY_GRAPH) {
                        errorHandler.reportException("Error while creating layout", exc2);
                    } else {
                        errorHandler.reportErrorMessage(exc2.getMessage());
                    }
                } catch (IllegalStateException exc3) {
                    monitor.done();
                    errorHandler.reportException("Error while creating layout", exc3);
                }
                if (exc.getType() != ErrorType.CYCLIC_GRAPH && exc.getType() != ErrorType.EMPTY_GRAPH) {
                    errorHandler.reportException("Error while creating layout", exc);
                } else {
                    errorHandler.reportErrorMessage(exc.getMessage());
                }
            } catch (IllegalStateException exc) {
                layout.setSelected(false);
                chosenLayout.setSelected(true);
                try {
                    handler.changeLayout(chosenLayout, windowSize);
                    drawArea.add(handler.getVisualizator());
                    if (satView != null) {
                        satView.add(handler.getSatelliteViewer());
                    }
                    window.pack();
                    monitor.done();
                } catch (BadLayoutException exc2) {
                    monitor.done();
                    if (exc2.getType() != ErrorType.CYCLIC_GRAPH && exc2.getType() != ErrorType.EMPTY_GRAPH) {
                        errorHandler.reportException("Error while creating layout", exc2);
                    } else {
                        errorHandler.reportErrorMessage(exc2.getMessage());
                    }
                } catch (IllegalStateException exc3) {
                    monitor.done();
                    errorHandler.reportException("Error while creating layout", exc3);
                }
                errorHandler.reportException("Error while creating layout", exc);
            }
            chosenLayout = layout.newInstance();
            monitor.done();
        }
    };
    final JMenu findMenu = new JMenu("Find");
    final JMenuItem nodeByName = new JMenuItem("Node by name (Ctrl+F)");
    final GraphEditor thisEditor = this;
    nodeByName.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (wndFind != null) {
                        wndFind.close();
                    }
                    try {
                        wndFind = new FindWindow<NodeDescriptor>(editorComposite.getShell(), thisEditor, graph.getVertices());
                        wndFind.open();
                    } catch (IllegalArgumentException e) {
                        errorHandler.reportException("", e);
                    }
                }
            });
        }
    });
    findMenu.add(nodeByName);
    final JMenu tools = new JMenu("Tools");
    final JMenuItem findCircles = new JMenuItem("Show circles");
    final JMenuItem findPaths = new JMenuItem("Show parallel paths");
    final JMenuItem clearResults = new JMenuItem("Clear Results");
    findCircles.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent ev) {
            final Job circlesJob = new Job("Searching for circles") {

                @Override
                protected IStatus run(final IProgressMonitor monitor) {
                    if (graph == null) {
                        return null;
                    }
                    CircleCheck<NodeDescriptor, EdgeDescriptor> checker = new CircleCheck<NodeDescriptor, EdgeDescriptor>(graph);
                    if (checker.isCyclic()) {
                        for (EdgeDescriptor e : graph.getEdges()) {
                            e.setColour(Color.lightGray);
                        }
                        for (Deque<EdgeDescriptor> st : checker.getCircles()) {
                            for (EdgeDescriptor e : st) {
                                e.setColour(NodeColours.DARK_RED);
                            }
                        }
                        refresh();
                    } else {
                        errorHandler.reportInformation("Result:\n\nThis graph is not cyclic!");
                    }
                    return Status.OK_STATUS;
                }
            };
            // end job
            circlesJob.schedule();
        }
    });
    findPaths.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent ev) {
            final Job pathsJob = new Job("Searching for parallel paths") {

                @Override
                protected IStatus run(final IProgressMonitor monitor) {
                    if (graph == null) {
                        return null;
                    }
                    CheckParallelPaths<NodeDescriptor, EdgeDescriptor> checker = null;
                    checker = new CheckParallelPaths<NodeDescriptor, EdgeDescriptor>(graph);
                    if (checker.hasParallelPaths()) {
                        for (EdgeDescriptor e : graph.getEdges()) {
                            e.setColour(Color.lightGray);
                        }
                        for (Deque<EdgeDescriptor> list : checker.getPaths()) {
                            for (EdgeDescriptor e : list) {
                                e.setColour(NodeColours.DARK_RED);
                            }
                        }
                        refresh();
                    } else {
                        errorHandler.reportInformation("Result:\n\nThere are no parallel paths in this graph!");
                    }
                    return Status.OK_STATUS;
                }
            };
            // end job
            pathsJob.schedule();
        }
    });
    clearResults.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent ev) {
            for (final EdgeDescriptor e : graph.getEdges()) {
                e.setColour(Color.black);
            }
            refresh();
        }
    });
    tools.add(findCircles);
    tools.add(findPaths);
    tools.add(clearResults);
    menuBar.add(mnFile);
    menuBar.add(findMenu);
    menuBar.add(tools);
    menuBar.add(layoutMenu);
    // TODO implement refresh action
    /*
		 * JMenuItem RefreshMenu=new JMenuItem("Refresh"); ActionListener
		 * RefreshAction=new ActionListener() { public void
		 * actionPerformed(ActionEvent ev) { GraphGenerator.schedule(); } };
		 * RefreshMenu.addActionListener(RefreshAction);
		 *
		 * menuBar.add(RefreshMenu);
		 */
    handlerService.activateHandler(GRAPH_SEARCHCMD_ID, new AbstractHandler() {

        @Override
        public Object execute(final ExecutionEvent event) throws ExecutionException {
            nodeByName.getActionListeners()[0].actionPerformed(null);
            handlers.add(this);
            return null;
        }
    });
    handlerService.activateHandler(GRAPH_SAVECMD_ID, new AbstractHandler() {

        @Override
        public Object execute(final ExecutionEvent event) throws ExecutionException {
            mntmSave.getActionListeners()[0].actionPerformed(null);
            handlers.add(this);
            return null;
        }
    });
    handlerService.activateHandler(GRAPH_EXPORTCMD_ID, new AbstractHandler() {

        @Override
        public Object execute(final ExecutionEvent event) throws ExecutionException {
            mntmExportToImage.getActionListeners()[0].actionPerformed(null);
            handlers.add(this);
            return null;
        }
    });
    try {
        generator.generateGraph();
        setLabeller(generator.getLabeler());
        setGraph(generator.getGraph());
    } catch (InterruptedException ex) {
        errorHandler.reportException("Error while creating the graph", ex);
    }
}
Also used : JPanel(javax.swing.JPanel) IStatus(org.eclipse.core.runtime.IStatus) BadLayoutException(org.eclipse.titanium.graph.visualization.BadLayoutException) ActionEvent(java.awt.event.ActionEvent) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) ImageExportType(org.eclipse.titanium.graph.visualization.GraphHandler.ImageExportType) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor) AbstractHandler(org.eclipse.core.commands.AbstractHandler) CheckParallelPaths(org.eclipse.titanium.graph.utils.CheckParallelPaths) LayoutEntry(org.eclipse.titanium.graph.gui.utils.LayoutEntry) CircleCheck(org.eclipse.titanium.graph.utils.CircleCheck) JMenuItem(javax.swing.JMenuItem) Job(org.eclipse.core.runtime.jobs.Job) ExecutionException(org.eclipse.core.commands.ExecutionException) QualifiedName(org.eclipse.core.runtime.QualifiedName) Dimension(java.awt.Dimension) Deque(java.util.Deque) CoreException(org.eclipse.core.runtime.CoreException) BadLayoutException(org.eclipse.titanium.graph.visualization.BadLayoutException) PartInitException(org.eclipse.ui.PartInitException) ExecutionException(org.eclipse.core.commands.ExecutionException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ActionListener(java.awt.event.ActionListener) CoreException(org.eclipse.core.runtime.CoreException) ButtonGroup(javax.swing.ButtonGroup) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ExportImagePreferencesDialog(org.eclipse.titanium.graph.gui.dialogs.ExportImagePreferencesDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 9 with EdgeDescriptor

use of org.eclipse.titanium.graph.components.EdgeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class AutomaticCluster method moveNode.

/**
 * Moves v from its original cluster to the one indexed by 'to'. It is much
 * faster than calculating the whole matrix again.
 *
 * @param v
 *            The node to be moved
 * @param to
 *            The index of the cluster
 */
private void moveNode(final NodeDescriptor v, final int to) {
    final int from = mapClusterIndex.get(v);
    if (from == to) {
        return;
    }
    if (size.get(to) == 0) {
        clusternum++;
    }
    if (size.get(from) == 1) {
        clusternum--;
    }
    for (final EdgeDescriptor e : moduleGraph.getInEdges(v)) {
        final NodeDescriptor u = moduleGraph.getSource(e);
        final int indexu = mapClusterIndex.get(u);
        changeCell(from, indexu, -1);
        changeCell(to, indexu, 1);
    }
    for (final EdgeDescriptor e : moduleGraph.getOutEdges(v)) {
        final NodeDescriptor w = moduleGraph.getDest(e);
        final int indexw = mapClusterIndex.get(w);
        changeCell(indexw, from, -1);
        changeCell(indexw, to, 1);
    }
    changeSize(from, -1);
    changeSize(to, 1);
    mapClusterIndex.put(v, to);
}
Also used : NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor)

Example 10 with EdgeDescriptor

use of org.eclipse.titanium.graph.components.EdgeDescriptor in project titan.EclipsePlug-ins by eclipse.

the class FullModuleNameCluster method createGraph.

@Override
public void createGraph() {
    mapNameNode = new HashMap<String, ClusterNode>();
    clusterGraph = new DirectedSparseGraph<NodeDescriptor, EdgeDescriptor>();
    stack = new LinkedList<String>();
    ClusterNode root = new ClusterNode(ALL, mapNameCluster.get(ALL));
    clusterGraph.addVertex(root);
    mapNameNode.put(ALL, root);
    traverseListOfNames();
}
Also used : ClusterNode(org.eclipse.titanium.graph.clustering.visualization.ClusterNode) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) EdgeDescriptor(org.eclipse.titanium.graph.components.EdgeDescriptor)

Aggregations

EdgeDescriptor (org.eclipse.titanium.graph.components.EdgeDescriptor)10 NodeDescriptor (org.eclipse.titanium.graph.components.NodeDescriptor)10 Dimension (java.awt.Dimension)4 HashMap (java.util.HashMap)3 DirectedSparseGraph (edu.uci.ics.jung.graph.DirectedSparseGraph)2 Point2D (java.awt.geom.Point2D)2 Set (java.util.Set)2 ClusterNode (org.eclipse.titanium.graph.clustering.visualization.ClusterNode)2 CustomVisualizationViewer (org.eclipse.titanium.graph.gui.common.CustomVisualizationViewer)2 Function (com.google.common.base.Function)1 CircleLayout (edu.uci.ics.jung.algorithms.layout.CircleLayout)1 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)1 KKLayout (edu.uci.ics.jung.algorithms.layout.KKLayout)1 SpringLayout (edu.uci.ics.jung.algorithms.layout.SpringLayout)1 StaticLayout (edu.uci.ics.jung.algorithms.layout.StaticLayout)1 VisualizationViewer (edu.uci.ics.jung.visualization.VisualizationViewer)1 Graphics2D (java.awt.Graphics2D)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 BufferedImage (java.awt.image.BufferedImage)1