1 package org.simantics.diagram.profile.view;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
7 import java.util.TreeSet;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.SelectionHints;
13 import org.simantics.diagram.stubs.DiagramResource;
14 import org.simantics.selectionview.ComparableTabContributor;
15 import org.simantics.selectionview.SelectionProcessor;
16 import org.simantics.utils.ui.ErrorLogger;
17 import org.simantics.utils.ui.ISelectionUtils;
20 * @author Tuukka Lehtonen
22 public class ProfileSelectionProcessor implements SelectionProcessor<Object, ReadGraph> {
25 public Collection<?> process(Object selection, ReadGraph g) {
27 Resource object = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class);
28 ResourcePair object2 = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, ResourcePair.class);
30 return processInternal(g, object, object2, selection);
32 } catch (DatabaseException e) {
33 ErrorLogger.defaultLogError(e);
36 return Collections.emptyList();
39 private Collection<?> processInternal(ReadGraph g, Resource object, ResourcePair pair, Object selection) throws DatabaseException {
41 Collection<Object> inputs = new ArrayList<Object>();
43 parseResourceInput(g, object, pair, inputs);
45 return accept(inputs);
48 Collection<ComparableTabContributor> accept(Collection<?> inputs) {
49 Set<ComparableTabContributor> result = new TreeSet<ComparableTabContributor>();
50 // System.out.println("accept:");
51 for (Object input : inputs) {
52 // System.out.println("\tINPUT: " + input);
53 if (input instanceof SCLInput) {
54 SCLInput configurationInput = (SCLInput)input;
55 result.add(new ComparableTabContributor(new SCLEditorComposite(), configurationInput.priority, configurationInput.getDatum(), configurationInput.text));
56 // result.add(new ComparableTabContributor(new ResourceDescriptionSourceComposite(), -4, configurationInput.getDatum(), "Source"));
62 private void parseResourceInput(ReadGraph g, Resource part, ResourcePair pair, Collection<Object> inputs) throws DatabaseException {
63 getGroups(g, part, pair, inputs);
66 void getGroups(ReadGraph g, Resource r, ResourcePair p, Collection<Object> result) throws DatabaseException {
67 DiagramResource dr = DiagramResource.getInstance(g);
68 if (r != null && g.isInstanceOf(r, dr.SCLGroup)) {
69 result.add(new SCLInput(r, 1, "SCL Group"));
71 if (r != null && g.isInstanceOf(r, dr.SCLTextStyle)) {
72 result.add(new SCLInput(r, 2, "SCL Text Style"));
74 if (p != null && g.isInstanceOf(p.getSecond(), dr.GroupStyleProfileEntry)) {
75 Resource group = g.getPossibleObject(p.getSecond(), dr.ProfileEntry_HasGroup);
76 if (group != null && g.isInstanceOf(group, dr.SCLGroup)) {
77 result.add(new SCLInput(group, 1, "SCL Group"));
79 Resource style = g.getPossibleObject(p.getSecond(), dr.ProfileEntry_HasStyle);
80 if (style != null && g.isInstanceOf(style, dr.SCLTextStyle)) {
81 result.add(new SCLInput(style, 2, "SCL Text Style"));