X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.browsing.ui.graph.impl%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fgraph%2Fimpl%2FGraphStringIndexModifier.java;h=cbde1d845232f4551e7f52f7c3d2bedc6cdcdb65;hb=b000e272429e157638c0384878b07b8dcd758472;hp=cb1fa176dc09d98f65f9e0fd71994042567d62bc;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GraphStringIndexModifier.java b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GraphStringIndexModifier.java index cb1fa176d..cbde1d845 100644 --- a/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GraphStringIndexModifier.java +++ b/bundles/org.simantics.browsing.ui.graph.impl/src/org/simantics/browsing/ui/graph/impl/GraphStringIndexModifier.java @@ -1,230 +1,226 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.browsing.ui.graph.impl; - -import java.util.concurrent.Semaphore; - -import org.simantics.browsing.ui.BuiltinKeys; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.content.Labeler.Modifier; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.Session; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.common.request.WriteRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.adapter.StringIndexModifier; -import org.simantics.db.layer0.adapter.StringModifier; -import org.simantics.db.layer0.adapter.TObjectIntPair; -import org.simantics.layer0.utils.representation.StringRepresentation2; -import org.simantics.utils.datastructures.Callback; -import org.simantics.utils.ui.ErrorLogger; - -/** - * Please implement: - *
- * Other points of customization: - *
- *non-null
, the modifier could not be fetched, e.g. adapted
- * from the specified INodeContext.
- */
- protected Throwable modifierFailed;
-
-
- /**
- * @param context
- * @param session
- */
- public GraphStringIndexModifier(NodeContext context, Session session, int index) throws DatabaseException {
- this.context = context;
- this.session = session;
- this.index = index;
-
- final Resource r = getResourceToModify();
- if (r == null)
- throw new IllegalArgumentException("This modifier does not work for INodeContexts that are not adaptable to a Resource. The context input is: " + context.getConstant(BuiltinKeys.INPUT));
-
- session.syncRequest(new ReadRequest() {
- @Override
- public void run(ReadGraph g) throws DatabaseException {
- initialValue = getInitialValue(g);
- GraphStringIndexModifier.this.modifier = g.adapt(r, StringIndexModifier.class);
- initializeGraphModifier(g);
- modifierReady.release();
- }
- });
-
- }
-
- /**
- * @param g
- * @return the value that shall be returned by {@link #getValue()}
- */
- protected String getInitialValue(ReadGraph g) throws DatabaseException {
- StringRepresentation2 sr = g.adapt(getResourceToModify(), StringRepresentation2.class);
- String s = sr.get(g, index);
- return s;
- }
-
- /**
- * Override to perform graph-based initialization actions for this modifier.
- *
- * @param g the graph handle
- */
- protected void initializeGraphModifier(ReadGraph g) {
- }
-
- /**
- * @return the Resource to modify based on the input INodeContext. This
- * resource must be adaptable to a {@link StringModifier} in order
- * for this modifier to work.
- */
- protected Resource getResourceToModify() {
- Resource r = (Resource) context.getAdapter(Resource.class);
- if (r == null)
- throw new AssertionError("context.getAdapter(Resource.class) returned null");
- return r;
- }
-
- /**
- * @return the modifier or null
if the StringModifier adaption
- * has not completed yet.
- */
- protected StringIndexModifier getModifier() {
- return modifier;
- }
-
- @Override
- public String getValue() {
- return initialValue;
- }
-
- @Override
- public String isValid(String label) {
- if (modifierFailed != null)
- return "Could not resolve validator for this value, modification denied. Reason: " + modifierFailed.getMessage();
- if (modifier == null)
- // Cannot validate yet, the validator has not been resolved.
- // For the time being, consider the value invalid for no
- // apparent reason to the user.
- return "";
- TObjectIntPair- * This default implementation will always allow the modification to proceed. - *
- * - * @param label the label to be given to the modifier - * @returntrue
to go forward with the transaction,
- * false
to bail out
- */
- protected boolean verifyModification(TObjectIntPair+ * Other points of customization: + *
+ *non-null
, the modifier could not be fetched, e.g. adapted
+ * from the specified INodeContext.
+ */
+ protected Throwable modifierFailed;
+
+
+ /**
+ * @param context
+ * @param session
+ */
+ public GraphStringIndexModifier(NodeContext context, Session session, int index) throws DatabaseException {
+ this.context = context;
+ this.session = session;
+ this.index = index;
+
+ final Resource r = getResourceToModify();
+ if (r == null)
+ throw new IllegalArgumentException("This modifier does not work for INodeContexts that are not adaptable to a Resource. The context input is: " + context.getConstant(BuiltinKeys.INPUT));
+
+ session.syncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph g) throws DatabaseException {
+ initialValue = getInitialValue(g);
+ GraphStringIndexModifier.this.modifier = g.adapt(r, StringIndexModifier.class);
+ initializeGraphModifier(g);
+ modifierReady.release();
+ }
+ });
+
+ }
+
+ /**
+ * @param g
+ * @return the value that shall be returned by {@link #getValue()}
+ */
+ protected String getInitialValue(ReadGraph g) throws DatabaseException {
+ StringRepresentation2 sr = g.adapt(getResourceToModify(), StringRepresentation2.class);
+ String s = sr.get(g, index);
+ return s;
+ }
+
+ /**
+ * Override to perform graph-based initialization actions for this modifier.
+ *
+ * @param g the graph handle
+ */
+ protected void initializeGraphModifier(ReadGraph g) {
+ }
+
+ /**
+ * @return the Resource to modify based on the input INodeContext. This
+ * resource must be adaptable to a {@link StringModifier} in order
+ * for this modifier to work.
+ */
+ protected Resource getResourceToModify() {
+ Resource r = (Resource) context.getAdapter(Resource.class);
+ if (r == null)
+ throw new AssertionError("context.getAdapter(Resource.class) returned null");
+ return r;
+ }
+
+ /**
+ * @return the modifier or null
if the StringModifier adaption
+ * has not completed yet.
+ */
+ protected StringIndexModifier getModifier() {
+ return modifier;
+ }
+
+ @Override
+ public String getValue() {
+ return initialValue;
+ }
+
+ @Override
+ public String isValid(String label) {
+ if (modifierFailed != null)
+ return "Could not resolve validator for this value, modification denied. Reason: " + modifierFailed.getMessage();
+ if (modifier == null)
+ // Cannot validate yet, the validator has not been resolved.
+ // For the time being, consider the value invalid for no
+ // apparent reason to the user.
+ return "";
+ TObjectIntPair+ * This default implementation will always allow the modification to proceed. + *
+ * + * @param label the label to be given to the modifier + * @returntrue
to go forward with the transaction,
+ * false
to bail out
+ */
+ protected boolean verifyModification(TObjectIntPair