X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram.profile%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fprofile%2Fview%2FProfileSelectionProcessor.java;h=c060f067ae22cd02ffd19becde47358d63cb8a19;hb=08dc7080753f3ea35985e76e9effb9d3ff92c3b5;hp=36c93aa5e7c46a4933c90ee85cac5b4910e45462;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileSelectionProcessor.java b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileSelectionProcessor.java index 36c93aa5e..c060f067a 100644 --- a/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileSelectionProcessor.java +++ b/bundles/org.simantics.diagram.profile/src/org/simantics/diagram/profile/view/ProfileSelectionProcessor.java @@ -1,86 +1,86 @@ -package org.simantics.diagram.profile.view; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; -import java.util.TreeSet; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.SelectionHints; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.selectionview.ComparableTabContributor; -import org.simantics.selectionview.SelectionProcessor; -import org.simantics.utils.ui.ErrorLogger; -import org.simantics.utils.ui.ISelectionUtils; - -/** - * @author Tuukka Lehtonen - */ -public class ProfileSelectionProcessor implements SelectionProcessor { - - @Override - public Collection process(Object selection, ReadGraph g) { - try { - Resource object = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class); - ResourcePair object2 = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, ResourcePair.class); - - return processInternal(g, object, object2, selection); - - } catch (DatabaseException e) { - ErrorLogger.defaultLogError(e); - } - - return Collections.emptyList(); - } - - private Collection processInternal(ReadGraph g, Resource object, ResourcePair pair, Object selection) throws DatabaseException { - - Collection inputs = new ArrayList(); - - parseResourceInput(g, object, pair, inputs); - - return accept(inputs); - } - - Collection accept(Collection inputs) { - Set result = new TreeSet(); -// System.out.println("accept:"); - for (Object input : inputs) { -// System.out.println("\tINPUT: " + input); - if (input instanceof SCLInput) { - SCLInput configurationInput = (SCLInput)input; - result.add(new ComparableTabContributor(new SCLEditorComposite(), configurationInput.priority, configurationInput.getDatum(), configurationInput.text)); -// result.add(new ComparableTabContributor(new ResourceDescriptionSourceComposite(), -4, configurationInput.getDatum(), "Source")); - } - } - return result; - } - - private void parseResourceInput(ReadGraph g, Resource part, ResourcePair pair, Collection inputs) throws DatabaseException { - getGroups(g, part, pair, inputs); - } - - void getGroups(ReadGraph g, Resource r, ResourcePair p, Collection result) throws DatabaseException { - DiagramResource dr = DiagramResource.getInstance(g); - if (r != null && g.isInstanceOf(r, dr.SCLGroup)) { - result.add(new SCLInput(r, 1, "SCL Group")); - } - if (r != null && g.isInstanceOf(r, dr.SCLTextStyle)) { - result.add(new SCLInput(r, 2, "SCL Text Style")); - } - if (p != null && g.isInstanceOf(p.getSecond(), dr.GroupStyleProfileEntry)) { - Resource group = g.getPossibleObject(p.getSecond(), dr.ProfileEntry_HasGroup); - if (group != null && g.isInstanceOf(group, dr.SCLGroup)) { - result.add(new SCLInput(group, 1, "SCL Group")); - } - Resource style = g.getPossibleObject(p.getSecond(), dr.ProfileEntry_HasStyle); - if (style != null && g.isInstanceOf(style, dr.SCLTextStyle)) { - result.add(new SCLInput(style, 2, "SCL Text Style")); - } - } - } - +package org.simantics.diagram.profile.view; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Set; +import java.util.TreeSet; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.SelectionHints; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.selectionview.ComparableTabContributor; +import org.simantics.selectionview.SelectionProcessor; +import org.simantics.utils.ui.ErrorLogger; +import org.simantics.utils.ui.ISelectionUtils; + +/** + * @author Tuukka Lehtonen + */ +public class ProfileSelectionProcessor implements SelectionProcessor { + + @Override + public Collection process(Object selection, ReadGraph g) { + try { + Resource object = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, Resource.class); + ProfileTuple object2 = ISelectionUtils.getSinglePossibleKey(selection, SelectionHints.KEY_MAIN, ProfileTuple.class); + + return processInternal(g, object, object2, selection); + + } catch (DatabaseException e) { + ErrorLogger.defaultLogError(e); + } + + return Collections.emptyList(); + } + + private Collection processInternal(ReadGraph g, Resource object, ProfileTuple pair, Object selection) throws DatabaseException { + + Collection inputs = new ArrayList(); + + parseResourceInput(g, object, pair, inputs); + + return accept(inputs); + } + + Collection accept(Collection inputs) { + Set result = new TreeSet(); +// System.out.println("accept:"); + for (Object input : inputs) { +// System.out.println("\tINPUT: " + input); + if (input instanceof SCLInput) { + SCLInput configurationInput = (SCLInput)input; + result.add(new ComparableTabContributor(new SCLEditorComposite(), configurationInput.priority, configurationInput.getDatum(), configurationInput.text)); +// result.add(new ComparableTabContributor(new ResourceDescriptionSourceComposite(), -4, configurationInput.getDatum(), "Source")); + } + } + return result; + } + + private void parseResourceInput(ReadGraph g, Resource part, ProfileTuple pair, Collection inputs) throws DatabaseException { + getGroups(g, part, pair, inputs); + } + + void getGroups(ReadGraph g, Resource r, ProfileTuple p, Collection result) throws DatabaseException { + DiagramResource dr = DiagramResource.getInstance(g); + if (r != null && g.isInstanceOf(r, dr.SCLGroup)) { + result.add(new SCLInput(r, 1, "SCL Group")); + } + if (r != null && g.isInstanceOf(r, dr.SCLTextStyle)) { + result.add(new SCLInput(r, 2, "SCL Text Style")); + } + if (p != null && g.isInstanceOf(p.getEntry(), dr.GroupStyleProfileEntry)) { + Resource group = g.getPossibleObject(p.getEntry(), dr.ProfileEntry_HasGroup); + if (group != null && g.isInstanceOf(group, dr.SCLGroup)) { + result.add(new SCLInput(group, 1, "SCL Group")); + } + Resource style = g.getPossibleObject(p.getEntry(), dr.ProfileEntry_HasStyle); + if (style != null && g.isInstanceOf(style, dr.SCLTextStyle)) { + result.add(new SCLInput(style, 2, "SCL Text Style")); + } + } + } + } \ No newline at end of file