-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccessorPaletteEntryProvider.java
60 lines (52 loc) · 2.81 KB
/
AccessorPaletteEntryProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package org.eclipse.triquetrum.ptolemy.capecode.palette;
import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.CLASS;
import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.DISPLAY_NAME;
import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.ICON;
import static org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement.TYPE;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.emf.common.util.URI;
import org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteConfigurationElement;
import org.eclipse.triquetrum.workflow.editor.palette.spi.PaletteEntryProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terraswarm.accessor.AccessorLibrary;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.Entity;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
public class AccessorPaletteEntryProvider implements PaletteEntryProvider {
private final static Logger LOGGER = LoggerFactory.getLogger(AccessorPaletteEntryProvider.class);
@Override
public IConfigurationElement[] getPaletteEntries() {
try {
AccessorLibrary accessorLibrary = buildAccessorLibrary();
List<IConfigurationElement> results = new ArrayList<>();
for (Entity<?> accessor : (List<Entity<?>>) accessorLibrary.entityList()) {
Map<String, String> attributes = new HashMap<>();
attributes.put(CLASS, accessor.getClass().getName());
attributes.put(DISPLAY_NAME, accessor.getDisplayName());
attributes.put(ICON, "icons/time_obj.gif");
attributes.put(TYPE, "Actor");
PaletteConfigurationElement pce = new PaletteConfigurationElement("entry", "org.eclipse.triquetrum.ptolemy.capecode.palette", attributes );
results.add(pce);
}
return results.toArray(new IConfigurationElement[0]);
} catch (IllegalActionException | NameDuplicationException | MalformedURLException e) {
LOGGER.error("Error obtaining palette entries for Acessors library", e);
return new IConfigurationElement[] {};
}
}
private AccessorLibrary buildAccessorLibrary() throws IllegalActionException, NameDuplicationException, MalformedURLException {
CompositeEntity ce = new CompositeEntity();
ce.setName("CapeCode configuration");
AccessorLibrary accessorLibrary = new AccessorLibrary(ce, "Accessors");
accessorLibrary.configure(null, URI.createPlatformPluginURI("org.eclipse.triquetrum.ptolemy.capecode.palette",true).toString() + "/src/main/resources", null);
accessorLibrary.populate();
return accessorLibrary;
}
}