]> gerrit.simantics Code Review - simantics/platform.git/blob
118d46f8e7c9edba9c88782b1730e0d5b9dbbe6e
[simantics/platform.git] /
1 package org.simantics.diagram.profile.view;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.Set;
7 import java.util.TreeSet;
8
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;
18
19 /**
20  * @author Tuukka Lehtonen
21  */
22 public class ProfileSelectionProcessor implements SelectionProcessor<Object, ReadGraph> {
23
24     @Override
25     public Collection<?> process(Object selection, ReadGraph g) {
26         try {
27             Resource object = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class);
28             ResourcePair object2 = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, ResourcePair.class);
29
30             return processInternal(g, object, object2, selection);
31                 
32         } catch (DatabaseException e) {
33             ErrorLogger.defaultLogError(e);
34         }
35
36         return Collections.emptyList();
37     }
38
39     private Collection<?> processInternal(ReadGraph g, Resource object, ResourcePair pair, Object selection) throws DatabaseException {
40
41         Collection<Object> inputs = new ArrayList<Object>();
42         
43         parseResourceInput(g, object, pair, inputs);
44
45         return accept(inputs);
46     }
47
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"));
57             }
58         }
59         return result;
60     }
61
62     private void parseResourceInput(ReadGraph g, Resource part, ResourcePair pair, Collection<Object> inputs) throws DatabaseException {
63         getGroups(g, part, pair, inputs);
64     }
65
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"));
70         }
71         if (r != null && g.isInstanceOf(r, dr.SCLTextStyle)) {
72             result.add(new SCLInput(r, 2, "SCL Text Style"));
73         }
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"));
78             }
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"));
82             }
83         }
84     }
85
86 }