Search in sources :

Example 11 with NodeDescriptor

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

the class ModuleNameCluster method createNames.

/**
 * Slice up the module names to guess the "package" name.
 */
private void createNames(final IProgressMonitor monitor) {
    addCluster(ALL);
    for (final NodeDescriptor v : moduleGraph.getVertices()) {
        final String name = v.getDisplayName();
        monitor.subTask("Checking " + name);
        boolean small = false;
        int i = 0;
        int splits = 0;
        final int length = name.length();
        char prev = '0';
        while (i < length && splits < depth) {
            final char c = name.charAt(i);
            if (checkDash(prev, c)) {
                addSubName(name, i);
                ++splits;
            }
            if (checkAlternatingCase) {
                if (small && Character.isUpperCase(c)) {
                    addSubName(name, i);
                    ++splits;
                }
                small = Character.isLowerCase(c);
            }
            prev = c;
            ++i;
        }
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        monitor.worked(1);
    }
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor)

Example 12 with NodeDescriptor

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

the class GraphEditor method elemChosen.

@Override
public void elemChosen(final NodeDescriptor element) {
    final CustomVisualizationViewer visualisator = handler.getVisualizator();
    visualisator.jumpToPlace(visualisator.getGraphLayout().apply(element));
    for (final NodeDescriptor node : graph.getVertices()) {
        node.setNodeColour(NodeColours.NOT_RESULT_COLOUR);
    }
    element.setNodeColour(NodeColours.RESULT_COLOUR);
}
Also used : CustomVisualizationViewer(org.eclipse.titanium.graph.gui.common.CustomVisualizationViewer) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor)

Example 13 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor 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 14 with NodeDescriptor

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

the class RegexpCluster method createMatchers.

/**
 * Creates the matcher objects.
 *
 * @return True if the regular expressions are correct.
 */
private boolean createMatchers() {
    matchers = new ArrayList<Matcher>();
    mapPatternCluster = new HashMap<String, Set<NodeDescriptor>>();
    final String stringList = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, PreferenceConstants.CLUSTER_REGEXP, "", null);
    final List<String> splittedList = ResourceExclusionHelper.intelligentSplit(stringList, '#', '\\');
    if (splittedList.isEmpty()) {
        setErronous("No regular expressions were defined.\n" + "Please visit the 'Clusters' Preference page to define them.");
        return false;
    }
    for (final String item : splittedList) {
        try {
            final Pattern pattern = Pattern.compile(item);
            final Set<NodeDescriptor> cluster = new HashSet<NodeDescriptor>();
            mapPatternCluster.put(pattern.toString(), cluster);
            final Matcher matcher = pattern.matcher("");
            matchers.add(matcher);
        } catch (PatternSyntaxException e) {
            final String errorString = "At least one of the regular expressions used is not correct.\n" + "Please visit the 'Clusters' Preference page to correct it.\n" + "Reason: " + e.getLocalizedMessage() + "\n" + "Incorrect pattern: " + item;
            ErrorReporter.logExceptionStackTrace(errorString, e);
            setErronous(errorString);
            return false;
        }
    }
    return true;
}
Also used : Pattern(java.util.regex.Pattern) Set(java.util.Set) HashSet(java.util.HashSet) Matcher(java.util.regex.Matcher) NodeDescriptor(org.eclipse.titanium.graph.components.NodeDescriptor) HashSet(java.util.HashSet) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 15 with NodeDescriptor

use of org.eclipse.titanium.graph.components.NodeDescriptor 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)

Aggregations

NodeDescriptor (org.eclipse.titanium.graph.components.NodeDescriptor)30 EdgeDescriptor (org.eclipse.titanium.graph.components.EdgeDescriptor)10 HashSet (java.util.HashSet)7 HashMap (java.util.HashMap)5 Set (java.util.Set)5 Dimension (java.awt.Dimension)4 CustomVisualizationViewer (org.eclipse.titanium.graph.gui.common.CustomVisualizationViewer)3 DirectedSparseGraph (edu.uci.ics.jung.graph.DirectedSparseGraph)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 Point2D (java.awt.geom.Point2D)2 Matcher (java.util.regex.Matcher)2 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 IResource (org.eclipse.core.resources.IResource)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 ClusterNode (org.eclipse.titanium.graph.clustering.visualization.ClusterNode)2 LayoutEntry (org.eclipse.titanium.graph.gui.utils.LayoutEntry)2 MetricsLayoutEntry (org.eclipse.titanium.graph.gui.utils.MetricsLayoutEntry)2 Function (com.google.common.base.Function)1