class="org.simantics.browsing.ui.model.tests.FailTest"
constructor="get">
</type>
+ <type uri="http://www.simantics.org/Viewpoint-0.0/HasURITest"
+ class="org.simantics.browsing.ui.model.tests.HasURITest"
+ constructor="get">
+ </type>
+ <type uri="http://www.simantics.org/Viewpoint-0.0/InDevelopmentModeTest"
+ class="org.simantics.browsing.ui.model.tests.InDevelopmentModeTest"
+ constructor="get">
+ </type>
</target>
<target interface="org.simantics.browsing.ui.model.actions.IActionCategory">
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2017 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.model.tests;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.exception.InvalidVariableException;
+import org.simantics.db.layer0.variable.Variable;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.30.0
+ */
+public enum HasURITest implements Test {
+ INSTANCE;
+
+ public static HasURITest get() {
+ return INSTANCE;
+ }
+
+ @Override
+ public boolean isCompatible(Class<?> contentType) {
+ return contentType.equals(Resource.class) || contentType.equals(Variable.class);
+ }
+
+ @Override
+ public boolean test(ReadGraph graph, Object content) throws DatabaseException {
+ if (content instanceof Resource) {
+ return graph.getPossibleURI((Resource) content) != null;
+ } else if (content instanceof Variable) {
+ try {
+ Variable v = (Variable) content;
+ return v.getURI(graph) != null;
+ } catch (InvalidVariableException e) {
+ return false;
+ }
+ }
+ return false;
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2017 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.browsing.ui.model.tests;
+
+import org.eclipse.core.runtime.Platform;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.exception.DatabaseException;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.30.0
+ */
+public enum InDevelopmentModeTest implements Test {
+ INSTANCE;
+
+ public static InDevelopmentModeTest get() {
+ return INSTANCE;
+ }
+
+ @Override
+ public boolean isCompatible(Class<?> contentType) {
+ return true;
+ }
+
+ @Override
+ public boolean test(ReadGraph graph, Object content) throws DatabaseException {
+ return Platform.inDevelopmentMode();
+ }
+
+}
VP.ActionContribution.HasCategory VP.EditActionCategory
VP.ActionContribution.HasNodeType L0.Entity
VP.ActionContribution.HasAction ACTIONS.Help
-
+
+MOD.Contributions.CopyURI : VP.ActionContribution
+ L0.HasLabel "Copy URI"
+ VP.ActionContribution.HasImage SILK.clipboard
+ VP.ActionContribution.HasCategory VP.EditActionCategory
+ VP.ActionContribution.HasNodeType L0.Entity
+ VP.ActionContribution.HasNodeType MBC.Variable
+ VP.ActionContribution.HasAction ACTIONS.CopyURI
+ VP.ActionContribution.IsVisibleIf _ : VP.AndTest
+ VP.AndTest.HasTest
+ _ : VP.InDevelopmentModeTest
+ _ : VP.HasURITest
+
// Actions
MAC
VP.BrowseContext.HasActionContribution MOD.Contributions.Help
+ VP.BrowseContext.HasActionContribution MOD.Contributions.CopyURI
VP.BrowseContext.HasActionContribution _ : VP.ActionContribution
L0.HasLabel "Migrate"
VP.ActionContribution.HasImage SILK.star
//ACTIONS.MigrateMasterTypical : ACT.Action
ACTIONS.RenameDiagramComponents : ACT.Action
ACTIONS.Help : ACT.Action
+ACTIONS.CopyURI : ACT.Action
ACTIONS.NavigateToSubstructure
@MOD.sclAction "navigateToSubstructureAction"
</type>
<resource uri="http://www.simantics.org/Modeling-0.0/ModelingActionContext/Actions/Help"
class="org.simantics.modeling.actions.Help" />
+ <resource uri="http://www.simantics.org/Modeling-0.0/ModelingActionContext/Actions/CopyURI"
+ class="org.simantics.modeling.actions.CopyURI" />
</target>
<target interface="org.simantics.db.layer0.adapter.DropActionFactory">
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2017 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:
+ * Semantum Oy - initial API and implementation
+ *******************************************************************************/
+package org.simantics.modeling.actions;
+
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.TextTransfer;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Display;
+import org.simantics.Simantics;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.adapter.ActionFactory;
+import org.simantics.db.layer0.request.PossibleURI;
+import org.simantics.db.layer0.request.VariableURI;
+import org.simantics.db.layer0.variable.Variable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Jani Simomaa
+ * @since 1.30.0
+ */
+public class CopyURI implements ActionFactory {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CopyURI.class);
+
+ @Override
+ public Runnable create(Object target) {
+ return () -> {
+ try {
+ String uri = getPossibleURI(target);
+ if (uri != null) {
+ Clipboard cb = new Clipboard(Display.getCurrent());
+ cb.setContents(new Object[] { uri }, new Transfer[] { TextTransfer.getInstance() });
+ }
+ } catch (Exception e) {
+ LOGGER.error("Could not get URI for input {} to copy to clipboard", target, e);
+ }
+ };
+ }
+
+ private String getPossibleURI(Object input) throws DatabaseException {
+ if (input instanceof Resource) {
+ return Simantics.getSession().syncRequest(new PossibleURI((Resource) input));
+ } else if (input instanceof Variable) {
+ return Simantics.getSession().syncRequest(new VariableURI((Variable) input));
+ }
+ return null;
+ }
+
+}
VP.FailTest <T VP.Test
L0.HasDescription "A test that is compatible with all content types and always fails, i.e. returns false."
+
+VP.HasURITest <T VP.Test
+ L0.HasDescription "A test that checks the Resource or Variable given as input has a proper URI."
+
+VP.InDevelopmentModeTest <T VP.Test
+ L0.HasDescription "A test that directly invokes org.eclipse.runtime.core.Platform.inDevelopmentMode()."