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();
}
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;
}
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) {
}
}
}
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);
}
}
}
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));
}
Aggregations