Search in sources :

Example 1 with LayoutMetaDataService

use of org.eclipse.elk.core.data.LayoutMetaDataService in project elk by eclipse.

the class LayoutOptionLabelProvider method getText.

@Override
@SuppressWarnings("rawtypes")
public String getText(final Object element) {
    switch(optionData.getType()) {
        case STRING:
            if (CoreOptions.ALGORITHM.equals(optionData) || optionData.getId().equals(LayoutPropertyDescriptor.DISCO_LAYOUT_ALG_ID)) {
                LayoutMetaDataService layoutDataService = LayoutMetaDataService.getInstance();
                LayoutAlgorithmData algorithmData = layoutDataService.getAlgorithmData((String) element);
                if (algorithmData != null) {
                    String bundleName = algorithmData.getBundleName();
                    if (bundleName == null) {
                        return algorithmData.getName();
                    } else {
                        return algorithmData.getName() + " (" + bundleName + ")";
                    }
                }
                return Messages.getString("elk.ui.8");
            }
            break;
        case BOOLEAN:
            if (element instanceof Boolean) {
                return ((Boolean) element).toString();
            }
        // fall through so the same method as for enums is applied
        case ENUM:
            if (element instanceof Integer) {
                return optionData.getChoices()[(Integer) element];
            }
            break;
        case ENUMSET:
            if (element instanceof String) {
                return (String) element;
            } else if (element instanceof String[]) {
                String[] arr = (String[]) element;
                if (arr.length == 0) {
                    return "";
                } else {
                    StringBuilder builder = new StringBuilder();
                    for (String s : arr) {
                        builder.append(", ").append(s);
                    }
                    return builder.substring(2);
                }
            } else if (element instanceof EnumSet) {
                EnumSet set = (EnumSet) element;
                if (set.isEmpty()) {
                    return "";
                }
                StringBuilder builder = new StringBuilder();
                for (Object o : set) {
                    builder.append(", " + ((Enum) o).name());
                }
                return builder.substring(2);
            }
    }
    return element.toString();
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) EnumSet(java.util.EnumSet) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService)

Example 2 with LayoutMetaDataService

use of org.eclipse.elk.core.data.LayoutMetaDataService in project elk by eclipse.

the class LayoutPropertySource method getPropertyValue.

@Override
public Object getPropertyValue(final Object id) {
    LayoutMetaDataService layoutServices = LayoutMetaDataService.getInstance();
    LayoutOptionData optionData = layoutServices.getOptionData((String) id);
    if (optionData != null) {
        Object value = configManager.getOptionValue(optionData, layoutConfig);
        return translateToUI(value, optionData);
    }
    return null;
}
Also used : LayoutOptionData(org.eclipse.elk.core.data.LayoutOptionData) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService)

Example 3 with LayoutMetaDataService

use of org.eclipse.elk.core.data.LayoutMetaDataService in project elk by eclipse.

the class ElkServicePlugin method loadLayoutProvidersThroughJavaServices.

// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Service and Extension Point Loading
/**
 * Creates a new instance, loading the extension point information in the process.
 */
@SuppressWarnings("unchecked")
private void loadLayoutProvidersThroughJavaServices() {
    Set<Class<? extends ILayoutMetaDataProvider>> providerClasses = new HashSet<>();
    // Gather the classes of all ILayoutMetaDataProvider implementations
    for (Bundle bundle : getBundle().getBundleContext().getBundles()) {
        try {
            URL providerFile = bundle.getResource("/META-INF/services/" + ILayoutMetaDataProvider.class.getCanonicalName());
            if (providerFile != null) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(providerFile.openStream()));
                // Read the class names of all implementations that we can find
                String line = reader.readLine();
                while (line != null) {
                    providerClasses.add((Class<? extends ILayoutMetaDataProvider>) bundle.loadClass(line));
                    line = reader.readLine();
                }
            }
        } catch (Exception e) {
        }
    }
    // Try instantiating and registering all of those classes
    LayoutMetaDataService service = LayoutMetaDataService.getInstance();
    for (Class<? extends ILayoutMetaDataProvider> providerClass : providerClasses) {
        ILayoutMetaDataProvider provider;
        try {
            provider = providerClass.getConstructor().newInstance();
            service.registerLayoutMetaDataProviders(provider);
        } catch (Exception e) {
        }
    }
}
Also used : ILayoutMetaDataProvider(org.eclipse.elk.core.data.ILayoutMetaDataProvider) InputStreamReader(java.io.InputStreamReader) Bundle(org.osgi.framework.Bundle) BufferedReader(java.io.BufferedReader) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) HashSet(java.util.HashSet)

Example 4 with LayoutMetaDataService

use of org.eclipse.elk.core.data.LayoutMetaDataService in project elk by eclipse.

the class LayoutConfigurationManager method configureElement.

/**
 * Transfer option values from the given configuration store to a configurator using the given graph
 * element as key.
 */
protected void configureElement(final ElkGraphElement element, final ILayoutConfigurationStore configStore, final LayoutConfigurator configurator) {
    LayoutMetaDataService layoutDataService = LayoutMetaDataService.getInstance();
    for (String optionId : configStore.getAffectedOptions()) {
        Object value = configStore.getOptionValue(optionId);
        LayoutOptionData optionData = layoutDataService.getOptionData(optionId);
        if (optionData != null && value != null) {
            if (value instanceof String) {
                value = optionData.parseValue((String) value);
            }
            configurator.configure(element).setProperty(optionData, value);
        }
    }
}
Also used : LayoutOptionData(org.eclipse.elk.core.data.LayoutOptionData) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService)

Example 5 with LayoutMetaDataService

use of org.eclipse.elk.core.data.LayoutMetaDataService in project elk by eclipse.

the class ScanlineOverlapRemovalTest method scanlineTest.

/**
 * Test whether the {@link ScanlineOverlapCheck} supports the overlap removal to find all
 * overlaps in a special case.
 */
@Test
public void scanlineTest() {
    // build test graphs
    ElkNode graph1 = ElkGraphUtil.createGraph();
    ElkNode n0 = ElkGraphUtil.createNode(graph1);
    ElkNode n1 = ElkGraphUtil.createNode(graph1);
    ElkNode n2 = ElkGraphUtil.createNode(graph1);
    ElkNode n3 = ElkGraphUtil.createNode(graph1);
    n0.setDimensions(160, 20);
    n1.setDimensions(160, 20);
    n2.setDimensions(20, 20);
    n3.setDimensions(20, 20);
    n0.setLocation(0, 30);
    n1.setLocation(150, 40);
    n2.setLocation(150, 0);
    n3.setLocation(150, 70);
    graph1.setProperty(CoreOptions.ALGORITHM, SporeOverlapRemovalOptions.ALGORITHM_ID);
    Copier copier = new Copier();
    ElkNode graph2 = (ElkNode) copier.copy(graph1);
    graph2.setProperty(SporeOverlapRemovalOptions.OVERLAP_REMOVAL_RUN_SCANLINE, false);
    // execute overlap removal with and without ScanlineOverlapCheck
    LayoutMetaDataService lService = LayoutMetaDataService.getInstance();
    lService.registerLayoutMetaDataProviders(new SporeMetaDataProvider());
    RecursiveGraphLayoutEngine lEngine = new RecursiveGraphLayoutEngine();
    lEngine.layout(graph1, new BasicProgressMonitor());
    lEngine.layout(graph2, new BasicProgressMonitor());
    // test
    assertFalse(hasOverlaps(graph1));
    assertTrue(hasOverlaps(graph2));
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) SporeMetaDataProvider(org.eclipse.elk.alg.spore.options.SporeMetaDataProvider) Copier(org.eclipse.emf.ecore.util.EcoreUtil.Copier) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService) Test(org.junit.Test)

Aggregations

LayoutMetaDataService (org.eclipse.elk.core.data.LayoutMetaDataService)10 LayoutAlgorithmData (org.eclipse.elk.core.data.LayoutAlgorithmData)3 LayoutOptionData (org.eclipse.elk.core.data.LayoutOptionData)3 ElkNode (org.eclipse.elk.graph.ElkNode)3 RecursiveGraphLayoutEngine (org.eclipse.elk.core.RecursiveGraphLayoutEngine)2 BasicProgressMonitor (org.eclipse.elk.core.util.BasicProgressMonitor)2 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 LayeredOptions (org.eclipse.elk.alg.layered.options.LayeredOptions)1 SporeMetaDataProvider (org.eclipse.elk.alg.spore.options.SporeMetaDataProvider)1 Algorithm (org.eclipse.elk.alg.test.framework.annotations.Algorithm)1 AllAlgorithms (org.eclipse.elk.alg.test.framework.annotations.AllAlgorithms)1